Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 400 and 403] [Versions 401 and 403] [Versions 402 and 403]

   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      if ($oldversion < 2015080605) {
  41          // Drop field description.
  42          $table5 = new xmldb_table('bigbluebuttonbn');
  43          $field4 = new xmldb_field('description');
  44          if ($dbman->field_exists($table5, $field4)) {
  45              $dbman->drop_field($table5, $field4, true, true);
  46          }
  47          // Change welcome, allow null.
  48          $fielddefinition = ['type' => XMLDB_TYPE_TEXT, 'precision' => null, 'unsigned' => null,
  49              'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => null, 'previous' => 'type'];
  50          xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'welcome',
  51              $fielddefinition);
  52          // Change userid definition in bigbluebuttonbn_log.
  53          $fielddefinition = ['type' => XMLDB_TYPE_INTEGER, 'precision' => '10', 'unsigned' => null,
  54              'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => null,
  55              'previous' => 'bigbluebuttonbnid'];
  56          xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn_log', 'userid',
  57              $fielddefinition);
  58          // No settings to migrate.
  59          // Update db version tag.
  60          upgrade_mod_savepoint(true, 2015080605, 'bigbluebuttonbn');
  61      }
  62      if ($oldversion < 2016011305) {
  63          // Define field type to be droped from bigbluebuttonbn.
  64          $table4 = new xmldb_table('bigbluebuttonbn');
  65          $field3 = new xmldb_field('type');
  66          if ($dbman->field_exists($table4, $field3)) {
  67              $dbman->drop_field($table4, $field3, true, true);
  68          }
  69          // Rename table bigbluebuttonbn_log to bigbluebuttonbn_logs.
  70          $table = new xmldb_table('bigbluebuttonbn_log');
  71          if ($dbman->table_exists($table)) {
  72              $dbman->rename_table($table, 'bigbluebuttonbn_logs', true, true);
  73          }
  74          // Rename field event to log in table bigbluebuttonbn_logs.
  75          $table1 = new xmldb_table('bigbluebuttonbn_logs');
  76          $field = new xmldb_field('event');
  77          if ($dbman->field_exists($table1, $field)) {
  78              $dbman->rename_field($table1, $field, 'log', true, true);
  79          }
  80          // No settings to migrate.
  81          // Update db version tag.
  82          upgrade_mod_savepoint(true, 2016011305, 'bigbluebuttonbn');
  83      }
  84      if ($oldversion < 2017101000) {
  85          // Drop field newwindow.
  86          $table3 = new xmldb_table('bigbluebuttonbn');
  87          $field2 = new xmldb_field('newwindow');
  88          if ($dbman->field_exists($table3, $field2)) {
  89              $dbman->drop_field($table3, $field2, true, true);
  90          }
  91          // Add field type.
  92          $fielddefinition = ['type' => XMLDB_TYPE_INTEGER, 'precision' => '2', 'unsigned' => null,
  93              'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => 'id'];
  94          xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'type',
  95              $fielddefinition);
  96          // Add field recordings_html.
  97          $fielddefinition = ['type' => XMLDB_TYPE_INTEGER, 'precision' => '1', 'unsigned' => null,
  98              'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => null];
  99          xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'recordings_html',
 100              $fielddefinition);
 101          // Add field recordings_deleted.
 102          $fielddefinition = ['type' => XMLDB_TYPE_INTEGER, 'precision' => '1', 'unsigned' => null,
 103              'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 1, 'previous' => null];
 104          xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'recordings_deleted',
 105              $fielddefinition);
 106          // Add field recordings_imported.
 107          $fielddefinition = ['type' => XMLDB_TYPE_INTEGER, 'precision' => '1', 'unsigned' => null,
 108              'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => null];
 109          xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'recordings_imported',
 110              $fielddefinition);
 111          // Drop field newwindow.
 112          $table2 = new xmldb_table('bigbluebuttonbn');
 113          $field1 = new xmldb_field('tagging');
 114          if ($dbman->field_exists($table2, $field1)) {
 115              $dbman->drop_field($table2, $field1, true, true);
 116          }
 117          // Migrate settings.
 118          unset_config('bigbluebuttonbn_recordingtagging_default', '');
 119          unset_config('bigbluebuttonbn_recordingtagging_editable', '');
 120          $cfgvalue = get_config('', 'bigbluebuttonbn_importrecordings_from_deleted_activities_enabled');
 121          set_config('bigbluebuttonbn_importrecordings_from_deleted_enabled', $cfgvalue, '');
 122          unset_config('bigbluebuttonbn_importrecordings_from_deleted_activities_enabled', '');
 123          $cfgvalue = get_config('', 'bigbluebuttonbn_moderator_default');
 124          set_config('bigbluebuttonbn_participant_moderator_default', $cfgvalue, '');
 125          unset_config('bigbluebuttonbn_moderator_default', '');
 126          // Update db version tag.
 127          upgrade_mod_savepoint(true, 2017101000, 'bigbluebuttonbn');
 128      }
 129      if ($oldversion < 2017101009) {
 130          // Add field recordings_preview.
 131          $fielddefinition = ['type' => XMLDB_TYPE_INTEGER, 'precision' => '1', 'unsigned' => null,
 132              'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => null];
 133          xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'recordings_preview',
 134              $fielddefinition);
 135          // Update db version tag.
 136          upgrade_mod_savepoint(true, 2017101009, 'bigbluebuttonbn');
 137      }
 138      if ($oldversion < 2017101010) {
 139          // Fix for CONTRIB-7221.
 140          if ($oldversion == 2017101003) {
 141              // A bug intorduced in 2017101003 causes new instances to be created without BBB passwords.
 142              // A workaround was put in place in version 2017101004 that was relabeled to 2017101005.
 143              // However, as the code was relocated to upgrade.php in version 2017101010, a new issue came up.
 144              // There is now a timeout error when the plugin is upgraded in large Moodle sites.
 145              // The script should only be considered when migrating from this version.
 146              $sql = "SELECT * FROM {bigbluebuttonbn} ";
 147              $sql .= "WHERE moderatorpass = ? OR viewerpass = ?";
 148              $instances = $DB->get_records_sql($sql, ['', '']);
 149              foreach ($instances as $instance) {
 150                  $instance->moderatorpass = plugin::random_password(12);
 151                  $instance->viewerpass = plugin::random_password(12, $instance->moderatorpass);
 152                  // Store passwords in the database.
 153                  $DB->update_record('bigbluebuttonbn', $instance);
 154              }
 155          }
 156          // Update db version tag.
 157          upgrade_mod_savepoint(true, 2017101010, 'bigbluebuttonbn');
 158      }
 159      if ($oldversion < 2017101012) {
 160          // Update field type (Fix for CONTRIB-7302).
 161          $fielddefinition = ['type' => XMLDB_TYPE_INTEGER, 'precision' => '2', 'unsigned' => null,
 162              'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => 'id'];
 163          xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'type',
 164              $fielddefinition);
 165          // Update field meetingid (Fix for CONTRIB-7302).
 166          $fielddefinition = ['type' => XMLDB_TYPE_CHAR, 'precision' => '255', 'unsigned' => null,
 167              'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => null, 'previous' => 'introformat'];
 168          xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'meetingid',
 169              $fielddefinition);
 170          // Update field recordings_imported (Fix for CONTRIB-7302).
 171          $fielddefinition = ['type' => XMLDB_TYPE_INTEGER, 'precision' => '1', 'unsigned' => null,
 172              'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => null];
 173          xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'recordings_imported',
 174              $fielddefinition);
 175          // Add field recordings_preview.(Fix for CONTRIB-7302).
 176          $fielddefinition = ['type' => XMLDB_TYPE_INTEGER, 'precision' => '1', 'unsigned' => null,
 177              'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => null];
 178          xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'recordings_preview',
 179              $fielddefinition);
 180          // Update db version tag.
 181          upgrade_mod_savepoint(true, 2017101012, 'bigbluebuttonbn');
 182      }
 183      if ($oldversion < 2017101015) {
 184          // Add field for client technology choice.
 185          $fielddefinition = ['type' => XMLDB_TYPE_INTEGER, 'precision' => '1', 'unsigned' => null,
 186              'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => null];
 187          xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'clienttype',
 188              $fielddefinition);
 189          // Update db version tag.
 190          upgrade_mod_savepoint(true, 2017101015, 'bigbluebuttonbn');
 191      }
 192      if ($oldversion < 2019042000) {
 193          // Add field for Mute on start feature.
 194          $fielddefinition = ['type' => XMLDB_TYPE_INTEGER, 'precision' => '1', 'unsigned' => null,
 195              'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => null];
 196          xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'muteonstart',
 197              $fielddefinition);
 198          // Add field for record all from start.
 199          $fielddefinition = ['type' => XMLDB_TYPE_INTEGER, 'precision' => '1', 'unsigned' => null,
 200              'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => null];
 201          xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'recordallfromstart',
 202              $fielddefinition);
 203          // Add field for record hide button.
 204          $fielddefinition = ['type' => XMLDB_TYPE_INTEGER, 'precision' => '1', 'unsigned' => null,
 205              'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => null];
 206          xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'recordhidebutton',
 207              $fielddefinition);
 208          // Update db version tag.
 209          upgrade_mod_savepoint(true, 2019042000, 'bigbluebuttonbn');
 210      }
 211      if ($oldversion < 2019101001) {
 212          // Add field for Completion with attendance.
 213          $fielddefinition = ['type' => XMLDB_TYPE_INTEGER, 'precision' => '9', 'unsigned' => null,
 214              'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => null];
 215          xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'completionattendance',
 216              $fielddefinition);
 217          // Add field for Completion with engagement through chats.
 218          $fielddefinition = ['type' => XMLDB_TYPE_INTEGER, 'precision' => '9', 'unsigned' => null,
 219              'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => null];
 220          xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'completionengagementchats',
 221              $fielddefinition);
 222          // Add field for Completion with engagement through talks.
 223          $fielddefinition = ['type' => XMLDB_TYPE_INTEGER, 'precision' => '9', 'unsigned' => null,
 224              'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => null];
 225          xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'completionengagementtalks',
 226              $fielddefinition);
 227          // Add field for Completion with engagement through raisehand.
 228          $fielddefinition = ['type' => XMLDB_TYPE_INTEGER, 'precision' => '9', 'unsigned' => null,
 229              'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => null];
 230          xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'completionengagementraisehand',
 231              $fielddefinition);
 232          // Add field for Completion with engagement through pollvotes.
 233          $fielddefinition = ['type' => XMLDB_TYPE_INTEGER, 'precision' => '9', 'unsigned' => null,
 234              'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => null];
 235          xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'completionengagementpollvotes',
 236              $fielddefinition);
 237          // Add field for Completion with engagement through emojis.
 238          $fielddefinition = ['type' => XMLDB_TYPE_INTEGER, 'precision' => '9', 'unsigned' => null,
 239              'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => null];
 240          xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'completionengagementemojis',
 241              $fielddefinition);
 242          // Add index to bigbluebuttonbn_logs (Fix for CONTRIB-8157).
 243          xmldb_bigbluebuttonbn_index_table($dbman, 'bigbluebuttonbn_logs', 'courseid',
 244              ['courseid']);
 245          xmldb_bigbluebuttonbn_index_table($dbman, 'bigbluebuttonbn_logs', 'log',
 246              ['log']);
 247          xmldb_bigbluebuttonbn_index_table($dbman, 'bigbluebuttonbn_logs', 'logrow',
 248              ['courseid', 'bigbluebuttonbnid', 'userid', 'log']);
 249          // Update db version tag.
 250          upgrade_mod_savepoint(true, 2019101001, 'bigbluebuttonbn');
 251      }
 252  
 253      if ($oldversion < 2019101002) {
 254  
 255          $fielddefinition = ['type' => XMLDB_TYPE_INTEGER, 'precision' => '1', 'unsigned' => null,
 256              'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => 'muteonstart'];
 257          xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'disablecam',
 258              $fielddefinition);
 259  
 260          $fielddefinition = ['type' => XMLDB_TYPE_INTEGER, 'precision' => '1', 'unsigned' => null,
 261              'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => 'disablecam'];
 262          xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'disablemic',
 263              $fielddefinition);
 264  
 265          $fielddefinition = ['type' => XMLDB_TYPE_INTEGER, 'precision' => '1', 'unsigned' => null,
 266              'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => 'disablemic'];
 267          xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'disableprivatechat',
 268              $fielddefinition);
 269  
 270          $fielddefinition = ['type' => XMLDB_TYPE_INTEGER, 'precision' => '1', 'unsigned' => null,
 271              'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => 'disableprivatechat'];
 272          xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'disablepublicchat',
 273              $fielddefinition);
 274  
 275          $fielddefinition = ['type' => XMLDB_TYPE_INTEGER, 'precision' => '1', 'unsigned' => null,
 276              'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => 'disablepublicchat'];
 277          xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'disablenote',
 278              $fielddefinition);
 279  
 280          $fielddefinition = ['type' => XMLDB_TYPE_INTEGER, 'precision' => '1', 'unsigned' => null,
 281              'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => 'disablenote'];
 282          xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'hideuserlist',
 283              $fielddefinition);
 284  
 285          $fielddefinition = ['type' => XMLDB_TYPE_INTEGER, 'precision' => '1', 'unsigned' => null,
 286              'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => 'hideuserlist'];
 287          xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'lockedlayout',
 288              $fielddefinition);
 289  
 290          $fielddefinition = ['type' => XMLDB_TYPE_INTEGER, 'precision' => '1', 'unsigned' => null,
 291              'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => 'lockedlayout'];
 292          xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'lockonjoin',
 293              $fielddefinition);
 294  
 295          $fielddefinition = ['type' => XMLDB_TYPE_INTEGER, 'precision' => '1', 'unsigned' => null,
 296              'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => 'lockonjoin'];
 297          xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'lockonjoinconfigurable',
 298              $fielddefinition);
 299  
 300          // Bigbluebuttonbn savepoint reached.
 301          upgrade_mod_savepoint(true, 2019101002, 'bigbluebuttonbn');
 302      }
 303  
 304      if ($oldversion < 2019101004) {
 305          // Add index to bigbluebuttonbn_logs (Leftover for CONTRIB-8157).
 306          xmldb_bigbluebuttonbn_index_table($dbman, 'bigbluebuttonbn_logs', 'userlog',
 307              ['userid', 'log']);
 308          // Bigbluebuttonbn savepoint reached.
 309          upgrade_mod_savepoint(true, 2019101004, 'bigbluebuttonbn');
 310      }
 311  
 312      if ($oldversion < 2021072905) {
 313          // Add table bigbluebuttonbn_recordings (CONTRIB-7994).
 314          // Define table bigbluebuttonbn_recordings to be created.
 315          $table = new xmldb_table('bigbluebuttonbn_recordings');
 316  
 317          // Adding fields to table bigbluebuttonbn_recordings.
 318          $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
 319          $table->add_field('courseid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
 320          $table->add_field('bigbluebuttonbnid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
 321          $table->add_field('groupid', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
 322          $table->add_field('recordingid', XMLDB_TYPE_CHAR, '64', null, XMLDB_NOTNULL, null, null);
 323          $table->add_field('headless', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0');
 324          $table->add_field('imported', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0');
 325          $table->add_field('state', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0');
 326          $table->add_field('recording', XMLDB_TYPE_TEXT, null, null, null, null, null);
 327          $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
 328          $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
 329          $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
 330  
 331          // Adding keys to table bigbluebuttonbn_recordings.
 332          $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
 333          $table->add_key('fk_bigbluebuttonbnid', XMLDB_KEY_FOREIGN, ['bigbluebuttonbnid'], 'bigbluebuttonbn', ['id']);
 334          $table->add_key('usermodified', XMLDB_KEY_FOREIGN, ['usermodified'], 'user', ['id']);
 335  
 336          // Adding indexes to table bigbluebuttonbn_recordings.
 337          $table->add_index('courseid', XMLDB_INDEX_NOTUNIQUE, ['courseid']);
 338          $table->add_index('recordingid', XMLDB_INDEX_NOTUNIQUE, ['recordingid']);
 339  
 340          // Conditionally launch create table for bigbluebuttonbn_recordings.
 341          if (!$dbman->table_exists($table)) {
 342              $dbman->create_table($table);
 343          }
 344          // Bigbluebuttonbn savepoint reached.
 345          upgrade_mod_savepoint(true, 2021072905, 'bigbluebuttonbn');
 346      }
 347      if ($oldversion < 2021072906) {
 348  
 349          // Rename field recording on table bigbluebuttonbn_recordings to remotedata, add new remotedatatstamp and status.
 350          $table = new xmldb_table('bigbluebuttonbn_recordings');
 351  
 352          $field = new xmldb_field('recording', XMLDB_TYPE_TEXT, null, null, null, null, null, 'state');
 353          // Launch rename field recording to remotedata.
 354          if ($dbman->field_exists($table, $field)) {
 355              $dbman->rename_field($table, $field, 'remotedata');
 356          }
 357          $field = new xmldb_field('remotedatatstamp', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
 358          // Conditionally launch add field remotedatatstamp.
 359          if (!$dbman->field_exists($table, $field)) {
 360              $dbman->add_field($table, $field);
 361          }
 362  
 363          // State is already used on remote bigbluebutton entity and has not the same semantic.
 364          $field = new xmldb_field('state', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'imported');
 365          // Launch rename field state to status.
 366          if ($dbman->field_exists($table, $field)) {
 367              $dbman->rename_field($table, $field, 'status');
 368          }
 369          // Bigbluebuttonbn savepoint reached.
 370          upgrade_mod_savepoint(true, 2021072906, 'bigbluebuttonbn');
 371      }
 372  
 373      if ($oldversion < 2021072907) {
 374          // Define field id to be dropped from bigbluebuttonbn_recordings.
 375          $table = new xmldb_table('bigbluebuttonbn_recordings');
 376          $remotedatatstamp = new xmldb_field('remotedatatstamp');
 377          $remotedata = new xmldb_field('remotedata', XMLDB_TYPE_TEXT, null, null, null, null, null, 'status');
 378          // Conditionally launch drop field remotedatatstamp.
 379          if ($dbman->field_exists($table, $remotedatatstamp)) {
 380              $dbman->drop_field($table, $remotedatatstamp);
 381          }
 382          // Launch rename field importeddata.
 383          if ($dbman->field_exists($table, $remotedata)) {
 384              $dbman->rename_field($table, $remotedata, 'importeddata');
 385          }
 386          // Bigbluebuttonbn savepoint reached.
 387          upgrade_mod_savepoint(true, 2021072907, 'bigbluebuttonbn');
 388      }
 389  
 390      if ($oldversion < 2021083100) {
 391          // Update the legacy notifications to use the legacy class which will be removed as per the deprecation policy.
 392          $DB->set_field('task_adhoc', 'classname', '\mod_bigbluebuttonbn\task\send_legacy_notification', [
 393              'component' => 'mod_bigbluebuttonbn',
 394              'classname' => '\mod_bigbluebuttonbn\task\send_notification',
 395          ]);
 396  
 397          // Bigbluebuttonbn savepoint reached.
 398          upgrade_mod_savepoint(true, 2021083100, 'bigbluebuttonbn');
 399      }
 400  
 401      if ($oldversion < 2021091408) {
 402          // Change BigBliueButton Server credentials to new defaults if test-install is being used.
 403          if (config::get('server_url') == 'http://test-install.blindsidenetworks.com/bigbluebutton/') {
 404              set_config('bigbluebuttonbn_server_url', config::DEFAULT_SERVER_URL);
 405              set_config('bigbluebuttonbn_shared_secret', config::DEFAULT_SHARED_SECRET);
 406          }
 407          // Bigbluebuttonbn savepoint reached.
 408          upgrade_mod_savepoint(true, 2021091408, 'bigbluebuttonbn');
 409      }
 410  
 411      if ($oldversion < 2022021601) {
 412          // Create adhoc task for upgrading of existing bigbluebuttonbn_logs related to recordings.
 413          upgrade_recordings_task::schedule_upgrade_per_meeting();
 414          upgrade_recordings_task::schedule_upgrade_per_meeting(true);
 415          // Bigbluebuttonbn savepoint reached.
 416          upgrade_mod_savepoint(true, 2022021601, 'bigbluebuttonbn');
 417      }
 418  
 419      // Automatically generated Moodle v4.0.0 release upgrade line.
 420      // Put any upgrade step following this.
 421  
 422      if ($oldversion < 2022050600) {
 423  
 424          set_config('bigbluebuttonbn_default_dpa_accepted', false);
 425  
 426          // If the default server configuration is used.
 427          if (config::get('server_url') === config::DEFAULT_SERVER_URL) {
 428              // Disable the BigBlueButton activity module.
 429              $DB->set_field('modules', 'visible', 0, ['name' => 'bigbluebuttonbn']);
 430  
 431              // Use an adhoc task to send a notification to inform the admin that the BigBlueButton activity module
 432              // has been disabled and they are required to confirm their acceptance of the data processing agreement
 433              // prior to re-enabling it.
 434              $notificationtask = new mod_bigbluebuttonbn\task\send_bigbluebutton_module_disabled_notification();
 435              core\task\manager::queue_adhoc_task($notificationtask);
 436          }
 437  
 438          // Bigbluebuttonbn savepoint reached.
 439          upgrade_mod_savepoint(true, 2022050600, 'bigbluebuttonbn');
 440      }
 441      if ($oldversion < 2022080400) {
 442  
 443          // Define field lockonjoin to be dropped from bigbluebuttonbn.
 444          $table = new xmldb_table('bigbluebuttonbn');
 445          $field = new xmldb_field('lockonjoin');
 446          // Conditionally launch drop field lockonjoin.
 447          if ($dbman->field_exists($table, $field)) {
 448              $dbman->drop_field($table, $field);
 449          }
 450          $field = new xmldb_field('lockonjoinconfigurable');
 451          // Conditionally launch drop field lockonjoinconfigurable.
 452          if ($dbman->field_exists($table, $field)) {
 453              $dbman->drop_field($table, $field);
 454          }
 455          // Bigbluebuttonbn savepoint reached.
 456          upgrade_mod_savepoint(true, 2022080400, 'bigbluebuttonbn');
 457      }
 458      if ($oldversion < 2022101900) {
 459          $table = new xmldb_table('bigbluebuttonbn');
 460  
 461          $field = new xmldb_field('guestallowed', XMLDB_TYPE_INTEGER, '2', null, null, null, '0', 'completionengagementemojis');
 462          // Conditionally launch add field guestallowed.
 463          if (!$dbman->field_exists($table, $field)) {
 464              $dbman->add_field($table, $field);
 465          }
 466  
 467          $field = new xmldb_field('mustapproveuser', XMLDB_TYPE_INTEGER, '2', null, null, null, '1', 'guestallowed');
 468          // Conditionally launch add field mustapproveuser.
 469          if (!$dbman->field_exists($table, $field)) {
 470              $dbman->add_field($table, $field);
 471          }
 472  
 473          $field = new xmldb_field('guestlinkuid', XMLDB_TYPE_CHAR, '1024', null, null, null, null, 'mustapproveuser');
 474          // Conditionally launch add field guestlinkuid.
 475          if (!$dbman->field_exists($table, $field)) {
 476              $dbman->add_field($table, $field);
 477          }
 478  
 479          $field = new xmldb_field('guestpassword', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'guestlinkuid');
 480          // Conditionally launch add field guestpassword.
 481          if (!$dbman->field_exists($table, $field)) {
 482              $dbman->add_field($table, $field);
 483          }
 484          upgrade_mod_savepoint(true, 2022101900, 'bigbluebuttonbn');
 485      }
 486      // Automatically generated Moodle v4.1.0 release upgrade line.
 487      // Put any upgrade step following this.
 488      if ($oldversion < 2023011800) {
 489  
 490          // Define index course_bbbid_ix (not unique) to be added to bigbluebuttonbn_logs.
 491          $table = new xmldb_table('bigbluebuttonbn_logs');
 492          $index = new xmldb_index('course_bbbid_ix', XMLDB_INDEX_NOTUNIQUE, ['courseid', 'bigbluebuttonbnid']);
 493  
 494          // Conditionally launch add index course_bbbid_ix.
 495          if (!$dbman->index_exists($table, $index)) {
 496              $dbman->add_index($table, $index);
 497          }
 498  
 499          // Bigbluebuttonbn savepoint reached.
 500          upgrade_mod_savepoint(true, 2023011800, 'bigbluebuttonbn');
 501      }
 502      if ($oldversion < 2023021300) {
 503  
 504          // Define field lockedlayout to be dropped from bigbluebuttonbn.
 505          $table = new xmldb_table('bigbluebuttonbn');
 506          $field = new xmldb_field('lockedlayout');
 507  
 508          // Conditionally launch drop field lockedlayout.
 509          if ($dbman->field_exists($table, $field)) {
 510              $dbman->drop_field($table, $field);
 511          }
 512  
 513          // Bigbluebuttonbn savepoint reached.
 514          upgrade_mod_savepoint(true, 2023021300, 'bigbluebuttonbn');
 515      }
 516  
 517      // Automatically generated Moodle v4.2.0 release upgrade line.
 518      // Put any upgrade step following this.
 519  
 520      // Automatically generated Moodle v4.3.0 release upgrade line.
 521      // Put any upgrade step following this.
 522  
 523      return true;
 524  }
 525  
 526  /**
 527   * Generic helper function for adding or changing a field in a table.
 528   *
 529   * @param database_manager $dbman
 530   * @param string $tablename
 531   * @param string $fieldname
 532   * @param array $fielddefinition
 533   * @deprecated  please do not use this anymore (historical migrations)
 534   */
 535  function xmldb_bigbluebuttonbn_add_change_field(database_manager $dbman, string $tablename, string $fieldname,
 536      array $fielddefinition) {
 537      $table = new xmldb_table($tablename);
 538      $field = new xmldb_field($fieldname);
 539      $field->set_attributes($fielddefinition['type'], $fielddefinition['precision'], $fielddefinition['unsigned'],
 540          $fielddefinition['notnull'], $fielddefinition['sequence'], $fielddefinition['default'],
 541          $fielddefinition['previous']);
 542      if (!$dbman->field_exists($table, $field)) {
 543          $dbman->add_field($table, $field, true, true);
 544          return;
 545      }
 546      // Drop key before if needed.
 547      $fieldkey = new xmldb_key($fieldname, XMLDB_KEY_FOREIGN, [$fieldname], 'user', ['id']);
 548      if ($dbman->find_key_name($table, $fieldkey)) {
 549          $dbman->drop_key($table, $fieldkey);
 550      }
 551      $dbman->change_field_type($table, $field, true, true);
 552      $dbman->change_field_precision($table, $field, true, true);
 553      $dbman->change_field_notnull($table, $field, true, true);
 554      $dbman->change_field_default($table, $field, true, true);
 555  }
 556  
 557  /**
 558   * Generic helper function for adding index to a table.
 559   *
 560   * @param database_manager $dbman
 561   * @param string $tablename
 562   * @param string $indexname
 563   * @param array $indexfields
 564   * @param string|false|null $indextype
 565   * @deprecated please do not use this anymore (historical migrations)
 566   */
 567  function xmldb_bigbluebuttonbn_index_table(database_manager $dbman, string $tablename, string $indexname, array $indexfields,
 568      $indextype = XMLDB_INDEX_NOTUNIQUE) {
 569      $table = new xmldb_table($tablename);
 570      if (!$dbman->table_exists($table)) {
 571          return;
 572      }
 573      $index = new xmldb_index($indexname, $indextype, $indexfields);
 574      if ($dbman->index_exists($table, $index)) {
 575          $dbman->drop_index($table, $index);
 576      }
 577      $dbman->add_index($table, $index, true, true);
 578  }