[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/mod/imscp/backup/moodle1/ -> lib.php (source)

   1  <?php
   2  
   3  // This file is part of Moodle - http://moodle.org/
   4  //
   5  // Moodle is free software: you can redistribute it and/or modify
   6  // it under the terms of the GNU General Public License as published by
   7  // the Free Software Foundation, either version 3 of the License, or
   8  // (at your option) any later version.
   9  //
  10  // Moodle is distributed in the hope that it will be useful,
  11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13  // GNU General Public License for more details.
  14  //
  15  // You should have received a copy of the GNU General Public License
  16  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  17  
  18  /**
  19   * Provides support for the conversion of moodle1 backup to the moodle2 format
  20   *
  21   * @package mod_imscp
  22   * @copyright  2011 Andrew Davis <[email protected]>
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  /**
  29   * imscp conversion handler. This resource handler is called by moodle1_mod_resource_handler
  30   */
  31  class moodle1_mod_imscp_handler extends moodle1_resource_successor_handler {
  32  
  33      /** @var moodle1_file_manager the file manager instance */
  34      protected $fileman = null;
  35  
  36      /**
  37       * Converts /MOODLE_BACKUP/COURSE/MODULES/MOD/RESOURCE data
  38       * Called by moodle1_mod_resource_handler::process_resource()
  39       */
  40      public function process_legacy_resource(array $data, array $raw = null) {
  41  
  42          $instanceid    = $data['id'];
  43          $currentcminfo = $this->get_cminfo($instanceid);
  44          $moduleid      = $currentcminfo['id'];
  45          $contextid     = $this->converter->get_contextid(CONTEXT_MODULE, $moduleid);
  46  
  47          // prepare the new imscp instance record
  48          $imscp                  = array();
  49          $imscp['id']            = $data['id'];
  50          $imscp['name']          = $data['name'];
  51          $imscp['intro']         = $data['intro'];
  52          $imscp['introformat']   = $data['introformat'];
  53          $imscp['revision']      = 1;
  54          $imscp['keepold']       = 1;
  55          $imscp['structure']     = null;
  56          $imscp['timemodified']  = $data['timemodified'];
  57  
  58          // prepare a fresh new file manager for this instance
  59          $this->fileman = $this->converter->get_file_manager($contextid, 'mod_imscp');
  60  
  61          // convert course files embedded into the intro
  62          $this->fileman->filearea = 'intro';
  63          $this->fileman->itemid   = 0;
  64          $imscp['intro'] = moodle1_converter::migrate_referenced_files($imscp['intro'], $this->fileman);
  65  
  66          // migrate package backup file
  67          if ($data['reference']) {
  68              $packagename = basename($data['reference']);
  69              $packagepath = $this->converter->get_tempdir_path().'/moddata/resource/'.$data['id'].'/'.$packagename;
  70              if (file_exists($packagepath)) {
  71                  $this->fileman->filearea = 'backup';
  72                  $this->fileman->itemid   = 1;
  73                  $this->fileman->migrate_file('moddata/resource/'.$data['id'].'/'.$packagename);
  74              } else {
  75                  $this->log('missing imscp package', backup::LOG_WARNING, 'moddata/resource/'.$data['id'].'/'.$packagename);
  76              }
  77          }
  78  
  79          // migrate extracted package data
  80          $this->fileman->filearea = 'content';
  81          $this->fileman->itemid   = 1;
  82          $this->fileman->migrate_directory('moddata/resource/'.$data['id']);
  83  
  84          // parse manifest
  85          $structure = $this->parse_structure($this->converter->get_tempdir_path().'/moddata/resource/'.$data['id'].'/imsmanifest.xml', $imscp, $contextid);
  86          $imscp['structure'] = is_array($structure) ? serialize($structure) : null;
  87  
  88          // write imscp.xml
  89          $this->open_xml_writer("activities/imscp_{$moduleid}/imscp.xml");
  90          $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid,
  91              'modulename' => 'imscp', 'contextid' => $contextid));
  92          $this->write_xml('imscp', $imscp, array('/imscp/id'));
  93          $this->xmlwriter->end_tag('activity');
  94          $this->close_xml_writer();
  95  
  96          // write inforef.xml
  97          $this->open_xml_writer("activities/imscp_{$moduleid}/inforef.xml");
  98          $this->xmlwriter->begin_tag('inforef');
  99          $this->xmlwriter->begin_tag('fileref');
 100          foreach ($this->fileman->get_fileids() as $fileid) {
 101              $this->write_xml('file', array('id' => $fileid));
 102          }
 103          $this->xmlwriter->end_tag('fileref');
 104          $this->xmlwriter->end_tag('inforef');
 105          $this->close_xml_writer();
 106      }
 107  
 108      /// internal implementation details follow /////////////////////////////////
 109  
 110      /**
 111       * Parse the IMS package structure for the $imscp->structure field
 112       *
 113       * @param string $manifestfilepath the full path to the manifest file to parse
 114       */
 115      protected function parse_structure($manifestfilepath, $imscp, $context) {
 116          global $CFG;
 117  
 118          if (!file_exists($manifestfilepath)) {
 119              $this->log('missing imscp manifest file', backup::LOG_WARNING);
 120              return null;
 121          }
 122          $manifestfilecontents = file_get_contents($manifestfilepath);
 123          if (empty($manifestfilecontents)) {
 124              $this->log('empty imscp manifest file', backup::LOG_WARNING);
 125              return null;
 126          }
 127  
 128          require_once($CFG->dirroot.'/mod/imscp/locallib.php');
 129          return imscp_parse_manifestfile($manifestfilecontents, $imscp, $context);
 130      }
 131  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1