aboutsummaryrefslogtreecommitdiff
path: root/db/migrations/1.245_tic7804_wiki_permissions.php
blob: 2f3ce321e02ff3f71dc014732b1149b948c6100d (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
<?php
class Tic7804WikiPermissions extends Migration
{
    public function description()
    {
        return 'add wiki page permissions';
    }

    public function up()
    {
        $db = DBManager::get();

        $stmt = $db->prepare('INSERT INTO config (field, value, type, `range`, mkdate, chdate, description)
                              VALUES (:name, :value, :type, :range, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), :description)');
        $stmt->execute([
            'name'        => 'WIKI_COURSE_EDIT_RESTRICTED',
            'description' => 'Legt fest, dass nur Teilnehmende ab Rechtestufe "tutor" das Wiki bearbeiten dürfen.',
            'range'       => 'course',
            'type'        => 'boolean',
            'value'       => '0'
        ]);

        // table for wiki page permissions settings
        $db->exec("CREATE TABLE wiki_page_config (
                    range_id CHAR(32) COLLATE latin1_bin NOT NULL,
                    keyword VARCHAR(255) COLLATE utf8mb4_bin NOT NULL,
                    read_restricted TINYINT(1) NOT NULL DEFAULT 0,
                    edit_restricted TINYINT(1) NOT NULL DEFAULT 0,
                    PRIMARY KEY (range_id, keyword)
                   ) ENGINE=InnoDB ROW_FORMAT=DYNAMIC");
    }

    public function down()
    {
        $db = DBManager::get();

        $db->exec('DROP TABLE wiki_page_config');

        $db->exec("DELETE config, config_values
                   FROM config
                   LEFT JOIN config_values USING (field)
                   WHERE field = 'WIKI_COURSE_EDIT_RESTRICTED'");
    }
}