예제 #1
0
 /**
  * Constructor for the backup controller class.
  *
  * @param int $type Type of the backup; One of backup::TYPE_1COURSE, TYPE_1SECTION, TYPE_1ACTIVITY
  * @param int $id The ID of the item to backup; e.g the course id
  * @param int $format The backup format to use; Most likely backup::FORMAT_MOODLE
  * @param bool $interactive Whether this backup will require user interaction; backup::INTERACTIVE_YES or INTERACTIVE_NO
  * @param int $mode One of backup::MODE_GENERAL, MODE_IMPORT, MODE_SAMESITE, MODE_HUB, MODE_AUTOMATED
  * @param int $userid The id of the user making the backup
  */
 public function __construct($type, $id, $format, $interactive, $mode, $userid)
 {
     $this->type = $type;
     $this->id = $id;
     $this->courseid = backup_controller_dbops::get_courseid_from_type_id($this->type, $this->id);
     $this->format = $format;
     $this->interactive = $interactive;
     $this->mode = $mode;
     $this->userid = $userid;
     // Apply some defaults
     $this->execution = backup::EXECUTION_INMEDIATE;
     $this->operation = backup::OPERATION_BACKUP;
     $this->executiontime = 0;
     $this->checksum = '';
     // Apply current backup version and release if necessary
     backup_controller_dbops::apply_version_and_release();
     // Check format and type are correct
     backup_check::check_format_and_type($this->format, $this->type);
     // Check id is correct
     backup_check::check_id($this->type, $this->id);
     // Check user is correct
     backup_check::check_user($this->userid);
     // Calculate unique $backupid
     $this->calculate_backupid();
     // Default logger chain (based on interactive/execution)
     $this->logger = backup_factory::get_logger_chain($this->interactive, $this->execution, $this->backupid);
     // By default there is no progress reporter. Interfaces that wish to
     // display progress must set it.
     $this->progress = new \core\progress\none();
     // Instantiate the output_controller singleton and active it if interactive and inmediate
     $oc = output_controller::get_instance();
     if ($this->interactive == backup::INTERACTIVE_YES && $this->execution == backup::EXECUTION_INMEDIATE) {
         $oc->set_active(true);
     }
     $this->log('instantiating backup controller', backup::LOG_INFO, $this->backupid);
     // Default destination chain (based on type/mode/execution)
     $this->destination = backup_factory::get_destination_chain($this->type, $this->id, $this->mode, $this->execution);
     // Set initial status
     $this->set_status(backup::STATUS_CREATED);
     // Load plan (based on type/format)
     $this->load_plan();
     // Apply all default settings (based on type/format/mode)
     $this->apply_defaults();
     // Perform all initial security checks and apply (2nd param) them to settings automatically
     backup_check::check_security($this, true);
     // Set status based on interactivity
     if ($this->interactive == backup::INTERACTIVE_YES) {
         $this->set_status(backup::STATUS_SETTING_UI);
     } else {
         $this->set_status(backup::STATUS_AWAITING);
     }
 }