Gitlab CSE Unil

upgrade.php 8.65 KB
Newer Older
M. Chardon's avatar
init  
M. Chardon committed
1
<?php
M. Chardon's avatar
M. Chardon committed
2

M. Chardon's avatar
init  
M. Chardon committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

/**
 * Upgrade code for the feedback_editpdfplus module.
 *
 * @package   assignfeedback_editpdfplus
 * @copyright 2013 Jerome Mouneyrac
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
defined('MOODLE_INTERNAL') || die();

27
28
use assignfeedback_editpdfplus\type_tool;

M. Chardon's avatar
init  
M. Chardon committed
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
 * EditPDF upgrade code
 * @param int $oldversion
 * @return bool
 */
function xmldb_assignfeedback_editpdfplus_upgrade($oldversion) {
    global $CFG, $DB;

    $dbman = $DB->get_manager();

    // Moodle v3.0.0 release upgrade line.
    if ($oldversion < 2016021600) {

        // Define table assignfeedback_editpdfplus_queue to be created.
        $table = new xmldb_table('assignfeedback_editpp_queue');

        // Adding fields to table assignfeedback_editpp_queue.
        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
        $table->add_field('submissionid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
        $table->add_field('submissionattempt', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);

        // Adding keys to table assignfeedback_editpp_queue.
        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));

        // Conditionally launch create table for assignfeedback_editpp_queue.
        if (!$dbman->table_exists($table)) {
            $dbman->create_table($table);
        }

        // Editpdf savepoint reached.
59
        upgrade_plugin_savepoint(true, 2016021600, 'assignfeedback', 'editpdfplus');
M. Chardon's avatar
init  
M. Chardon committed
60
61
    }

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
    // Automatically generated Moodle v3.2.0 release upgrade line.
    if ($oldversion < 2017022700) {

        // Get orphaned, duplicate files and delete them.
        $fs = get_file_storage();
        $sqllike = $DB->sql_like("filename", "?");
        $where = "component='assignfeedback_editpdfplus' AND filearea = 'importhtml' AND " . $sqllike;
        $filerecords = $DB->get_records_select("files", $where, ["onlinetext-%"]);
        foreach ($filerecords as $filerecord) {
            $file = $fs->get_file_instance($filerecord);
            $file->delete();
        }

        // Editpdf savepoint reached.
        upgrade_plugin_savepoint(true, 2017022700, 'assignfeedback', 'editpdfplus');
    }

79
80
81
82
83
84
85
    if ($oldversion < 2017071202) {

        $table = new xmldb_table('assignfeedback_editpp_typet');
        $field = new xmldb_field('configurable', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, 1);
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
86

87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
        $record1 = $DB->get_record('assignfeedback_editpp_typet', array('label' => 'highlight'), '*', MUST_EXIST);
        $typeTool1 = new type_tool($record1);
        $typeTool1->configurable = 0;
        $DB->update_record('assignfeedback_editpp_typet', $typeTool1);
        $record2 = $DB->get_record('assignfeedback_editpp_typet', array('label' => 'oval'), '*', MUST_EXIST);
        $typeTool2 = new type_tool($record2);
        $typeTool2->configurable = 0;
        $DB->update_record('assignfeedback_editpp_typet', $typeTool2);
        $record3 = $DB->get_record('assignfeedback_editpp_typet', array('label' => 'rectangle'), '*', MUST_EXIST);
        $typeTool3 = new type_tool($record3);
        $typeTool3->configurable = 0;
        $DB->update_record('assignfeedback_editpp_typet', $typeTool3);
        $record4 = $DB->get_record('assignfeedback_editpp_typet', array('label' => 'line'), '*', MUST_EXIST);
        $typeTool4 = new type_tool($record4);
        $typeTool4->configurable = 0;
        $DB->update_record('assignfeedback_editpp_typet', $typeTool4);
        $record5 = $DB->get_record('assignfeedback_editpp_typet', array('label' => 'pen'), '*', MUST_EXIST);
        $typeTool5 = new type_tool($record5);
        $typeTool5->configurable = 0;
        $DB->update_record('assignfeedback_editpp_typet', $typeTool5);

        // Editpdf savepoint reached.
        upgrade_plugin_savepoint(true, 2017071202, 'assignfeedback', 'editpdfplus');
    }
111

112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
    if ($oldversion < 2017081306) {
        $sql = "UPDATE {assignfeedback_editpp_typet}
                   SET color = :htmlcolor
                 WHERE color = :textcolor";
        // Update query params.
        $params = [
            'htmlcolor' => '#FF0000',
            'textcolor' => 'red'
        ];
        // Execute DB update for assign instances.
        $DB->execute($sql, $params);
        $sql = "UPDATE {assignfeedback_editpp_tool}
                   SET colors = :htmlcolor
                 WHERE colors = :textcolor";
        // Update query params.
        $params = [
            'htmlcolor' => '#FFA500',
            'textcolor' => 'orange'
        ];
        // Execute DB update for assign instances.
        $DB->execute($sql, $params);
        $sql = "UPDATE {assignfeedback_editpp_tool}
                   SET colors = :htmlcolor
                 WHERE colors = :textcolor";
        // Update query params.
        $params = [
            'htmlcolor' => '#008000',
            'textcolor' => 'green'
        ];
        // Execute DB update for assign instances.
        $DB->execute($sql, $params);
        $sql = "UPDATE {assignfeedback_editpp_tool}
                   SET colors = :htmlcolor
                 WHERE colors = :textcolor";
        // Update query params.
        $params = [
            'htmlcolor' => '#0000FF',
            'textcolor' => 'blue'
        ];
        // Execute DB update for assign instances.
        $DB->execute($sql, $params);
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213

        // Editpdf savepoint reached.
        upgrade_plugin_savepoint(true, 2017081306, 'assignfeedback', 'editpdfplus');
    }

    if ($oldversion < 2017081601) {
        $table = new xmldb_table('assignfeedback_editpp_typet');
        $field = new xmldb_field('configurable_cartridge', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, 1);
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        $field = new xmldb_field('configurable_cartridge_color', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, 1);
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        $field = new xmldb_field('configurable_color', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, 1);
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        $field = new xmldb_field('configurable_texts', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, 1);
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }
        $field = new xmldb_field('configurable_question', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, 1);
        if (!$dbman->field_exists($table, $field)) {
            $dbman->add_field($table, $field);
        }

        $sql = "UPDATE {assignfeedback_editpp_typet}
                   SET configurable_cartridge = 0,
                   configurable_cartridge_color = 0,
                   configurable_texts = 0,
                   configurable_question = 0
                 WHERE id = 3";
        // Update query params.
        $params = [];
        // Execute DB update for assign instances.
        $DB->execute($sql, $params);

        $sql = "UPDATE {assignfeedback_editpp_typet}
                   SET configurable_cartridge_color = 0,
                   configurable_color = 0
                 WHERE id = 4";
        // Execute DB update for assign instances.
        $DB->execute($sql, []);

        $sql = "UPDATE {assignfeedback_editpp_typet}
                   SET configurable_color = 0,
                   configurable_texts = 0
                 WHERE id = 7";
        // Execute DB update for assign instances.
        $DB->execute($sql, []);

        $sql = "UPDATE {assignfeedback_editpp_typet}
                   SET configurable_color = 0
                 WHERE id = 6";
        // Execute DB update for assign instances.
        $DB->execute($sql, []);

        // Editpdf savepoint reached.
        upgrade_plugin_savepoint(true, 2017081601, 'assignfeedback', 'editpdfplus');
214
    }
215

M. Chardon's avatar
init  
M. Chardon committed
216
217
    return true;
}