From c2f2798e4435813d6ce25f1d59aa9f32a8fadab1 Mon Sep 17 00:00:00 2001
From: Moritz Strohm <strohm@data-quest.de>
Date: Mon, 15 Aug 2022 11:18:06 +0000
Subject: [PATCH] do not remove assigned course dates when bulk-updating course
 groups, closes #1427

Closes #1427

Merge request studip/studip!890
---
 app/controllers/course/statusgroups.php | 14 ++++++++++----
 lib/models/Statusgruppen.php            | 25 ++++++++++++-------------
 2 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/app/controllers/course/statusgroups.php b/app/controllers/course/statusgroups.php
index fa5438600e5..4013c8c5f0c 100644
--- a/app/controllers/course/statusgroups.php
+++ b/app/controllers/course/statusgroups.php
@@ -1112,11 +1112,17 @@ class Course_StatusgroupsController extends AuthenticatedController
         $groups = Statusgruppen::findMany(Request::getArray('groups'));
 
         foreach ($groups as $g) {
-            Statusgruppen::createOrUpdate($g->id, $g->name,
-                $g->position, $this->course_id,
+            Statusgruppen::createOrUpdate(
+                $g->id,
+                $g->name,
+                $g->position,
+                $this->course_id,
                 Request::int('size', 0),
-                $g->selfassign, $g->selfassign_start, $g->selfassign_end,
-                false);
+                $g->selfassign,
+                $g->selfassign_start,
+                $g->selfassign_end,
+                false
+            );
         }
         PageLayout::postSuccess(_('Die Einstellungen der ausgewählten Gruppen wurden gespeichert.'));
         $this->relocate('course/statusgroups');
diff --git a/lib/models/Statusgruppen.php b/lib/models/Statusgruppen.php
index 03e57d2ab25..7520c975edd 100644
--- a/lib/models/Statusgruppen.php
+++ b/lib/models/Statusgruppen.php
@@ -109,15 +109,16 @@ class Statusgruppen extends SimpleORMap implements PrivacyObject
     /**
      * Creates or updates a statusgroup.
      *
-     * @param string $id                ID of an existing group or empty if new group
-     * @param string $name              group name
-     * @param int    $position          position or null if automatic position after other groups
-     * @param string $range_id          ID of the object this group belongs to
-     * @param int    $size              max number of members or 0 if unlimited
-     * @param int    $selfassign        may users join this group by themselves?
-     * @param int    $selfassign_start  group joining is possible starting at ...
-     * @param int    $makefolder        create a document folder assigned to this group?
-     * @param array  $dates             dates assigned to this group
+     * @param string      $id                ID of an existing group or empty if new group
+     * @param string      $name              group name
+     * @param int         $position          position or null if automatic position after other groups
+     * @param string      $range_id          ID of the object this group belongs to
+     * @param int         $size              max number of members or 0 if unlimited
+     * @param int         $selfassign        may users join this group by themselves?
+     * @param int         $selfassign_start  group joining is possible starting at ...
+     * @param int         $makefolder        create a document folder assigned to this group?
+     * @param array|null  $dates             dates assigned to this group. Defaults to null which means already assigned
+     *                                       dates are not changed.
      * @return Statusgruppen The saved statusgroup.
      * @throws Exception
      */
@@ -131,7 +132,7 @@ class Statusgruppen extends SimpleORMap implements PrivacyObject
         $selfassign_start,
         $selfassign_end,
         $makefolder,
-        $dates = []
+        $dates = null
     )
     {
         $group = new Statusgruppen($id);
@@ -145,10 +146,8 @@ class Statusgruppen extends SimpleORMap implements PrivacyObject
         $group->selfassign_end = $selfassign ? $selfassign_end : 0;
 
         // Set assigned dates.
-        if ($dates) {
+        if (isset($dates)) {
             $group->dates = CourseDate::findMany($dates);
-        } else {
-            $group->dates = [];
         }
 
         $group->store();
-- 
GitLab