From f80a7291a9cbe87ab966ba97fa5db9065835e463 Mon Sep 17 00:00:00 2001 From: heathdutton Date: Tue, 20 Aug 2019 13:33:37 -0400 Subject: [PATCH 1/3] Do not duplicate internal IPs with a DB cluster. --- app/bundles/CampaignBundle/Entity/LeadEventLog.php | 6 +++++- .../CampaignBundle/Entity/LeadEventLogRepository.php | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/bundles/CampaignBundle/Entity/LeadEventLog.php b/app/bundles/CampaignBundle/Entity/LeadEventLog.php index 9d0a59286ee..d3c18fffe4b 100644 --- a/app/bundles/CampaignBundle/Entity/LeadEventLog.php +++ b/app/bundles/CampaignBundle/Entity/LeadEventLog.php @@ -135,7 +135,11 @@ public static function loadMetadata(ORM\ClassMetadata $metadata) ->addJoinColumn('campaign_id', 'id') ->build(); - $builder->addIpAddress(true); + $builder->createManyToOne('ipAddress', 'Mautic\CoreBundle\Entity\IpAddress') + ->cascadeDetach() + ->cascadeMerge() + ->addJoinColumn('ip_id', 'id', true) + ->build(); $builder->createField('dateTriggered', 'datetime') ->columnName('date_triggered') diff --git a/app/bundles/CampaignBundle/Entity/LeadEventLogRepository.php b/app/bundles/CampaignBundle/Entity/LeadEventLogRepository.php index 7f2a3ac01f4..ac875d71ee1 100644 --- a/app/bundles/CampaignBundle/Entity/LeadEventLogRepository.php +++ b/app/bundles/CampaignBundle/Entity/LeadEventLogRepository.php @@ -487,7 +487,7 @@ public function getScheduledCounts($campaignId, \DateTime $date, ContactLimiter ->from(MAUTIC_TABLE_PREFIX.'campaign_lead_event_log', 'l') ->join('l', MAUTIC_TABLE_PREFIX.'campaigns', 'c', 'l.campaign_id = c.id') ->where($expr) - ->setParameter('campaignId', $campaignId) + ->setParameter('campaignId', (int) $campaignId, \PDO::PARAM_INT) ->setParameter('now', $now->format('Y-m-d H:i:s')) ->setParameter('true', true, \PDO::PARAM_BOOL) ->groupBy('l.event_id') From ae7d5d6c2a481e7f4c9ead36265c8bc976e3eb28 Mon Sep 17 00:00:00 2001 From: heathdutton Date: Tue, 20 Aug 2019 14:13:22 -0400 Subject: [PATCH 2/3] Avoid persisting IP when executed by cron. --- app/bundles/CampaignBundle/Entity/LeadEventLog.php | 6 +----- .../CampaignBundle/Entity/LeadEventLogRepository.php | 2 +- .../CampaignBundle/Executioner/Logger/EventLogger.php | 4 +++- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/bundles/CampaignBundle/Entity/LeadEventLog.php b/app/bundles/CampaignBundle/Entity/LeadEventLog.php index d3c18fffe4b..9d0a59286ee 100644 --- a/app/bundles/CampaignBundle/Entity/LeadEventLog.php +++ b/app/bundles/CampaignBundle/Entity/LeadEventLog.php @@ -135,11 +135,7 @@ public static function loadMetadata(ORM\ClassMetadata $metadata) ->addJoinColumn('campaign_id', 'id') ->build(); - $builder->createManyToOne('ipAddress', 'Mautic\CoreBundle\Entity\IpAddress') - ->cascadeDetach() - ->cascadeMerge() - ->addJoinColumn('ip_id', 'id', true) - ->build(); + $builder->addIpAddress(true); $builder->createField('dateTriggered', 'datetime') ->columnName('date_triggered') diff --git a/app/bundles/CampaignBundle/Entity/LeadEventLogRepository.php b/app/bundles/CampaignBundle/Entity/LeadEventLogRepository.php index ac875d71ee1..7f2a3ac01f4 100644 --- a/app/bundles/CampaignBundle/Entity/LeadEventLogRepository.php +++ b/app/bundles/CampaignBundle/Entity/LeadEventLogRepository.php @@ -487,7 +487,7 @@ public function getScheduledCounts($campaignId, \DateTime $date, ContactLimiter ->from(MAUTIC_TABLE_PREFIX.'campaign_lead_event_log', 'l') ->join('l', MAUTIC_TABLE_PREFIX.'campaigns', 'c', 'l.campaign_id = c.id') ->where($expr) - ->setParameter('campaignId', (int) $campaignId, \PDO::PARAM_INT) + ->setParameter('campaignId', $campaignId) ->setParameter('now', $now->format('Y-m-d H:i:s')) ->setParameter('true', true, \PDO::PARAM_BOOL) ->groupBy('l.event_id') diff --git a/app/bundles/CampaignBundle/Executioner/Logger/EventLogger.php b/app/bundles/CampaignBundle/Executioner/Logger/EventLogger.php index 14c8bd79c23..a5f66e450f2 100644 --- a/app/bundles/CampaignBundle/Executioner/Logger/EventLogger.php +++ b/app/bundles/CampaignBundle/Executioner/Logger/EventLogger.php @@ -113,7 +113,9 @@ public function buildLogEntry(Event $event, Lead $contact = null, $isInactiveEve { $log = new LeadEventLog(); - $log->setIpAddress($this->ipLookupHelper->getIpAddress()); + if (!defined('MAUTIC_CAMPAIGN_SYSTEM_TRIGGERED')) { + $log->setIpAddress($this->ipLookupHelper->getIpAddress()); + } $log->setEvent($event); $log->setCampaign($event->getCampaign()); From 5e39c77fea29f8b6473c1491456221e7dce80d89 Mon Sep 17 00:00:00 2001 From: heathdutton Date: Tue, 20 Aug 2019 14:20:43 -0400 Subject: [PATCH 3/3] Avoid persisting IP when executed by cron. --- app/bundles/CampaignBundle/Model/EventLogModel.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/bundles/CampaignBundle/Model/EventLogModel.php b/app/bundles/CampaignBundle/Model/EventLogModel.php index d337d50a79a..0cde7a8fbb9 100644 --- a/app/bundles/CampaignBundle/Model/EventLogModel.php +++ b/app/bundles/CampaignBundle/Model/EventLogModel.php @@ -168,9 +168,11 @@ public function updateContactEvent(Event $event, Lead $contact, array $parameter ); break; case 'ipAddress': - $log->setIpAddress( - $this->ipLookupHelper->getIpAddress($value) - ); + if (!defined('MAUTIC_CAMPAIGN_SYSTEM_TRIGGERED')) { + $log->setIpAddress( + $this->ipLookupHelper->getIpAddress($value) + ); + } break; case 'metadata': $metadata = $log->getMetadata();