Merge branch 'MDL-69760-master' of https://github.com/inkjet2000/moodle into master
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 7 Oct 2020 22:23:47 +0000 (00:23 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 7 Oct 2020 22:23:47 +0000 (00:23 +0200)
1  2 
lib/db/install.xml
lib/db/upgrade.php

          <KEY NAME="userid" TYPE="foreign" FIELDS="userid" REFTABLE="user" REFFIELDS="id" COMMENT="Foreign key for the userid"/>
        </KEYS>
      </TABLE>
 +    <TABLE NAME="oauth2_refresh_token" COMMENT="Stores refresh tokens which can be exchanged for access tokens">
 +      <FIELDS>
 +        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
 +        <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="Time this record was created."/>
 +        <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="Time this record was modified."/>
 +        <FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="The user to whom this refresh token belongs."/>
 +        <FIELD NAME="issuerid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="Corresponding oauth2 issuer"/>
 +        <FIELD NAME="token" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="refresh token"/>
 +        <FIELD NAME="scopehash" TYPE="char" LENGTH="40" NOTNULL="true" SEQUENCE="false" COMMENT="sha1 hash of the scopes used when requesting the refresh token"/>
 +      </FIELDS>
 +      <KEYS>
 +        <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
 +        <KEY NAME="issueridkey" TYPE="foreign" FIELDS="issuerid" REFTABLE="oauth2_issuer" REFFIELDS="id" COMMENT="Issuer id foreign key"/>
 +        <KEY NAME="useridkey" TYPE="foreign" FIELDS="userid" REFTABLE="user" REFFIELDS="id" COMMENT="User id foreign key"/>
 +      </KEYS>
 +      <INDEXES>
 +        <INDEX NAME="userid-issuerid-scopehash" UNIQUE="true" FIELDS="userid, issuerid, scopehash"/>
 +      </INDEXES>
 +    </TABLE>
    </TABLES>
- </XMLDB>
+ </XMLDB>
@@@ -2708,35 -2708,29 +2708,59 @@@ function xmldb_main_upgrade($oldversion
          upgrade_main_savepoint(true, 2021052500.15);
      }
  
 +    if ($oldversion < 2021052500.19) {
 +        // Define table oauth2_refresh_token to be created.
 +        $table = new xmldb_table('oauth2_refresh_token');
 +
 +        // Adding fields to table oauth2_refresh_token.
 +        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
 +        $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
 +        $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
 +        $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
 +        $table->add_field('issuerid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
 +        $table->add_field('token', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
 +        $table->add_field('scopehash', XMLDB_TYPE_CHAR, 40, null, XMLDB_NOTNULL, null, null);
 +
 +        // Adding keys to table oauth2_refresh_token.
 +        $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
 +        $table->add_key('issueridkey', XMLDB_KEY_FOREIGN, ['issuerid'], 'oauth2_issuer', ['id']);
 +        $table->add_key('useridkey', XMLDB_KEY_FOREIGN, ['userid'], 'user', ['id']);
 +
 +        // Adding indexes to table oauth2_refresh_token.
 +        $table->add_index('userid-issuerid-scopehash', XMLDB_INDEX_UNIQUE, array('userid', 'issuerid', 'scopehash'));
 +
 +        // Conditionally launch create table for oauth2_refresh_token.
 +        if (!$dbman->table_exists($table)) {
 +            $dbman->create_table($table);
 +        }
 +
 +        // Main savepoint reached.
 +        upgrade_main_savepoint(true, 2021052500.19);
 +    }
 +
+     if ($oldversion < 2021052500.20) {
+         // Define index modulename-instance-eventtype (not unique) to be added to event.
+         $table = new xmldb_table('event');
+         $index = new xmldb_index('modulename-instance-eventtype', XMLDB_INDEX_NOTUNIQUE, ['modulename', 'instance', 'eventtype']);
+         // Conditionally launch add index modulename-instance-eventtype.
+         if (!$dbman->index_exists($table, $index)) {
+             $dbman->add_index($table, $index);
+         }
+         // Define index modulename-instance (not unique) to be dropped form event.
+         $table = new xmldb_table('event');
+         $index = new xmldb_index('modulename-instance', XMLDB_INDEX_NOTUNIQUE, ['modulename', 'instance']);
+         // Conditionally launch drop index modulename-instance.
+         if ($dbman->index_exists($table, $index)) {
+             $dbman->drop_index($table, $index);
+         }
+         // Main savepoint reached.
+         upgrade_main_savepoint(true, 2021052500.20);
+     }
      return true;
  }