1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Function to upgrade tool_courserating.
|
|
|
19 |
*
|
|
|
20 |
* @package tool_courserating
|
|
|
21 |
* @category upgrade
|
|
|
22 |
* @copyright 2022 Marina Glancy <marina.glancy@gmail.com>
|
|
|
23 |
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
/**
|
|
|
27 |
* Function to upgrade tool_courserating.
|
|
|
28 |
*
|
|
|
29 |
* @param int $oldversion the version we are upgrading from
|
|
|
30 |
* @return bool result
|
|
|
31 |
*/
|
|
|
32 |
function xmldb_tool_courserating_upgrade($oldversion) {
|
|
|
33 |
global $CFG, $DB;
|
|
|
34 |
$dbman = $DB->get_manager();
|
|
|
35 |
|
|
|
36 |
if ($oldversion < 2022111300) {
|
|
|
37 |
|
|
|
38 |
// Define index avgrating (not unique) to be dropped form tool_courserating_summary.
|
|
|
39 |
$table = new xmldb_table('tool_courserating_summary');
|
|
|
40 |
$index = new xmldb_index('avgrating', XMLDB_INDEX_NOTUNIQUE, ['avgrating']);
|
|
|
41 |
|
|
|
42 |
// Conditionally launch drop index avgrating.
|
|
|
43 |
if ($dbman->index_exists($table, $index)) {
|
|
|
44 |
$dbman->drop_index($table, $index);
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
// Changing nullability of field avgrating on table tool_courserating_summary to null.
|
|
|
48 |
$table = new xmldb_table('tool_courserating_summary');
|
|
|
49 |
$field = new xmldb_field('avgrating', XMLDB_TYPE_NUMBER, '10, 2', null, null, null, null, 'cntall');
|
|
|
50 |
|
|
|
51 |
// Launch change of nullability for field avgrating.
|
|
|
52 |
$dbman->change_field_notnull($table, $field);
|
|
|
53 |
|
|
|
54 |
$DB->execute('UPDATE {tool_courserating_summary} SET avgrating = NULL WHERE cntall = 0');
|
|
|
55 |
|
|
|
56 |
// Define index avgrating (not unique) to be added to tool_courserating_summary.
|
|
|
57 |
$table = new xmldb_table('tool_courserating_summary');
|
|
|
58 |
$index = new xmldb_index('avgrating', XMLDB_INDEX_NOTUNIQUE, ['avgrating']);
|
|
|
59 |
|
|
|
60 |
// Conditionally launch add index avgrating.
|
|
|
61 |
if (!$dbman->index_exists($table, $index)) {
|
|
|
62 |
$dbman->add_index($table, $index);
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
// Courserating savepoint reached.
|
|
|
66 |
upgrade_plugin_savepoint(true, 2022111300, 'tool', 'courserating');
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
return true;
|
|
|
70 |
}
|