MDL-38196 Backup/restore: Display log if non-empty

When doing a backup or restore operation with the normal user interface,
if there is anything in the backup/restore log, it will now be displayed
at the end of the process below the Continue button.

If you have developer debugging enabled, it sets the display level to
LOG_DEBUG and there will always be content in the log. Otherwise, it
uses LOG_INFO which generally means the log is empty, and nothing
displays (no visible change for users).
This commit is contained in:
sam marshall 2013-09-10 13:25:04 +01:00
parent 56cc9b387e
commit 77b3d9dfdf
15 changed files with 220 additions and 73 deletions

View file

@ -69,6 +69,7 @@ require_once($CFG->dirroot . '/backup/util/xml/parser/progressive_parser.class.p
require_once($CFG->dirroot . '/backup/util/loggers/base_logger.class.php');
require_once($CFG->dirroot . '/backup/util/loggers/error_log_logger.class.php');
require_once($CFG->dirroot . '/backup/util/loggers/file_logger.class.php');
require_once($CFG->dirroot . '/backup/util/loggers/core_backup_html_logger.class.php');
require_once($CFG->dirroot . '/backup/util/loggers/database_logger.class.php');
require_once($CFG->dirroot . '/backup/util/loggers/output_indented_logger.class.php');
require_once($CFG->dirroot . '/backup/util/progress/core_backup_progress.class.php');
@ -89,6 +90,7 @@ require_once($CFG->dirroot . '/backup/util/plan/base_step.class.php');
require_once($CFG->dirroot . '/backup/util/plan/backup_step.class.php');
require_once($CFG->dirroot . '/backup/util/plan/backup_structure_step.class.php');
require_once($CFG->dirroot . '/backup/util/plan/backup_execution_step.class.php');
require_once($CFG->dirroot . '/backup/controller/base_controller.class.php');
require_once($CFG->dirroot . '/backup/controller/backup_controller.class.php');
require_once($CFG->dirroot . '/backup/util/ui/base_moodleform.class.php');
require_once($CFG->dirroot . '/backup/util/ui/base_ui.class.php');

View file

@ -58,6 +58,7 @@ require_once($CFG->dirroot . '/backup/util/checks/restore_check.class.php');
require_once($CFG->dirroot . '/backup/util/loggers/base_logger.class.php');
require_once($CFG->dirroot . '/backup/util/loggers/error_log_logger.class.php');
require_once($CFG->dirroot . '/backup/util/loggers/file_logger.class.php');
require_once($CFG->dirroot . '/backup/util/loggers/core_backup_html_logger.class.php');
require_once($CFG->dirroot . '/backup/util/loggers/database_logger.class.php');
require_once($CFG->dirroot . '/backup/util/loggers/output_indented_logger.class.php');
require_once($CFG->dirroot . '/backup/util/progress/core_backup_progress.class.php');
@ -84,6 +85,7 @@ require_once($CFG->dirroot . '/backup/util/plan/restore_step.class.php');
require_once($CFG->dirroot . '/backup/util/plan/restore_structure_step.class.php');
require_once($CFG->dirroot . '/backup/util/plan/restore_execution_step.class.php');
require_once($CFG->dirroot . '/backup/moodle2/restore_plan_builder.class.php');
require_once($CFG->dirroot . '/backup/controller/base_controller.class.php');
require_once($CFG->dirroot . '/backup/controller/restore_controller.class.php');
require_once($CFG->dirroot . '/backup/util/ui/base_moodleform.class.php');
require_once($CFG->dirroot . '/backup/util/ui/base_ui.class.php');

View file

@ -0,0 +1,46 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Logger that stores HTML log data in memory, ready for later display.
*
* @package core_backup
* @copyright 2013 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_backup_html_logger extends base_logger {
/**
* @var string HTML output
*/
protected $html = '';
protected function action($message, $level, $options = null) {
$prefix = $this->get_prefix($level, $options);
$depth = isset($options['depth']) ? $options['depth'] : 0;
$this->html .= $prefix . str_repeat('&nbsp;&nbsp;', $depth) .
s($message) . '<br/>' . PHP_EOL;
return true;
}
/**
* Gets the full HTML content of the log.
*
* @return string HTML content of log
*/
public function get_html() {
return $this->html;
}
}

View file

@ -55,6 +55,24 @@ class core_backup_renderer extends plugin_renderer_base {
}
return html_writer::tag('div', join(get_separator(), $items), array('class'=>'backup_progress clearfix'));
}
/**
* The backup and restore pages may display a log (if any) in a scrolling box.
*
* @param string $loghtml Log content in HTML format
* @return string HTML content that shows the log
*/
public function log_display($loghtml) {
global $OUTPUT;
$out = html_writer::start_div('backup_log');
$out .= $OUTPUT->heading(get_string('backuplog', 'backup'));
$out .= html_writer::start_div('backup_log_contents');
$out .= $loghtml;
$out .= html_writer::end_div();
$out .= html_writer::end_div();
return $out;
}
/**
* Prints a dependency notification
* @param string $message