| 16766 |
efrain |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
declare(strict_types=1);
|
|
|
4 |
|
|
|
5 |
namespace LeadersLinked\Command;
|
|
|
6 |
|
|
|
7 |
use Symfony\Component\Console\Command\Command;
|
|
|
8 |
use Symfony\Component\Console\Input\InputInterface;
|
|
|
9 |
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
10 |
use Laminas\Db\Adapter\AdapterInterface;
|
|
|
11 |
use LeadersLinked\Cache\CacheInterface;
|
|
|
12 |
use Laminas\Log\LoggerInterface;
|
|
|
13 |
use GeoIp2\Database\Reader As GeoIp2Reader;
|
|
|
14 |
use LeadersLinked\Library\Functions;
|
|
|
15 |
use LeadersLinked\Mapper\CompanyServiceMapper;
|
|
|
16 |
use LeadersLinked\Mapper\DiscoveryContactInteractionTypeMapper;
|
|
|
17 |
use LeadersLinked\Model\Service;
|
|
|
18 |
use LeadersLinked\Model\DiscoveryContactInteractionType;
|
|
|
19 |
use LeadersLinked\Mapper\DiscoveryContactLogMapper;
|
|
|
20 |
use LeadersLinked\Mapper\DiscoveryContactMapper;
|
|
|
21 |
use LeadersLinked\Mapper\DiscoveryContactInteractionMapper;
|
|
|
22 |
use LeadersLinked\Model\DiscoveryContactLog;
|
|
|
23 |
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
|
|
|
24 |
use LeadersLinked\Mapper\QueryMapper;
|
|
|
25 |
use Laminas\Db\Sql\Expression;
|
|
|
26 |
|
|
|
27 |
class DuplicateDiscoveryContactCommand extends Command
|
|
|
28 |
{
|
|
|
29 |
/**
|
|
|
30 |
*
|
|
|
31 |
* @var AdapterInterface
|
|
|
32 |
*/
|
|
|
33 |
private $adapter;
|
|
|
34 |
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
*
|
|
|
38 |
* @var CacheInterface
|
|
|
39 |
*/
|
|
|
40 |
private $cache;
|
|
|
41 |
|
|
|
42 |
/**
|
|
|
43 |
*
|
|
|
44 |
* @var LoggerInterface
|
|
|
45 |
*/
|
|
|
46 |
private $logger;
|
|
|
47 |
|
|
|
48 |
/**
|
|
|
49 |
*
|
|
|
50 |
* @var array
|
|
|
51 |
*/
|
|
|
52 |
private $config;
|
|
|
53 |
|
|
|
54 |
|
|
|
55 |
/**
|
|
|
56 |
*
|
|
|
57 |
* @param AdapterInterface $adapter
|
|
|
58 |
*@param CacheInterface $cache
|
|
|
59 |
* @param LoggerInterface $logger
|
|
|
60 |
* @param array $config
|
|
|
61 |
*/
|
|
|
62 |
public function __construct($adapter, $cache, $logger, $config)
|
|
|
63 |
{
|
|
|
64 |
$this->adapter = $adapter;
|
|
|
65 |
$this->cache = $cache;
|
|
|
66 |
$this->logger = $logger;
|
|
|
67 |
$this->config = $config;
|
|
|
68 |
|
|
|
69 |
parent::__construct();
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
|
|
|
73 |
protected function execute(InputInterface $input, OutputInterface $output) : int
|
|
|
74 |
{
|
|
|
75 |
$output->writeln('Inicio del proceso');
|
|
|
76 |
|
|
|
77 |
|
|
|
78 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
|
|
79 |
|
|
|
80 |
$select = $queryMapper->getSql()->select();
|
|
|
81 |
$select->from(DiscoveryContactMapper::_TABLE);
|
|
|
82 |
$select->columns(['corporate_email']);
|
|
|
83 |
$select->group('corporate_email');
|
|
|
84 |
$select->having('COUNT(*) > 1');
|
|
|
85 |
|
|
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
|
89 |
$records = $queryMapper->fetchAll($select);
|
|
|
90 |
|
|
|
91 |
$output->writeln('hay ' . count($records) . ' registro(s) duplicado(s)');
|
|
|
92 |
|
|
|
93 |
foreach($records as $record)
|
|
|
94 |
{
|
|
|
95 |
$sentence = 'DELETE FROM ' . DiscoveryContactMapper::_TABLE .
|
|
|
96 |
' WHERE corporate_email = :corporate_email ORDER BY id DESC LIMIT 1';
|
|
|
97 |
|
|
|
98 |
$queryMapper->delete($sentence, [':corporate_email' => $record['corporate_email'] ]);
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
|
|
|
105 |
|
|
|
106 |
|
|
|
107 |
//echo $select->getSqlString($this->adapter->platform); exit;
|
|
|
108 |
|
|
|
109 |
|
|
|
110 |
|
|
|
111 |
|
|
|
112 |
$output->writeln('Fin del proceso');
|
|
|
113 |
|
|
|
114 |
return 0;
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
|
|
|
119 |
}
|