const OPERATION_RESTORE ='restore';// We are performing one restore
// Version (to keep CFG->backup_version (and release) updated automatically)
- const VERSION = 2010070500;
+ const VERSION = 2010071800;
const RELEASE = '2.0 Preview 5';
}
protected $samesite; // Are we restoring to the same site where the backup was generated
protected $status; // Current status of the controller (created, planned, configured...)
+ protected $precheck; // Results of the execution of restore prechecks
protected $info; // Information retrieved from backup contents
protected $plan; // Restore execution plan
$this->executiontime = 0;
$this->samesite = false;
$this->checksum = '';
+ $this->precheck = null;
// Apply current backup version and release if necessary
backup_controller_dbops::apply_version_and_release();
'samesite-' . $this->samesite .
'operation-' . $this->operation .
'status-' . $this->status .
+ 'precheck-' . backup_general_helper::array_checksum_recursive(array($this->precheck)) .
'execution-' . $this->execution .
'plan-' . backup_general_helper::array_checksum_recursive(array($this->plan)) .
'info-' . backup_general_helper::array_checksum_recursive(array($this->info)) .
}
public function execute_precheck() {
- debugging ('TODO: Not applying prechecks yet, need to link them to proper restore_precheck class!', DEBUG_DEVELOPER);
- $this->set_status(backup::STATUS_AWAITING); // TODO: Delete this once prechecks and steps are in place
- //return $this->precheck->execute();
- return true;
+ if (is_array($this->precheck)) {
+ throw new restore_controller_exception('precheck_alredy_executed', $this->status);
+ }
+ if ($this->status != backup::STATUS_NEED_PRECHECK) {
+ throw new restore_controller_exception('cannot_precheck_wrong_status', $this->status);
+ }
+ $this->precheck = restore_prechecks_helper::execute_prechecks($this);
+ if (!array_key_exists('errors', $this->precheck)) { // No errors, can be executed
+ $this->set_status(backup::STATUS_AWAITING);
+ }
+ if (empty($this->precheck)) { // No errors nor warnings, return true
+ return true;
+ }
+ return false;
}
public function get_results() {
}
public function get_precheck_results() {
- debugging ('TODO: Not applying prechecks yet, need to link them to proper restore_precheck class!', DEBUG_DEVELOPER);
- return array();
- //return $this->precheck->get_results();
+ if (!is_array($this->precheck)) {
+ throw new restore_controller_exception('precheck_not_executed');
+ }
+ return $this->precheck;
}
public function log($message, $level, $a = null, $depth = null, $display = false) {
$info['backup_release'] = $CFG->backup_release;
$info['backup_date'] = time();
$info['backup_uniqueid']= $this->get_backupid();
+ $info['mnet_remoteusers']=backup_controller_dbops::backup_includes_mnet_remote_users($this->get_backupid());
$info['original_wwwroot']=$CFG->wwwroot;
$info['original_site_identifier_hash'] = md5(get_site_identifier());
$info['original_course_id'] = $this->get_courseid();
$information = new backup_nested_element('information', null, array(
'name', 'moodle_version', 'moodle_release', 'backup_version',
- 'backup_release', 'backup_date', 'original_wwwroot',
+ 'backup_release', 'backup_date', 'mnet_remoteusers', 'original_wwwroot',
'original_site_identifier_hash', 'original_course_id', 'original_course_contextid', 'original_system_contextid'));
$details = new backup_nested_element('details');
// Unconditionally, load create all the needed scales
$this->add_step(new restore_scales_structure_step('create_scales', 'scales.xml'));
+ // Unconditionally, load create all the needed outcomes.
+ // TODO: restore outcomes
+ // $this->add_step(new restore_outcomes_structure_step('create_outcomes', 'outcomes.xml'));
+
// At the end, mark it as built
$this->built = true;
}
}
}
+ /**
+ * Given the backupid, detect if the backup includes "mnet" remote users or no
+ */
+ public static function backup_includes_mnet_remote_users($backupid) {
+ global $CFG, $DB;
+
+ $sql = "SELECT COUNT(*)
+ FROM {backup_ids_temp} b
+ JOIN {user} u ON u.id = b.itemid
+ WHERE b.backupid = ?
+ AND b.itemname = 'userfinal'
+ AND u.mnethostid != ?";
+ $count = $DB->count_records_sql($sql, array($backupid, $CFG->mnet_localhost_id));
+ return (int)(bool)$count;
+ }
+
/**
* Sets the controller settings default values from the backup config.
*
$info->backup_version = $infoarr['backup_version'];
$info->backup_release = $infoarr['backup_release'];
$info->backup_date = $infoarr['backup_date'];
+ $info->mnet_remoteusers = $infoarr['mnet_remoteusers'];
$info->original_wwwroot = $infoarr['original_wwwroot'];
$info->original_site_identifier_hash = $infoarr['original_site_identifier_hash'];
$info->original_course_id = $infoarr['original_course_id'];
require_once($CFG->dirroot . '/backup/util/interfaces/checksumable.class.php');
require_once($CFG->dirroot . '/backup/util/interfaces/loggable.class.php');
require_once($CFG->dirroot . '/backup/util/interfaces/executable.class.php');
+require_once($CFG->dirroot . '/backup/backup.class.php');
require_once($CFG->dirroot . '/backup/util/structure/restore_path_element.class.php');
require_once($CFG->dirroot . '/backup/util/helper/backup_file_manager.class.php');
+require_once($CFG->dirroot . '/backup/util/helper/restore_prechecks_helper.class.php');
require_once($CFG->dirroot . '/backup/util/helper/restore_moodlexml_parser_processor.class.php');
require_once($CFG->dirroot . '/backup/util/helper/restore_inforef_parser_processor.class.php');
require_once($CFG->dirroot . '/backup/util/helper/restore_users_parser_processor.class.php');
require_once($CFG->dirroot . '/backup/util/helper/restore_structure_parser_processor.class.php');
require_once($CFG->dirroot . '/backup/util/xml/parser/progressive_parser.class.php');
-require_once($CFG->dirroot . '/backup/backup.class.php');
require_once($CFG->dirroot . '/backup/util/output/output_controller.class.php');
require_once($CFG->dirroot . '/backup/util/dbops/backup_dbops.class.php');
require_once($CFG->dirroot . '/backup/util/dbops/restore_dbops.class.php');