serviceFactory = $serviceFactory; } public function run(array $options, array $flagList) { $id = $options['id'] ?? null; $filePath = $options['file'] ?? null; $paramsId = $options['paramsId'] ?? null; $service = $this->serviceFactory->create('Import'); $forceResume = in_array('resume', $flagList); $revert = in_array('revert', $flagList); if (!$id && $filePath) { if (!$paramsId) { $this->out("You need to specify --params-id option.\n"); return; } if (!file_exists($filePath)) { $this->out("File not found.\n"); return; } $contents = file_get_contents($filePath); try { $result = $service->importFileWithParamsId($contents, $paramsId); $resultId = $result->id; $countCreated = $result->countCreated; $countUpdated = $result->countUpdated; } catch (Throwable $e) { $this->out("Error occured: ".$e->getMessage()."\n"); return; } $this->out("Finished. Import ID: {$resultId}. Created: {$countCreated}. Updated: {$countUpdated}.\n"); return; } if ($id && $revert) { $this->out("Reverting import...\n"); try { $service->revert($id); } catch (Throwable $e) { $this->out("Error occured: " . $e->getMessage() . "\n"); return; } $this->out("Finished.\n"); return; } if ($id) { $this->out("Running import, this may take a while...\n"); try { $result = $service->importById($id, true, $forceResume); } catch (Throwable $e) { $this->out("Error occured: " . $e->getMessage() . "\n"); return; } $countCreated = $result->countCreated; $countUpdated = $result->countUpdated; $this->out("Finished. Created: {$countCreated}. Updated: {$countUpdated}.\n"); return; } $this->out("Not enough params passed.\n"); return; } protected function out($string) { fwrite(\STDOUT, $string); } }