public final function execute() { if (!$this->execute_condition()) { // Check any condition to execute this return; } $fullpath = $this->task->get_taskbasepath(); // We MUST have one fullpath here, else, error if (empty($fullpath)) { throw new restore_step_exception('restore_structure_step_undefined_fullpath'); } // Append the filename to the fullpath $fullpath = rtrim($fullpath, '/') . '/' . $this->filename; // And it MUST exist if (!file_exists($fullpath)) { // Shouldn't happen ever, but... throw new restore_step_exception('missing_moodle_backup_xml_file', $fullpath); } // Get restore_path elements array adapting and preparing it for processing $structure = $this->define_structure(); if (!is_array($structure)) { throw new restore_step_exception('restore_step_structure_not_array', $this->get_name()); } $this->prepare_pathelements($structure); // Create parser and processor $xmlparser = new progressive_parser(); $xmlparser->set_file($fullpath); $xmlprocessor = new restore_structure_parser_processor($this->task->get_courseid(), $this); $this->contentprocessor = $xmlprocessor; // Save the reference to the contentprocessor // as far as we are going to need it out // from parser (blame serialized data!) $xmlparser->set_processor($xmlprocessor); // Add pathelements to processor foreach ($this->pathelements as $element) { $xmlprocessor->add_path($element->get_path(), $element->is_grouped()); } // Set up progress tracking. $progress = $this->get_task()->get_progress(); $progress->start_progress($this->get_name(), \core\progress\base::INDETERMINATE); $xmlparser->set_progress($progress); // And process it, dispatch to target methods in step will start automatically $xmlparser->process(); // Have finished, launch the after_execute method of all the processing objects $this->launch_after_execute_methods(); $progress->end_progress(); }
/** * Load the needed users.xml file to backup_ids table for future reference * * @param string $restoreid Restore id * @param string $usersfile File path * @param \core\progress\base $progress Progress tracker */ public static function load_users_to_tempids($restoreid, $usersfile, \core\progress\base $progress = null) { if (!file_exists($usersfile)) { // Shouldn't happen ever, but... throw new backup_helper_exception('missing_users_xml_file', $usersfile); } // Set up progress tracking (indeterminate). if (!$progress) { $progress = new \core\progress\none(); } $progress->start_progress('Loading users into temporary table'); // Let's parse, custom processor will do its work, sending info to DB $xmlparser = new progressive_parser(); $xmlparser->set_file($usersfile); $xmlprocessor = new restore_users_parser_processor($restoreid); $xmlparser->set_processor($xmlprocessor); $xmlparser->set_progress($progress); $xmlparser->process(); // Finish progress. $progress->end_progress(); }