Skip to content
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Versioning](https://semver.org/spec/v2.0.0.html).

- [PR-412](https://github.com/itk-dev/os2loop/pull/412)
- Fixed bug in toc
- Fixed mail notifications not being sent to users whose last notification
time was stored by Drupal 10 (regression since 1.3.0)

## [1.5.2] - 2026-11-18

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function sendNotifications(DrupalDateTime $now) {
// loading until actually needed.
$messages = NULL;
foreach ($users as $user) {
if ($this->getUserLastNotifiedAt($user) > $startTime) {
if ($this->getUserLastNotifiedAt($user) > $startTime->getTimestamp()) {
continue;
}
if (NULL === $messages) {
Expand Down Expand Up @@ -204,15 +204,26 @@ public function userInsert(EntityInterface $entity) {
* @param \Drupal\user\UserInterface $user
* The user.
*
* @return \Drupal\Core\Datetime\DrupalDateTime
* The last notification time.
* @return int
* The last notification time as a Unix timestamp (0 if never notified).
*/
private function getUserLastNotifiedAt(UserInterface $user) {
private function getUserLastNotifiedAt(UserInterface $user): int {
if (NULL === $this->userLastNotifiedAt) {
$this->userLastNotifiedAt = $this->userData->get(static::MODULE, NULL, self::USER_LAST_NOTIFIED_AT);
}

return $this->userLastNotifiedAt[$user->id()] ?? new DrupalDateTime('@0');
$value = $this->userLastNotifiedAt[$user->id()] ?? NULL;

// Older versions stored a serialized DrupalDateTime object. Comparing such
// objects with < or > compares their properties one by one (not the
// actual time), and objects serialized by an older Drupal core (with a
// different set of properties) always compare as "later", i.e. users were
// never notified again. Therefore, we always work on timestamps.
if ($value instanceof DrupalDateTime || $value instanceof \DateTimeInterface) {
return (int) $value->getTimestamp();
}

return is_numeric($value) ? (int) $value : 0;
}

/**
Expand All @@ -224,7 +235,8 @@ private function getUserLastNotifiedAt(UserInterface $user) {
* The notification time.
*/
private function setUserLastNotifiedAt(UserInterface $user, DrupalDateTime $notifiedAt) {
$this->userData->set(static::MODULE, $user->id(), self::USER_LAST_NOTIFIED_AT, $notifiedAt);
// Store a plain timestamp (cf. getUserLastNotifiedAt()).
$this->userData->set(static::MODULE, $user->id(), self::USER_LAST_NOTIFIED_AT, $notifiedAt->getTimestamp());
}

/**
Expand Down
Loading