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 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [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  defined('MOODLE_INTERNAL') || die();
  18  
  19  /**
  20   * @param int $oldversion the version we are upgrading from
  21   * @return bool result
  22   */
  23  function xmldb_repository_dropbox_upgrade($oldversion) {
  24      global $CFG, $DB;
  25  
  26      // Automatically generated Moodle v3.9.0 release upgrade line.
  27      // Put any upgrade step following this.
  28  
  29      if ($oldversion < 2021052501) {
  30          $key = get_config('dropbox', 'dropbox_key');
  31          $secret = get_config('dropbox', 'dropbox_secret');
  32  
  33          if ($key && $secret) {
  34              $params = [
  35                  'name' => 'Dropbox',
  36                  'clientid' => $key,
  37                  'clientsecret' => $secret,
  38                  'loginparamsoffline' => 'token_access_type=offline',
  39                  'image' => '',
  40                  'showonloginpage' => 0, // Internal services only.
  41              ];
  42              $record = $DB->get_record('oauth2_issuer', ['name' => 'Dropbox'], 'id');
  43              if (!$record) {
  44                  $params = array_merge($params, [
  45                      'timecreated' => time(),
  46                      'timemodified' => time(),
  47                      'usermodified' => time(),
  48                      'baseurl' => 0,
  49                      'sortorder' => '',
  50                      'loginparams' => '',
  51                      'requireconfirmation' => 1,
  52                      'alloweddomains' => '',
  53                      'loginscopes' => 'openid profile email',
  54                      'loginscopesoffline' => 'openid profile email',
  55                  ]);
  56                  $id = $DB->insert_record('oauth2_issuer', $params);
  57              } else {
  58                  $id = $record->id;
  59                  $params['id'] = $id;
  60                  $DB->update_record('oauth2_issuer', $params);
  61              }
  62  
  63              set_config('dropbox_issuerid', $id, 'dropbox');
  64              unset_config('dropbox_key', 'dropbox');
  65              unset_config('dropbox_secret', 'dropbox');
  66          }
  67  
  68          // Dropbox savepoint reached.
  69          upgrade_plugin_savepoint(true, 2021052501, 'repository', 'dropbox');
  70      }
  71  
  72      // Automatically generated Moodle v4.0.0 release upgrade line.
  73      // Put any upgrade step following this.
  74  
  75      // Automatically generated Moodle v4.1.0 release upgrade line.
  76      // Put any upgrade step following this.
  77  
  78      return true;
  79  }