diff options
Diffstat (limited to 'apps/dav/lib/BackgroundJob/UserStatusAutomation.php')
-rw-r--r-- | apps/dav/lib/BackgroundJob/UserStatusAutomation.php | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/apps/dav/lib/BackgroundJob/UserStatusAutomation.php b/apps/dav/lib/BackgroundJob/UserStatusAutomation.php index 8edc28c9a69..43fccbf233e 100644 --- a/apps/dav/lib/BackgroundJob/UserStatusAutomation.php +++ b/apps/dav/lib/BackgroundJob/UserStatusAutomation.php @@ -92,7 +92,7 @@ class UserStatusAutomation extends TimedJob { $isCurrentlyAvailable = false; $nextPotentialToggles = []; - $now = new \DateTime('now'); + $now = $this->time->getDateTime(); $lastMidnight = (clone $now)->setTime(0, 0); $vObject = Reader::read($property); @@ -105,9 +105,16 @@ class UserStatusAutomation extends TimedJob { foreach ($availables as $available) { /** @var Available $available */ if ($available->name === 'AVAILABLE') { - /** @var \DateTimeInterface $effectiveStart */ - /** @var \DateTimeInterface $effectiveEnd */ - [$effectiveStart, $effectiveEnd] = $available->getEffectiveStartEnd(); + /** @var \DateTimeImmutable $originalStart */ + /** @var \DateTimeImmutable $originalEnd */ + [$originalStart, $originalEnd] = $available->getEffectiveStartEnd(); + + // Little shenanigans to fix the automation on the day the rules were adjusted + // Otherwise the $originalStart would match rules for Thursdays on a Friday, etc. + // So we simply wind back a week and then fastForward to the next occurrence + // since today's midnight, which then also accounts for the week days. + $effectiveStart = \DateTime::createFromImmutable($originalStart)->sub(new \DateInterval('P7D')); + $effectiveEnd = \DateTime::createFromImmutable($originalEnd)->sub(new \DateInterval('P7D')); try { $it = new RRuleIterator((string) $available->RRULE, $effectiveStart); @@ -150,8 +157,10 @@ class UserStatusAutomation extends TimedJob { $this->setLastRunToNextToggleTime($userId, $nextAutomaticToggle - 1); if ($isCurrentlyAvailable) { + $this->logger->debug('User is currently available, reverting DND status if applicable'); $this->manager->revertUserStatus($userId, IUserStatus::MESSAGE_AVAILABILITY, IUserStatus::DND); } else { + $this->logger->debug('User is currently NOT available, reverting call status if applicable and then setting DND'); // The DND status automation is more important than the "Away - In call" so we also restore that one if it exists. $this->manager->revertUserStatus($userId, IUserStatus::MESSAGE_CALL, IUserStatus::AWAY); $this->manager->setUserStatus($userId, IUserStatus::MESSAGE_AVAILABILITY, IUserStatus::DND, true); |