aboutsummaryrefslogtreecommitdiff
path: root/db/migrations/1.235_tic8335_paper_related_topics.php
blob: 086f6d34698dd7ad43de8d9e728e2586e7b1239f (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
<?php
/**
 * This migration adds the required database column that allows teachers to
 * flag a topic as "paper related" ("Hausarbeit/Referat") and create groups
 * especially for these topics.
 *
 * @author  Jan-Hendrik Willms <tleilax+studip@gmail.com>
 * @license GPL2 or any later version
 * @since   Stud.IP 4.2
 */
class Tic8335PaperRelatedTopics extends Migration
{
    public function up()
    {
        if ($this->hasColumn()) {
            return;
        }

        $query = "ALTER TABLE `themen`
                    ADD COLUMN `paper_related` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0 AFTER `priority`";
        DBManager::get()->exec($query);
    }

    public function down()
    {
        if (!$this->hasColumn()) {
            return;
        }

        $query = "ALTER TABLE `themen` DROP COLUMN `paper_related`";
        DBManager::get()->exec($query);
    }

    private function hasColumn()
    {
        $query = "SHOW COLUMNS FROM `themen`";
        $columns = DBManager::get()->fetchFirst($query);

        return in_array('paper_related', $columns);
    }
}