-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathUpdateModuleCommand.php
More file actions
87 lines (71 loc) · 2.38 KB
/
UpdateModuleCommand.php
File metadata and controls
87 lines (71 loc) · 2.38 KB
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
<?php
namespace RetailCrm\DeliveryModuleBundle\Command;
use RetailCrm\DeliveryModuleBundle\Command\Traits\AccountAwareTrait;
use RetailCrm\DeliveryModuleBundle\Service\AccountManager;
use RetailCrm\DeliveryModuleBundle\Service\ModuleManagerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Command\LockableTrait;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class UpdateModuleCommand extends Command
{
use LockableTrait;
use AccountAwareTrait;
/**
* @var ModuleManagerInterface
*/
private $moduleManager;
/**
* @var AccountManager
*/
private $accountManager;
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('module:update')
->setDescription('Update module')
->addArgument('accountId', InputArgument::OPTIONAL, 'Choose account, or make it for all');
}
public function __construct(ModuleManagerInterface $moduleManager, AccountManager $accountManager)
{
$this->moduleManager = $moduleManager;
$this->accountManager = $accountManager;
parent::__construct();
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
if (!$this->lock()) {
$output->writeln('The command is already running in another process.');
return 0;
}
$accountId = $input->hasArgument('accountId')
? (int) $input->getArgument('accountId')
: null;
$accounts = $this->getAccounts($accountId);
$count = 0;
foreach ($accounts as $account) {
try {
$this->moduleManager
->setAccount($account)
->updateModuleConfiguration()
;
++$count;
} catch (\Exception $e) {
$output->writeln(
"<error>Failed to update configuration for account {$account->getCrmUrl()}[{$account->getId()}]</error>"
);
$output->writeln("<error>Error: {$e->getMessage()}</error>");
}
}
$output->writeln("<info>{$count} modules updated.</info>");
$this->release();
return 0;
}
}