2
2
3
3
namespace Jh \Import \Command ;
4
4
5
+ use Jh \Import \Config as ImportConfig ;
5
6
use Jh \Import \Config \Data ;
6
7
use Jh \Import \Locker \Locker ;
7
8
use Magento \Cron \Model \Config ;
9
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
8
10
use Magento \Framework \Console \Cli ;
9
11
use Symfony \Component \Console \Command \Command ;
10
12
use Symfony \Component \Console \Helper \Table ;
@@ -31,12 +33,18 @@ class ListImportsCommand extends Command
31
33
*/
32
34
private $ locker ;
33
35
34
- public function __construct (Data $ importConfig , Config $ cronConfig , Locker $ locker )
36
+ /**
37
+ * @var ScopeConfigInterface
38
+ */
39
+ private $ scopeConfig ;
40
+
41
+ public function __construct (Data $ importConfig , Config $ cronConfig , Locker $ locker , ScopeConfigInterface $ scopeConfig )
35
42
{
43
+ parent ::__construct ();
36
44
$ this ->importConfig = $ importConfig ;
37
45
$ this ->cronConfig = $ cronConfig ;
38
46
$ this ->locker = $ locker ;
39
- parent :: __construct () ;
47
+ $ this -> scopeConfig = $ scopeConfig ;
40
48
}
41
49
42
50
protected function configure ()
@@ -60,19 +68,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
60
68
->setHeaders (['Name ' , 'Type ' , 'Match Files ' , 'Incoming Directory ' , 'Cron Expr ' , 'Locked? ' ])
61
69
->setRows (array_map (function ($ import ) use ($ jobs ) {
62
70
$ config = $ this ->importConfig ->getImportConfigByName ($ import );
63
-
64
- if ($ config ->hasCron () && isset ($ jobs [$ config ->getCronGroup ()][$ config ->getCron ()])) {
65
- $ cron = $ jobs [$ config ->getCronGroup ()][$ config ->getCron ()]['schedule ' ];
66
- } else {
67
- $ cron = 'N/A ' ;
68
- }
71
+ $ schedule = $ this ->resolveSchedule ($ jobs , $ config );
69
72
70
73
return [
71
74
$ config ->getImportName (),
72
75
$ config ->getType (),
73
76
$ config ->get ('match_files ' ),
74
77
$ config ->get ('incoming_directory ' ),
75
- $ cron ,
78
+ $ schedule ,
76
79
$ this ->locker ->locked ($ import ) ? '<error>Yes</error> ' : 'No '
77
80
];
78
81
}, $ this ->importConfig ->getAllImportNames ()))
@@ -82,4 +85,25 @@ protected function execute(InputInterface $input, OutputInterface $output)
82
85
83
86
return Cli::RETURN_SUCCESS ;
84
87
}
88
+
89
+ private function resolveSchedule (array $ jobs , ImportConfig $ importConfig ): string
90
+ {
91
+ $ unknownSchedule = 'N/A ' ;
92
+
93
+ if (!$ importConfig ->hasCron () || !isset ($ jobs [$ importConfig ->getCronGroup ()][$ importConfig ->getCron ()])) {
94
+ return $ unknownSchedule ;
95
+ }
96
+
97
+ $ cronConfiguration = $ jobs [$ importConfig ->getCronGroup ()][$ importConfig ->getCron ()];
98
+
99
+ if (isset ($ cronConfiguration ['schedule ' ])) {
100
+ return $ cronConfiguration ['schedule ' ];
101
+ }
102
+
103
+ if (isset ($ cronConfiguration ['config_path ' ])) {
104
+ return (string ) $ this ->scopeConfig ->getValue ($ cronConfiguration ['config_path ' ]);
105
+ }
106
+
107
+ return $ unknownSchedule ;
108
+ }
85
109
}
0 commit comments