public static function get_instance()
 {
     if (!isset(self::$instance)) {
         self::$instance = new output_controller();
     }
     return self::$instance;
 }
 /**
  * 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);
     }
 }
Beispiel #3
0
 /**
  * This function will be invoked by any log() method in backup/restore, acting
  * as a simple forwarder to the standard loggers but also, if the $display
  * parameter is true, supporting translation via get_string() and sending to
  * standard output.
  */
 public static function log($message, $level, $a, $depth, $display, $logger)
 {
     // Send to standard loggers
     $logmessage = $message;
     $options = empty($depth) ? array() : array('depth' => $depth);
     if (!empty($a)) {
         $logmessage = $logmessage . ' ' . implode(', ', (array) $a);
     }
     $logger->process($logmessage, $level, $options);
     // If $display specified, send translated string to output_controller
     if ($display) {
         output_controller::get_instance()->output($message, 'backup', $a, $depth);
     }
 }
 /**
  *
  * @param string $tempdir Directory under tempdir/backup awaiting restore
  * @param int $courseid Course id where restore is going to happen
  * @param bool $interactive backup::INTERACTIVE_YES[true] or backup::INTERACTIVE_NO[false]
  * @param int $mode backup::MODE_[ GENERAL | HUB | IMPORT | SAMESITE ]
  * @param int $userid
  * @param int $target backup::TARGET_[ NEW_COURSE | CURRENT_ADDING | CURRENT_DELETING | EXISTING_ADDING | EXISTING_DELETING ]
  */
 public function __construct($tempdir, $courseid, $interactive, $mode, $userid, $target)
 {
     $this->tempdir = $tempdir;
     $this->courseid = $courseid;
     $this->interactive = $interactive;
     $this->mode = $mode;
     $this->userid = $userid;
     $this->target = $target;
     // 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;
     $this->checksum = '';
     $this->precheck = null;
     // Apply current backup version and release if necessary
     backup_controller_dbops::apply_version_and_release();
     // Check courseid is correct
     restore_check::check_courseid($this->courseid);
     // Check user is correct
     restore_check::check_user($this->userid);
     // Calculate unique $restoreid
     $this->calculate_restoreid();
     // Default logger chain (based on interactive/execution)
     $this->logger = backup_factory::get_logger_chain($this->interactive, $this->execution, $this->restoreid);
     // 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 restore controller', backup::LOG_INFO, $this->restoreid);
     // Set initial status
     $this->set_status(backup::STATUS_CREATED);
     // Calculate original restore format
     $this->format = backup_general_helper::detect_backup_format($tempdir);
     // If format is not moodle2, set to conversion needed
     if ($this->format !== backup::FORMAT_MOODLE) {
         $this->set_status(backup::STATUS_REQUIRE_CONV);
         // Else, format is moodle2, load plan, apply security and set status based on interactivity
     } else {
         // 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);
         }
     }
 }