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  /**
  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  require_once("{$CFG->dirroot}/my/lib.php");
  29  require_once("{$CFG->libdir}/db/upgradelib.php");
  30  
  31  /**
  32   * Upgrade code for the MyOverview block.
  33   *
  34   * @param int $oldversion
  35   */
  36  function xmldb_block_myoverview_upgrade($oldversion) {
  37      global $DB, $CFG, $OUTPUT;
  38  
  39      // Automatically generated Moodle v3.9.0 release upgrade line.
  40      // Put any upgrade step following this.
  41  
  42      if ($oldversion < 2021052504) {
  43          upgrade_block_delete_instances('myoverview', '__default', 'my-index');
  44  
  45          // Add new instance to the /my/courses.php page.
  46          $subpagepattern = $DB->get_record('my_pages', [
  47              'userid' => null,
  48              'name' => MY_PAGE_COURSES,
  49              'private' => MY_PAGE_PUBLIC,
  50          ], 'id', IGNORE_MULTIPLE)->id;
  51  
  52          $blockname = 'myoverview';
  53          $pagetypepattern = 'my-index';
  54  
  55          $blockparams = [
  56              'blockname' => $blockname,
  57              'pagetypepattern' => $pagetypepattern,
  58              'subpagepattern' => $subpagepattern,
  59          ];
  60  
  61          // See if this block already somehow exists, it should not but who knows.
  62          if (!$DB->record_exists('block_instances', $blockparams)) {
  63              $page = new moodle_page();
  64              $page->set_context(context_system::instance());
  65              // Add the block to the default /my/courses.
  66              $page->blocks->add_region('content');
  67              $page->blocks->add_block($blockname, 'content', 0, false, $pagetypepattern, $subpagepattern);
  68          }
  69  
  70          upgrade_block_savepoint(true, 2021052504, 'myoverview', false);
  71      }
  72  
  73      if ($oldversion < 2022041901) {
  74          upgrade_block_set_my_user_parent_context('myoverview', '__default', 'my-index');
  75          upgrade_block_savepoint(true, 2022041901, 'myoverview', false);
  76      }
  77  
  78      // Automatically generated Moodle v4.0.0 release upgrade line.
  79      // Put any upgrade step following this.
  80  
  81      // Automatically generated Moodle v4.1.0 release upgrade line.
  82      // Put any upgrade step following this.
  83  
  84      return true;
  85  }