From c6503d3bfc7e82841c7d706abe65378059f651f7 Mon Sep 17 00:00:00 2001
From: Moritz Strohm <strohm@data-quest.de>
Date: Fri, 1 Oct 2021 17:07:46 +0200
Subject: [PATCH 1/5] SeminarCycleDate: modify booking instead of deleting it
 when the date time range is smaller than the booking time range

---
 lib/models/SeminarCycleDate.class.php | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/lib/models/SeminarCycleDate.class.php b/lib/models/SeminarCycleDate.class.php
index eb877360094..18e111f5b2c 100644
--- a/lib/models/SeminarCycleDate.class.php
+++ b/lib/models/SeminarCycleDate.class.php
@@ -344,7 +344,19 @@ class SeminarCycleDate extends SimpleORMap
                     ($date->date < $tos || $date->end_time > $toe || $old_cycle->weekday != $this->weekday)) {
 
                 if (!is_null($date->room_booking)) {
-                    $date->room_booking->delete();
+                    //Check if the time range of the date has decreased and did not exceed the
+                    //boundaries of the existing room booking. In that case, the room booking is shortened.
+                    if ($date->date >= $date->room_booking->begin && $date->end_time <= $date->room_booking->end) {
+                        //The room booking must be shortened.
+                        $date->room_booking->begin = $date->date;
+                        $date->room_booking->end = $date->end_time;
+                        if ($date->room_booking->isDirty()) {
+                            $date->room_booking->store();
+                        }
+                    } else {
+                        //The room booking must be deleted.
+                        $date->room_booking->delete();
+                    }
                 }
             }
 
-- 
GitLab


From 6d94aa28b8562ca82a7e32881882f1945890afb4 Mon Sep 17 00:00:00 2001
From: Moritz Strohm <strohm@data-quest.de>
Date: Wed, 6 Oct 2021 17:25:57 +0200
Subject: [PATCH 2/5] fixed check for shortened course dates

---
 lib/models/SeminarCycleDate.class.php | 28 ++++++++++++---------------
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/lib/models/SeminarCycleDate.class.php b/lib/models/SeminarCycleDate.class.php
index 18e111f5b2c..31dc7b906b4 100644
--- a/lib/models/SeminarCycleDate.class.php
+++ b/lib/models/SeminarCycleDate.class.php
@@ -340,22 +340,18 @@ class SeminarCycleDate extends SimpleORMap
             $date->date = mktime(date('G', strtotime($this->start_time)), date('i', strtotime($this->start_time)), 0, date('m', $tos), date('d', $tos), date('Y', $tos)) + $day * 24 * 60 * 60;
             $date->end_time = mktime(date('G', strtotime($this->end_time)), date('i', strtotime($this->end_time)), 0, date('m', $toe), date('d', $toe), date('Y', $toe)) + $day * 24 * 60 * 60;
 
