Completed
Push — 1.10 ( 93e51c...7f32fb )
by
unknown
11:06
created

ReSyncCustomersAddressCommand::execute()   B

Complexity

Conditions 6
Paths 9

Size

Total Lines 33
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 33
rs 8.439
cc 6
eloc 21
nc 9
nop 2
1
<?php
2
3
namespace OroCRM\Bundle\MagentoBundle\Command;
4
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Input\InputOption;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
10
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
11
12
use Oro\Component\Log\OutputLogger;
13
14
use OroCRM\Bundle\MagentoBundle\Manager\CustomerInfoManager;
15
16
class ReSyncCustomersAddressCommand extends Command implements ContainerAwareInterface
17
{
18
    use ContainerAwareTrait;
19
20
    const BATCH_SIZE = 25;
21
22
    /**
23
     * {@inheritdoc}
24
     */
25 View Code Duplication
    public function configure()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
    {
27
        $this
28
            ->setName('oro:magento:re-sync-customer-address')
29
            ->addOption(
30
                'id',
31
                null,
32
                InputOption::VALUE_OPTIONAL|InputOption::VALUE_IS_ARRAY,
33
                'If option exists then customer addresses will be resynced for given magento customer by id'
34
            )
35
            ->addOption(
36
                'integration-id',
37
                null,
38
                InputOption::VALUE_REQUIRED,
39
                'Customer addresses will be resynced 
40
                for given magento customers by integration_id'
41
            )
42
            ->addOption(
43
                'batch-size',
44
                null,
45
                InputOption::VALUE_OPTIONAL,
46
                'Number of customers in batch. The default value is 25.'
47
            )
48
            ->setDescription('Make resync addresses of magento customers');
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function execute(InputInterface $input, OutputInterface $output)
55
    {
56
        $logger    = new OutputLogger($output);
57
        $integrationId = $input->getOption('integration-id');
58
        if (!$integrationId) {
59
            throw new \RuntimeException(
60
                'The "--integration-id" option is required.'
61
            );
62
        }
63
        $ids = $input->getOption('id');
64
        $batchSize = $input->getOption('batch-size') ? $input->getOption('batch-size') : self::BATCH_SIZE;
65
66
        $logger->info('Executing command started.');
67
        $logger->info('Parameters:');
68
        $logger->info(sprintf('--integration-id=%s', $integrationId));
69
70
        if ($ids) {
71
            foreach ($ids as $item) {
72
                $logger->info(sprintf('--id=%s', $item));
73
            }
74
        }
75
76
        if ($batchSize) {
77
            $logger->info(sprintf('--batch-size=%s', $batchSize));
78
            $logger->info('');
79
        }
80
81
        /** @var CustomerInfoManager $customerInfoManager */
82
        $customerInfoManager = $this->container->get('oro_magento.manager.customer_info_manager');
83
        $customerInfoManager->setLogger($logger);
84
        $customerInfoManager->reSyncData($integrationId, $ids, $batchSize);
85
        $logger->info('Executing command finished.');
86
    }
87
}
88