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( "Failed to update configuration for account {$account->getCrmUrl()}[{$account->getId()}]" ); $output->writeln("Error: {$e->getMessage()}"); } } $output->writeln("{$count} modules updated."); $this->release(); return 0; } }