From 43e85a9a757d2e17122988944f06d58621b6d2a8 Mon Sep 17 00:00:00 2001
From: David Siegfried <david.siegfried@uni-vechta.de>
Date: Fri, 15 Mar 2024 15:40:30 +0000
Subject: [PATCH] fixes #2735

Closes #2735

Merge request studip/studip!2670
---
 .../5.1.54_fix_single_date_logging.php        | 24 +++++++++++++++++++
 lib/models/CourseDate.class.php               |  8 +++----
 lib/models/LogEvent.php                       |  1 +
 lib/raumzeit/SingleDate.class.php             |  4 ++--
 4 files changed, 31 insertions(+), 6 deletions(-)
 create mode 100644 db/migrations/5.1.54_fix_single_date_logging.php

diff --git a/db/migrations/5.1.54_fix_single_date_logging.php b/db/migrations/5.1.54_fix_single_date_logging.php
new file mode 100644
index 00000000000..d35c20ae5ef
--- /dev/null
+++ b/db/migrations/5.1.54_fix_single_date_logging.php
@@ -0,0 +1,24 @@
+<?php
+
+final class FixSingleDateLogging extends Migration
+{
+    public function description()
+    {
+        return 'Fix broken SingleDate-Logging';
+    }
+
+    public function up()
+    {
+        DBManager::get()->exec("UPDATE `log_actions` SET `info_template`= '%user hat in %sem(%affected) den Einzeltermin %singledate(%coaffected) geändert.' WHERE `name` = 'SINGLEDATE_CHANGE_TIME'");
+        DBManager::get()->exec("UPDATE `log_actions` SET `info_template`= '%user hat in %sem(%affected) den Einzeltermin %singledate(%coaffected) hinzugefügt' WHERE `name` = 'SEM_ADD_SINGLEDATE'");
+
+        DBManager::get()->exec("
+            UPDATE `log_events`
+            SET `dbg_info` = `info`, `info` = `coaffected_range_id`, `coaffected_range_id` = null
+            WHERE `action_id` IN (
+                SELECT `action_id` FROM `log_actions` WHERE `name` IN ('SINGLEDATE_CHANGE_TIME', 'SEM_ADD_SINGLEDATE')
+            )
+        ");
+    }
+
+}
diff --git a/lib/models/CourseDate.class.php b/lib/models/CourseDate.class.php
index 2a5b77e848a..f6e165742f3 100644
--- a/lib/models/CourseDate.class.php
+++ b/lib/models/CourseDate.class.php
@@ -387,12 +387,12 @@ class CourseDate extends SimpleORMap implements PrivacyObject, Event
     protected function cbStudipLog($type)
     {
         if (!$this->metadate_id) {
-            if ($type == 'after_create') {
-                StudipLog::log('SEM_ADD_SINGLEDATE', $this->range_id, $this->getFullname());
+            if ($type === 'after_create') {
+                StudipLog::log('SEM_ADD_SINGLEDATE', $this->range_id, $this->id, $this->getFullName());
             }
-            if ($type == 'before_store' && !$this->isNew() && ($this->isFieldDirty('date') || $this->isFieldDirty('end_time'))) {
+            if ($type === 'before_store' && !$this->isNew() && ($this->isFieldDirty('date') || $this->isFieldDirty('end_time'))) {
                 $old_entry = self::build($this->content_db);
-                StudipLog::log('SINGLEDATE_CHANGE_TIME', $this->range_id, $this->getFullname(), $old_entry->getFullname() . ' -> ' . $this->getFullname());
+                StudipLog::log('SINGLEDATE_CHANGE_TIME', $this->range_id, $this->id, $old_entry->getFullName() . ' -> ' . $this->getFullName());
             }
         }
     }
diff --git a/lib/models/LogEvent.php b/lib/models/LogEvent.php
index 8be1f74b840..782157a5841 100644
--- a/lib/models/LogEvent.php
+++ b/lib/models/LogEvent.php
@@ -111,6 +111,7 @@ class LogEvent extends SimpleORMap implements PrivacyObject
             '/%user\(%coaffected\)/',
             '/%user/',
             '/%singledate\(%affected\)/',
+            '/%singledate\(%coaffected\)/',
             '/%semester\(%coaffected\)/',
             '/%plugin\(%coaffected\)/',
             '/%group\(%coaffected\)/',
diff --git a/lib/raumzeit/SingleDate.class.php b/lib/raumzeit/SingleDate.class.php
index f9980924425..82a89db6852 100644
--- a/lib/raumzeit/SingleDate.class.php
+++ b/lib/raumzeit/SingleDate.class.php
@@ -147,9 +147,9 @@ class SingleDate
                 $after = $this->toString();
                 // logging
                 if ($before) {
-                    StudipLog::log("SINGLEDATE_CHANGE_TIME", $this->range_id, $before, $before . ' -> ' . $after);
+                    StudipLog::log('SINGLEDATE_CHANGE_TIME', $this->range_id, $this->id, $before . ' -> ' . $after);
                 } else {
-                    StudipLog::log("SEM_ADD_SINGLEDATE", $this->range_id, $after);
+                    StudipLog::log('SEM_ADD_SINGLEDATE', $this->range_id, $this->id, $after);
                 }
 
                 return true;
-- 
GitLab