Skip to content

Commit

Permalink
Fix issue with tooltip getting frozen in campaign UI and fix issue wh…
Browse files Browse the repository at this point in the history
…ere campaign events were rescheduled in UTC rather than the configured hour (#7448)

Fix issue with tooltip getting frozen in campaign UI and fix issue where campaign events were rescheduled in UTC rather than the configured hour
  • Loading branch information
kuzmany committed May 19, 2019
2 parents 2991302 + bad42fb commit 4e1ad92
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 34 deletions.
4 changes: 2 additions & 2 deletions app/bundles/CampaignBundle/Assets/js/campaign.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Mautic.campaignOnLoad = function (container, response) {
var thisSelect = mQuery(event.target).attr('id');
Mautic.campaignBuilderUpdateEventListTooltips(thisSelect, false);

mQuery('#'+thisSelect+'_chosen .chosen-search input').on('keydown.toolip', function () {
mQuery('#'+thisSelect+'_chosen .chosen-search input').on('keydown.tooltip', function () {
// Destroy tooltips that are filtered out
Mautic.campaignBuilderUpdateEventListTooltips(thisSelect, true);
}).on('keyup.tooltip', function() {
Expand All @@ -64,7 +64,7 @@ Mautic.campaignOnLoad = function (container, response) {
var thisSelect = mQuery(event.target).attr('id');
Mautic.campaignBuilderUpdateEventListTooltips(thisSelect, true);

mQuery('#'+thisSelect+'_chosen .chosen-search input').off('keyup.toolip')
mQuery('#'+thisSelect+'_chosen .chosen-search input').off('keyup.tooltip')
.off('keydown.tooltip');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ private function scheduleEvents(ArrayCollection $events, ArrayCollection $contac

$this->logger->debug(
'CAMPAIGN: Event ID# '.$event->getId().
' to be executed on '.$executionDate->format('Y-m-d H:i:s')
' to be executed on '.$executionDate->format('Y-m-d H:i:s e')
);

// Check if we need to schedule this if it is not an inactivity check
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ private function executeLogsForInactiveEvents(ArrayCollection $events, ArrayColl

$this->logger->debug(
'CAMPAIGN: Event ID# '.$event->getId().
' to be executed on '.$eventExecutionDate->format('Y-m-d H:i:s')
' to be executed on '.$eventExecutionDate->format('Y-m-d H:i:s e')
);

if ($this->scheduler->shouldSchedule($eventExecutionDate, $executionDate)) {
Expand Down
4 changes: 2 additions & 2 deletions app/bundles/CampaignBundle/Executioner/KickoffExecutioner.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ private function executeOrScheduleEvent()
$executionDate = $this->scheduler->getExecutionDateTime($event, $now);
$this->logger->debug(
'CAMPAIGN: Event ID# '.$event->getId().
' to be executed on '.$executionDate->format('Y-m-d H:i:s').
' compared to '.$now->format('Y-m-d H:i:s')
' to be executed on '.$executionDate->format('Y-m-d H:i:s e').
' compared to '.$now->format('Y-m-d H:i:s e')
);

// Adjust the hour based on contact timezone if applicable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ private function executeAssociatedEvents(ArrayCollection $children, \DateTime $n
$executionDate = $this->scheduler->getExecutionDateTime($child, $now);
$this->logger->debug(
'CAMPAIGN: Event ID# '.$child->getId().
' to be executed on '.$executionDate->format('Y-m-d H:i:s')
' to be executed on '.$executionDate->format('Y-m-d H:i:s e')
);

if ($this->scheduler->shouldSchedule($executionDate, $now)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,8 @@ private function validateSchedule(ArrayCollection $logs, \DateTime $now, $schedu
$executionDate = $this->scheduler->validateExecutionDateTime($log, $now);
$this->logger->debug(
'CAMPAIGN: Log ID #'.$log->getID().
' to be executed on '.$executionDate->format('Y-m-d H:i:s').
' compared to '.$now->format('Y-m-d H:i:s')
' to be executed on '.$executionDate->format('Y-m-d H:i:s e').
' compared to '.$now->format('Y-m-d H:i:s e')
);

if ($this->scheduler->shouldSchedule($executionDate, $now)) {
Expand Down
49 changes: 44 additions & 5 deletions app/bundles/CampaignBundle/Executioner/Scheduler/Mode/Interval.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,21 @@ public function groupContactsByDate(Event $event, ArrayCollection $contacts, \Da

// Get the difference between now and the date we're supposed to be executing
$compareFromDateTime = $compareFromDateTime ? clone $compareFromDateTime : new \DateTime('now');
$compareFromDateTime->setTimezone($this->getDefaultTimezone());

$diff = $compareFromDateTime->diff($executionDate);
$diff->f = 0; // we don't care about microseconds
$diff = $compareFromDateTime->diff($executionDate);
$diff->f = 0; // we don't care about microseconds

/** @var Lead $contact */
foreach ($contacts as $contact) {
$groupExecutionDate = $this->getGroupExecutionDateTime($event->getId(), $contact, $diff, $compareFromDateTime, $hour, $startTime, $endTime, $daysOfWeek);
$groupExecutionDate = $this->getGroupExecutionDateTime(
$event->getId(),
$contact,
$diff,
$compareFromDateTime,
$hour,
$startTime,
$endTime,
$daysOfWeek
);
if (!isset($groupedExecutionDates[$groupExecutionDate->getTimestamp()])) {
$groupedExecutionDates[$groupExecutionDate->getTimestamp()] = new GroupExecutionDateDAO($groupExecutionDate);
}
Expand Down Expand Up @@ -202,16 +209,46 @@ private function getGroupExecutionDateTime(
\DateTime $endTime = null,
array $daysOfWeek = []
) {
$this->logger->debug(
sprintf('CAMPAIGN: Comparing calculated executed time for event ID %s and contact ID %s with %s', $eventId, $contact->getId(), $compareFromDateTime->format('Y-m-d H:i:s e'))
);

if ($hour) {
$this->logger->debug(
sprintf('CAMPAIGN: Scheduling event ID %s for contact ID %s based on hour of %s', $eventId, $contact->getId(), $hour->format('H:i e'))
);
$groupDateTime = $this->getExecutionDateTimeFromHour($contact, $hour, $diff, $eventId, $compareFromDateTime);
} elseif ($startTime && $endTime) {
$this->logger->debug(
sprintf(
'CAMPAIGN: Scheduling event ID %s for contact ID %s based on hour range of %s to %s',
$eventId,
$contact->getId(),
$startTime->format('H:i e'),
$endTime->format('H:i e')
)
);

$groupDateTime = $this->getExecutionDateTimeBetweenHours($contact, $startTime, $endTime, $diff, $eventId, $compareFromDateTime);
} else {
$this->logger->debug(
sprintf('CAMPAIGN: Scheduling event ID %s for contact ID %s without hour restrictions.', $eventId, $contact->getId())
);

$groupDateTime = clone $compareFromDateTime;
$groupDateTime->add($diff);
}

if ($daysOfWeek) {
$this->logger->debug(
sprintf(
'CAMPAIGN: Scheduling event ID %s for contact ID %s based on DOW restrictions of %s',
$eventId,
$contact->getId(),
implode(',', $daysOfWeek)
)
);

// Schedule for the next day of the week if applicable
while (!in_array((int) $groupDateTime->format('w'), $daysOfWeek)) {
$groupDateTime->modify('+1 day');
Expand Down Expand Up @@ -262,6 +299,7 @@ private function getExecutionDateTimeFromHour(Lead $contact, \DateTime $hour, \D
}

$groupExecutionDate = clone $compareFromDateTime;
$groupExecutionDate->setTimezone($this->getDefaultTimezone());
$groupExecutionDate->add($diff);

$groupExecutionDate->setTime($groupHour->format('H'), $groupHour->format('i'));
Expand Down Expand Up @@ -323,6 +361,7 @@ private function getExecutionDateTimeBetweenHours(

if (!isset($groupExecutionDate)) {
$groupExecutionDate = clone $compareFromDateTime;
$groupExecutionDate->setTimezone($this->getDefaultTimezone());
$groupExecutionDate->add($diff);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function testRescheduledToDueBeingBeforeSpecificHourRestriction()
->willReturn('America/Los_Angeles');
$contacts = new ArrayCollection([$contact1]);

$grouped = $interval->groupContactsByDate($event, $contacts, new \DateTime('2018-10-18 07:00:00', new \DateTimeZone('America/Los_Angeles')));
$grouped = $interval->groupContactsByDate($event, $contacts, new \DateTime('2018-10-18 14:00:00', new \DateTimeZone('UTC')));
$firstGroup = reset($grouped);

$executionDate = $firstGroup->getExecutionDate();
Expand Down Expand Up @@ -83,7 +83,7 @@ public function testRescheduledDueToBeingAfterSpecificHourRestriction()
->willReturn('America/Los_Angeles');
$contacts = new ArrayCollection([$contact1]);

$grouped = $interval->groupContactsByDate($event, $contacts, new \DateTime('2018-10-18 10:00:00', new \DateTimeZone('America/Los_Angeles')));
$grouped = $interval->groupContactsByDate($event, $contacts, new \DateTime('2018-10-18 16:00:00', new \DateTimeZone('UTC')));
$firstGroup = reset($grouped);

$executionDate = $firstGroup->getExecutionDate();
Expand Down Expand Up @@ -118,7 +118,7 @@ public function testNotRescheduledDueToSpecificHourRestriction()
->willReturn('America/New_York');
$contacts = new ArrayCollection([$contact1]);

$grouped = $interval->groupContactsByDate($event, $contacts, new \DateTime('2018-10-18 6:00:00', new \DateTimeZone('America/Los_Angeles')));
$grouped = $interval->groupContactsByDate($event, $contacts, new \DateTime('2018-10-18 14:00:00', new \DateTimeZone('UTC')));
$firstGroup = reset($grouped);
$executionDate = $firstGroup->getExecutionDate();

Expand Down Expand Up @@ -152,7 +152,7 @@ public function testRescheduledToSameDayDueToStartHourRestriction()
$contacts = new ArrayCollection([$contact1]);

$interval = $this->getInterval();
$scheduledExecutionDate = new \DateTime('2018-10-18 07:00', new \DateTimeZone('America/New_York'));
$scheduledExecutionDate = new \DateTime('2018-10-18 12:00', new \DateTimeZone('UTC'));
$grouped = $interval->groupContactsByDate($event, $contacts, $scheduledExecutionDate);

$firstGroup = reset($grouped);
Expand Down Expand Up @@ -183,11 +183,11 @@ public function testIsNotRescheduledDueToStartAndStopHourRestrictions()
$contact1->method('getId')
->willReturn(1);
$contact1->method('getTimezone')
->willReturn('America/New_York');
->willReturn('Etc/GMT+5');
$contacts = new ArrayCollection([$contact1]);

$interval = $this->getInterval();
$scheduledExecutionDate = new \DateTime('2018-10-18 11:00', new \DateTimeZone('America/New_York'));
$scheduledExecutionDate = new \DateTime('2018-10-18 16:00', new \DateTimeZone('UTC'));
$grouped = $interval->groupContactsByDate($event, $contacts, $scheduledExecutionDate);

$firstGroup = reset($grouped);
Expand Down Expand Up @@ -222,7 +222,7 @@ public function testRescheduledToNextDayDueToStopHourRestriction()
$contacts = new ArrayCollection([$contact1]);

$interval = $this->getInterval();
$scheduledExecutionDate = new \DateTime('2018-10-18 21:00', new \DateTimeZone('America/New_York'));
$scheduledExecutionDate = new \DateTime('2018-10-19 02:00', new \DateTimeZone('UTC'));
$grouped = $interval->groupContactsByDate($event, $contacts, $scheduledExecutionDate);

$firstGroup = reset($grouped);
Expand All @@ -238,7 +238,7 @@ public function testRescheduledDueDayOfWeekRestriction()
->willReturn(1);

// Thursday/4
$scheduledExecutionDate = new \DateTime('2018-10-18 10:00:00', new \DateTimeZone('America/New_York'));
$scheduledExecutionDate = new \DateTime('2018-10-18 15:00:00', new \DateTimeZone('UTC'));

$event = $this->createMock(Event::class);
$event->method('getTriggerMode')
Expand All @@ -262,7 +262,8 @@ public function testRescheduledDueDayOfWeekRestriction()
$firstGroup = reset($grouped);
$executionDate = $firstGroup->getExecutionDate();

$this->assertEquals('2018-10-20 10:00', $executionDate->format('Y-m-d H:i'));
$executionDate->setTimezone(new \DateTimeZone('UTC'));
$this->assertEquals('2018-10-20 15:00', $executionDate->format('Y-m-d H:i'));
}

public function testNotRescheduledDueDayOfWeekRestriction()
Expand All @@ -272,7 +273,7 @@ public function testNotRescheduledDueDayOfWeekRestriction()
->willReturn(1);

// Thursday/4
$scheduledExecutionDate = new \DateTime('2018-10-18 10:00:00', new \DateTimeZone('America/New_York'));
$scheduledExecutionDate = new \DateTime('2018-10-18 15:00:00', new \DateTimeZone('UTC'));

$event = $this->createMock(Event::class);
$event->method('getTriggerMode')
Expand All @@ -295,7 +296,8 @@ public function testNotRescheduledDueDayOfWeekRestriction()
$firstGroup = reset($grouped);
$executionDate = $firstGroup->getExecutionDate();

$this->assertEquals('2018-10-18 10:00', $executionDate->format('Y-m-d H:i'));
$executionDate->setTimezone(new \DateTimeZone('UTC'));
$this->assertEquals('2018-10-18 15:00', $executionDate->format('Y-m-d H:i'));
}

public function testRescheduledDueToSpecificHourAndDayOfWeekRestrictions()
Expand All @@ -305,7 +307,7 @@ public function testRescheduledDueToSpecificHourAndDayOfWeekRestrictions()
->willReturn(1);

// Thursday/4
$scheduledExecutionDate = new \DateTime('2018-10-18 10:00:00', new \DateTimeZone('America/New_York'));
$scheduledExecutionDate = new \DateTime('2018-10-18 15:00:00', new \DateTimeZone('UTC'));

$event = $this->createMock(Event::class);
$event->method('getTriggerMode')
Expand Down Expand Up @@ -342,7 +344,7 @@ public function testNotRescheduledDueToSpecificHourAndDayOfWeekRestrictions()
->willReturn(1);

// Thursday/4
$scheduledExecutionDate = new \DateTime('2018-10-18 10:00:00', new \DateTimeZone('America/New_York'));
$scheduledExecutionDate = new \DateTime('2018-10-18 15:00:00', new \DateTimeZone('UTC'));

$event = $this->createMock(Event::class);
$event->method('getTriggerMode')
Expand Down Expand Up @@ -379,7 +381,7 @@ public function testRescheduledDueToStartEndHoursAndDayOfWeekRestrictions()
->willReturn(1);

// Thursday/4
$scheduledExecutionDate = new \DateTime('2018-10-18 9:00:00', new \DateTimeZone('America/New_York'));
$scheduledExecutionDate = new \DateTime('2018-10-18 14:00:00', new \DateTimeZone('UTC'));

$event = $this->createMock(Event::class);
$event->method('getTriggerMode')
Expand Down Expand Up @@ -416,7 +418,7 @@ public function testNotRescheduledDueToStartEndHoursAndDayOfWeekRestrictions()
->willReturn(1);

// Thursday/4
$scheduledExecutionDate = new \DateTime('2018-10-18 11:00:00', new \DateTimeZone('America/New_York'));
$scheduledExecutionDate = new \DateTime('2018-10-18 16:00:00', new \DateTimeZone('UTC'));

$event = $this->createMock(Event::class);
$event->method('getTriggerMode')
Expand All @@ -434,7 +436,7 @@ public function testNotRescheduledDueToStartEndHoursAndDayOfWeekRestrictions()
$contact1->method('getId')
->willReturn(1);
$contact1->method('getTimezone')
->willReturn('America/New_York');
->willReturn('Etc/GMT+5');
$contacts = new ArrayCollection([$contact1]);

$interval = $this->getInterval();
Expand All @@ -453,7 +455,7 @@ public function testRescheduledDueToStartEndHoursAndDayOfWeekRestrictionsWithOnl
->willReturn(1);

// Thursday/4
$scheduledExecutionDate = new \DateTime('2018-10-18 10:00:00', new \DateTimeZone('America/New_York'));
$scheduledExecutionDate = new \DateTime('2018-10-18 15:00:00', new \DateTimeZone('UTC'));

$event = $this->createMock(Event::class);
$event->method('getTriggerMode')
Expand All @@ -471,7 +473,7 @@ public function testRescheduledDueToStartEndHoursAndDayOfWeekRestrictionsWithOnl
$contact1->method('getId')
->willReturn(1);
$contact1->method('getTimezone')
->willReturn('America/New_York');
->willReturn('Etc/GMT+5');
$contacts = new ArrayCollection([$contact1]);

$interval = $this->getInterval();
Expand All @@ -490,7 +492,7 @@ public function testRescheduledToSameDayDueToStartEndHoursAndDayOfWeekRestrictio
->willReturn(1);

// Thursday/4
$scheduledExecutionDate = new \DateTime('2018-10-18 08:00:00', new \DateTimeZone('America/New_York'));
$scheduledExecutionDate = new \DateTime('2018-10-18 13:00:00', new \DateTimeZone('UTC'));

$event = $this->createMock(Event::class);
$event->method('getTriggerMode')
Expand Down Expand Up @@ -527,7 +529,7 @@ public function testRescheduledToNextDayDueToStartEndHoursAndDayOfWeekRestrictio
->willReturn(1);

// Thursday/4
$scheduledExecutionDate = new \DateTime('2018-10-18 21:00:00', new \DateTimeZone('America/New_York'));
$scheduledExecutionDate = new \DateTime('2018-10-19 02:00:00', new \DateTimeZone('UTC'));

$event = $this->createMock(Event::class);
$event->method('getTriggerMode')
Expand Down

0 comments on commit 4e1ad92

Please sign in to comment.