MDL-28346 Backup: Backup does not fail when a file is missing
Conflicts: backup/util/ui/backup_ui_stage.class.php
This commit is contained in:
@@ -91,14 +91,19 @@ class file_nested_element extends backup_nested_element {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -94,11 +94,22 @@ abstract class backup_structure_step extends backup_step {
|
||||
// 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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 @@ class backup_nested_element extends base_nested_element implements processable {
|
||||
$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 @@ class backup_nested_element extends base_nested_element implements processable {
|
||||
$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;
|
||||
|
||||
@@ -469,6 +469,9 @@ class backup_ui_stage_complete extends backup_ui_stage_final {
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
@@ -153,6 +153,7 @@ $string['lockedbypermission'] = 'You don\'t have sufficient permissions to chang
|
||||
$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';
|
||||
|
||||
Reference in New Issue
Block a user