forked from WeareJH/m2-module-import
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RunImportCommand.php
55 lines (47 loc) · 1.41 KB
/
RunImportCommand.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
<?php
namespace Jh\Import\Command;
use Magento\Framework\App\State;
use Magento\Framework\Console\Cli;
use Magento\Framework\Exception\LocalizedException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Jh\Import\Import\Manager;
/**
* @author Aydin Hassan <[email protected]>
*/
class RunImportCommand extends Command
{
/**
* @var Manager
*/
private $manager;
/**
* @var State
*/
private $state;
public function __construct(Manager $manager, State $state)
{
$this->manager = $manager;
$this->state = $state;
parent::__construct();
}
protected function configure()
{
$this->setName('jh-import:run')
->setDescription('Manually run an import immediately')
->addArgument('import_name', InputArgument::REQUIRED, 'The import to run as defined in imports.xml');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
try {
$this->state->setAreaCode('crontab');
} catch (LocalizedException $exception) {
//no-op
return Cli::RETURN_FAILURE;
}
$this->manager->executeImportByName($input->getArgument('import_name'));
return Cli::RETURN_SUCCESS;
}
}