|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @author Rafał Muszyński <[email protected]> |
|
5
|
|
|
* @copyright 2015 Sourcefabric z.ú. |
|
6
|
|
|
* @license http://www.gnu.org/licenses/gpl-3.0.txt |
|
7
|
|
|
*/ |
|
8
|
|
|
namespace Newscoop\PaywallBundle\Command; |
|
9
|
|
|
|
|
10
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
13
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Import currencies echange rates from diffrent services. |
|
17
|
|
|
*/ |
|
18
|
|
|
class CurrencyExchangeRateImportCommand extends ContainerAwareCommand |
|
19
|
|
|
{ |
|
20
|
|
|
protected function configure() |
|
21
|
|
|
{ |
|
22
|
|
|
$this |
|
23
|
|
|
->setName('paywall:currency:import') |
|
24
|
|
|
->setDescription('Import currencies exchange rates. Default service is European Central Bank') |
|
25
|
|
|
->addArgument('service', InputArgument::OPTIONAL, 'Name of the service', 'ecb') |
|
26
|
|
|
->addArgument('currency', InputArgument::OPTIONAL, 'Default currency', 'EUR') |
|
27
|
|
|
; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
31
|
|
|
{ |
|
32
|
|
|
$container = $this->getContainer(); |
|
33
|
|
|
$service = $container->get('newscoop_paywall.currency_importer.'.$input->getArgument('service')); |
|
34
|
|
|
$provider = $container->get('newscoop_paywall.currency_provider'); |
|
35
|
|
|
|
|
36
|
|
|
if ($input->getOption('verbose')) { |
|
37
|
|
|
$output->writeln('<info>Importing exchange rates started!</info>'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
$service->setBaseCurrency($input->getArgument('currency')); |
|
41
|
|
|
$service->import($provider->getAvailableCurrencies()); |
|
42
|
|
|
|
|
43
|
|
|
if ($input->getOption('verbose')) { |
|
44
|
|
|
$output->writeln('<info>Exchange rates imported successfully!</info>'); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|