Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(userstatus): trigger absence start job even for absences starting in the past #47183

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 24 additions & 19 deletions apps/dav/lib/Service/AbsenceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,27 +81,32 @@ public function createOrUpdateAbsence(
}

$now = $this->timeFactory->getTime();
if ($eventData->getStartDate() > $now) {
$this->jobList->scheduleAfter(
OutOfOfficeEventDispatcherJob::class,
$eventData->getStartDate(),
[
'id' => $absence->getId(),
'event' => OutOfOfficeEventDispatcherJob::EVENT_START,
],
);
}
if ($eventData->getEndDate() > $now) {
$this->jobList->scheduleAfter(
OutOfOfficeEventDispatcherJob::class,
$eventData->getEndDate(),
[
'id' => $absence->getId(),
'event' => OutOfOfficeEventDispatcherJob::EVENT_END,
],
);
if($eventData->getEndDate() < $now) {
// absence is in the past
return $absence;
}

// If the absence is for today the timestamp will be smaller than $now
// so run the job now if that is the case
$runJobAt = ($eventData->getStartDate() < $now) ? $now : $eventData->getStartDate();
$this->jobList->scheduleAfter(
OutOfOfficeEventDispatcherJob::class,
$runJobAt,
[
'id' => $absence->getId(),
'event' => OutOfOfficeEventDispatcherJob::EVENT_START,
],
);
Comment on lines +91 to +99
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$runJobAt = ($eventData->getStartDate() < $now) ? $now : $eventData->getStartDate();
$this->jobList->scheduleAfter(
OutOfOfficeEventDispatcherJob::class,
$runJobAt,
[
'id' => $absence->getId(),
'event' => OutOfOfficeEventDispatcherJob::EVENT_START,
],
);
$this->jobList->scheduleAfter(
OutOfOfficeEventDispatcherJob::class,
$eventData->getStartDate(),
[
'id' => $absence->getId(),
'event' => OutOfOfficeEventDispatcherJob::EVENT_START,
],
);

Can always use getStartDate() here as the job will be picked up if it is in the past IIRC.


$this->jobList->scheduleAfter(
OutOfOfficeEventDispatcherJob::class,
$eventData->getEndDate(),
[
'id' => $absence->getId(),
'event' => OutOfOfficeEventDispatcherJob::EVENT_END,
],
);

return $absence;
}

Expand Down
34 changes: 24 additions & 10 deletions apps/dav/tests/unit/Service/AbsenceServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,21 @@ public function testCreateAbsenceSchedulesOnlyEndJob() {
->method('getUserTimezone')
->with('user')
->willReturn($tz->getName());
$time = (new DateTimeImmutable('2023-01-07', $tz))->getTimestamp();
$this->timeFactory->expects(self::once())
->method('getTime')
->willReturn((new DateTimeImmutable('2023-01-07', $tz))->getTimestamp());
$this->jobList->expects(self::once())
->willReturn($time);
$this->jobList->expects(self::exactly(2))
->method('scheduleAfter')
->with(OutOfOfficeEventDispatcherJob::class, $endDate->getTimestamp() + 3600 * 23 + 59 * 60, [
'id' => '1',
'event' => OutOfOfficeEventDispatcherJob::EVENT_END,
->willReturnMap([
[OutOfOfficeEventDispatcherJob::class, $time, [
'id' => '1',
'event' => OutOfOfficeEventDispatcherJob::EVENT_START,
]],
[OutOfOfficeEventDispatcherJob::class, $endDate->getTimestamp() + 3600 * 23 + 59 * 60, [
'id' => '1',
'event' => OutOfOfficeEventDispatcherJob::EVENT_END,
]],
]);

$this->absenceService->createOrUpdateAbsence(
Expand Down Expand Up @@ -391,14 +398,21 @@ public function testUpdateSchedulesOnlyEndJob() {
->method('getUserTimezone')
->with('user')
->willReturn($tz->getName());
$time = (new DateTimeImmutable('2023-01-07', $tz))->getTimestamp();
$this->timeFactory->expects(self::once())
->method('getTime')
->willReturn((new DateTimeImmutable('2023-01-07', $tz))->getTimestamp());
$this->jobList->expects(self::once())
->willReturn($time);
$this->jobList->expects(self::exactly(2))
->method('scheduleAfter')
->with(OutOfOfficeEventDispatcherJob::class, $endDate->getTimestamp() + 23 * 3600 + 59 * 60, [
'id' => '1',
'event' => OutOfOfficeEventDispatcherJob::EVENT_END,
->willReturnMap([
[OutOfOfficeEventDispatcherJob::class, $time, [
'id' => '1',
'event' => OutOfOfficeEventDispatcherJob::EVENT_START,
]],
[OutOfOfficeEventDispatcherJob::class, $endDate->getTimestamp() + 3600 * 23 + 59 * 60, [
'id' => '1',
'event' => OutOfOfficeEventDispatcherJob::EVENT_END,
]],
]);

$this->absenceService->createOrUpdateAbsence(
Expand Down
Loading