Esempio n. 1
0
 public function test_inforef_manager()
 {
     $converter = convert_factory::get_converter('moodle1', $this->tempdir);
     $inforef = $converter->get_inforef_manager('unittest');
     $inforef->add_ref('file', 45);
     $inforef->add_refs('file', array(46, 47));
     // todo test the write_refs() via some dummy xml_writer
     $this->setExpectedException('coding_exception');
     $inforef->add_ref('unknown_referenced_item_name', 76);
 }
 /**
  * Converts the given directory with the backup into moodle2 format
  *
  * @param string $tempdir The directory to convert
  * @param string $format The current format, if already detected
  * @param base_logger|null if the conversion should be logged, use this logger
  * @throws convert_helper_exception
  * @return bool false if unable to find the conversion path, true otherwise
  */
 public static function to_moodle2_format($tempdir, $format = null, $logger = null)
 {
     if (is_null($format)) {
         $format = backup_general_helper::detect_backup_format($tempdir);
     }
     // get the supported conversion paths from all available converters
     $converters = self::available_converters();
     $descriptions = array();
     foreach ($converters as $name) {
         $classname = "{$name}_converter";
         if (!class_exists($classname)) {
             throw new convert_helper_exception('class_not_loaded', $classname);
         }
         if ($logger instanceof base_logger) {
             backup_helper::log('available converter', backup::LOG_DEBUG, $classname, 1, false, $logger);
         }
         $descriptions[$name] = call_user_func($classname . '::description');
     }
     // choose the best conversion path for the given format
     $path = self::choose_conversion_path($format, $descriptions);
     if (empty($path)) {
         if ($logger instanceof base_logger) {
             backup_helper::log('unable to find the conversion path', backup::LOG_ERROR, null, 0, false, $logger);
         }
         return false;
     }
     if ($logger instanceof base_logger) {
         backup_helper::log('conversion path established', backup::LOG_INFO, implode(' => ', array_merge($path, array('moodle2'))), 0, false, $logger);
     }
     foreach ($path as $name) {
         if ($logger instanceof base_logger) {
             backup_helper::log('running converter', backup::LOG_INFO, $name, 0, false, $logger);
         }
         $converter = convert_factory::get_converter($name, $tempdir, $logger);
         $converter->convert();
     }
     // make sure we ended with moodle2 format
     if (!self::detect_moodle2_format($tempdir)) {
         throw new convert_helper_exception('conversion_failed');
     }
     return true;
 }