*/ class UpdateCurrenciesRates extends ContainerAwareCommand { protected function configure() { $this ->setName("currency:update-rates") ->setDescription("Update currency rates") ; } protected function execute(InputInterface $input, OutputInterface $output) { /** @var EventDispatcherInterface $dispatcher */ try { $event = new CurrencyUpdateRateEvent(); $this->getDispatcher()->dispatch(TheliaEvents::CURRENCY_UPDATE_RATES, $event); if ($event->hasUndefinedRates()) { $output->writeln("Rate was not found for the following currencies:"); $undefinedCurrencies = CurrencyQuery::create() ->filterById($event->getUndefinedRates()) ->find(); /** @var Currency $currency */ foreach ($undefinedCurrencies as $currency) { $output->writeln(" -" . $currency->getName() . " (".$currency->getCode()."), current rate is " . $currency->getRate()); } $output->writeln("Update done with errors"); } else { $output->writeln("Update done withour errors"); return 1; } } catch (\Exception $ex) { // Any error $output->writeln("Update failed: " . $ex->getMessage() . ""); return 2; } return 0; } }