Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400] [Versions 400 and 401] [Versions 400 and 402] [Versions 400 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   * Atto upgrade script.
  19   *
  20   * @package    editor_atto
  21   * @copyright  2014 Damyon Wiese
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  /**
  28   * Run all Atto upgrade steps between the current DB version and the current version on disk.
  29   * @param int $oldversion The old version of atto in the DB.
  30   * @return bool
  31   */
  32  function xmldb_editor_atto_upgrade($oldversion) {
  33      global $CFG;
  34  
  35      // Automatically generated Moodle v3.6.0 release upgrade line.
  36      // Put any upgrade step following this.
  37  
  38      // Automatically generated Moodle v3.7.0 release upgrade line.
  39      // Put any upgrade step following this.
  40  
  41      if ($oldversion < 2019090900) {
  42          $toolbar = get_config('editor_atto', 'toolbar');
  43  
  44          if (strpos($toolbar, 'h5p') === false) {
  45              $glue = "\r\n";
  46              if (strpos($toolbar, $glue) === false) {
  47                  $glue = "\n";
  48              }
  49              $groups = explode($glue, $toolbar);
  50              // Try to put h5p in the files group.
  51              foreach ($groups as $i => $group) {
  52                  $parts = explode('=', $group);
  53                  if (trim($parts[0]) == 'files') {
  54                      $groups[$i] = 'files = ' . trim($parts[1]) . ', h5p';
  55                      // Update config variable.
  56                      $toolbar = implode($glue, $groups);
  57                      set_config('toolbar', $toolbar, 'editor_atto');
  58                  }
  59              }
  60          }
  61          // Atto editor savepoint reached.
  62          upgrade_plugin_savepoint(true, 2019090900, 'editor', 'atto');
  63      }
  64      // Automatically generated Moodle v3.8.0 release upgrade line.
  65      // Put any upgrade step following this.
  66  
  67      if ($oldversion < 2020052100) {
  68          // The old default toolbar config for 38 and below.
  69          $oldtoolbar = 'collapse = collapse
  70  style1 = title, bold, italic
  71  list = unorderedlist, orderedlist
  72  links = link
  73  files = image, media, recordrtc, managefiles, h5p
  74  style2 = underline, strike, subscript, superscript
  75  align = align
  76  indent = indent
  77  insert = equation, charmap, table, clear
  78  undo = undo
  79  accessibility = accessibilitychecker, accessibilityhelper
  80  other = html';
  81  
  82          // Check if the current toolbar config matches the old toolbar config.
  83          if (get_config('editor_atto', 'toolbar') === $oldtoolbar) {
  84              // If the site is still using the old defaults, upgrade to the new default.
  85              $newtoolbar = 'collapse = collapse
  86  style1 = title, bold, italic
  87  list = unorderedlist, orderedlist, indent
  88  links = link
  89  files = emojipicker, image, media, recordrtc, managefiles, h5p
  90  style2 = underline, strike, subscript, superscript
  91  align = align
  92  insert = equation, charmap, table, clear
  93  undo = undo
  94  accessibility = accessibilitychecker, accessibilityhelper
  95  other = html';
  96              set_config('toolbar', $newtoolbar, 'editor_atto');
  97          }
  98  
  99          upgrade_plugin_savepoint(true, 2020052100, 'editor', 'atto');
 100      }
 101  
 102      // Automatically generated Moodle v3.9.0 release upgrade line.
 103      // Put any upgrade step following this.
 104  
 105      if ($oldversion < 2021062400) {
 106          // The old default toolbar config for 311 and below.
 107          $oldtoolbar = 'collapse = collapse
 108  style1 = title, bold, italic
 109  list = unorderedlist, orderedlist, indent
 110  links = link
 111  files = emojipicker, image, media, recordrtc, managefiles, h5p
 112  style2 = underline, strike, subscript, superscript
 113  align = align
 114  insert = equation, charmap, table, clear
 115  undo = undo
 116  accessibility = accessibilitychecker, accessibilityhelper
 117  other = html';
 118  
 119          // Check if the current toolbar config matches the old toolbar config.
 120          $sametoolbar = str_replace(["\r\n", "\r"], "\n", get_config('editor_atto', 'toolbar')) == $oldtoolbar;
 121          // Check if the current showgroups config matches the old showgroups config.
 122          $sameshowgroups = get_config('atto_collapse', 'showgroups') == 5;
 123  
 124          if ($sametoolbar && $sameshowgroups) {
 125              // If the site is still using the old defaults, upgrade to the new default.
 126              $newtoolbar = 'collapse = collapse
 127  style1 = title, bold, italic
 128  list = unorderedlist, orderedlist, indent
 129  links = link
 130  files = emojipicker, image, media, recordrtc, managefiles, h5p
 131  accessibility = accessibilitychecker, accessibilityhelper
 132  style2 = underline, strike, subscript, superscript
 133  align = align
 134  insert = equation, charmap, table, clear
 135  undo = undo
 136  other = html';
 137              set_config('toolbar', $newtoolbar, 'editor_atto');
 138              set_config('showgroups', 6, 'atto_collapse');
 139          }
 140  
 141          upgrade_plugin_savepoint(true, 2021062400, 'editor', 'atto');
 142      }
 143  
 144      // Automatically generated Moodle v4.0.0 release upgrade line.
 145      // Put any upgrade step following this.
 146  
 147      return true;
 148  }