From fd1e2f2e403dbc817de1d272de6e2a9b46090569 Mon Sep 17 00:00:00 2001 From: Maikel Koek Date: Tue, 15 Aug 2023 12:02:18 +0200 Subject: [PATCH 1/2] refactor(TEN-661): prettier on abstract class import profile --- src/Model/ImportProfile.php | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/Model/ImportProfile.php b/src/Model/ImportProfile.php index 3f77a8a..3a5bc4f 100644 --- a/src/Model/ImportProfile.php +++ b/src/Model/ImportProfile.php @@ -65,7 +65,6 @@ public function __construct( $this->log = $log; } - /** * Run the actual import * @@ -85,12 +84,11 @@ public function run() $errors = $importer->processImport($items); $stopwatchEvent = $this->stopwatch->stop('importinstance'); - $output = (string) new Phrase( - '%1 items imported in %2 sec, %3 items / sec (%4mb used)', [ + $output = (string) new Phrase('%1 items imported in %2 sec, %3 items / sec (%4mb used)', [ count($items), round($stopwatchEvent->getDuration() / 1000, 1), round(count($items) / ($stopwatchEvent->getDuration() / 1000), 1), - round($stopwatchEvent->getMemory() / 1024 / 1024, 1) + round($stopwatchEvent->getMemory() / 1024 / 1024, 1), ]); $this->consoleOutput->writeln($output); @@ -135,17 +133,16 @@ private function getItemsMeasured() $items = $this->getItems(); $stopwatchEvent = $this->stopwatch->stop('profileinstance'); - if (! $stopwatchEvent->getDuration()) { + if (!$stopwatchEvent->getDuration()) { return $items; } - $output = (string) new Phrase('%1 items processed in %2 sec, %3 items / sec (%4mb used)', - [ - count($items), - round($stopwatchEvent->getDuration() / 1000, 1), - round(count($items) / ($stopwatchEvent->getDuration() / 1000), 1), - round($stopwatchEvent->getMemory() / 1024 / 1024, 1) - ]); + $output = (string) new Phrase('%1 items processed in %2 sec, %3 items / sec (%4mb used)', [ + count($items), + round($stopwatchEvent->getDuration() / 1000, 1), + round(count($items) / ($stopwatchEvent->getDuration() / 1000), 1), + round($stopwatchEvent->getMemory() / 1024 / 1024, 1), + ]); $this->consoleOutput->writeln($output); $this->log->info($output); @@ -153,7 +150,6 @@ private function getItemsMeasured() return $items; } - /** * Gets initialized object manager * - Loads the Admin space from the CLI @@ -170,7 +166,6 @@ private function getObjectManager() $omParams[\Magento\Store\Model\Store::CUSTOM_ENTRY_POINT_PARAM] = true; $this->objectManager = $this->objectManagerFactory->create($omParams); - $area = \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE; /** @var \Magento\Framework\App\State $appState */ $appState = $this->objectManager->get(\Magento\Framework\App\State::class); From 9c88df43526275098e6997716f1b651da44774aa Mon Sep 17 00:00:00 2001 From: Maikel Koek Date: Tue, 15 Aug 2023 12:16:47 +0200 Subject: [PATCH 2/2] feat(TEN-661): store errors in import profile class --- src/Api/ImportProfileInterface.php | 7 +++++-- src/Model/ImportProfile.php | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Api/ImportProfileInterface.php b/src/Api/ImportProfileInterface.php index 72f4652..4cf5bbe 100644 --- a/src/Api/ImportProfileInterface.php +++ b/src/Api/ImportProfileInterface.php @@ -15,7 +15,6 @@ interface ImportProfileInterface */ public function getItems(); - /** * Array of the config values * @@ -23,7 +22,6 @@ public function getItems(); */ public function getConfig(); - /** * Run the import * @@ -35,4 +33,9 @@ public function run(); * @return \Exception */ public function getException(); + + /** + * @return string + */ + public function getErrors(); } diff --git a/src/Model/ImportProfile.php b/src/Model/ImportProfile.php index 3a5bc4f..67e5159 100644 --- a/src/Model/ImportProfile.php +++ b/src/Model/ImportProfile.php @@ -47,6 +47,11 @@ abstract class ImportProfile implements ImportProfileInterface */ private $exception; + /** + * @var ?string + */ + private $errors = null; + /** * @param ObjectManagerFactory $objectManagerFactory * @param Stopwatch $stopwatch @@ -97,6 +102,8 @@ public function run() $this->consoleOutput->writeln("$errors"); $this->log->error($errors); + $this->errors = $errors; + return \Magento\Framework\Console\Cli::RETURN_SUCCESS; } catch (\Exception $e) { $this->consoleOutput->writeln($e->getMessage()); @@ -120,6 +127,14 @@ public function getException(): \Exception return $this->exception; } + /** + * @return string + */ + public function getErrors() + { + return $this->errors; + } + /** * Get all items that need to be imported *