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\CustomerAddressManager; |
15
|
|
|
|
16
|
|
|
class CopyCustomerAddressesToContactCommand 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() |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
$this |
28
|
|
|
->setName('oro:magento:copy-data-to-contact:addresses') |
29
|
|
|
->addOption( |
30
|
|
|
'id', |
31
|
|
|
null, |
32
|
|
|
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, |
33
|
|
|
'If option exists then customer addresses will be copied to contact for given magento customer by id' |
34
|
|
|
) |
35
|
|
|
->addOption( |
36
|
|
|
'integration-id', |
37
|
|
|
null, |
38
|
|
|
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, |
39
|
|
|
'If option exists then customer addresses will be copied to contact |
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 copy addresses of magento customers to the contact'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
|
|
public function execute(InputInterface $input, OutputInterface $output) |
55
|
|
|
{ |
56
|
|
|
$logger = new OutputLogger($output); |
57
|
|
|
$logger->info('Executing command started.'); |
58
|
|
|
|
59
|
|
|
$integrationIds = $input->getOption('integration-id'); |
60
|
|
|
$ids = $input->getOption('id'); |
61
|
|
|
$batchSize = $input->getOption('batch-size') ? $input->getOption('batch-size') : self::BATCH_SIZE; |
62
|
|
|
|
63
|
|
|
$logger->info('Parameters:'); |
64
|
|
|
if ($integrationIds) { |
65
|
|
|
foreach ($integrationIds as $item) { |
66
|
|
|
$logger->info(sprintf('--integration-id=%s', $item)); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
if ($ids) { |
70
|
|
|
foreach ($integrationIds as $item) { |
71
|
|
|
$logger->info(sprintf('--id=%s', $item)); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
if ($batchSize) { |
75
|
|
|
$logger->info(sprintf('--batch-size=%s', $batchSize)); |
76
|
|
|
$logger->info(''); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** @var CustomerAddressManager $customerAddressManager */ |
80
|
|
|
$customerAddressManager = $this->container->get('oro_magento.manager.customer_address_manager'); |
81
|
|
|
$customerAddressManager->setLogger($logger); |
82
|
|
|
$customerAddressManager->copyToContact($ids, $integrationIds, $batchSize); |
83
|
|
|
|
84
|
|
|
$logger->info('Executing command finished.'); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
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.