Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
 
1441 ariadna 41
    // Automatically generated Moodle v4.2.0 release upgrade line.
1 efrain 42
    // Put any upgrade step following this.
43
 
1441 ariadna 44
    // Automatically generated Moodle v4.3.0 release upgrade line.
45
    // Put any upgrade step following this.
46
 
47
    // Automatically generated Moodle v4.4.0 release upgrade line.
48
    // Put any upgrade step following this.
49
 
50
    if ($oldversion < 2024071900) {
51
 
52
        // Define field showpresentation to be added to bigbluebuttonbn.
53
        $table = new xmldb_table('bigbluebuttonbn');
54
        $field = new xmldb_field('showpresentation', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'guestpassword');
55
 
56
        // Conditionally launch add field showpresentation.
57
        if (!$dbman->field_exists($table, $field)) {
58
            $dbman->add_field($table, $field);
1 efrain 59
        }
60
 
61
        // Bigbluebuttonbn savepoint reached.
1441 ariadna 62
        upgrade_mod_savepoint(true, 2024071900, 'bigbluebuttonbn');
1 efrain 63
    }
1441 ariadna 64
 
65
    // Automatically generated Moodle v4.5.0 release upgrade line.
66
    // Put any upgrade step following this.
67
 
68
    if ($oldversion < 2025011000) {
69
 
70
        // Define field grade to be added to bigbluebuttonbn.
1 efrain 71
        $table = new xmldb_table('bigbluebuttonbn');
1441 ariadna 72
        $field = new xmldb_field('grade', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'showpresentation');
1 efrain 73
 
1441 ariadna 74
        // Conditionally launch add field grade.
75
        if (!$dbman->field_exists($table, $field)) {
76
            $dbman->add_field($table, $field);
1 efrain 77
        }
78
 
79
        // Bigbluebuttonbn savepoint reached.
1441 ariadna 80
        upgrade_mod_savepoint(true, 2025011000, 'bigbluebuttonbn');
1 efrain 81
    }
82
 
1441 ariadna 83
    // Automatically generated Moodle v5.0.0 release upgrade line.
1 efrain 84
    // Put any upgrade step following this.
85
 
86
    return true;
87
}
88
 
89
/**
90
 * Generic helper function for adding or changing a field in a table.
91
 *
92
 * @param database_manager $dbman
93
 * @param string $tablename
94
 * @param string $fieldname
95
 * @param array $fielddefinition
96
 * @deprecated  please do not use this anymore (historical migrations)
97
 */
98
function xmldb_bigbluebuttonbn_add_change_field(
99
    database_manager $dbman,
100
    string $tablename,
101
    string $fieldname,
102
    array $fielddefinition
103
) {
104
    $table = new xmldb_table($tablename);
105
    $field = new xmldb_field($fieldname);
106
    $field->set_attributes(
107
        $fielddefinition['type'],
108
        $fielddefinition['precision'],
109
        $fielddefinition['unsigned'],
110
        $fielddefinition['notnull'],
111
        $fielddefinition['sequence'],
112
        $fielddefinition['default'],
113
        $fielddefinition['previous']
114
    );
115
    if (!$dbman->field_exists($table, $field)) {
116
        $dbman->add_field($table, $field, true, true);
117
        return;
118
    }
119
    // Drop key before if needed.
120
    $fieldkey = new xmldb_key($fieldname, XMLDB_KEY_FOREIGN, [$fieldname], 'user', ['id']);
121
    if ($dbman->find_key_name($table, $fieldkey)) {
122
        $dbman->drop_key($table, $fieldkey);
123
    }
124
    $dbman->change_field_type($table, $field, true, true);
125
    $dbman->change_field_precision($table, $field, true, true);
126
    $dbman->change_field_notnull($table, $field, true, true);
127
    $dbman->change_field_default($table, $field, true, true);
128
}
129
 
130
/**
131
 * Generic helper function for adding index to a table.
132
 *
133
 * @param database_manager $dbman
134
 * @param string $tablename
135
 * @param string $indexname
136
 * @param array $indexfields
137
 * @param string|false|null $indextype
138
 * @deprecated please do not use this anymore (historical migrations)
139
 */
140
function xmldb_bigbluebuttonbn_index_table(
141
    database_manager $dbman,
142
    string $tablename,
143
    string $indexname,
144
    array $indexfields,
145
    $indextype = XMLDB_INDEX_NOTUNIQUE
146
) {
147
    $table = new xmldb_table($tablename);
148
    if (!$dbman->table_exists($table)) {
149
        return;
150
    }
151
    $index = new xmldb_index($indexname, $indextype, $indexfields);
152
    if ($dbman->index_exists($table, $index)) {
153
        $dbman->drop_index($table, $index);
154
    }
155
    $dbman->add_index($table, $index, true, true);
156
}