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.
   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   * Install code for tours.
  19   *
  20   * @package    tool_usertours
  21   * @copyright  2016 Andrew Nicols <andrew@nicols.co.uk>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die;
  26  
  27  use tool_usertours\manager;
  28  
  29  /**
  30   * Perform the post-install procedures.
  31   */
  32  function xmldb_tool_usertours_install() {
  33      global $DB;
  34  
  35      $localplugin = core_plugin_manager::instance()->get_plugin_info('local_usertours');
  36      if ($localplugin) {
  37          // If the old local plugin was previously installed, copy over the data from the old tables.
  38  
  39          // The 'comment' field was renamed to 'description' in:
  40          // * 3.0 version 2015111604
  41          // * 3.1 version 2016052303
  42          // We need to attempt to fetch comment for these older versions.
  43          $hasdescription = ($localplugin->versiondb < 2016052301 && $localplugin->versiondb >= 2015111604);
  44          $hasdescription = $hasdescription || ($localplugin->versiondb > 2016052303);
  45  
  46          $tours = $DB->get_recordset('usertours_tours');
  47          $mapping = [];
  48          foreach ($tours as $tour) {
  49              if (!$hasdescription) {
  50                  if (property_exists($tour, 'comment')) {
  51                      $tour->description = $tour->comment;
  52                      unset($tour->comment);
  53                  } else {
  54                      $tour->description = '';
  55                  }
  56              }
  57              $mapping[$tour->id] = $DB->insert_record('tool_usertours_tours', $tour);
  58          }
  59          $tours->close();
  60  
  61          $steps = $DB->get_recordset('usertours_steps');
  62          foreach ($steps as $step) {
  63              if (!isset($mapping[$step->tourid])) {
  64                  // Skip this one. It has somehow become orphaned.
  65                  continue;
  66              }
  67              $step->tourid = $mapping[$step->tourid];
  68              $DB->insert_record('tool_usertours_steps', $step);
  69          }
  70          $steps->close();
  71  
  72          // Delete the old records.
  73          $DB->delete_records('usertours_steps', null);
  74          $DB->delete_records('usertours_tours', null);
  75      }
  76  
  77      // Update the tours shipped with Moodle.
  78      manager::update_shipped_tours();
  79  }