/** * Converts from current format to backup::MOODLE format */ public function convert() { global $CFG; require_once $CFG->dirroot . '/backup/util/helper/convert_helper.class.php'; // Basic/initial prevention against time/memory limits set_time_limit(1 * 60 * 60); // 1 hour for 1 course initially granted raise_memory_limit(MEMORY_EXTRA); if ($this->status != backup::STATUS_REQUIRE_CONV) { throw new restore_controller_exception('cannot_convert_not_required_status'); } $this->log('backup format conversion required', backup::LOG_INFO); // Run conversion to the proper format if (!convert_helper::to_moodle2_format($this->get_tempdir(), $this->format, $this->get_logger())) { // todo - unable to find the conversion path, what to do now? // throwing the exception as a temporary solution throw new restore_controller_exception('unable_to_find_conversion_path'); } $this->log('backup format conversion successful', backup::LOG_INFO); // If no exceptions were thrown, then we are in the proper format $this->format = backup::FORMAT_MOODLE; // Load plan, apply security and set status based on interactivity $this->load_plan(); // Perform all initial security checks and apply (2nd param) them to settings automatically restore_check::check_security($this, true); if ($this->interactive == backup::INTERACTIVE_YES) { $this->set_status(backup::STATUS_SETTING_UI); } else { $this->set_status(backup::STATUS_NEED_PRECHECK); } }
/** * convert from current format to backup::MOODLE format */ public function convert() { if ($this->status != backup::STATUS_REQUIRE_CONV) { throw new restore_controller_exception('cannot_convert_not_required_status'); } if ($this->format == backup::FORMAT_UNKNOWN) { throw new restore_controller_exception('cannot_convert_from_unknown_format'); } if ($this->format == backup::FORMAT_MOODLE1) { // TODO: Implement moodle1 => moodle2 conversion throw new restore_controller_exception('cannot_convert_yet_from_moodle1_format'); } // Once conversions have finished, we check again the format $newformat = backup_general_helper::detect_backup_format($tempdir); // If format is moodle2, load plan, apply security and set status based on interactivity if ($newformat === backup::FORMAT_MOODLE) { // Load plan $this->load_plan(); // Perform all initial security checks and apply (2nd param) them to settings automatically restore_check::check_security($this, true); if ($this->interactive == backup::INTERACTIVE_YES) { $this->set_status(backup::STATUS_SETTING_UI); } else { $this->set_status(backup::STATUS_NEED_PRECHECK); } } else { throw new restore_controller_exception('conversion_ended_with_wrong_format', $newformat); } }