Differences Between: [Versions 310 and 311] [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]
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 /** 19 * This file keeps track of upgrades to the lti enrolment plugin 20 * 21 * @package enrol_lti 22 * @copyright 2016 John Okely <john@moodle.com> 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 defined('MOODLE_INTERNAL') || die; 27 28 /** 29 * xmldb_lti_upgrade is the function that upgrades 30 * the lti module database when is needed 31 * 32 * This function is automaticly called when version number in 33 * version.php changes. 34 * 35 * @param int $oldversion New old version number. 36 * 37 * @return boolean 38 */ 39 function xmldb_enrol_lti_upgrade($oldversion) { 40 global $CFG, $DB; 41 42 // Automatically generated Moodle v3.6.0 release upgrade line. 43 // Put any upgrade step following this. 44 45 // Automatically generated Moodle v3.7.0 release upgrade line. 46 // Put any upgrade step following this. 47 48 // Automatically generated Moodle v3.8.0 release upgrade line. 49 // Put any upgrade step following this. 50 51 // Automatically generated Moodle v3.9.0 release upgrade line. 52 // Put any upgrade step following this. 53 54 // Automatically generated Moodle v3.10.0 release upgrade line. 55 // Put any upgrade step following this. 56 57 // Automatically generated Moodle v3.11.0 release upgrade line. 58 // Put any upgrade step following this. 59 60 if ($oldversion < 2021051701) { 61 // Disable all orphaned enrolment method instances. 62 $sql = "id IN (SELECT t.enrolid 63 FROM {enrol_lti_tools} t 64 LEFT JOIN {context} c ON (t.contextid = c.id) 65 WHERE c.id IS NULL)"; 66 $DB->set_field_select('enrol', 'status', 1, $sql); 67 68 // Lti savepoint reached. 69 upgrade_plugin_savepoint(true, 2021051701, 'enrol', 'lti'); 70 } 71 72 if ($oldversion < 2021051702) { 73 // Update lti user information for LTI 2.0 users having the wrong consumer secret recorded. 74 // This applies to any LTI 2.0 user who has launched the tool (i.e. has lastaccess) and fixes a non-functional grade sync 75 // for LTI 2.0 consumers. 76 $sql = "SELECT lu.id, lc.secret 77 FROM {enrol_lti_users} lu 78 JOIN {enrol_lti_lti2_consumer} lc 79 ON (" . $DB->sql_compare_text('lu.consumerkey', 255) . " = lc.consumerkey256) 80 WHERE lc.ltiversion = :ltiversion 81 AND " . $DB->sql_compare_text('lu.consumersecret') . " != lc.secret 82 AND lu.lastaccess IS NOT NULL"; 83 $affectedltiusersrs = $DB->get_recordset_sql($sql, ['ltiversion' => 'LTI-2p0']); 84 foreach ($affectedltiusersrs as $ltiuser) { 85 $DB->set_field('enrol_lti_users', 'consumersecret', $ltiuser->secret, ['id' => $ltiuser->id]); 86 } 87 $affectedltiusersrs->close(); 88 89 // Lti savepoint reached. 90 upgrade_plugin_savepoint(true, 2021051702, 'enrol', 'lti'); 91 } 92 93 if ($oldversion < 2021051703) { 94 // Update lti user information for any users missing a consumer secret. 95 // This applies to any user who has launched the tool (i.e. has lastaccess) but who doesn't have a secret recorded. 96 // This fixes a bug where enrol_lti_users records are created first during a member sync, and are missing the secret, 97 // even despite having launched the tool subsequently. 98 $sql = "SELECT lu.id, lc.secret 99 FROM {enrol_lti_users} lu 100 JOIN {enrol_lti_lti2_consumer} lc 101 ON (" . $DB->sql_compare_text('lu.consumerkey', 255) . " = lc.consumerkey256) 102 WHERE lu.consumersecret IS NULL 103 AND lu.lastaccess IS NOT NULL"; 104 $affectedltiusersrs = $DB->get_recordset_sql($sql); 105 foreach ($affectedltiusersrs as $ltiuser) { 106 $DB->set_field('enrol_lti_users', 'consumersecret', $ltiuser->secret, ['id' => $ltiuser->id]); 107 } 108 $affectedltiusersrs->close(); 109 110 // Lti savepoint reached. 111 upgrade_plugin_savepoint(true, 2021051703, 'enrol', 'lti'); 112 } 113 114 return true; 115 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body