mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-38190 (3) Backup/restore: Progress display in main user interface
This commit is contained in:
parent
2531ae2922
commit
f06abc2ac1
@ -89,11 +89,6 @@ if (!($bc = backup_ui::load_controller($backupid))) {
|
||||
}
|
||||
$backup = new backup_ui($bc);
|
||||
$backup->process();
|
||||
if ($backup->get_stage() == backup_ui::STAGE_FINAL) {
|
||||
$backup->execute();
|
||||
} else {
|
||||
$backup->save_controller();
|
||||
}
|
||||
|
||||
$PAGE->set_title($heading.': '.$backup->get_stage_name());
|
||||
$PAGE->set_heading($heading);
|
||||
@ -104,6 +99,19 @@ echo $OUTPUT->header();
|
||||
if ($backup->enforce_changed_dependencies()) {
|
||||
debugging('Your settings have been altered due to unmet dependencies', DEBUG_DEVELOPER);
|
||||
}
|
||||
|
||||
if ($backup->get_stage() == backup_ui::STAGE_FINAL) {
|
||||
// Display an extra progress bar so that we can show the progress first.
|
||||
echo html_writer::start_div('', array('id' => 'executionprogress'));
|
||||
echo $renderer->progress_bar($backup->get_progress_bar());
|
||||
$backup->get_controller()->set_progress(new core_backup_display_progress());
|
||||
$backup->execute();
|
||||
echo html_writer::end_div();
|
||||
echo html_writer::script('document.getElementById("executionprogress").style.display = "none";');
|
||||
} else {
|
||||
$backup->save_controller();
|
||||
}
|
||||
|
||||
echo $renderer->progress_bar($backup->get_progress_bar());
|
||||
echo $backup->display($renderer);
|
||||
$backup->destroy();
|
||||
|
@ -90,11 +90,25 @@ if ($backup->get_stage() == backup_ui::STAGE_CONFIRMATION) {
|
||||
|
||||
// If it's the final stage process the import
|
||||
if ($backup->get_stage() == backup_ui::STAGE_FINAL) {
|
||||
echo $OUTPUT->header();
|
||||
|
||||
// Display an extra progress bar so that we can show the current stage.
|
||||
echo html_writer::start_div('', array('id' => 'executionprogress'));
|
||||
echo $renderer->progress_bar($backup->get_progress_bar());
|
||||
|
||||
// Start the progress display - we split into 2 chunks for backup and restore.
|
||||
$progress = new core_backup_display_progress();
|
||||
$progress->start_progress('', 2);
|
||||
$backup->get_controller()->set_progress($progress);
|
||||
|
||||
// First execute the backup
|
||||
$backup->execute();
|
||||
$backup->destroy();
|
||||
unset($backup);
|
||||
|
||||
// Note that we've done that progress.
|
||||
$progress->progress(1);
|
||||
|
||||
// Check whether the backup directory still exists. If missing, something
|
||||
// went really wrong in backup, throw error. Note that backup::MODE_IMPORT
|
||||
// backups don't store resulting files ever
|
||||
@ -106,6 +120,7 @@ if ($backup->get_stage() == backup_ui::STAGE_FINAL) {
|
||||
// Prepare the restore controller. We don't need a UI here as we will just use what
|
||||
// ever the restore has (the user has just chosen).
|
||||
$rc = new restore_controller($backupid, $course->id, backup::INTERACTIVE_YES, backup::MODE_IMPORT, $USER->id, $restoretarget);
|
||||
$rc->set_progress($progress);
|
||||
// Convert the backup if required.... it should NEVER happed
|
||||
if ($rc->get_status() == backup::STATUS_REQUIRE_CONV) {
|
||||
$rc->convert();
|
||||
@ -135,8 +150,12 @@ if ($backup->get_stage() == backup_ui::STAGE_FINAL) {
|
||||
// Delete the temp directory now
|
||||
fulldelete($tempdestination);
|
||||
|
||||
// All progress complete. Hide progress area.
|
||||
$progress->end_progress();
|
||||
echo html_writer::end_div();
|
||||
echo html_writer::script('document.getElementById("executionprogress").style.display = "none";');
|
||||
|
||||
// Display a notification and a continue button
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->notification(get_string('importsuccess', 'backup'),'notifysuccess');
|
||||
echo $OUTPUT->continue_button(new moodle_url('/course/view.php', array('id'=>$course->id)));
|
||||
echo $OUTPUT->footer();
|
||||
|
@ -44,18 +44,6 @@ if ($stage & restore_ui::STAGE_CONFIRM + restore_ui::STAGE_DESTINATION) {
|
||||
}
|
||||
|
||||
$outcome = $restore->process();
|
||||
if (!$restore->is_independent()) {
|
||||
if ($restore->get_stage() == restore_ui::STAGE_PROCESS && !$restore->requires_substage()) {
|
||||
try {
|
||||
$restore->execute();
|
||||
} catch(Exception $e) {
|
||||
$restore->cleanup();
|
||||
throw $e;
|
||||
}
|
||||
} else {
|
||||
$restore->save_controller();
|
||||
}
|
||||
}
|
||||
$heading = $course->fullname;
|
||||
|
||||
$PAGE->set_title($heading.': '.$restore->get_stage_name());
|
||||
@ -67,6 +55,26 @@ echo $OUTPUT->header();
|
||||
if (!$restore->is_independent() && $restore->enforce_changed_dependencies()) {
|
||||
debugging('Your settings have been altered due to unmet dependencies', DEBUG_DEVELOPER);
|
||||
}
|
||||
|
||||
if (!$restore->is_independent()) {
|
||||
if ($restore->get_stage() == restore_ui::STAGE_PROCESS && !$restore->requires_substage()) {
|
||||
try {
|
||||
// Display an extra progress bar so that we can show the progress first.
|
||||
echo html_writer::start_div('', array('id' => 'executionprogress'));
|
||||
echo $renderer->progress_bar($restore->get_progress_bar());
|
||||
$restore->get_controller()->set_progress(new core_backup_display_progress());
|
||||
$restore->execute();
|
||||
echo html_writer::end_div();
|
||||
echo html_writer::script('document.getElementById("executionprogress").style.display = "none";');
|
||||
} catch(Exception $e) {
|
||||
$restore->cleanup();
|
||||
throw $e;
|
||||
}
|
||||
} else {
|
||||
$restore->save_controller();
|
||||
}
|
||||
}
|
||||
|
||||
echo $renderer->progress_bar($restore->get_progress_bar());
|
||||
echo $restore->display($renderer);
|
||||
$restore->destroy();
|
||||
|
@ -73,6 +73,7 @@ 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');
|
||||
require_once($CFG->dirroot . '/backup/util/progress/core_backup_null_progress.class.php');
|
||||
require_once($CFG->dirroot . '/backup/util/progress/core_backup_display_progress.class.php');
|
||||
require_once($CFG->dirroot . '/backup/util/settings/setting_dependency.class.php');
|
||||
require_once($CFG->dirroot . '/backup/util/settings/base_setting.class.php');
|
||||
require_once($CFG->dirroot . '/backup/util/settings/backup_setting.class.php');
|
||||
|
@ -62,6 +62,7 @@ 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');
|
||||
require_once($CFG->dirroot . '/backup/util/progress/core_backup_null_progress.class.php');
|
||||
require_once($CFG->dirroot . '/backup/util/progress/core_backup_display_progress.class.php');
|
||||
require_once($CFG->dirroot . '/backup/util/factories/backup_factory.class.php');
|
||||
require_once($CFG->dirroot . '/backup/util/factories/restore_factory.class.php');
|
||||
require_once($CFG->dirroot . '/backup/util/helper/backup_helper.class.php');
|
||||
|
136
backup/util/progress/core_backup_display_progress.class.php
Normal file
136
backup/util/progress/core_backup_display_progress.class.php
Normal file
@ -0,0 +1,136 @@
|
||||
<?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/>.
|
||||
|
||||
/**
|
||||
* Progress handler that uses a standard Moodle progress bar to display
|
||||
* progress. The Moodle progress bar cannot show indeterminate progress,
|
||||
* so we do extra output in addition to the bar.
|
||||
*
|
||||
* @package core_backup
|
||||
* @copyright 2013 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_backup_display_progress extends core_backup_progress {
|
||||
/**
|
||||
* @var int Number of wibble states (state0...stateN-1 classes in CSS)
|
||||
*/
|
||||
const WIBBLE_STATES = 13;
|
||||
|
||||
/**
|
||||
* @var progress_bar Current progress bar.
|
||||
*/
|
||||
private $bar;
|
||||
|
||||
private $lastwibble, $currentstate = 0, $direction = 1;
|
||||
|
||||
/**
|
||||
* @var bool True to display names
|
||||
*/
|
||||
protected $displaynames = false;
|
||||
|
||||
/**
|
||||
* Constructs the progress reporter. This will output HTML code for the
|
||||
* progress bar, and an indeterminate wibbler below it.
|
||||
*
|
||||
* @param bool $startnow If true, outputs HTML immediately.
|
||||
*/
|
||||
public function __construct($startnow = true) {
|
||||
if ($startnow) {
|
||||
$this->start_html();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* By default, the progress section names do not display because (in backup)
|
||||
* these are usually untranslated and incomprehensible. To make them
|
||||
* display, call this method.
|
||||
*
|
||||
* @param bool $displaynames True to display names
|
||||
*/
|
||||
public function set_display_names($displaynames = true) {
|
||||
$this->displaynames = $displaynames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts to output progress.
|
||||
*
|
||||
* Called in constructor and in update_progress if required.
|
||||
*
|
||||
* @throws coding_exception If already started
|
||||
*/
|
||||
public function start_html() {
|
||||
if ($this->bar) {
|
||||
throw new coding_exception('Already started');
|
||||
}
|
||||
$this->bar = new progress_bar();
|
||||
$this->bar->create();
|
||||
echo html_writer::start_div('wibbler');
|
||||
}
|
||||
|
||||
/**
|
||||
* Finishes output. (Progress can begin again later if there are more
|
||||
* calls to update_progress.)
|
||||
*
|
||||
* Automatically called from update_progress when progress finishes.
|
||||
*/
|
||||
public function end_html() {
|
||||
// Finish progress bar.
|
||||
$this->bar->update_full(100, '');
|
||||
$this->bar = null;
|
||||
|
||||
// End wibbler div.
|
||||
echo html_writer::end_div();
|
||||
}
|
||||
|
||||
public function update_progress() {
|
||||
// If finished...
|
||||
if (!$this->is_in_progress_section()) {
|
||||
if ($this->bar) {
|
||||
$this->end_html();
|
||||
}
|
||||
} else {
|
||||
if (!$this->bar) {
|
||||
$this->start_html();
|
||||
}
|
||||
// In case of indeterminate or small progress, update the wibbler
|
||||
// (up to once per second).
|
||||
if (time() != $this->lastwibble) {
|
||||
$this->lastwibble = time();
|
||||
echo html_writer::div('', 'wibble state' . $this->currentstate);
|
||||
|
||||
// Go on to next colour.
|
||||
$this->currentstate += $this->direction;
|
||||
if ($this->currentstate < 0 || $this->currentstate >= self::WIBBLE_STATES) {
|
||||
$this->direction = -$this->direction;
|
||||
$this->currentstate += 2 * $this->direction;
|
||||
}
|
||||
}
|
||||
|
||||
// Get progress.
|
||||
list ($min, $max) = $this->get_progress_proportion_range();
|
||||
|
||||
// Update progress bar.
|
||||
$message = '';
|
||||
if ($this->displaynames) {
|
||||
$message = $this->get_current_description();
|
||||
}
|
||||
$this->bar->update_full($min * 100, $message);
|
||||
|
||||
// Flush output.
|
||||
flush();
|
||||
}
|
||||
}
|
||||
}
|
@ -540,6 +540,21 @@ body.tag .managelink {padding: 5px;}
|
||||
.path-backup .fitemtitle .iconlarge.icon-post { padding-left: 6px; }
|
||||
.path-backup.dir-rtl .fitemtitle .iconlarge.icon-post { padding-right: 6px; padding-right: 0; }
|
||||
.path-backup .fitem .smallicon { vertical-align: text-bottom; }
|
||||
.path-backup .wibbler { width: 500px; margin: 0 auto 10px; border-bottom: 1px solid black; border-right: 1px solid black; border-left: 1px solid black; position: relative; min-height: 4px;}
|
||||
.path-backup .wibbler .wibble { position: absolute; left: 0; right: 0; top: 0; height: 4px; }
|
||||
.path-backup .wibbler .state0 { background: #eee; }
|
||||
.path-backup .wibbler .state1 { background: #ddd; }
|
||||
.path-backup .wibbler .state2 { background: #ccc; }
|
||||
.path-backup .wibbler .state3 { background: #bbb; }
|
||||
.path-backup .wibbler .state4 { background: #aaa; }
|
||||
.path-backup .wibbler .state5 { background: #999; }
|
||||
.path-backup .wibbler .state6 { background: #888; }
|
||||
.path-backup .wibbler .state7 { background: #777; }
|
||||
.path-backup .wibbler .state8 { background: #666; }
|
||||
.path-backup .wibbler .state9 { background: #555; }
|
||||
.path-backup .wibbler .state10 { background: #444; }
|
||||
.path-backup .wibbler .state11 { background: #333; }
|
||||
.path-backup .wibbler .state12 { background: #222; }
|
||||
|
||||
/**
|
||||
* Web Service
|
||||
|
@ -162,3 +162,58 @@
|
||||
background-color: #eee;
|
||||
padding: 3px;
|
||||
}
|
||||
.path-backup .wibbler {
|
||||
width: 500px;
|
||||
margin: 0 auto 10px;
|
||||
border-bottom: 1px solid black;
|
||||
border-right: 1px solid black;
|
||||
border-left: 1px solid black;
|
||||
position: relative;
|
||||
min-height: 4px;
|
||||
}
|
||||
.path-backup .wibbler .wibble {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
top: 0;
|
||||
height: 4px;
|
||||
}
|
||||
.path-backup .wibbler .state0 {
|
||||
background: #eee;
|
||||
}
|
||||
.path-backup .wibbler .state1 {
|
||||
background: #ddd;
|
||||
}
|
||||
.path-backup .wibbler .state2 {
|
||||
background: #ccc;
|
||||
}
|
||||
.path-backup .wibbler .state3 {
|
||||
background: #bbb;
|
||||
}
|
||||
.path-backup .wibbler .state4 {
|
||||
background: #aaa;
|
||||
}
|
||||
.path-backup .wibbler .state5 {
|
||||
background: #999;
|
||||
}
|
||||
.path-backup .wibbler .state6 {
|
||||
background: #888;
|
||||
}
|
||||
.path-backup .wibbler .state7 {
|
||||
background: #777;
|
||||
}
|
||||
.path-backup .wibbler .state8 {
|
||||
background: #666;
|
||||
}
|
||||
.path-backup .wibbler .state9 {
|
||||
background: #555;
|
||||
}
|
||||
.path-backup .wibbler .state10 {
|
||||
background: #444;
|
||||
}
|
||||
.path-backup .wibbler .state11 {
|
||||
background: #333;
|
||||
}
|
||||
.path-backup .wibbler .state12 {
|
||||
background: #222;
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user