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]

   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   * Provides support for the conversion of moodle1 backup to the moodle2 format
  19   *
  20   * @package    block_html
  21   * @copyright  2012 Paul Nicholls
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  /**
  28   * Block conversion handler for html
  29   */
  30  class moodle1_block_html_handler extends moodle1_block_handler {
  31      private $fileman = null;
  32      protected function convert_configdata(array $olddata) {
  33          global $CFG;
  34          require_once($CFG->libdir . '/db/upgradelib.php');
  35          $instanceid = $olddata['id'];
  36          $contextid  = $this->converter->get_contextid(CONTEXT_BLOCK, $olddata['id']);
  37          $decodeddata = base64_decode($olddata['configdata']);
  38          list($updated, $configdata) = upgrade_fix_serialized_objects($decodeddata);
  39          $configdata = unserialize_object($configdata);
  40  
  41          // get a fresh new file manager for this instance
  42          $this->fileman = $this->converter->get_file_manager($contextid, 'block_html');
  43  
  44          // convert course files embedded in the block content
  45          $this->fileman->filearea = 'content';
  46          $this->fileman->itemid   = 0;
  47          $configdata->text = moodle1_converter::migrate_referenced_files($configdata->text ?? '', $this->fileman);
  48          $configdata->format = FORMAT_HTML;
  49  
  50          return base64_encode(serialize($configdata));
  51      }
  52  
  53      protected function write_inforef_xml($newdata, $data) {
  54          $this->open_xml_writer("course/blocks/{$data['name']}_{$data['id']}/inforef.xml");
  55          $this->xmlwriter->begin_tag('inforef');
  56          $this->xmlwriter->begin_tag('fileref');
  57          foreach ($this->fileman->get_fileids() as $fileid) {
  58              $this->write_xml('file', array('id' => $fileid));
  59          }
  60          $this->xmlwriter->end_tag('fileref');
  61          $this->xmlwriter->end_tag('inforef');
  62          $this->close_xml_writer();
  63      }
  64  }