Skip to content
Snippets Groups Projects
Commit cff86c5c authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

align open groups config for my courses and notifications, fixes #328

parent b58c7b56
No related branches found
No related tags found
No related merge requests found
...@@ -180,8 +180,10 @@ class Settings_NotificationController extends Settings_SettingsController ...@@ -180,8 +180,10 @@ class Settings_NotificationController extends Settings_SettingsController
*/ */
public function open_action($id) public function open_action($id)
{ {
$open = $this->config->MY_COURSES_OPEN_GROUPS; $open = $this->config->MY_COURSES_OPEN_GROUPS;
$open[$id] = true; if (!in_array($id, $open)) {
$open[] = $id;
}
$this->config->store('MY_COURSES_OPEN_GROUPS', $open); $this->config->store('MY_COURSES_OPEN_GROUPS', $open);
$this->redirect('settings/notification'); $this->redirect('settings/notification');
...@@ -195,7 +197,7 @@ class Settings_NotificationController extends Settings_SettingsController ...@@ -195,7 +197,7 @@ class Settings_NotificationController extends Settings_SettingsController
public function close_action($id) public function close_action($id)
{ {
$open = $this->config->MY_COURSES_OPEN_GROUPS; $open = $this->config->MY_COURSES_OPEN_GROUPS;
unset($open[$id]); $open = array_diff($open, [$id]);
$this->config->store('MY_COURSES_OPEN_GROUPS', $open); $this->config->store('MY_COURSES_OPEN_GROUPS', $open);
$this->redirect('settings/notification'); $this->redirect('settings/notification');
......
<?php
final class FixMyCoursesGroupConfig extends Migration
{
public function up()
{
ConfigValue::findEachBySQL(
function ($value) {
$groups = json_decode($value->value, true);
$changed = false;
foreach ($groups as $index => $val) {
if ($val === true) {
unset($groups[$index]);
$groups[] = $index;
$changed = true;
}
}
if ($changed) {
$value->value = json_encode($groups);
$value->store();
}
},
'field = ?',
['MY_COURSES_OPEN_GROUPS']
);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment