| 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 |  |  | defined('MOODLE_INTERNAL') || die(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | require_once(dirname(dirname(__FILE__)).'/locallib.php'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  * Performs data migrations and updates on upgrade. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  * @param   integer   $oldversion | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  * @return  boolean | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 |  |  |         xmldb_bigbluebuttonbn_drop_field($dbman, 'bigbluebuttonbn', 'description'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         // Change welcome, allow null. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $fielddefinition = array('type' => XMLDB_TYPE_TEXT, 'precision' => null, 'unsigned' => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |             'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => null, 'previous' => 'type'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'welcome', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             $fielddefinition); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         // Change userid definition in bigbluebuttonbn_log. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         $fielddefinition = array('type' => XMLDB_TYPE_INTEGER, 'precision' => '10', 'unsigned' => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             'previous' => 'bigbluebuttonbnid'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn_log', 'userid', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |             $fielddefinition); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         // No settings to migrate. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         // Update db version tag. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         upgrade_mod_savepoint(true, 2015080605, 'bigbluebuttonbn'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     if ($oldversion < 2016011305) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         // Define field type to be droped from bigbluebuttonbn. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         xmldb_bigbluebuttonbn_drop_field($dbman, 'bigbluebuttonbn', 'type'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         // Rename table bigbluebuttonbn_log to bigbluebuttonbn_logs. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         xmldb_bigbluebuttonbn_rename_table($dbman, 'bigbluebuttonbn_log', 'bigbluebuttonbn_logs'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         // Rename field event to log in table bigbluebuttonbn_logs. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         xmldb_bigbluebuttonbn_rename_field($dbman, 'bigbluebuttonbn_logs', 'event', 'log'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         // No settings to migrate. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         // Update db version tag. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         upgrade_mod_savepoint(true, 2016011305, 'bigbluebuttonbn'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     if ($oldversion < 2017101000) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         // Drop field newwindow. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         xmldb_bigbluebuttonbn_drop_field($dbman, 'bigbluebuttonbn', 'newwindow'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         // Add field type. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         $fielddefinition = array('type' => XMLDB_TYPE_INTEGER, 'precision' => '2', 'unsigned' => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => 'id'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'type', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |             $fielddefinition); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         // Add field recordings_html. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $fielddefinition = array('type' => XMLDB_TYPE_INTEGER, 'precision' => '1', 'unsigned' => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |             'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'recordings_html', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |             $fielddefinition); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         // Add field recordings_deleted. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         $fielddefinition = array('type' => XMLDB_TYPE_INTEGER, 'precision' => '1', 'unsigned' => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |             'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 1, 'previous' => null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'recordings_deleted', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |             $fielddefinition); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         // Add field recordings_imported. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         $fielddefinition = array('type' => XMLDB_TYPE_INTEGER, 'precision' => '1', 'unsigned' => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |             'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'recordings_imported', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |             $fielddefinition); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         // Drop field newwindow. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         xmldb_bigbluebuttonbn_drop_field($dbman, 'bigbluebuttonbn', 'tagging'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         // Migrate settings. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         unset_config('bigbluebuttonbn_recordingtagging_default', ''); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         unset_config('bigbluebuttonbn_recordingtagging_editable', ''); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         $cfgvalue = get_config('', 'bigbluebuttonbn_importrecordings_from_deleted_activities_enabled'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         set_config('bigbluebuttonbn_importrecordings_from_deleted_enabled', $cfgvalue, ''); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         unset_config('bigbluebuttonbn_importrecordings_from_deleted_activities_enabled', ''); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         $cfgvalue = get_config('', 'bigbluebuttonbn_moderator_default'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |         set_config('bigbluebuttonbn_participant_moderator_default', $cfgvalue, ''); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         unset_config('bigbluebuttonbn_moderator_default', ''); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         // Update db version tag. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         upgrade_mod_savepoint(true, 2017101000, 'bigbluebuttonbn'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     } | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 106 |  | View Code Duplication |     if ($oldversion < 2017101009) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         // Add field recordings_preview. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         $fielddefinition = array('type' => XMLDB_TYPE_INTEGER, 'precision' => '1', 'unsigned' => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |             'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |         xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'recordings_preview', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |             $fielddefinition); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |         // Update db version tag. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         upgrade_mod_savepoint(true, 2017101009, 'bigbluebuttonbn'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |     if ($oldversion < 2017101010) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |         // Fix for CONTRIB-7221. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |         if ($oldversion == 2017101003) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |             // A bug intorduced in 2017101003 causes new instances to be created without BBB passwords. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |             // A workaround was put in place in version 2017101004 that was relabeled to 2017101005. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |             // However, as the code was relocated to upgrade.php in version 2017101010, a new issue came up. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |             // There is now a timeout error when the plugin is upgraded in large Moodle sites. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |             // The script should only be considered when migrating from this version. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |             $sql  = "SELECT * FROM {bigbluebuttonbn} "; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |             $sql .= "WHERE moderatorpass = ? OR viewerpass = ?"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |             $instances = $DB->get_records_sql($sql, array('', '')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |             foreach ($instances as $instance) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |                 $instance->moderatorpass = bigbluebuttonbn_random_password(12); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |                 $instance->viewerpass = bigbluebuttonbn_random_password(12, $instance->moderatorpass); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |                 // Store passwords in the database. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |                 $DB->update_record('bigbluebuttonbn', $instance); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |         // Update db version tag. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |         upgrade_mod_savepoint(true, 2017101010, 'bigbluebuttonbn'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |     if ($oldversion < 2017101012) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |         // Update field type (Fix for CONTRIB-7302). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |         $fielddefinition = array('type' => XMLDB_TYPE_INTEGER, 'precision' => '2', 'unsigned' => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |             'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => 'id'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |         xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'type', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |             $fielddefinition); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |         // Update field meetingid (Fix for CONTRIB-7302). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |         $fielddefinition = array('type' => XMLDB_TYPE_CHAR, 'precision' => '255', 'unsigned' => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |             'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => null, 'previous' => 'introformat'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |         xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'meetingid', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |             $fielddefinition); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |         // Update field recordings_imported (Fix for CONTRIB-7302). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |         $fielddefinition = array('type' => XMLDB_TYPE_INTEGER, 'precision' => '1', 'unsigned' => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |             'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |         xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'recordings_imported', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |             $fielddefinition); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |         // Add field recordings_preview.(Fix for CONTRIB-7302). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |         $fielddefinition = array('type' => XMLDB_TYPE_INTEGER, 'precision' => '1', 'unsigned' => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |             'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |         xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'recordings_preview', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |             $fielddefinition); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |         // Update db version tag. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |         upgrade_mod_savepoint(true, 2017101012, 'bigbluebuttonbn'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |     } | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 160 |  | View Code Duplication |     if ($oldversion < 2017101015) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |         // Add field for client technology choice. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |         $fielddefinition = array('type' => XMLDB_TYPE_INTEGER, 'precision' => '1', 'unsigned' => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |             'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |         xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'clienttype', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |             $fielddefinition); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |         // Update db version tag. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |         upgrade_mod_savepoint(true, 2017101015, 'bigbluebuttonbn'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |     if ($oldversion < 2019042000) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |         // Add field for Mute on start feature. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |         $fielddefinition = array('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', 'muteonstart', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |             $fielddefinition); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |         // Add field for record all from start. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |         $fielddefinition = array('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', 'recordallfromstart', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |             $fielddefinition); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |         // Add field for record hide button. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |         $fielddefinition = array('type' => XMLDB_TYPE_INTEGER, 'precision' => '1', 'unsigned' => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |             'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |         xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'recordhidebutton', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |             $fielddefinition); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |         // Update db version tag. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |         upgrade_mod_savepoint(true, 2019042000, 'bigbluebuttonbn'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |     if ($oldversion < 2019042009) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |         // Add field for Completion with attendance. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |         $fielddefinition = array('type' => XMLDB_TYPE_INTEGER, 'precision' => '9', 'unsigned' => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |             'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |         xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'completionattendance', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |             $fielddefinition); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |         // Add field for Completion with engagement through chats. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |         $fielddefinition = array('type' => XMLDB_TYPE_INTEGER, 'precision' => '9', 'unsigned' => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |             'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |         xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'completionengagementchats', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |             $fielddefinition); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |         // Add field for Completion with engagement through talks. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |         $fielddefinition = array('type' => XMLDB_TYPE_INTEGER, 'precision' => '9', 'unsigned' => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |             'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |         xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'completionengagementtalks', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |             $fielddefinition); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |         // Add field for Completion with engagement through raisehand. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |         $fielddefinition = array('type' => XMLDB_TYPE_INTEGER, 'precision' => '9', 'unsigned' => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |             'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |         xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'completionengagementraisehand', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |             $fielddefinition); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |         // Add field for Completion with engagement through pollvotes. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |         $fielddefinition = array('type' => XMLDB_TYPE_INTEGER, 'precision' => '9', 'unsigned' => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |             'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |         xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'completionengagementpollvotes', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |             $fielddefinition); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |         // Add field for Completion with engagement through emojis. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |         $fielddefinition = array('type' => XMLDB_TYPE_INTEGER, 'precision' => '9', 'unsigned' => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |             'notnull' => XMLDB_NOTNULL, 'sequence' => null, 'default' => 0, 'previous' => null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |         xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'completionengagementemojis', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |             $fielddefinition); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |         // Update db version tag. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |         upgrade_mod_savepoint(true, 2019042009, 'bigbluebuttonbn'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |     if ($oldversion < 2019042010) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |         // Add index to bigbluebuttonbn_logs (Fix for CONTRIB-8157). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |         xmldb_bigbluebuttonbn_index_table($dbman, 'bigbluebuttonbn_logs', 'courseid', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |             ['courseid']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |         xmldb_bigbluebuttonbn_index_table($dbman, 'bigbluebuttonbn_logs', 'log', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |             ['log']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |         xmldb_bigbluebuttonbn_index_table($dbman, 'bigbluebuttonbn_logs', 'logrow', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |             ['courseid', 'bigbluebuttonbnid', 'userid', 'log']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |         // Update db version tag. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |         upgrade_mod_savepoint(true, 2019042010, 'bigbluebuttonbn'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |     return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |  * Generic helper function for adding or changing a field in a table. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |  * @param   object    $dbman | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |  * @param   string    $tablename | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |  * @param   string    $fieldname | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |  * @param   array     $fielddefinition | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  | function xmldb_bigbluebuttonbn_add_change_field($dbman, $tablename, $fieldname, $fielddefinition) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |     $table = new xmldb_table($tablename); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |     $field = new xmldb_field($fieldname); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |     $field->set_attributes($fielddefinition['type'], $fielddefinition['precision'], $fielddefinition['unsigned'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |         $fielddefinition['notnull'], $fielddefinition['sequence'], $fielddefinition['default'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |         $fielddefinition['previous']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |     if ($dbman->field_exists($table, $field)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |         $dbman->change_field_type($table, $field, true, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |         $dbman->change_field_precision($table, $field, true, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |         $dbman->change_field_notnull($table, $field, true, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |         $dbman->change_field_default($table, $field, true, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |         return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  |     $dbman->add_field($table, $field, true, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  |  * Generic helper function for dropping a field from a table. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |  * @param   object    $dbman | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |  * @param   string    $tablename | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  |  * @param   string    $fieldname | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |  */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 267 |  | View Code Duplication | function xmldb_bigbluebuttonbn_drop_field($dbman, $tablename, $fieldname) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |     $table = new xmldb_table($tablename); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  |     $field = new xmldb_field($fieldname); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |     if ($dbman->field_exists($table, $field)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  |         $dbman->drop_field($table, $field, true, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  |  * Generic helper function for renaming a field in a table. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  |  * @param   object    $dbman | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  |  * @param   string    $tablename | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  |  * @param   string    $fieldnameold | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  |  * @param   string    $fieldnamenew | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 282 |  |  |  */ | 
            
                                                                        
                            
            
                                                                    
                                                                                                        
            
            
                | 283 |  | View Code Duplication | function xmldb_bigbluebuttonbn_rename_field($dbman, $tablename, $fieldnameold, $fieldnamenew) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 284 |  |  |     $table = new xmldb_table($tablename); | 
            
                                                                        
                            
            
                                    
            
            
                | 285 |  |  |     $field = new xmldb_field($fieldnameold); | 
            
                                                                        
                            
            
                                    
            
            
                | 286 |  |  |     if ($dbman->field_exists($table, $field)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 287 |  |  |         $dbman->rename_field($table, $field, $fieldnamenew, true, true); | 
            
                                                                        
                            
            
                                    
            
            
                | 288 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 289 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  |  * Generic helper function for renaming a table. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  |  * @param   object    $dbman | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  |  * @param   string    $tablenameold | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 |  |  |  * @param   string    $tablenamenew | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 |  |  | function xmldb_bigbluebuttonbn_rename_table($dbman, $tablenameold, $tablenamenew) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 |  |  |     $table = new xmldb_table($tablenameold); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 300 |  |  |     if ($dbman->table_exists($table)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 301 |  |  |         $dbman->rename_table($table, $tablenamenew, true, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 302 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 303 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 304 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 305 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 306 |  |  |  * Generic helper function for adding index to a table. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 307 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 308 |  |  |  * @param   object    $dbman | 
            
                                                                                                            
                            
            
                                    
            
            
                | 309 |  |  |  * @param   string    $tablename | 
            
                                                                                                            
                            
            
                                    
            
            
                | 310 |  |  |  * @param   string    $indexname | 
            
                                                                                                            
                            
            
                                    
            
            
                | 311 |  |  |  * @param   array     $indexfields | 
            
                                                                                                            
                            
            
                                    
            
            
                | 312 |  |  |  * @param   string    $indextype | 
            
                                                                                                            
                            
            
                                    
            
            
                | 313 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 314 |  |  | function xmldb_bigbluebuttonbn_index_table($dbman, $tablename, $indexname, $indexfields, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 315 |  |  |         $indextype = XMLDB_INDEX_NOTUNIQUE) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 316 |  |  |     $table = new xmldb_table($tablename); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 317 |  |  |     if (!$dbman->table_exists($table)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 318 |  |  |         return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 319 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 320 |  |  |     $index = new xmldb_index($indexname, $indextype, $indexfields); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 321 |  |  |     if ($dbman->index_exists($table, $index)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 322 |  |  |         $dbman->drop_index($table, $index); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 323 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 324 |  |  |     $dbman->add_index($table, $index, true, true); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 325 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 326 |  |  |  | 
            
                        
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.