Skip to content
Browse files

MDL-28346 Backup: Backup does not fail when a file is missing

Conflicts:

	backup/util/ui/backup_ui_stage.class.php
  • Loading branch information...
1 parent 5ef242f commit aae03dd4d4fa5aa88f93144463fcf2f2a8c90d0c @FMCorz FMCorz committed Jul 9, 2012
View
9 backup/moodle2/backup_custom_fields.php
@@ -91,14 +91,19 @@ public function process($processor) {
if (is_null($this->backupid)) {
$this->backupid = $processor->get_var(backup::VAR_BACKUPID);
}
- parent::process($processor);
+ return parent::process($processor);
}
public function fill_values($values) {
// Fill values
parent::fill_values($values);
// Do our own tasks (copy file from moodle to backup)
- backup_file_manager::copy_file_moodle2backup($this->backupid, $values);
+ try {
+ backup_file_manager::copy_file_moodle2backup($this->backupid, $values);
+ } catch (file_exception $e) {
+ $this->add_result(array('missing_files_in_pool' => true));
+ $this->add_log('missing file in pool: ' . $e->debuginfo, backup::LOG_WARNING);
+ }
}
}
View
11 backup/util/plan/backup_structure_step.class.php
@@ -94,11 +94,22 @@ public function execute() {
// Process structure definition
$structure->process($pr);
+ // Get the results from the nested elements
+ $results = $structure->get_results();
+
+ // Get the log messages to append to the log
+ $logs = $structure->get_logs();
+ foreach ($logs as $log) {
+ $this->log($log->message, $log->level, $log->a, $log->depth, $log->display);
+ }
+
// Close everything
$xw->stop();
// Destroy the structure. It helps PHP 5.2 memory a lot!
$structure->destroy();
+
+ return $results;
}
/**
View
73 backup/util/structure/backup_nested_element.class.php
@@ -37,6 +37,8 @@ class backup_nested_element extends base_nested_element implements processable {
protected $aliases; // Define DB->final element aliases
protected $fileannotations; // array of file areas to be searched by file annotations
protected $counter; // Number of instances of this element that have been processed
+ protected $results; // Logs the results we encounter during the process.
+ protected $logs; // Some log messages that could be retrieved later.
/**
* Constructor - instantiates one backup_nested_element, specifying its basic info.
@@ -55,8 +57,16 @@ public function __construct($name, $attributes = null, $final_elements = null) {
$this->aliases = array();
$this->fileannotations = array();
$this->counter = 0;
+ $this->results = array();
+ $this->logs = array();
}
+ /**
+ * Process the nested element
+ *
+ * @param object $processor the processor
+ * @return void
+ */
public function process($processor) {
if (!$processor instanceof base_processor) { // No correct processor, throw exception
throw new base_element_struct_exception('incorrect_processor');
@@ -113,6 +123,69 @@ public function process($processor) {
$iterator->close();
}
+ /**
+ * Saves a log message to an array
+ *
+ * @see backup_helper::log()
+ * @param string $message to add to the logs
+ * @param int $level level of importance {@link backup::LOG_DEBUG} and other constants
+ * @param mixed $a to be included in $message
+ * @param int $depth of the message
+ * @param display $bool supporting translation via get_string() if true
+ * @return void
+ */
+ protected function add_log($message, $level, $a = null, $depth = null, $display = false) {
+ // Adding the result to the oldest parent.
+ if ($this->get_parent()) {
+ $parent = $this->get_grandparent();
+ $parent->add_log($message, $level, $a, $depth, $display);
+ } else {
+ $log = new stdClass();
+ $log->message = $message;
+ $log->level = $level;
+ $log->a = $a;
+ $log->depth = $depth;
+ $log->display = $display;
+ $this->logs[] = $log;
+ }
+ }
+
+ /**
+ * Saves the results to an array
+ *
+ * @param array $result associative array
+ * @return void
+ */
+ protected function add_result($result) {
+ if (is_array($result)) {
+ // Adding the result to the oldest parent.
+ if ($this->get_parent()) {
+ $parent = $this->get_grandparent();
+ $parent->add_result($result);
+ } else {
+ $this->results = array_merge($this->results, $result);
+ }
+ }
+ }
+
+ /**
+ * Returns the logs
+ *
+ * @return array of log objects
+ */
+ public function get_logs() {
+ return $this->logs;
+ }
+
+ /**
+ * Returns the results
+ *
+ * @return associative array of results
+ */
+ public function get_results() {
+ return $this->results;
+ }
+
public function set_source_array($arr) {
// TODO: Only elements having final elements can set source
$this->var_array = $arr;
View
3 backup/util/ui/backup_ui_stage.class.php
@@ -469,6 +469,9 @@ public function display() {
}
echo $OUTPUT->box_start();
+ if (!empty($this->results['missing_files_in_pool'])) {
+ echo $OUTPUT->notification(get_string('missingfilesinpool', 'backup'), 'notifyproblem');
+ }
echo $OUTPUT->notification(get_string('executionsuccess', 'backup'), 'notifysuccess');
echo $OUTPUT->continue_button($restorerul);
echo $OUTPUT->box_end();
View
1 lang/en/backup.php
@@ -153,6 +153,7 @@
$string['lockedbyconfig'] = 'This setting has been locked by the default backup settings';
$string['lockedbyhierarchy'] = 'Locked by dependencies';
$string['managefiles'] = 'Manage backup files';
+$string['missingfilesinpool'] = 'Some files could not be saved during the backup, it won\'t be possible to restore them.';
$string['moodleversion'] = 'Moodle version';
$string['moreresults'] = 'There are too many results, enter a more specific search.';
$string['nomatchingcourses'] = 'There are no courses to display';

0 comments on commit aae03dd

Please sign in to comment.
Something went wrong with that request. Please try again.