Skip to content

Commit

Permalink
Merge pull request #40 from ho-nl/TEN-661
Browse files Browse the repository at this point in the history
Ten 661
  • Loading branch information
Maikel-Koek authored Aug 15, 2023
2 parents 54e210e + 9c88df4 commit 4a6e731
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
7 changes: 5 additions & 2 deletions src/Api/ImportProfileInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ interface ImportProfileInterface
*/
public function getItems();


/**
* Array of the config values
*
* @return \[]
*/
public function getConfig();


/**
* Run the import
*
Expand All @@ -35,4 +33,9 @@ public function run();
* @return \Exception
*/
public function getException();

/**
* @return string
*/
public function getErrors();
}
38 changes: 24 additions & 14 deletions src/Model/ImportProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ abstract class ImportProfile implements ImportProfileInterface
*/
private $exception;

/**
* @var ?string
*/
private $errors = null;

/**
* @param ObjectManagerFactory $objectManagerFactory
* @param Stopwatch $stopwatch
Expand All @@ -65,7 +70,6 @@ public function __construct(
$this->log = $log;
}


/**
* Run the actual import
*
Expand All @@ -85,12 +89,11 @@ public function run()
$errors = $importer->processImport($items);
$stopwatchEvent = $this->stopwatch->stop('importinstance');

$output = (string) new Phrase(
'%1 items imported in %2 sec, <info>%3 items / sec</info> (%4mb used)', [
$output = (string) new Phrase('%1 items imported in %2 sec, <info>%3 items / sec</info> (%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);
Expand All @@ -99,6 +102,8 @@ public function run()
$this->consoleOutput->writeln("<error>$errors</error>");
$this->log->error($errors);

$this->errors = $errors;

return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
} catch (\Exception $e) {
$this->consoleOutput->writeln($e->getMessage());
Expand All @@ -122,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
*
Expand All @@ -135,25 +148,23 @@ 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, <info>%3 items / sec</info> (%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, <info>%3 items / sec</info> (%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);

return $items;
}


/**
* Gets initialized object manager
* - Loads the Admin space from the CLI
Expand All @@ -170,7 +181,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);
Expand Down

0 comments on commit 4a6e731

Please sign in to comment.