function cc_convert($dir) { global $OUTPUT; $manifest_file = $dir . DIRECTORY_SEPARATOR . 'imsmanifest.xml'; $moodle_file = $dir . DIRECTORY_SEPARATOR . 'moodle.xml'; $schema_file = 'cc' . DIRECTORY_SEPARATOR . '' . DIRECTORY_SEPARATOR . 'schemas' . DIRECTORY_SEPARATOR . 'cclibxml2validator.xsd'; if (is_readable($manifest_file) && !is_readable($moodle_file)) { $is_cc = detect_cc_format($manifest_file); if ($is_cc) { $detected_requirements = detect_requirements(); if (!$detected_requirements["php5"]) { echo $OUTPUT->notification(get_string('cc_import_req_php5', 'imscc')); return false; } if (!$detected_requirements["dom"]) { echo $OUTPUT->notification(get_string('cc_import_req_dom', 'imscc')); return false; } if (!$detected_requirements["libxml"]) { echo $OUTPUT->notification(get_string('cc_import_req_libxml', 'imscc')); return false; } if (!$detected_requirements["libxmlminversion"]) { echo $OUTPUT->notification(get_string('cc_import_req_libxmlminversion', 'imscc')); return false; } if (!$detected_requirements["xsl"]) { echo $OUTPUT->notification(get_string('cc_import_req_xsl', 'imscc')); return false; } echo get_string('cc2moodle_checking_schema', 'imscc') . '<br />'; $cc_manifest = new DOMDocument(); if ($cc_manifest->load($manifest_file)) { if ($cc_manifest->schemaValidate($schema_file)) { echo get_string('cc2moodle_valid_schema', 'imscc') . '<br />'; $cc2moodle = new cc2moodle($manifest_file); if (!$cc2moodle->is_auth()) { return $cc2moodle->generate_moodle_xml(); } else { echo $OUTPUT->notification(get_string('cc2moodle_req_auth', 'imscc')); return false; } } else { echo $OUTPUT->notification(get_string('cc2moodle_invalid_schema', 'imscc')); return false; } } else { echo $OUTPUT->notification(get_string('cc2moodle_manifest_dont_load', 'imscc')); return false; } } } return true; }
protected function execute() { global $CFG; $manifest = cc2moodle::get_manifest($this->get_tempdir_path()); if (empty($manifest)) { throw new imscc1_convert_exception('No Manifest detected!'); } $this->log('validating manifest', backup::LOG_DEBUG, null, 1); $validator = new manifest10_validator($CFG->dirroot . '/backup/cc/schemas'); if (!$validator->validate($manifest)) { $this->log('validation error(s): ' . PHP_EOL . error_messages::instance(), backup::LOG_DEBUG, null, 2); throw new imscc1_convert_exception(error_messages::instance()->to_string(true)); } $manifestdir = dirname($manifest); $cc2moodle = new cc2moodle($manifest); if ($cc2moodle->is_auth()) { throw new imscc1_convert_exception('Protected cartridge content - Skipping import!'); } $status = $cc2moodle->generate_moodle_xml(); //Final cleanup $xml_error = new libxml_errors_mgr(true); $mdoc = new DOMDocument(); $mdoc->preserveWhiteSpace = false; $mdoc->formatOutput = true; $mdoc->validateOnParse = false; $mdoc->strictErrorChecking = false; if ($mdoc->load($manifestdir . '/moodle.xml', LIBXML_NONET)) { $mdoc->save($this->get_workdir_path() . '/moodle.xml', LIBXML_NOEMPTYTAG); } else { $xml_error->collect(); $this->log('validation error(s): ' . PHP_EOL . error_messages::instance(), backup::LOG_DEBUG, null, 2); throw new imscc1_convert_exception(error_messages::instance()->to_string(true)); } //Move the files to the workdir rename($manifestdir . '/course_files', $this->get_workdir_path() . '/course_files'); }