Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 400 and 401] [Versions 401 and 402] [Versions 401 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   * LTI authentication plugin upgrade code
  19   *
  20   * @package    auth_lti
  21   * @copyright  2021 Jake Dallimore <jrhdallimore@gmail.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  /**
  28   * Upgrade function.
  29   *
  30   * @param int $oldversion the version we are upgrading from.
  31   * @return bool result.
  32   */
  33  function xmldb_auth_lti_upgrade($oldversion) {
  34      global $DB;
  35  
  36      $dbman = $DB->get_manager();
  37  
  38      if ($oldversion < 2021100500) {
  39          // Define table auth_lti_linked_login to be created.
  40          $table = new xmldb_table('auth_lti_linked_login');
  41  
  42          // Adding fields to table auth_lti_linked_login.
  43          $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
  44          $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
  45          $table->add_field('issuer', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
  46          $table->add_field('issuer256', XMLDB_TYPE_CHAR, '64', null, XMLDB_NOTNULL, null, null);
  47          $table->add_field('sub', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
  48          $table->add_field('sub256', XMLDB_TYPE_CHAR, '64', null, XMLDB_NOTNULL, null, null);
  49          $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
  50          $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
  51  
  52          // Adding keys to table auth_lti_linked_login.
  53          $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
  54          $table->add_key('userid_key', XMLDB_KEY_FOREIGN, ['userid'], 'user', ['id']);
  55          $table->add_key('unique_key', XMLDB_KEY_UNIQUE, ['userid', 'issuer256', 'sub256']);
  56  
  57          // Conditionally launch create table for auth_lti_linked_login.
  58          if (!$dbman->table_exists($table)) {
  59              $dbman->create_table($table);
  60          }
  61  
  62          // Auth LTI savepoint reached.
  63          upgrade_plugin_savepoint(true, 2021100500, 'auth', 'lti');
  64      }
  65  
  66      if ($oldversion < 2022030900) {
  67          // Fix the unique key made up of {userid, issuer256, sub256}.
  68          // This was improperly defined as ['userid, issuer256, sub256'] in the upgrade step above (note the quotes),
  69          // resulting in the potential for missing keys on some databases.
  70          // Drop and re-add the key to make sure we have it in place.
  71  
  72          // Define table auth_lti_linked_login to be modified.
  73          $table = new xmldb_table('auth_lti_linked_login');
  74  
  75          // Define the key to be dropped and re-added.
  76          $key = new xmldb_key('unique_key', XMLDB_KEY_UNIQUE, ['userid', 'issuer256', 'sub256'], 'auth_lti_linked_login');
  77  
  78          // Drop the key.
  79          $dbman->drop_key($table, $key);
  80  
  81          // Create the key.
  82          $dbman->add_key($table, $key);
  83  
  84          // Auth LTI savepoint reached.
  85          upgrade_plugin_savepoint(true, 2022030900, 'auth', 'lti');
  86      }
  87  
  88      // Automatically generated Moodle v4.0.0 release upgrade line.
  89      // Put any upgrade step following this.
  90  
  91      // Automatically generated Moodle v4.1.0 release upgrade line.
  92      // Put any upgrade step following this.
  93  
  94      return true;
  95  }