Rev 16768 | AutorÃa | Comparar con el anterior | Ultima modificación | Ver Log |
<?phpdeclare(strict_types=1);namespace LeadersLinked\Command;use Symfony\Component\Console\Command\Command;use Symfony\Component\Console\Input\InputInterface;use Symfony\Component\Console\Output\OutputInterface;use Laminas\Db\Adapter\AdapterInterface;use Laminas\Log\LoggerInterface;use GeoIp2\Database\Reader As GeoIp2Reader;use LeadersLinked\Library\Functions;use LeadersLinked\Mapper\CompanyServiceMapper;use LeadersLinked\Mapper\DiscoveryContactInteractionTypeMapper;use LeadersLinked\Model\Service;use LeadersLinked\Model\DiscoveryContactInteractionType;use LeadersLinked\Mapper\DiscoveryContactLogMapper;use LeadersLinked\Mapper\DiscoveryContactMapper;use LeadersLinked\Mapper\DiscoveryContactInteractionMapper;use LeadersLinked\Model\DiscoveryContactLog;use LeadersLinked\Hydrator\ObjectPropertyHydrator;class CheckDiscoveryContactCommand extends Command{/**** @var \Laminas\Db\Adapter\AdapterInterface*/private $adapter;/**** @var \LeadersLinked\Cache\CacheInterface*/private $cache;/**** @var \Laminas\Log\LoggerInterface*/private $logger;/**** @var array*/private $config;/**** @var \Laminas\Mvc\I18n\Translator*/private $translator;/**** @param \Laminas\Db\Adapter\AdapterInterface $adapter* @param \LeadersLinked\Cache\CacheInterface $cache* @param \Laminas\Log\LoggerInterface* @param array $config* @param \Laminas\Mvc\I18n\Translator $translator*/public function __construct($adapter, $cache, $logger, $config, $translator){$this->adapter = $adapter;$this->cache = $cache;$this->logger = $logger;$this->config = $config;$this->translator = $translator;parent::__construct();}protected function execute(InputInterface $input, OutputInterface $output) : int{$output->writeln('Inicio del proceso');$hydrator = new ObjectPropertyHydrator();$companyServiceMapper = CompanyServiceMapper::getInstance($this->adapter);$companiesService = $companyServiceMapper->fetchAllActiveByServiceId(Service::DISCOVERY_CONTACTS);$discoveryContactInteractionTypeMapper = DiscoveryContactInteractionTypeMapper::getInstance($this->adapter);$discoveryContactMapper = DiscoveryContactMapper::getInstance($this->adapter);$discoveryContactInteractionMapper = DiscoveryContactInteractionMapper::getInstance($this->adapter);$discoveryContactLogMapper = DiscoveryContactLogMapper::getInstance($this->adapter);foreach($companiesService as $companyService){$discoveryContactInteractionTypeDefault = $discoveryContactInteractionTypeMapper->fetchOneDefaultByCompanyId($companyService->company_id);if(!$discoveryContactInteractionTypeDefault) {$discoveryContactInteractionTypeDefault = $discoveryContactInteractionTypeMapper->fetchOneFirstActiveByCompanyId($companyService->company_id);$discoveryContactInteractionTypeDefault->default = DiscoveryContactInteractionType::DEFAULT_YES;$discoveryContactInteractionTypeMapper->update($discoveryContactInteractionTypeDefault);}$discoveryContacts = $discoveryContactMapper ->fetchAllByCompanyId($companyService->company_id);foreach($discoveryContacts as $discoveryContact){$discoveryContactInteraction = $discoveryContactInteractionMapper->fetchByContactIdAndInteractionTypeId($discoveryContact->id, $discoveryContactInteractionTypeDefault->id);if($discoveryContactInteraction) {$discoveryContactLog = $discoveryContactLogMapper->fetchOneFirstByContactId($discoveryContact->id);if(!$discoveryContactLog) {$discoveryContactLog = new DiscoveryContactLog();$discoveryContactLog->company_id = $discoveryContactInteraction->company_id;$discoveryContactLog->contact_id = $discoveryContact->id;$discoveryContactLog->user_id = $discoveryContactInteraction->user_id;$discoveryContactLog->activity = 'LABEL_RECORD_CONTACT_ADDED';$discoveryContactLog->details = 'LABEL_FIRST_NAME : ' . $discoveryContact->first_name . PHP_EOL .'LABEL_LAST_NAME : ' . $discoveryContact->last_name . PHP_EOL .'LABEL_CORPORATE_EMAIL : ' . $discoveryContact->corporate_email . PHP_EOL .'LABEL_COMPANY : ' . $discoveryContact->company . PHP_EOL .'LABEL_POSITION : ' . $discoveryContact->position . PHP_EOL .'LABEL_COUNTRY : ' . $discoveryContact->country . PHP_EOL;if ($discoveryContact->state) {$discoveryContactLog->details .= 'LABEL_STATE : ' . $discoveryContact->state . PHP_EOL;}if ($discoveryContact->city) {$discoveryContactLog->details .= 'LABEL_CITY : ' . $discoveryContact->city . PHP_EOL;}if ($discoveryContact->phone) {$discoveryContactLog->details .= 'LABEL_PHONE : ' . $discoveryContact->phone . PHP_EOL;}if ($discoveryContact->phone_extension) {$discoveryContactLog->details .= 'LABEL_PHONE_EXTENSION : ' . $discoveryContact->phone_extension . PHP_EOL;}if ($discoveryContact->personal_email) {$discoveryContactLog->details .= 'LABEL_PERSONAL_EMAIL : ' . $discoveryContact->personal_email . PHP_EOL;}if ($discoveryContact->celular) {$discoveryContactLog->details .= 'LABEL_CELULAR : ' . $discoveryContact->celular . PHP_EOL;}if ($discoveryContact->whatsapp) {$discoveryContactLog->details .= 'LABEL_WHATSAPP : ' . $discoveryContact->whatsapp . PHP_EOL;}if ($discoveryContact->linkedin) {$discoveryContactLog->details .= 'LABEL_LINKEDIN : ' . $discoveryContact->linkedin . PHP_EOL;}$values = $hydrator->extract($discoveryContactLog);$values['added_on'] = $discoveryContactInteraction->added_on;$discoveryContactLogMapper->insertRaw($values);}} else {$discoveryContactLog = $discoveryContactLogMapper->fetchOneFirstByContactId($discoveryContact->id);if($discoveryContactLog) {$values = ['company_id' => $discoveryContact->company_id,'contact_id' => $discoveryContact->id,'user_id' => $discoveryContactLog->user_id,'interaction_type_id' => $discoveryContactInteractionTypeDefault->id,'notes' => '','added_on' => $discoveryContactLog->added_on] ;$discoveryContactInteractionMapper->insertRaw($values);}}}}$output->writeln('Fin del proceso');return 0;}}