Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 16768 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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;
16768 efrain 11
 
16766 efrain 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
     *
16769 efrain 31
     * @var \Laminas\Db\Adapter\AdapterInterface
16766 efrain 32
     */
33
    private $adapter;
34
 
16769 efrain 35
    /**
36
     *
37
     * @var \LeadersLinked\Cache\CacheInterface
38
     */
39
    private $cache;
16766 efrain 40
 
16769 efrain 41
 
16766 efrain 42
    /**
43
     *
16769 efrain 44
     * @var \Laminas\Log\LoggerInterface
16766 efrain 45
     */
46
    private $logger;
16769 efrain 47
 
16766 efrain 48
    /**
49
     *
50
     * @var array
51
     */
52
    private $config;
53
 
54
 
55
    /**
56
     *
16769 efrain 57
     * @var \Laminas\Mvc\I18n\Translator
58
     */
59
    private $translator;
60
 
61
 
62
    /**
63
     *
64
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
65
     * @param \LeadersLinked\Cache\CacheInterface $cache
66
     * @param \Laminas\Log\LoggerInterface
16766 efrain 67
     * @param array $config
16769 efrain 68
     * @param \Laminas\Mvc\I18n\Translator $translator
16766 efrain 69
     */
16769 efrain 70
    public function __construct($adapter, $cache, $logger, $config, $translator)
16766 efrain 71
    {
72
        $this->adapter      = $adapter;
16769 efrain 73
        $this->cache        = $cache;
16766 efrain 74
        $this->logger       = $logger;
75
        $this->config       = $config;
16769 efrain 76
        $this->translator   = $translator;
16766 efrain 77
 
78
        parent::__construct();
79
    }
80
 
81
 
82
    protected function execute(InputInterface $input, OutputInterface $output) : int
83
    {
84
        $output->writeln('Inicio del proceso');
85
 
86
 
87
        $queryMapper = QueryMapper::getInstance($this->adapter);
88
 
89
        $select = $queryMapper->getSql()->select();
90
        $select->from(DiscoveryContactMapper::_TABLE);
91
        $select->columns(['corporate_email']);
92
        $select->group('corporate_email');
93
        $select->having('COUNT(*) > 1');
94
 
95
 
96
 
97
 
98
        $records = $queryMapper->fetchAll($select);
99
 
100
        $output->writeln('hay ' . count($records) . ' registro(s) duplicado(s)');
101
 
102
        foreach($records as $record)
103
        {
104
            $sentence = 'DELETE FROM ' . DiscoveryContactMapper::_TABLE .
105
            ' WHERE corporate_email = :corporate_email ORDER BY id DESC LIMIT 1';
106
 
107
            $queryMapper->delete($sentence, [':corporate_email' => $record['corporate_email'] ]);
108
 
109
 
110
 
111
        }
112
 
113
 
114
 
115
 
116
        //echo $select->getSqlString($this->adapter->platform); exit;
117
 
118
 
119
 
120
 
121
        $output->writeln('Fin del proceso');
122
 
123
        return 0;
124
    }
125
 
126
 
127
 
128
}