Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400] [Versions 400 and 401] [Versions 400 and 402] [Versions 400 and 403]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Upgrade code for install 19 * 20 * @package tool_usertours 21 * @copyright 2016 Ryan Wyllie <ryan@moodle.com> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 defined('MOODLE_INTERNAL') || die(); 26 27 use tool_usertours\manager; 28 use tool_usertours\tour; 29 30 /** 31 * Upgrade the user tours plugin. 32 * 33 * @param int $oldversion The old version of the user tours plugin 34 * @return bool 35 */ 36 function xmldb_tool_usertours_upgrade($oldversion) { 37 global $CFG, $DB; 38 39 $dbman = $DB->get_manager(); 40 41 // Automatically generated Moodle v3.6.0 release upgrade line. 42 // Put any upgrade step following this. 43 44 // Automatically generated Moodle v3.7.0 release upgrade line. 45 // Put any upgrade step following this. 46 47 // Automatically generated Moodle v3.8.0 release upgrade line. 48 // Put any upgrade step following this. 49 50 // Automatically generated Moodle v3.9.0 release upgrade line. 51 // Put any upgrade step following this. 52 53 if ($oldversion < 2021052501) { 54 // Clean up user preferences of deleted tours. 55 $select = $DB->sql_like('name', ':lastcompleted') . ' OR ' . $DB->sql_like('name', ':requested'); 56 $params = [ 57 'lastcompleted' => tour::TOUR_LAST_COMPLETED_BY_USER . '%', 58 'requested' => tour::TOUR_REQUESTED_BY_USER . '%', 59 ]; 60 61 $preferences = $DB->get_records_select('user_preferences', $select, $params, '', 'DISTINCT name'); 62 foreach ($preferences as $preference) { 63 // Match tour ID at the end of the preference name, remove all of that preference type if tour ID doesn't exist. 64 if (preg_match('/(?<tourid>\d+)$/', $preference->name, $matches) && 65 !$DB->record_exists('tool_usertours_tours', ['id' => $matches['tourid']])) { 66 67 $DB->delete_records('user_preferences', ['name' => $preference->name]); 68 } 69 } 70 71 upgrade_plugin_savepoint(true, 2021052501, 'tool', 'usertours'); 72 } 73 74 if ($oldversion < 2021092300) { 75 // Define field endtourlabel to be added to tool_usertours_tours. 76 $table = new xmldb_table('tool_usertours_tours'); 77 $field = new xmldb_field('endtourlabel', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'sortorder'); 78 79 // Conditionally launch add field endtourlabel. 80 if (!$dbman->field_exists($table, $field)) { 81 $dbman->add_field($table, $field); 82 } 83 84 // Usertours savepoint reached. 85 upgrade_plugin_savepoint(true, 2021092300, 'tool', 'usertours'); 86 } 87 88 if ($oldversion < 2021100700) { 89 90 // Define field displaystepnumbers to be added to tool_usertours_tours. 91 $table = new xmldb_table('tool_usertours_tours'); 92 $field = new xmldb_field('displaystepnumbers', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'configdata'); 93 94 // Conditionally launch add field displaystepnumbers. 95 if (!$dbman->field_exists($table, $field)) { 96 $dbman->add_field($table, $field); 97 } 98 99 // Usertours savepoint reached. 100 upgrade_plugin_savepoint(true, 2021100700, 'tool', 'usertours'); 101 } 102 103 if ($oldversion < 2022040601) { 104 // Define field contentformat to be added to tool_usertours_steps. 105 $table = new xmldb_table('tool_usertours_steps'); 106 $field = new xmldb_field('contentformat', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, FORMAT_MOODLE, 'content'); 107 108 // Conditionally launch add field contentformat. 109 if (!$dbman->field_exists($table, $field)) { 110 $dbman->add_field($table, $field); 111 } else { 112 // Field was added by previous upgrade step with the default value is FORMAT_HTML. 113 // Need to drop the field and re-create with the new structure to make sure all the existing tours use FORMAT_MOODLE. 114 // FORMAT_MOODLE will force the external_format_text method to use nl2br to convert the new line to line break tag. 115 $dbman->drop_field($table, $field); 116 // Add the field again. 117 $dbman->add_field($table, $field); 118 } 119 120 // Usertours savepoint reached. 121 upgrade_plugin_savepoint(true, 2022040601, 'tool', 'usertours'); 122 } 123 124 if ($oldversion < 2022040602) { 125 // Update shipped tours. 126 // Normally, we just bump the version numbers because we need to call update_shipped_tours only once. 127 manager::update_shipped_tours(); 128 129 upgrade_plugin_savepoint(true, 2022040602, 'tool', 'usertours'); 130 } 131 132 // Automatically generated Moodle v4.0.0 release upgrade line. 133 // Put any upgrade step following this. 134 135 return true; 136 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body