Total Complexity | 5 |
Total Lines | 63 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
17 | class ImportTask extends BuildTask |
||
18 | { |
||
19 | use Yieldable; |
||
20 | |||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | private static $segment = 'SalsifyImportTask'; |
||
|
|||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $title = 'Import products from salsify'; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $description = 'Imports products from salsify into silverstripe'; |
||
35 | |||
36 | /** |
||
37 | * @var bool |
||
38 | */ |
||
39 | protected $enabled = true; |
||
40 | |||
41 | /** |
||
42 | * @var |
||
43 | */ |
||
44 | private static $lineEnding; |
||
45 | |||
46 | /** |
||
47 | * @var bool |
||
48 | */ |
||
49 | private static $output = true; |
||
50 | |||
51 | /** |
||
52 | * @param \SilverStripe\Control\HTTPRequest $request |
||
53 | */ |
||
54 | public function run($request) |
||
55 | { |
||
56 | static::$lineEnding = Director::is_cli() ? PHP_EOL : '<br />'; |
||
57 | |||
58 | // gets all importers |
||
59 | $injectorConfig = array_keys(Config::inst()->get(Injector::class)); |
||
60 | $importers = array_filter( |
||
61 | $injectorConfig, |
||
62 | function ($element) { |
||
63 | return strncmp($element, Importer::class, strlen(Importer::class)) === 0; |
||
64 | } |
||
65 | ); |
||
66 | |||
67 | foreach ($this->yieldSingle($importers) as $importerClass) { |
||
68 | $importer = Injector::inst()->create($importerClass); |
||
69 | $importer->run(); |
||
70 | } |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @param $string |
||
75 | */ |
||
76 | public static function output($string) |
||
80 | } |
||
81 | } |
||
83 |