MDL-42815 Backup/restore: Error saving files - log messages unhelpful
This commit contains three changes in the three files: 1. A bug in the backup process meant that anything logged after a certain point did not appear in the on-screen display of the backup log, because the logger was serialised and deserialised but display code referred to the old version. Changed so that code retrieves new object. 2. Add more information to backup log when there is a missing file. 3. Add more information to restore log when there is a missing file (and remove existing code duplication of the current message). The 'missing file' situation is one that generally shouldn't occur in normal usage, but when it does happen, it is useful to have full information about the file.
This commit is contained in:
@@ -130,6 +130,13 @@ if ($backup->get_stage() == backup_ui::STAGE_FINAL) {
|
||||
// Carry out actual backup.
|
||||
$backup->execute();
|
||||
|
||||
// Backup controller gets saved/loaded so the logger object changes and we
|
||||
// have to retrieve it.
|
||||
$logger = $backup->get_controller()->get_logger();
|
||||
while (!is_a($logger, 'core_backup_html_logger')) {
|
||||
$logger = $logger->get_next();
|
||||
}
|
||||
|
||||
// Get HTML from logger.
|
||||
$loghtml = $logger->get_html();
|
||||
|
||||
|
||||
@@ -107,7 +107,19 @@ class file_nested_element extends backup_nested_element {
|
||||
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);
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -995,11 +995,7 @@ abstract class restore_dbops {
|
||||
if ($includesfiles) {
|
||||
// The file is not found in the backup.
|
||||
if (!file_exists($backuppath)) {
|
||||
$result = new stdClass();
|
||||
$result->code = 'file_missing_in_backup';
|
||||
$result->message = sprintf('missing file %s%s in backup', $file->filepath, $file->filename);
|
||||
$result->level = backup::LOG_WARNING;
|
||||
$results[] = $result;
|
||||
$results[] = self::get_missing_file_result($file);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1028,11 +1024,7 @@ abstract class restore_dbops {
|
||||
$fs->create_file_from_storedfile($file_record, $foundfile->id);
|
||||
} else {
|
||||
// A matching existing file record was not found in the database.
|
||||
$result = new stdClass();
|
||||
$result->code = 'file_missing_in_backup';
|
||||
$result->message = sprintf('missing file %s%s in backup', $file->filepath, $file->filename);
|
||||
$result->level = backup::LOG_WARNING;
|
||||
$results[] = $result;
|
||||
$results[] = self::get_missing_file_result($file);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -1063,6 +1055,22 @@ abstract class restore_dbops {
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns suitable entry to include in log when there is a missing file.
|
||||
*
|
||||
* @param stdClass $file File definition
|
||||
* @return stdClass Log entry
|
||||
*/
|
||||
protected static function get_missing_file_result($file) {
|
||||
$result = new stdClass();
|
||||
$result->code = 'file_missing_in_backup';
|
||||
$result->message = 'Missing file in backup: ' . $file->filepath . $file->filename .
|
||||
' (old context ' . $file->contextid . ', component ' . $file->component .
|
||||
', filearea ' . $file->filearea . ', old itemid ' . $file->itemid . ')';
|
||||
$result->level = backup::LOG_WARNING;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given one restoreid, create in DB all the users present
|
||||
* in backup_ids having newitemid = 0, as far as
|
||||
|
||||
Reference in New Issue
Block a user