-            if ($date instanceof CourseDate &&
-                    ($date->date < $tos || $date->end_time > $toe || $old_cycle->weekday != $this->weekday)) {
-
-                if (!is_null($date->room_booking)) {
-                    //Check if the time range of the date has decreased and did not exceed the
-                    //boundaries of the existing room booking. In that case, the room booking is shortened.
-                    if ($date->date >= $date->room_booking->begin && $date->end_time <= $date->room_booking->end) {
-                        //The room booking must be shortened.
-                        $date->room_booking->begin = $date->date;
-                        $date->room_booking->end = $date->end_time;
-                        if ($date->room_booking->isDirty()) {
-                            $date->room_booking->store();
-                        }
-                    } else {
-                        //The room booking must be deleted.
-                        $date->room_booking->delete();
+            if ($date instanceof CourseDate && !is_null($date->room_booking)) {
+                //Check if the time range of the date has decreased and did not exceed the
+                //boundaries of the existing room booking. In that case, the room booking is shortened.
+                if ($date->date < $tos || $date->end_time > $toe) {
+                    //The room booking must be deleted.
+                    $date->room_booking->delete();
+                } else {
+                    //The room booking must be shortened.
+                    $date->room_booking->begin = $date->date;
+                    $date->room_booking->end = $date->end_time;
+                    if ($date->room_booking->isDirty()) {
+                        $date->room_booking->store();
                     }
                 }
             }
-- 
GitLab


From ae1d8830622aa8c088ee7361a95d5fdfebb52df6 Mon Sep 17 00:00:00 2001
From: Moritz Strohm <strohm@data-quest.de>
Date: Fri, 1 Oct 2021 17:07:46 +0200
Subject: [PATCH 3/5] SeminarCycleDate: modify booking instead of deleting it
 when the date time range is smaller than the booking time range

---
 lib/models/SeminarCycleDate.class.php | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/lib/models/SeminarCycleDate.class.php b/lib/models/SeminarCycleDate.class.php
index eb877360094..18e111f5b2c 100644
--- a/lib/models/SeminarCycleDate.class.php
+++ b/lib/models/SeminarCycleDate.class.php
@@ -344,7 +344,19 @@ class SeminarCycleDate extends SimpleORMap
                     ($date->date < $tos || $date->end_time > $toe || $old_cycle->weekday != $this->weekday)) {
 
                 if (!is_null($date->room_booking)) {
-                    $date->room_booking->delete();
+                    //Check if the time range of the date has decreased and did not exceed the
+                    //boundaries of the existing room booking. In that case, the room booking is shortened.
+                    if ($date->date >= $date->room_booking->begin && $date->end_time <= $date->room_booking->end) {
+                        //The room booking must be shortened.
+                        $date->room_booking->begin = $date->date;
+                        $date->room_booking->end = $date->end_time;
+                        if ($date->room_booking->isDirty()) {
+                            $date->room_booking->store();
+                        }
+                    } else {
+                        //The room booking must be deleted.
+                        $date->room_booking->delete();
+                    }
                 }
             }
 
-- 
GitLab


From f7217e8bc42986382041583fe9c5ba2cff2eb1e8 Mon Sep 17 00:00:00 2001
From: Moritz Strohm <strohm@data-quest.de>
Date: Wed, 6 Oct 2021 17:25:57 +0200
Subject: [PATCH 4/5] fixed check for shortened course dates

---
 lib/models/SeminarCycleDate.class.php | 28 ++++++++++++---------------
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/lib/models/SeminarCycleDate.class.php b/lib/models/SeminarCycleDate.class.php
index 18e111f5b2c..31dc7b906b4 100644
--- a/lib/models/SeminarCycleDate.class.php
+++ b/lib/models/SeminarCycleDate.class.php
@@ -340,22 +340,18 @@ class SeminarCycleDate extends SimpleORMap
             $date->date = mktime(date('G', strtotime($this->start_time)), date('i', strtotime($this->start_time)), 0, date('m', $tos), date('d', $tos), date('Y', $tos)) + $day * 24 * 60 * 60;
             $date->end_time = mktime(date('G', strtotime($this->end_time)), date('i', strtotime($this->end_time)), 0, date('m', $toe), date('d', $toe), date('Y', $toe)) + $day * 24 * 60 * 60;
 
-            if ($date instanceof CourseDate &&
-                    ($date->date < $tos || $date->end_time > $toe || $old_cycle->weekday != $this->weekday)) {
-
-                if (!is_null($date->room_booking)) {
-                    //Check if the time range of the date has decreased and did not exceed the
-                    //boundaries of the existing room booking. In that case, the room booking is shortened.
-                    if ($date->date >= $date->room_booking->begin && $date->end_time <= $date->room_booking->end) {
-                        //The room booking must be shortened.
-                        $date->room_booking->begin = $date->date;
-                        $date->room_booking->end = $date->end_time;
-                        if ($date->room_booking->isDirty()) {
-                            $date->room_booking->store();
-                        }
-                    } else {
-                        //The room booking must be deleted.
-                        $date->room_booking->delete();
+            if ($date instanceof CourseDate && !is_null($date->room_booking)) {
+                //Check if the time range of the date has decreased and did not exceed the
+                //boundaries of the existing room booking. In that case, the room booking is shortened.
+                if ($date->date < $tos || $date->end_time > $toe) {
+                    //The room booking must be deleted.
+                    $date->room_booking->delete();
+                } else {
+                    //The room booking must be shortened.
+                    $date->room_booking->begin = $date->date;
+                    $date->room_booking->end = $date->end_time;
+                    if ($date->room_booking->isDirty()) {
+                        $date->room_booking->store();
                     }
                 }
             }
-- 
GitLab


From c1987c54409ca1018db05003a9e41d0a99081bd8 Mon Sep 17 00:00:00 2001
From: Moritz Strohm <strohm@data-quest.de>
Date: Thu, 7 Oct 2021 12:21:37 +0200
Subject: [PATCH 5/5] removed isDirty call

---
 lib/models/SeminarCycleDate.class.php | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/lib/models/SeminarCycleDate.class.php b/lib/models/SeminarCycleDate.class.php
index 31dc7b906b4..4daef1e0ac8 100644
--- a/lib/models/SeminarCycleDate.class.php
+++ b/lib/models/SeminarCycleDate.class.php
@@ -350,9 +350,7 @@ class SeminarCycleDate extends SimpleORMap
                     //The room booking must be shortened.
                     $date->room_booking->begin = $date->date;
                     $date->room_booking->end = $date->end_time;
-                    if ($date->room_booking->isDirty()) {
-                        $date->room_booking->store();
-                    }
+                    $date->room_booking->store();
                 }
             }
 
-- 
GitLab