diff --git a/backup/backup.php b/backup/backup.php index 1c1cf29f6c1..0f3bf7add3f 100644 --- a/backup/backup.php +++ b/backup/backup.php @@ -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(); diff --git a/backup/moodle2/backup_custom_fields.php b/backup/moodle2/backup_custom_fields.php index 12929de6578..b5c32a5e84b 100644 --- a/backup/moodle2/backup_custom_fields.php +++ b/backup/moodle2/backup_custom_fields.php @@ -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); } } } diff --git a/backup/util/dbops/restore_dbops.class.php b/backup/util/dbops/restore_dbops.class.php index a6d5bce169f..00fb8f3616f 100644 --- a/backup/util/dbops/restore_dbops.class.php +++ b/backup/util/dbops/restore_dbops.class.php @@ -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