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'); }
private function collect_errors($filename = '') { $errors = libxml_get_errors(); static $error_types = array(LIBXML_ERR_ERROR => 'Error', LIBXML_ERR_FATAL => 'Fatal Error', LIBXML_ERR_WARNING => 'Warning'); $result = array(); foreach ($errors as $error) { $add = ''; if (!empty($filename)) { $add = " in {$filename}"; } elseif (!empty($error->file)) { $add = " in {$error->file}"; } $line = ''; if (!empty($error->line)) { $line = " at line {$error->line}"; } $err = "{$error_types[$error->level]}{$add}: {$error->message}{$line}"; error_messages::instance()->add($err); } libxml_clear_errors(); return $result; }