/** @var restore_plan */
protected $plan; // Restore execution plan
- protected $execution; // inmediate/delayed
+ /**
+ * Immediate/delayed execution type.
+ * @var integer
+ */
+ protected $execution;
protected $executiontime; // epoch time when we want the restore to be executed (requires cron to run)
protected $checksum; // Cache @checksumable results for lighter @is_checksum_correct() uses
// Apply some defaults
$this->type = '';
$this->format = backup::FORMAT_UNKNOWN;
- $this->execution = backup::EXECUTION_INMEDIATE;
$this->operation = backup::OPERATION_RESTORE;
$this->executiontime = 0;
$this->samesite = false;
// Default logger chain (based on interactive/execution)
$this->logger = backup_factory::get_logger_chain($this->interactive, $this->execution, $this->restoreid);
+ // Set execution based on backup mode.
+ if ($mode == backup::MODE_ASYNC) {
+ $this->execution = backup::EXECUTION_DELAYED;
+ } else {
+ $this->execution = backup::EXECUTION_INMEDIATE;
+ }
+
// By default there is no progress reporter unless you specify one so it
// can be used during loading of the plan.
if ($progress) {
}
$this->progress->start_progress('Constructing restore_controller');
- // Instantiate the output_controller singleton and active it if interactive and inmediate
+ // Instantiate the output_controller singleton and active it if interactive and immediate.
$oc = output_controller::get_instance();
if ($this->interactive == backup::INTERACTIVE_YES && $this->execution == backup::EXECUTION_INMEDIATE) {
$oc->set_active(true);
// TODO: Check it's a correct status.
$this->status = $status;
// Ensure that, once set to backup::STATUS_AWAITING | STATUS_NEED_PRECHECK, controller is stored in DB.
- if ($status == backup::STATUS_AWAITING || $status == backup::STATUS_NEED_PRECHECK) {
+ // Also save if executing so we can better track progress.
+ if ($status == backup::STATUS_AWAITING || $status == backup::STATUS_NEED_PRECHECK || $status == backup::STATUS_EXECUTING) {
$this->save_controller();
$tbc = self::load_controller($this->restoreid);
$this->logger = $tbc->logger; // wakeup loggers
// If the operation has ended without error (backup::STATUS_FINISHED_OK)
// proceed by cleaning the object from database. MDL-29262.
$this->save_controller(false, true);
+ } else if ($status == backup::STATUS_FINISHED_ERR) {
+ // If the operation has ended with an error save the controller
+ // preserving the object in the database. We may want it for debugging.
+ $this->save_controller();
}
}
public function set_execution($execution, $executiontime = 0) {
$this->log('setting controller execution', backup::LOG_DEBUG);
- // TODO: Check valid execution mode
- // TODO: Check time in future
- // TODO: Check time = 0 if inmediate
+ // TODO: Check valid execution mode.
+ // TODO: Check time in future.
+ // TODO: Check time = 0 if immediate.
$this->execution = $execution;
$this->executiontime = $executiontime;