diff --git a/Command/SourceCreatedMigrationCommand.php b/Command/SourceCreatedMigrationCommand.php index b425df7..60c2355 100644 --- a/Command/SourceCreatedMigrationCommand.php +++ b/Command/SourceCreatedMigrationCommand.php @@ -13,6 +13,7 @@ use Doctrine\ORM\EntityManager; use Mautic\CoreBundle\Command\ModeratedCommand; +use MauticPlugin\MauticCustomReportBundle\Entity\CustomCreatedContactLog; use phpDocumentor\Reflection\Types\Parent_; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -59,16 +60,17 @@ protected function execute(InputInterface $input, OutputInterface $output) return 0; } - $maxIdQuery = 'SELECT MAX(ccl.log_id) FROM '.MAUTIC_TABLE_PREFIX.'custom_contact_log ccl'; - $maxLogId = (int) $this->entityManager->getConnection()->query($maxIdQuery)->fetchColumn(); + $maxIdQuery = 'SELECT MAX(ccl.log_id) FROM '.MAUTIC_TABLE_PREFIX.CustomCreatedContactLog::TABLE.' ccl'; + $maxLogId = (int) $this->entityManager->getConnection()->query($maxIdQuery)->fetchColumn(); - $countQuery = 'SELECT COUNT(lel.id) FROM '.$this->getLeadEventLogQueryPart().' AND lel.id > '.$maxLogId; - $numberOfImportedRows = $this->entityManager->getConnection()->query($countQuery)->fetchColumn(); + $countQuery = 'SELECT COUNT(lel.id) FROM '.$this->getLeadEventLogQueryPart( + ).' AND lel.id > '.$maxLogId; + $numberOfImportedRows = $this->entityManager->getConnection()->query($countQuery)->fetchColumn(); - $query = 'INSERT INTO '.MAUTIC_TABLE_PREFIX.'custom_contact_log (lead_id, log_id, url, date_added) + $query = 'INSERT INTO '.MAUTIC_TABLE_PREFIX.CustomCreatedContactLog::TABLE.' (lead_id, log_id, url, date_added) SELECT lel.lead_id, lel.id,ph.url,lel.date_added FROM '.$this->getLeadEventLogQueryPart(); if ($maxLogId) { - $query.= ' AND lel.id > '.$maxLogId; + $query .= ' AND lel.id > '.$maxLogId; } $this->entityManager->getConnection()->query($query); diff --git a/Entity/CustomLog.php b/Entity/CustomCreatedContactLog.php similarity index 89% rename from Entity/CustomLog.php rename to Entity/CustomCreatedContactLog.php index a23180d..c510bc5 100644 --- a/Entity/CustomLog.php +++ b/Entity/CustomCreatedContactLog.php @@ -17,9 +17,11 @@ use Mautic\CoreBundle\Doctrine\Mapping\ClassMetadataBuilder; use Mautic\LeadBundle\Entity\Lead; use Mautic\LeadBundle\Entity\LeadEventLog; +use phpDocumentor\Reflection\Types\Self_; -class CustomLog +class CustomCreatedContactLog { + CONST TABLE = 'custom_created_contact_log'; /** * @var int */ @@ -57,8 +59,8 @@ public function __construct() public static function loadMetadata(ORM\ClassMetadata $metadata) { $builder = new ClassMetadataBuilder($metadata); - $builder->setTable('custom_contact_log') - ->setCustomRepositoryClass(CustomLogRepository::class) + $builder->setTable(self::TABLE) + ->setCustomRepositoryClass(CustomCreatedContactLogRepository::class) ->addId() ->addIndex(['url', 'date_added'], 'url_date_added') ->addIndex(['date_added'], 'date_added'); @@ -90,7 +92,7 @@ public static function loadMetadata(ORM\ClassMetadata $metadata) */ public static function loadApiMetadata(ApiMetadataDriver $metadata) { - $metadata->setGroupPrefix('custom_log') + $metadata->setGroupPrefix(self::TABLE) ->addListProperties( [ 'id', @@ -154,7 +156,7 @@ public function getPublishStatus() /** * @param string $url * - * @return CustomLog + * @return CustomCreatedContactLog */ public function setUrl($url) { @@ -174,7 +176,7 @@ public function getUrl() /** * @param Lead $lead * - * @return CustomLog + * @return CustomCreatedContactLog */ public function setLead($lead) { @@ -194,7 +196,7 @@ public function getLead() /** * @param LeadEventLog $log * - * @return CustomLog + * @return CustomCreatedContactLog */ public function setLog($log) { diff --git a/Entity/CustomLogRepository.php b/Entity/CustomCreatedContactLogRepository.php similarity index 82% rename from Entity/CustomLogRepository.php rename to Entity/CustomCreatedContactLogRepository.php index aff37e8..cd83201 100644 --- a/Entity/CustomLogRepository.php +++ b/Entity/CustomCreatedContactLogRepository.php @@ -13,6 +13,6 @@ use Mautic\CoreBundle\Entity\CommonRepository; -class CustomLogRepository extends CommonRepository +class CustomCreatedContactLogRepository extends CommonRepository { } diff --git a/EventListener/SourceCreatedContactReportSubscriber.php b/EventListener/SourceCreatedContactReportSubscriber.php index 40e0eb7..435afc5 100644 --- a/EventListener/SourceCreatedContactReportSubscriber.php +++ b/EventListener/SourceCreatedContactReportSubscriber.php @@ -17,6 +17,7 @@ use Mautic\ReportBundle\Event\ReportBuilderEvent; use Mautic\ReportBundle\Event\ReportGeneratorEvent; use Mautic\ReportBundle\ReportEvents; +use MauticPlugin\MauticCustomReportBundle\Entity\CustomCreatedContactLog; class SourceCreatedContactReportSubscriber extends CommonSubscriber { @@ -70,7 +71,7 @@ public function onReportBuilder(ReportBuilderEvent $event) 'type' => 'datetime', ], 'hits' => [ - 'formula'=>'(SELECT COUNT(ccl2.url) FROM '.MAUTIC_TABLE_PREFIX.'custom_contact_log ccl2 + 'formula'=>'(SELECT COUNT(ccl2.url) FROM '.MAUTIC_TABLE_PREFIX.CustomCreatedContactLog::TABLE.' ccl2 INNER JOIN '.MAUTIC_TABLE_PREFIX.'leads l ON l.id = ccl2.lead_id AND l.email IS NOT NULL WHERE ccl2.date_added BETWEEN :dateFrom AND :dateTo AND ccl2.url = ccl.url)', 'label' => 'mautic.customreport.report.hits', @@ -100,7 +101,7 @@ public function onReportGenerate(ReportGeneratorEvent $event) } $qb = $event->getQueryBuilder(); - $qb->from(MAUTIC_TABLE_PREFIX.'custom_contact_log', 'ccl'); + $qb->from(MAUTIC_TABLE_PREFIX.CustomCreatedContactLog::TABLE, 'ccl'); $qb->innerJoin('ccl',MAUTIC_TABLE_PREFIX.'leads', 'l', 'l.id = ccl.lead_id AND l.email IS NOT NULL');