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 |
* Upgrade logic.
|
|
|
19 |
*
|
|
|
20 |
* @package mod_bigbluebuttonbn
|
|
|
21 |
* @copyright 2010 onwards, Blindside Networks Inc
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
* @author Jesus Federico (jesus [at] blindsidenetworks [dt] com)
|
|
|
24 |
* @author Fred Dixon (ffdixon [at] blindsidenetworks [dt] com)
|
|
|
25 |
*/
|
|
|
26 |
|
|
|
27 |
use mod_bigbluebuttonbn\plugin;
|
|
|
28 |
use mod_bigbluebuttonbn\local\config;
|
|
|
29 |
use mod_bigbluebuttonbn\task\upgrade_recordings_task;
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
* Performs data migrations and updates on upgrade.
|
|
|
33 |
*
|
|
|
34 |
* @param int $oldversion
|
|
|
35 |
* @return bool
|
|
|
36 |
*/
|
|
|
37 |
function xmldb_bigbluebuttonbn_upgrade($oldversion = 0) {
|
|
|
38 |
global $DB;
|
|
|
39 |
$dbman = $DB->get_manager();
|
|
|
40 |
|
|
|
41 |
// Automatically generated Moodle v4.1.0 release upgrade line.
|
|
|
42 |
// Put any upgrade step following this.
|
|
|
43 |
if ($oldversion < 2023011800) {
|
|
|
44 |
// Define index course_bbbid_ix (not unique) to be added to bigbluebuttonbn_logs.
|
|
|
45 |
$table = new xmldb_table('bigbluebuttonbn_logs');
|
|
|
46 |
$index = new xmldb_index('course_bbbid_ix', XMLDB_INDEX_NOTUNIQUE, ['courseid', 'bigbluebuttonbnid']);
|
|
|
47 |
|
|
|
48 |
// Conditionally launch add index course_bbbid_ix.
|
|
|
49 |
if (!$dbman->index_exists($table, $index)) {
|
|
|
50 |
$dbman->add_index($table, $index);
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
// Bigbluebuttonbn savepoint reached.
|
|
|
54 |
upgrade_mod_savepoint(true, 2023011800, 'bigbluebuttonbn');
|
|
|
55 |
}
|
|
|
56 |
if ($oldversion < 2023021300) {
|
|
|
57 |
// Define field lockedlayout to be dropped from bigbluebuttonbn.
|
|
|
58 |
$table = new xmldb_table('bigbluebuttonbn');
|
|
|
59 |
$field = new xmldb_field('lockedlayout');
|
|
|
60 |
|
|
|
61 |
// Conditionally launch drop field lockedlayout.
|
|
|
62 |
if ($dbman->field_exists($table, $field)) {
|
|
|
63 |
$dbman->drop_field($table, $field);
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
// Bigbluebuttonbn savepoint reached.
|
|
|
67 |
upgrade_mod_savepoint(true, 2023021300, 'bigbluebuttonbn');
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
// Automatically generated Moodle v4.2.0 release upgrade line.
|
|
|
71 |
// Put any upgrade step following this.
|
|
|
72 |
|
|
|
73 |
// Automatically generated Moodle v4.3.0 release upgrade line.
|
|
|
74 |
// Put any upgrade step following this.
|
|
|
75 |
|
|
|
76 |
// Automatically generated Moodle v4.4.0 release upgrade line.
|
|
|
77 |
// Put any upgrade step following this.
|
|
|
78 |
|
|
|
79 |
return true;
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
/**
|
|
|
83 |
* Generic helper function for adding or changing a field in a table.
|
|
|
84 |
*
|
|
|
85 |
* @param database_manager $dbman
|
|
|
86 |
* @param string $tablename
|
|
|
87 |
* @param string $fieldname
|
|
|
88 |
* @param array $fielddefinition
|
|
|
89 |
* @deprecated please do not use this anymore (historical migrations)
|
|
|
90 |
*/
|
|
|
91 |
function xmldb_bigbluebuttonbn_add_change_field(
|
|
|
92 |
database_manager $dbman,
|
|
|
93 |
string $tablename,
|
|
|
94 |
string $fieldname,
|
|
|
95 |
array $fielddefinition
|
|
|
96 |
) {
|
|
|
97 |
$table = new xmldb_table($tablename);
|
|
|
98 |
$field = new xmldb_field($fieldname);
|
|
|
99 |
$field->set_attributes(
|
|
|
100 |
$fielddefinition['type'],
|
|
|
101 |
$fielddefinition['precision'],
|
|
|
102 |
$fielddefinition['unsigned'],
|
|
|
103 |
$fielddefinition['notnull'],
|
|
|
104 |
$fielddefinition['sequence'],
|
|
|
105 |
$fielddefinition['default'],
|
|
|
106 |
$fielddefinition['previous']
|
|
|
107 |
);
|
|
|
108 |
if (!$dbman->field_exists($table, $field)) {
|
|
|
109 |
$dbman->add_field($table, $field, true, true);
|
|
|
110 |
return;
|
|
|
111 |
}
|
|
|
112 |
// Drop key before if needed.
|
|
|
113 |
$fieldkey = new xmldb_key($fieldname, XMLDB_KEY_FOREIGN, [$fieldname], 'user', ['id']);
|
|
|
114 |
if ($dbman->find_key_name($table, $fieldkey)) {
|
|
|
115 |
$dbman->drop_key($table, $fieldkey);
|
|
|
116 |
}
|
|
|
117 |
$dbman->change_field_type($table, $field, true, true);
|
|
|
118 |
$dbman->change_field_precision($table, $field, true, true);
|
|
|
119 |
$dbman->change_field_notnull($table, $field, true, true);
|
|
|
120 |
$dbman->change_field_default($table, $field, true, true);
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
/**
|
|
|
124 |
* Generic helper function for adding index to a table.
|
|
|
125 |
*
|
|
|
126 |
* @param database_manager $dbman
|
|
|
127 |
* @param string $tablename
|
|
|
128 |
* @param string $indexname
|
|
|
129 |
* @param array $indexfields
|
|
|
130 |
* @param string|false|null $indextype
|
|
|
131 |
* @deprecated please do not use this anymore (historical migrations)
|
|
|
132 |
*/
|
|
|
133 |
function xmldb_bigbluebuttonbn_index_table(
|
|
|
134 |
database_manager $dbman,
|
|
|
135 |
string $tablename,
|
|
|
136 |
string $indexname,
|
|
|
137 |
array $indexfields,
|
|
|
138 |
$indextype = XMLDB_INDEX_NOTUNIQUE
|
|
|
139 |
) {
|
|
|
140 |
$table = new xmldb_table($tablename);
|
|
|
141 |
if (!$dbman->table_exists($table)) {
|
|
|
142 |
return;
|
|
|
143 |
}
|
|
|
144 |
$index = new xmldb_index($indexname, $indextype, $indexfields);
|
|
|
145 |
if ($dbman->index_exists($table, $index)) {
|
|
|
146 |
$dbman->drop_index($table, $index);
|
|
|
147 |
}
|
|
|
148 |
$dbman->add_index($table, $index, true, true);
|
|
|
149 |
}
|