diff options
| author | Moritz Strohm <strohm@data-quest.de> | 2024-12-03 15:20:59 +0000 |
|---|---|---|
| committer | Moritz Strohm <strohm@data-quest.de> | 2024-12-03 15:20:59 +0000 |
| commit | 2835b3b966dc60ebcf85e7bb77be9d85e24d9920 (patch) | |
| tree | e2580e6295d48672af1142ec751dd5a1a3e0c049 /db | |
| parent | 60c88b927ed3d9409660832d16dadb527bd4506c (diff) | |
added GUI improvements to schedule, re #4421
Merge request studip/studip!3578
Diffstat (limited to 'db')
| -rw-r--r-- | db/migrations/6.0.13_alter_schedule_table.php | 4 | ||||
| -rw-r--r-- | db/migrations/6.0.35_new_schedule_improvements.php | 75 |
2 files changed, 77 insertions, 2 deletions
diff --git a/db/migrations/6.0.13_alter_schedule_table.php b/db/migrations/6.0.13_alter_schedule_table.php index d27bf81..ecd692f 100644 --- a/db/migrations/6.0.13_alter_schedule_table.php +++ b/db/migrations/6.0.13_alter_schedule_table.php @@ -16,7 +16,7 @@ class AlterScheduleTable extends Migration $db->exec( "ALTER TABLE `schedule_entries` - DROP COLUMN color, + RENAME COLUMN color TO colour_id, CHANGE COLUMN start start_time SMALLINT(6) NOT NULL, CHANGE COLUMN end end_time SMALLINT(6) NOT NULL, CHANGE COLUMN day dow TINYINT(1) NOT NULL, @@ -51,7 +51,7 @@ class AlterScheduleTable extends Migration $db->exec( "ALTER TABLE `schedule_entries` - ADD COLUMN color TINYINT(4) NULL DEFAULT NULL, + RENAME COLUMN colour_id TO color, CHANGE COLUMN start_time start SMALLINT(6) NOT NULL, CHANGE COLUMN end_time end SMALLINT(6) NOT NULL, CHANGE COLUMN dow day TINYINT(1) NOT NULL, diff --git a/db/migrations/6.0.35_new_schedule_improvements.php b/db/migrations/6.0.35_new_schedule_improvements.php new file mode 100644 index 0000000..2a038b9 --- /dev/null +++ b/db/migrations/6.0.35_new_schedule_improvements.php @@ -0,0 +1,75 @@ +<?php + + +class NewScheduleImprovements extends Migration +{ + public function description() + { + return 'A bugfix migration to add colours to personal schedule entries again and to migrate schedule configurations.'; + } + + protected function up() + { + $db = DBManager::get(); + $db->exec( + "ALTER TABLE `schedule_entries` + ADD COLUMN IF NOT EXISTS `colour_id` TINYINT(3) NOT NULL DEFAULT 0" + ); + + //Migrate the content of schedule configuration entries: + + $fetch_stmt = $db->prepare( + "SELECT `range_id`, `value` + FROM `config_values` + WHERE `field` = 'SCHEDULE_SETTINGS'" + ); + $update_stmt = $db->prepare( + "UPDATE `config_values` + SET `value` = :new_value, `chdate` = UNIX_TIMESTAMP() + WHERE `field` = 'SCHEDULE_SETTINGS' + AND `range_id` = :range_id" + ); + $delete_stmt = $db->prepare( + "DELETE FROM `config_values` + WHERE `field` = 'SCHEDULE_SETTINGS' + AND `range_id` = :range_id" + ); + + $fetch_stmt->execute(); + while ($row = $fetch_stmt->fetch(PDO::FETCH_ASSOC)) { + $old_config = json_decode($row['value'], true); + if (is_array($old_config)) { + //Convert the configuration: + $new_config = [ + 'start_time' => sprintf('%02u:00', $old_config['glb_start_time']), + 'end_time' => sprintf('%02u:00', $old_config['glb_end_time']), + 'semester_id' => $old_config['semester_id'] + ]; + if (count($old_config['glb_days']) === 7) { + $new_config['weekdays'] = 7; + } else { + $new_config['weekdays'] = 5; + } + //Convert the visible days array: + $visible_days = []; + if (is_array($old_config['glb_days'])) { + foreach ($old_config['glb_days'] as $day) { + if ($day == 0) { + $visible_days[] = 7; + } else { + $visible_days[] = (int) $day; + } + } + } + $new_config['visible_days'] = $visible_days; + $update_stmt->execute([ + 'range_id' => $row['range_id'], + 'new_value' => json_encode($new_config) + ]); + } else { + //Delete the configuration: + $delete_stmt->execute(['range_id' => $old_config['range_id']]); + } + } + } +} |
