-
Notifications
You must be signed in to change notification settings - Fork 31
/
CategoryImportCommand.php
116 lines (97 loc) · 2.98 KB
/
CategoryImportCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
/**
* @package Divante\PimcoreIntegration
* @author Mateusz Bukowski <mbukowski@divante.pl>
* @copyright 2018 Divante Sp. z o.o.
* @license See LICENSE_DIVANTE.txt for license details.
*/
namespace Divante\PimcoreIntegration\Console\Command;
use Divante\PimcoreIntegration\Queue\Processor\CategoryQueueProcessorFactory;
use Magento\Framework\App\Area;
use Magento\Framework\App\State;
use Magento\Framework\Registry;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Class CategoryImportCommand
*/
class CategoryImportCommand extends Command
{
/**
* @var CategoryQueueProcessorFactory
*/
private $categoryQueueProcessorFactory;
/**
* @var State
*/
private $state;
/**
* @var Registry
*/
private $registry;
/**
* CategoryImport constructor.
*
* @param CategoryQueueProcessorFactory $categoryQueueProcessorFactory
* @param State $state
* @param Registry $registry
* @param null $name
*/
public function __construct(
CategoryQueueProcessorFactory $categoryQueueProcessorFactory,
State $state,
Registry $registry,
$name = null
) {
parent::__construct($name);
$this->categoryQueueProcessorFactory = $categoryQueueProcessorFactory;
$this->state = $state;
$this->registry = $registry;
}
/**
* Configures the current command.a
*
* @return void
*/
public function configure()
{
$this->setName('divante:queue-category:process');
$this->setDescription('Process category import queue from Pimcore');
}
/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|null
*
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
try {
$this->state->setAreaCode(Area::AREA_ADMINHTML);
} catch (\Exception $ex) {
// fail gracefully
}
$this->registry->register('isSecureArea', true);
$start = $this->getCurrentMs();
$output->writeln('<info>Initialization processing of categories queue.</info>');
$output->writeln(sprintf('<info>Started at %s</info>', (new \DateTime())->format('Y-m-d H:i:s')));
$output->writeln('Processing...');
$categoryQueueProcessor = $this->categoryQueueProcessorFactory->create();
$categoryQueueProcessor->process();
$end = $this->getCurrentMs();
$output->writeln(sprintf('<info>Finished at %s</info>', (new \DateTime())->format('Y-m-d H:i:s')));
$output->writeln(sprintf('<info>Total execution time %sms</info>', $end - $start));
return 0;
}
/**
*
* @return float|int
*/
private function getCurrentMs()
{
$mt = explode(' ', microtime());
return ((int) $mt[1]) * 1000 + ((int) round($mt[0] * 1000));
}
}