From 13121792b56c52483dc3fd7e41e2063bb1dca595 Mon Sep 17 00:00:00 2001
From: Moritz Strohm <strohm@data-quest.de>
Date: Fri, 22 Mar 2024 14:05:25 +0100
Subject: [PATCH] CalendarDateAssignment::cbSendDateDeletedMail: name the user
 that deleted the date instead of the editor

---
 lib/models/calendar/CalendarDateAssignment.class.php | 7 +++++--
 locale/de/LC_MAILS/date_deleted.php                  | 2 +-
 locale/en/LC_MAILS/date_deleted.php                  | 2 +-
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/lib/models/calendar/CalendarDateAssignment.class.php b/lib/models/calendar/CalendarDateAssignment.class.php
index 4e084c2436e..18cd6101cb3 100644
--- a/lib/models/calendar/CalendarDateAssignment.class.php
+++ b/lib/models/calendar/CalendarDateAssignment.class.php
@@ -102,7 +102,9 @@ class CalendarDateAssignment extends SimpleORMap implements Event
         if ($this->suppress_mails) {
             return;
         }
-        if ($this->range_id === $this->calendar_date->editor_id) {
+        $actor = User::findCurrent() ?? $this->calendar_date->editor;
+        if ($this->range_id === $actor->id) {
+            //The user who deleted the date shall not get notified about this.
             return;
         }
         if (!$this->calendar_date || !$this->user) {
@@ -116,12 +118,13 @@ class CalendarDateAssignment extends SimpleORMap implements Event
         $lang_path = getUserLanguagePath($this->range_id);
         $template = $template_factory->open($lang_path . '/LC_MAILS/date_deleted.php');
         $template->set_attribute('date', $this->calendar_date);
+        $template->set_attribute('actor', $actor);
         $template->set_attribute('receiver', $this->user);
         $mail_text = $template->render();
         Message::send(
             '____%system%____',
             [$this->user->username],
-            sprintf(_('%s hat einen Termin im Kalender gelöscht'), $this->calendar_date->editor->getFullName()),
+            sprintf(_('%s hat einen Termin im Kalender gelöscht'), $actor->getFullName()),
             $mail_text
         );
 
diff --git a/locale/de/LC_MAILS/date_deleted.php b/locale/de/LC_MAILS/date_deleted.php
index 0ff6ef80a9d..0f319d37f88 100644
--- a/locale/de/LC_MAILS/date_deleted.php
+++ b/locale/de/LC_MAILS/date_deleted.php
@@ -1,4 +1,4 @@
-<?= $date->editor->getFullName() ?> hat einen Termin im Kalender gelöscht.
+<?= $actor->getFullName() ?> hat einen Termin im Kalender gelöscht.
 
 <?= $this->render_partial(__DIR__ . '/_date_information', [
     'date' => $date,
diff --git a/locale/en/LC_MAILS/date_deleted.php b/locale/en/LC_MAILS/date_deleted.php
index b4bafd66c40..91ef248c32d 100644
--- a/locale/en/LC_MAILS/date_deleted.php
+++ b/locale/en/LC_MAILS/date_deleted.php
@@ -1,4 +1,4 @@
-<?= $date->editor->getFullName() ?> has deleted a date in the calendar.
+<?= $actor->getFullName() ?> has deleted a date in the calendar.
 
 <?= $this->render_partial(__DIR__ . '/_date_information', [
     'date' => $date,
-- 
GitLab