return $this->includefiles;
}
+ /**
+ * Returns the default value for $this->includefiles before we consider any settings.
+ *
+ * @return bool
+ * @throws dml_exception
+ */
+ protected function get_include_files_default() : bool {
+ // We normally include files.
+ $includefiles = true;
+
+ // In an import, we don't need to include files.
+ if ($this->get_mode() === backup::MODE_IMPORT) {
+ $includefiles = false;
+ }
+
+ // When a backup is intended for the same site, we don't need to include the files.
+ // Note, this setting is only used for duplication of an entire course.
+ if ($this->get_mode() === backup::MODE_SAMESITE) {
+ $includefiles = false;
+ }
+
+ // If backup is automated and we have set auto backup config to exclude
+ // files then set them to be excluded here.
+ $backupautofiles = (bool) get_config('backup', 'backup_auto_files');
+ if ($this->get_mode() === backup::MODE_AUTOMATED && !$backupautofiles) {
+ $includefiles = false;
+ }
+
+ return $includefiles;
+ }
+
public function get_operation() {
return $this->operation;
}
// Basic/initial prevention against time/memory limits
core_php_time_limit::raise(1 * 60 * 60); // 1 hour for 1 course initially granted
raise_memory_limit(MEMORY_EXTRA);
+
+ // If the controller has decided that we can include files, then check the setting, otherwise do not include files.
+ if ($this->get_include_files()) {
+ $this->set_include_files((bool) $this->get_plan()->get_setting('files')->get_value());
+ }
+
// If this is not a course backup, or single activity backup (e.g. duplicate) inform the plan we are not
// including all the activities for sure. This will affect any
// task/step executed conditionally to stop including information
$this->log('applying plan defaults', backup::LOG_DEBUG);
backup_controller_dbops::apply_config_defaults($this);
$this->set_status(backup::STATUS_CONFIGURED);
- $this->set_include_files();
+ $this->set_include_files($this->get_include_files_default());
}
/**
* Set the initial value for the include_files setting.
*
+ * @param bool $includefiles
* @see backup_controller::get_include_files for further information on the purpose of this setting.
- * @return int Indicates whether files should be included in backups.
*/
- protected function set_include_files() {
- // We normally include files.
- $includefiles = true;
-
- // In an import, we don't need to include files.
- if ($this->get_mode() === backup::MODE_IMPORT) {
- $includefiles = false;
- }
-
- // When a backup is intended for the same site, we don't need to include the files.
- // Note, this setting is only used for duplication of an entire course.
- if ($this->get_mode() === backup::MODE_SAMESITE) {
- $includefiles = false;
- }
-
- // If backup is automated and we have set auto backup config to exclude
- // files then set them to be excluded here.
- $backupautofiles = (bool)get_config('backup', 'backup_auto_files');
- if ($this->get_mode() === backup::MODE_AUTOMATED && !$backupautofiles) {
- $includefiles = false;
- }
-
- $this->includefiles = (int) $includefiles;
+ protected function set_include_files(bool $includefiles) {
$this->log("setting file inclusion to {$this->includefiles}", backup::LOG_DEBUG);
- return $this->includefiles;
+ $this->includefiles = (int) $includefiles;
}
-
}
/*
protected $backupid;
- /**
- * @var bool Are we including the files?
- */
- protected $includefiles = true;
-
public function process($processor) {
// Get current backupid from processor, we'll need later
if (is_null($this->backupid)) {
// Fill values
parent::fill_values($values);
// Do our own tasks (copy file from moodle to backup)
- if ($this->includefiles) {
- try {
- backup_file_manager::copy_file_moodle2backup($this->backupid, $values);
- } catch (file_exception $e) {
- $this->add_result(array('missing_files_in_pool' => true));
-
- // Build helpful log message with all information necessary to identify
- // file location.
- $context = context::instance_by_id($values->contextid, IGNORE_MISSING);
- $contextname = '';
- if ($context) {
- $contextname = ' \'' . $context->get_context_name() . '\'';
- }
- $message = 'Missing file in pool: ' . $values->filepath . $values->filename .
- ' (context ' . $values->contextid . $contextname . ', component ' .
- $values->component . ', filearea ' . $values->filearea . ', itemid ' .
- $values->itemid . ') [' . $e->debuginfo . ']';
- $this->add_log($message, backup::LOG_WARNING);
+ try {
+ backup_file_manager::copy_file_moodle2backup($this->backupid, $values);
+ } catch (file_exception $e) {
+ $this->add_result(array('missing_files_in_pool' => true));
+
+ // Build helpful log message with all information necessary to identify
+ // file location.
+ $context = context::instance_by_id($values->contextid, IGNORE_MISSING);
+ $contextname = '';
+ if ($context) {
+ $contextname = ' \'' . $context->get_context_name() . '\'';
}
+ $message = 'Missing file in pool: ' . $values->filepath . $values->filename .
+ ' (context ' . $values->contextid . $contextname . ', component ' .
+ $values->component . ', filearea ' . $values->filearea . ', itemid ' .
+ $values->itemid . ') [' . $e->debuginfo . ']';
+ $this->add_log($message, backup::LOG_WARNING);
}
}
-
- /**
- * Sets the value for includefiles.
- *
- * @param bool $value The value to set it to
- */
- public function set_include_files(bool $value) {
- $this->includefiles = $value;
- }
}
/**
'source', 'author', 'license', 'sortorder',
'repositorytype', 'repositoryid', 'reference'));
- // Set whether we want to store the actual files in the backup.
- $file->set_include_files($this->get_setting_value('files'));
-
// Build the tree
$files->add_child($file);
$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['include_files'] = $this->get_setting_value('files') &&
- backup_controller_dbops::backup_includes_files($this->get_backupid());
+ $info['include_files'] = backup_controller_dbops::backup_includes_files($this->get_backupid());
$info['include_file_references_to_external_content'] =
backup_controller_dbops::backup_includes_file_references($this->get_backupid());
$info['original_wwwroot']=$CFG->wwwroot;