aboutsummaryrefslogtreecommitdiff
path: root/db/migrations/5.3.11_courseware_cron_events.php
blob: 48dbfcf130a18627dd70f2db755144ea6bd27efb (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

require_once('lib/cronjobs/courseware.php');

class CoursewareCronEvents extends Migration
{
    public function description()
    {
        return 'Prepares database tables for storing timestamps of courseware cron events, ' .
            'like certificate sending and reminders.';
    }

    public function up()
    {
        // Create a table for certificates
        DBManager::get()->exec("CREATE TABLE IF NOT EXISTS `cw_certificates` (
            `id` CHAR(32) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL,
            `user_id` CHAR(32) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL,
            `course_id` CHAR(32) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL,
            `mkdate` INT(11) NOT NULL,
            PRIMARY KEY (`id`),
            INDEX index_user_id (`user_id`),
            INDEX index_course_id (`course_id`),
            INDEX index_user_ourse (`user_id`, `course_id`)
        )");

        CoursewareCronjob::register()->schedulePeriodic(41, 1)->activate();
    }

    public function down()
    {
        CoursewareCronjob::unregister();

        DBManager::get()->exec("DROP TABLE IF EXISTS `cw_certificates`");

        $fields = [
            'COURSEWARE_CERTIFICATE_SETTINGS',
            'COURSEWARE_REMINDER_SETTINGS',
            'COURSEWARE_RESET_PROGRESS_SETTINGS',
            'COURSEWARE_LAST_REMINDER',
            'COURSEWARE_LAST_PROGRESS_RESET'
        ];
        DBManager::get()->execute("DELETE FROM `config` WHERE `field` IN (:fields)",
            ['fields' => $fields]);
        DBManager::get()->execute("DELETE FROM `config_values` WHERE `field` IN (:fields)",
            ['fields' => $fields]);
    }

}