aboutsummaryrefslogtreecommitdiff
path: root/db/migrations/1.313_tic11044_admin_course_notices.php
blob: c5c1a2f93721939d4ed7ebc40c4f44b3b45ae91e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
class Tic11044AdminCourseNotices extends Migration
{
    public function description()
    {
        return 'TIC #11044: Adds neccessary datafield that stores notice for courses';
    }

    public function up()
    {
        $query = "SELECT 1 + MAX(`priority`)
                  FROM `datafields`
                  WHERE `object_type` = 'sem'";
        $priority = DBManager::get()->fetchColumn($query) ?: 0;

        $query = "INSERT IGNORE INTO `datafields` (
                    `datafield_id`, `name`,
                    `object_type`, `object_class`,
                    `edit_perms`, `view_perms`,
                    `system`, `priority`,
                    `mkdate`, `chdate`,
                    `type`, `typeparam`,
                    `is_required`, `is_userfilter`,
                    `description`
                  ) VALUES (
                      :id, 'Notiz zu einer Veranstaltung',
                      'sem', NULL,
                      'admin', 'admin',
                      1, :priority,
                      UNIX_TIMESTAMP(), UNIX_TIMESTAMP(),
                      'textarea', '',
                      0, 0,
                      'Enthält etwaige Notizen von Admins zu Veranstaltungen'
                  )";
        DBManager::get()->execute($query, [
            ':id'       => md5(uniqid(__CLASS__, true)),
            ':priority' => $priority,
        ]);
    }

    public function down()
    {
        $query = "DELETE `datafields`, `datafields_entries`
                  FROM `datafields`
                  LEFT JOIN `datafields_entries` USING (`datafield_id`)
                  WHERE `datafields`.`name` = 'Notiz zu einer Veranstaltung'";
        DBManager::get()->execute($query);
    }
}