aboutsummaryrefslogtreecommitdiff
path: root/db/migrations/5.5.9_extend_cw_certificates.php
blob: ed05beb77dabd3a0c27e019948579d8f12b21beb (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
<?php

final class ExtendCwCertificates extends Migration
{
    use DatabaseMigrationTrait;

    public function description()
    {
        return 'Provide global config entry for Courseware certificates and add a fileref_id to the ' .
            'cw_certificates table to track which certificate was generated';
    }

    protected function up()
    {
        // Create global config entry for (de-)activating Courseware certificate and reminder functionality.
        DBManager::get()->execute("INSERT IGNORE INTO `config`
            (`field`, `value`, `type`, `range`, `section`, `mkdate`, `chdate`, `description`)
            VALUES
            (:field, :value, :type, 'global', '', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), :description)",
            [
                'field' => 'COURSEWARE_CERTIFICATES_ENABLE',
                'value' => 1,
                'type' => 'boolean',
                'description' => 'Schaltet Courseware-Zertifikate, -Erinnerungen und -Fortschrittsrücksetzung ein oder aus'
            ]
        );

        if (!$this->columnExists('cw_certificates', 'fileref_id')) {
            DBManager::get()->execute(
                "ALTER TABLE `cw_certificates` ADD `fileref_id` CHAR(32) NULL DEFAULT NULL COLLATE latin1_bin AFTER `unit_id`"
            );
        }
    }

    protected function down()
    {
        if ($this->columnExists('cw_certificates', 'fileref_id')) {
            DBManager::get()->execute("ALTER TABLE `cw_certificates` DROP `fileref_id`");
        }

        DBManager::get()->execute("DELETE FROM `config_values` WHERE `field` = :field",
            ['field' => 'COURSEWARE_CERTIFICATES_ENABLE']);
        DBManager::get()->execute("DELETE FROM `config` WHERE `field` = :field",
            ['field' => 'COURSEWARE_CERTIFICATES_ENABLE']);
    }
}