Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Rename table
  • Loading branch information
kuzmany committed Nov 21, 2019
1 parent 009e692 commit c36656d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
14 changes: 8 additions & 6 deletions Command/SourceCreatedMigrationCommand.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
16 changes: 9 additions & 7 deletions Entity/CustomLog.php → Entity/CustomCreatedContactLog.php
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -154,7 +156,7 @@ public function getPublishStatus()
/**
* @param string $url
*
* @return CustomLog
* @return CustomCreatedContactLog
*/
public function setUrl($url)
{
Expand All @@ -174,7 +176,7 @@ public function getUrl()
/**
* @param Lead $lead
*
* @return CustomLog
* @return CustomCreatedContactLog
*/
public function setLead($lead)
{
Expand All @@ -194,7 +196,7 @@ public function getLead()
/**
* @param LeadEventLog $log
*
* @return CustomLog
* @return CustomCreatedContactLog
*/
public function setLog($log)
{
Expand Down
Expand Up @@ -13,6 +13,6 @@

use Mautic\CoreBundle\Entity\CommonRepository;

class CustomLogRepository extends CommonRepository
class CustomCreatedContactLogRepository extends CommonRepository
{
}
5 changes: 3 additions & 2 deletions EventListener/SourceCreatedContactReportSubscriber.php
Expand Up @@ -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
{
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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');


Expand Down

0 comments on commit c36656d

Please sign in to comment.