aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/BackgroundJob/UserStatusAutomation.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/lib/BackgroundJob/UserStatusAutomation.php')
-rw-r--r--apps/dav/lib/BackgroundJob/UserStatusAutomation.php31
1 files changed, 15 insertions, 16 deletions
diff --git a/apps/dav/lib/BackgroundJob/UserStatusAutomation.php b/apps/dav/lib/BackgroundJob/UserStatusAutomation.php
index e17fa604ab9..027b3349802 100644
--- a/apps/dav/lib/BackgroundJob/UserStatusAutomation.php
+++ b/apps/dav/lib/BackgroundJob/UserStatusAutomation.php
@@ -28,18 +28,21 @@ use Sabre\VObject\Reader;
use Sabre\VObject\Recur\RRuleIterator;
class UserStatusAutomation extends TimedJob {
- public function __construct(private ITimeFactory $timeFactory,
+ public function __construct(
+ private ITimeFactory $timeFactory,
private IDBConnection $connection,
private IJobList $jobList,
private LoggerInterface $logger,
private IManager $manager,
private IConfig $config,
private IAvailabilityCoordinator $coordinator,
- private IUserManager $userManager) {
+ private IUserManager $userManager,
+ ) {
parent::__construct($timeFactory);
- // Interval 0 might look weird, but the last_checked is always moved
- // to the next time we need this and then it's 0 seconds ago.
+ // interval = 0 might look odd, but it's intentional. last_run is set to
+ // the user's next available time, so the job runs immediately when
+ // that time comes.
$this->setInterval(0);
}
@@ -55,14 +58,14 @@ class UserStatusAutomation extends TimedJob {
$userId = $argument['userId'];
$user = $this->userManager->get($userId);
- if($user === null) {
+ if ($user === null) {
return;
}
$ooo = $this->coordinator->getCurrentOutOfOfficeData($user);
$continue = $this->processOutOfOfficeData($user, $ooo);
- if($continue === false) {
+ if ($continue === false) {
return;
}
@@ -196,20 +199,18 @@ class UserStatusAutomation extends TimedJob {
return;
}
- if(!$hasDndForOfficeHours) {
+ if (!$hasDndForOfficeHours) {
// Office hours are not set to DND, so there is nothing to do.
return;
}
- $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->logger->debug('User is currently NOT available, reverting call and meeting status if applicable and then setting DND');
$this->manager->setUserStatus($userId, IUserStatus::MESSAGE_AVAILABILITY, IUserStatus::DND, true);
$this->logger->debug('User status automation ran');
}
private function processOutOfOfficeData(IUser $user, ?IOutOfOfficeData $ooo): bool {
- if(empty($ooo)) {
+ if (empty($ooo)) {
// Reset the user status if the absence doesn't exist
$this->logger->debug('User has no OOO period in effect, reverting DND status if applicable');
$this->manager->revertUserStatus($user->getUID(), IUserStatus::MESSAGE_OUT_OF_OFFICE, IUserStatus::DND);
@@ -217,12 +218,12 @@ class UserStatusAutomation extends TimedJob {
return true;
}
- if(!$this->coordinator->isInEffect($ooo)) {
+ if (!$this->coordinator->isInEffect($ooo)) {
// Reset the user status if the absence is (no longer) in effect
$this->logger->debug('User has no OOO period in effect, reverting DND status if applicable');
$this->manager->revertUserStatus($user->getUID(), IUserStatus::MESSAGE_OUT_OF_OFFICE, IUserStatus::DND);
- if($ooo->getStartDate() > $this->time->getTime()) {
+ if ($ooo->getStartDate() > $this->time->getTime()) {
// Set the next run to take place at the start of the ooo period if it is in the future
// This might be overwritten if there is an availability setting, but we can't determine
// if this is the case here
@@ -232,10 +233,8 @@ class UserStatusAutomation extends TimedJob {
}
$this->logger->debug('User is currently in an OOO period, reverting other automated status and setting OOO DND status');
- // Revert both a possible 'CALL - away' and 'office hours - DND' status
- $this->manager->revertUserStatus($user->getUID(), IUserStatus::MESSAGE_CALL, IUserStatus::DND);
- $this->manager->revertUserStatus($user->getUID(), IUserStatus::MESSAGE_AVAILABILITY, IUserStatus::DND);
$this->manager->setUserStatus($user->getUID(), IUserStatus::MESSAGE_OUT_OF_OFFICE, IUserStatus::DND, true, $ooo->getShortMessage());
+
// Run at the end of an ooo period to return to availability / regular user status
// If it's overwritten by a custom status in the meantime, there's nothing we can do about it
$this->setLastRunToNextToggleTime($user->getUID(), $ooo->getEndDate());