Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

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   * This file keeps track of upgrades to the myoverview block
  19   *
  20   * @since 3.8
  21   * @package block_myoverview
  22   * @copyright 2019 Jake Dallimore <jrhdallimore@gmail.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   * Upgrade code for the MyOverview block.
  30   *
  31   * @param int $oldversion
  32   */
  33  function xmldb_block_myoverview_upgrade($oldversion) {
  34      global $DB, $CFG, $OUTPUT;
  35  
  36      if ($oldversion < 2019091800) {
  37          // Remove orphaned course favourites, which weren't being deleted when the course was deleted.
  38          $sql = 'SELECT f.id
  39                    FROM {favourite} f
  40               LEFT JOIN {course} c
  41                      ON (c.id = f.itemid)
  42                   WHERE f.component = :component
  43                     AND f.itemtype = :itemtype
  44                     AND c.id IS NULL';
  45          $params = ['component' => 'core_course', 'itemtype' => 'courses'];
  46  
  47          if ($records = $DB->get_fieldset_sql($sql, $params)) {
  48              $chunks = array_chunk($records, 1000);
  49              foreach ($chunks as $chunk) {
  50                  list($insql, $inparams) = $DB->get_in_or_equal($chunk);
  51                  $DB->delete_records_select('favourite', "id $insql", $inparams);
  52              }
  53          }
  54  
  55          upgrade_block_savepoint(true, 2019091800, 'myoverview', false);
  56      }
  57  
  58      // Automatically generated Moodle v3.8.0 release upgrade line.
  59      // Put any upgrade step following this.
  60  
  61      if ($oldversion < 2019111801) {
  62          // Renaming the setting from displaygroupingstarred to displaygroupingfavourites to match Moodle convention.
  63  
  64          // Check to see if record exists. get_config doesn't allow differentiation between not exists and false.
  65          $dbval = $DB->get_field('config_plugins', 'value', ['plugin' => 'block_myoverview', 'name' => 'displaygroupingstarred']);
  66          if ($dbval !== false) {
  67              set_config('displaygroupingfavourites', $dbval, 'block_myoverview');
  68              unset_config('displaygroupingstarred', 'block_myoverview');
  69          }
  70  
  71          if (isset($CFG->forced_plugin_settings['block_myoverview']['displaygroupingstarred'])) {
  72              // Check to see if the starred setting is defined in the config file. Display a warning if so.
  73              $warn = 'Setting block_myoverview->displaygroupingstarred has been renamed '.
  74                      'to block_myoverview->displaygroupingfavourites. Old setting present in config.php.';
  75              echo $OUTPUT->notification($warn, 'notifyproblem');
  76          }
  77  
  78          upgrade_block_savepoint(true, 2019111801, 'myoverview', false);
  79      }
  80  
  81      // Automatically generated Moodle v3.9.0 release upgrade line.
  82      // Put any upgrade step following this.
  83  
  84      // Automatically generated Moodle v3.10.0 release upgrade line.
  85      // Put any upgrade step following this.
  86  
  87      // Automatically generated Moodle v3.11.0 release upgrade line.
  88      // Put any upgrade step following this.
  89  
  90      return true;
  91  }