// Prepare a progress bar which can display optionally during long-running
// operations while setting up the UI.
-$slowprogress = new core_backup_display_progress_if_slow(get_string('preparingui', 'backup'));
+$slowprogress = new \core\progress\display_if_slow(get_string('preparingui', 'backup'));
$previous = optional_param('previous', false, PARAM_BOOL);
if ($backup->get_stage() == backup_ui::STAGE_SCHEMA && !$previous) {
// Display an extra backup step bar so that we can show the 'processing' step 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->get_controller()->set_progress(new \core\progress\display());
// Prepare logger and add to end of chain.
$logger = new core_backup_html_logger($CFG->debugdeveloper ? backup::LOG_DEBUG : backup::LOG_INFO);
// By default there is no progress reporter. Interfaces that wish to
// display progress must set it.
- $this->progress = new core_backup_null_progress();
+ $this->progress = new \core\progress\null();
// Instantiate the output_controller singleton and active it if interactive and inmediate
$oc = output_controller::get_instance();
*/
abstract class base_controller extends backup implements loggable {
/**
- * @var core_backup_progress Progress reporting object.
+ * @var \core\progress\base Progress reporting object.
*/
protected $progress;
* Gets the progress reporter, which can be used to report progress within
* the backup or restore process.
*
- * @return core_backup_progress Progress reporting object
+ * @return \core\progress\base Progress reporting object
*/
public function get_progress() {
return $this->progress;
/**
* Sets the progress reporter.
*
- * @param core_backup_progress $progress Progress reporting object
+ * @param \core\progress\base $progress Progress reporting object
*/
- public function set_progress(core_backup_progress $progress) {
+ public function set_progress(\core\progress\base $progress) {
$this->progress = $progress;
}
public function log($message, $level, $a = null, $depth = null, $display = false) {
backup_helper::log($message, $level, $a, $depth, $display, $this->logger);
}
-}
\ No newline at end of file
+}
* @param int $mode backup::MODE_[ GENERAL | HUB | IMPORT | SAMESITE ]
* @param int $userid
* @param int $target backup::TARGET_[ NEW_COURSE | CURRENT_ADDING | CURRENT_DELETING | EXISTING_ADDING | EXISTING_DELETING ]
- * @param core_backup_progress $progress Optional progress monitor
+ * @param \core\progress\base $progress Optional progress monitor
*/
public function __construct($tempdir, $courseid, $interactive, $mode, $userid, $target,
- core_backup_progress $progress = null) {
+ \core\progress\base $progress = null) {
$this->tempdir = $tempdir;
$this->courseid = $courseid;
$this->interactive = $interactive;
if ($progress) {
$this->progress = $progress;
} else {
- $this->progress = new core_backup_null_progress();
+ $this->progress = new \core\progress\null();
}
$this->progress->start_progress('Constructing restore_controller');
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 = new \core\progress\display();
$progress->start_progress('', 2);
$backup->get_controller()->set_progress($progress);
// Start tracking progress if necessary.
if (!$this->startedprogress) {
$reporter->start_progress('extract_file_to_dir', ($max == file_progress::INDETERMINATE)
- ? core_backup_progress::INDETERMINATE : $max);
+ ? \core\progress\base::INDETERMINATE : $max);
$this->startedprogress = true;
}
// Pass progress through to whatever handles it.
$reporter->progress(($progress == file_progress::INDETERMINATE)
- ? core_backup_progress::INDETERMINATE : $progress);
+ ? \core\progress\base::INDETERMINATE : $progress);
}
}
// Track progress, as this task can take a long time.
$progress = $this->task->get_progress();
- $progress->start_progress($this->get_name(), core_backup_progress::INDETERMINATE);
+ $progress->start_progress($this->get_name(), \core\progress\base::INDETERMINATE);
// Let's process only created questions
$questionsrs = $DB->get_recordset_sql("SELECT bi.itemid, bi.newitemid, bi.parentitemid, q.qtype
// Prepare a progress bar which can display optionally during long-running
// operations while setting up the UI.
-$slowprogress = new core_backup_display_progress_if_slow(get_string('preparingui', 'backup'));
+$slowprogress = new \core\progress\display_if_slow(get_string('preparingui', 'backup'));
// Overall, allow 10 units of progress.
$slowprogress->start_progress('', 10);
if (!$restore->is_independent()) {
// Use a temporary (disappearing) progress bar to show the precheck progress if any.
- $precheckprogress = new core_backup_display_progress_if_slow(get_string('preparingdata', 'backup'));
+ $precheckprogress = new \core\progress\display_if_slow(get_string('preparingdata', 'backup'));
$restore->get_controller()->set_progress($precheckprogress);
if ($restore->get_stage() == restore_ui::STAGE_PROCESS && !$restore->requires_substage()) {
try {
// Show the current restore state (header with bolded item).
echo $renderer->progress_bar($restore->get_progress_bar());
// Start displaying the actual progress bar percentage.
- $restore->get_controller()->set_progress(new core_backup_display_progress());
+ $restore->get_controller()->set_progress(new \core\progress\display());
// Prepare logger.
$logger = new core_backup_html_logger($CFG->debugdeveloper ? backup::LOG_DEBUG : backup::LOG_INFO);
$restore->get_controller()->add_logger($logger);
* to track progress in processing (in case this task takes a long time).
*
* @param string $backupid Backup ID
- * @param core_backup_progress $progress Optional progress monitor
+ * @param \core\progress\base $progress Optional progress monitor
*/
public static function get_moodle_backup_information($backupid,
- core_backup_progress $progress = null) {
+ \core\progress\base $progress = null) {
// Start tracking progress if required (for load_controller).
if ($progress) {
*
* @param string $backupid Backup ID
* @param string $itemname Item name
- * @param core_backup_progress $progress Progress tracker
+ * @param \core\progress\base $progress Progress tracker
*/
- public static function move_annotations_to_final($backupid, $itemname, core_backup_progress $progress) {
+ public static function move_annotations_to_final($backupid, $itemname, \core\progress\base $progress) {
global $DB;
$progress->start_progress('move_annotations_to_final');
$rs = $DB->get_recordset('backup_ids_temp', array('backupid' => $backupid, 'itemname' => $itemname));
*
* @param string $restoreid Restore id
* @param string $inforeffile File path
- * @param core_backup_progress $progress Progress tracker
+ * @param \core\progress\base $progress Progress tracker
*/
public static function load_inforef_to_tempids($restoreid, $inforeffile,
- core_backup_progress $progress = null) {
+ \core\progress\base $progress = null) {
if (!file_exists($inforeffile)) { // Shouldn't happen ever, but...
throw new backup_helper_exception('missing_inforef_xml_file', $inforeffile);
// Set up progress tracking (indeterminate).
if (!$progress) {
- $progress = new core_backup_null_progress();
+ $progress = new \core\progress\null();
}
$progress->start_progress('Loading inforef.xml file');
*
* @param string $restoreid Restore id
* @param string $usersfile File path
- * @param core_backup_progress $progress Progress tracker
+ * @param \core\progress\base $progress Progress tracker
*/
public static function load_users_to_tempids($restoreid, $usersfile,
- core_backup_progress $progress = null) {
+ \core\progress\base $progress = null) {
if (!file_exists($usersfile)) { // Shouldn't happen ever, but...
throw new backup_helper_exception('missing_users_xml_file', $usersfile);
// Set up progress tracking (indeterminate).
if (!$progress) {
- $progress = new core_backup_null_progress();
+ $progress = new \core\progress\null();
}
$progress->start_progress('Loading users into temporary table');
* @param int|null $olditemid
* @param int|null $forcenewcontextid explicit value for the new contextid (skip mapping)
* @param bool $skipparentitemidctxmatch
- * @param core_backup_progress $progress Optional progress reporter
+ * @param \core\progress\base $progress Optional progress reporter
* @return array of result object
*/
public static function send_files_to_pool($basepath, $restoreid, $component, $filearea,
$oldcontextid, $dfltuserid, $itemname = null, $olditemid = null,
$forcenewcontextid = null, $skipparentitemidctxmatch = false,
- core_backup_progress $progress = null) {
+ \core\progress\base $progress = null) {
global $DB, $CFG;
$backupinfo = backup_general_helper::get_backup_information(basename($basepath));
* @param string $basepath Base path of unzipped backup
* @param string $restoreid Restore ID
* @param int $userid Default userid for files
- * @param core_backup_progress $progress Object used for progress tracking
+ * @param \core\progress\base $progress Object used for progress tracking
*/
public static function create_included_users($basepath, $restoreid, $userid,
- core_backup_progress $progress) {
+ \core\progress\base $progress) {
global $CFG, $DB;
$progress->start_progress('Creating included users');
* @param int $courseid Course id
* @param int $userid User id
* @param bool $samesite True if restore is to same site
- * @param core_backup_progress $progress Progress reporter
+ * @param \core\progress\base $progress Progress reporter
*/
public static function precheck_included_users($restoreid, $courseid, $userid, $samesite,
- core_backup_progress $progress) {
+ \core\progress\base $progress) {
global $CFG, $DB;
// To return any problem found
* @param int $courseid Course id
* @param int $userid User id
* @param bool $samesite True if restore is to same site
- * @param core_backup_progress $progress Optional progress tracker
+ * @param \core\progress\base $progress Optional progress tracker
*/
public static function process_included_users($restoreid, $courseid, $userid, $samesite,
- core_backup_progress $progress = null) {
+ \core\progress\base $progress = null) {
global $DB;
// Just let precheck_included_users() to do all the hard work
* progress reports.
*
* @param string $backupid Backup id
- * @param core_backup_progress $progress Optional progress reporting object
+ * @param \core\progress\base $progress Optional progress reporting object
*/
- static public function clear_backup_dir($backupid, core_backup_progress $progress = null) {
+ static public function clear_backup_dir($backupid, \core\progress\base $progress = null) {
global $CFG;
if (!self::delete_dir_contents($CFG->tempdir . '/backup/' . $backupid, '', $progress)) {
throw new backup_helper_exception('cannot_empty_backup_temp_dir');
* progress reports.
*
* @param string $backupid Backup id
- * @param core_backup_progress $progress Optional progress reporting object
+ * @param \core\progress\base $progress Optional progress reporting object
*/
- static public function delete_backup_dir($backupid, core_backup_progress $progress = null) {
+ static public function delete_backup_dir($backupid, \core\progress\base $progress = null) {
global $CFG;
self::clear_backup_dir($backupid, $progress);
return rmdir($CFG->tempdir . '/backup/' . $backupid);
*
* @param string $dir Directory to delete
* @param string $excludedir Exclude this directory
- * @param core_backup_progress $progress Optional progress reporting object
+ * @param \core\progress\base $progress Optional progress reporting object
*/
- static public function delete_dir_contents($dir, $excludeddir='', core_backup_progress $progress = null) {
+ static public function delete_dir_contents($dir, $excludeddir='', \core\progress\base $progress = null) {
global $CFG;
if ($progress) {
* progress reports.
*
* @param int $deletefrom Time to delete from
- * @param core_backup_progress $progress Optional progress reporting object
+ * @param \core\progress\base $progress Optional progress reporting object
*/
- static public function delete_old_backup_dirs($deletefrom, core_backup_progress $progress = null) {
+ static public function delete_old_backup_dirs($deletefrom, \core\progress\base $progress = null) {
global $CFG;
$status = true;
*
* @param int $backupid
* @param string $filepath zip file containing the backup
- * @param core_backup_progress $progress Optional progress monitor
+ * @param \core\progress\base $progress Optional progress monitor
* @return stored_file if created, null otherwise
*
* @throws moodle_exception in case of any problems
*/
- static public function store_backup_file($backupid, $filepath, core_backup_progress $progress = null) {
+ static public function store_backup_file($backupid, $filepath, \core\progress\base $progress = null) {
global $CFG;
// First of all, get some information from the backup_controller to help us decide
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');
-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/progress/core_backup_display_progress_if_slow.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');
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');
-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/progress/core_backup_display_progress_if_slow.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');
* Gets the progress reporter, which can be used to report progress within
* the backup or restore process.
*
- * @return core_backup_progress Progress reporting object
+ * @return \core\progress\base Progress reporting object
*/
public function get_progress() {
return $this->controller->get_progress();
* Gets the progress reporter, which can be used to report progress within
* the backup or restore process.
*
- * @return core_backup_progress Progress reporting object
+ * @return \core\progress\base Progress reporting object
*/
public abstract function get_progress();
* Gets the progress reporter, which can be used to report progress within
* the backup or restore process.
*
- * @return core_backup_progress Progress reporting object
+ * @return \core\progress\base Progress reporting object
*/
public function get_progress() {
return $this->plan->get_progress();
* Gets the progress reporter, which can be used to report progress within
* the backup or restore process.
*
- * @return core_backup_progress Progress reporting object
+ * @return \core\progress\base Progress reporting object
*/
public function get_progress() {
return $this->controller->get_progress();
// Set up progress tracking.
$progress = $this->get_task()->get_progress();
- $progress->start_progress($this->get_name(), core_backup_progress::INDETERMINATE);
+ $progress->start_progress($this->get_name(), \core\progress\base::INDETERMINATE);
$xmlparser->set_progress($progress);
// And process it, dispatch to target methods in step will start automatically
// the execute() method here, which does set up progress like this.)
$progress = $this->get_task()->get_progress();
if (!$progress->is_in_progress_section() ||
- $progress->get_current_max() !== core_backup_progress::INDETERMINATE) {
+ $progress->get_current_max() !== \core\progress\base::INDETERMINATE) {
$progress = null;
}
protected $vars; // array of backup::VAR_XXX => helper value pairs to be used by source specifications
/**
- * @var core_backup_progress Progress tracker (null if none)
+ * @var \core\progress\base Progress tracker (null if none)
*/
protected $progress;
* Constructor.
*
* @param xml_writer $writer XML writer to save data
- * @param core_backup_progress $progress Progress tracker (optional)
+ * @param c\core\progress\base$progress Progress tracker (optional)
*/
- public function __construct(xml_writer $writer, core_backup_progress $progress = null) {
+ public function __construct(xml_writer $writer, \core\progress\base $progress = null) {
$this->writer = $writer;
$this->progress = $progress;
$this->vars = array();
protected $stage = null;
/**
- * @var core_backup_progress Progress indicator (where there is no controller)
+ * @var \core\progress\base Progress indicator (where there is no controller)
*/
protected $progressreporter = null;
* there are long-running tasks even though there is no restore controller
* in use.
*
- * @return core_backup_null_progress
+ * @return \core\progress\null
*/
public function get_progress_reporter() {
if (!$this->progressreporter) {
- $this->progressreporter = new core_backup_null_progress();
+ $this->progressreporter = new \core\progress\null();
}
return $this->progressreporter;
}
/**
* Sets the progress reporter that will be returned by get_progress_reporter.
*
- * @param core_backup_progress $progressreporter Progress reporter
+ * @param c\core\progress\base$progressreporter Progress reporter
*/
- public function set_progress_reporter(core_backup_progress $progressreporter) {
+ public function set_progress_reporter(\core\progress\base $progressreporter) {
$this->progressreporter = $progressreporter;
}
*/
abstract class restore_ui_independent_stage {
/**
- * @var core_backup_progress Optional progress reporter
+ * @var \core\progress\base Optional progress reporter
*/
private $progressreporter;
* in use. There is a similar function in restore_ui. but that class is not
* used on some stages.
*
- * @return core_backup_null_progress
+ * @return \core\progress\null
*/
public function get_progress_reporter() {
if (!$this->progressreporter) {
- $this->progressreporter = new core_backup_null_progress();
+ $this->progressreporter = new \core\progress\null();
}
return $this->progressreporter;
}
/**
* Sets the progress reporter that will be returned by get_progress_reporter.
*
- * @param core_backup_progress $progressreporter Progress reporter
+ * @param \core\progress\base $progressreporter Progress reporter
*/
- public function set_progress_reporter(core_backup_progress $progressreporter) {
+ public function set_progress_reporter(\core\progress\base $progressreporter) {
$this->progressreporter = $progressreporter;
}
// Start tracking progress if necessary.
if (!$this->startedprogress) {
$reporter->start_progress('extract_file_to_dir',
- ($max == file_progress::INDETERMINATE) ? core_backup_progress::INDETERMINATE : $max);
+ ($max == file_progress::INDETERMINATE) ? \core\progress\base::INDETERMINATE : $max);
$this->startedprogress = true;
}
// Pass progress through to whatever handles it.
$reporter->progress(
- ($progress == file_progress::INDETERMINATE) ? core_backup_progress::INDETERMINATE : $progress);
+ ($progress == file_progress::INDETERMINATE) ? \core\progress\base::INDETERMINATE : $progress);
}
/**
* attributes and case folding and works only with UTF-8 content. It's one
* progressive push parser because, intead of loading big crunchs of information
* in memory, it "publishes" (pushes) small information in a "propietary array format" througt
- * the corresponding @progressive_parser_procesor, that will be the responsibe for
+ * the corresponding @progressive_parser_processor, that will be the responsibe for
* returning information into handy formats to higher levels.
*
* Note that, while this progressive parser is able to process any XML file, it is
* the expected behaviour) so information belonging to the same path can be returned in
* different chunks if there are inner levels/paths in the middle. Be warned!
*
- * The "propietary array format" that the parser publishes to the @progressive_parser_procesor
+ * The "propietary array format" that the parser publishes to the @progressive_parser_processor
* is this:
* array (
* 'path' => path where the tags belong to,
protected $xml_parser; // PHP's low level XML SAX parser
protected $file; // full path to file being progressively parsed | => mutually exclusive
protected $contents; // contents being progressively parsed |
- protected $procesor; // progressive_parser_procesor to be used to publish processed information
+
+ /**
+ * @var progressive_parser_processor to be used to publish processed information
+ */
+ protected $processor;
protected $level; // level of the current tag
protected $path; // path of the current tag
protected $currtag; // name/value/attributes of the tag being processed
/**
- * @var core_backup_progress Progress tracker called for each action
+ * @var \core\progress\base Progress tracker called for each action
*/
protected $progress;
*
* The caller should have already called start_progress on the progress tracker.
*
- * @param core_backup_progress $progress Progress tracker
+ * @param \core\progress\base $progress Progress tracker
*/
- public function set_progress(core_backup_progress $progress) {
+ public function set_progress(\core\progress\base $progress) {
$this->progress = $progress;
}
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+namespace core\progress;
+
+defined('MOODLE_INTERNAL') || die();
+
/**
- * Base class for handling progress information during a backup and restore.
+ * Base class for handling progress information.
*
* Subclasses should generally override the current_progress function which
* summarises all progress information.
*
- * @package core_backup
+ * @package core_progress
* @copyright 2013 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-abstract class core_backup_progress {
+abstract class base {
/**
* @var int Constant indicating that the number of progress calls is unknown.
*/
protected $currents = array();
/**
- * @var int Array of counts within parent progress entry (ignored for first)
+ * @var int[] Array of counts within parent progress entry (ignored for first)
*/
protected $parentcounts = array();
* @param string $description Description to display
* @param int $max Maximum value of progress for this section
* @param int $parentcount How many progress points this section counts for
- * @throws coding_exception If max is invalid
+ * @throws \coding_exception If max is invalid
*/
public function start_progress($description, $max = self::INDETERMINATE,
$parentcount = 1) {
if ($max != self::INDETERMINATE && $max < 0) {
- throw new coding_exception(
+ throw new \coding_exception(
'start_progress() max value cannot be negative');
}
if ($parentcount < 1) {
- throw new coding_exception(
+ throw new \coding_exception(
'start_progress() parent progress count must be at least 1');
}
if (!empty($this->descriptions)) {
if ($prevmax !== self::INDETERMINATE) {
$prevcurrent = end($this->currents);
if ($prevcurrent + $parentcount > $prevmax) {
- throw new coding_exception(
+ throw new \coding_exception(
'start_progress() parent progress would exceed max');
}
}
} else {
if ($parentcount != 1) {
- throw new coding_exception(
+ throw new \coding_exception(
'start_progress() progress count must be 1 when no parent');
}
}
* If there is a parent progress section, its progress will be increased
* automatically to reflect the end of the child section.
*
- * @throws coding_exception If progress hasn't been started
+ * @throws \coding_exception If progress hasn't been started
*/
public function end_progress() {
if (!count($this->descriptions)) {
- throw new coding_exception('end_progress() without start_progress()');
+ throw new \coding_exception('end_progress() without start_progress()');
}
array_pop($this->descriptions);
array_pop($this->maxes);
* INDETERMINATE. Otherwise it must not be indeterminate.
*
* @param int $progress Progress so far
- * @throws coding_exception If progress value is invalid
+ * @throws \coding_exception If progress value is invalid
*/
public function progress($progress = self::INDETERMINATE) {
// Ignore too-frequent progress calls (more than once per second).
// Check we are inside a progress section.
$max = end($this->maxes);
if ($max === false) {
- throw new coding_exception(
+ throw new \coding_exception(
'progress() without start_progress');
}
if ($progress === self::INDETERMINATE) {
// Indeterminate progress.
if ($max !== self::INDETERMINATE) {
- throw new coding_exception(
+ throw new \coding_exception(
'progress() INDETERMINATE, expecting value');
}
} else {
// Determinate progress.
$current = end($this->currents);
if ($max === self::INDETERMINATE) {
- throw new coding_exception(
+ throw new \coding_exception(
'progress() with value, expecting INDETERMINATE');
} else if ($progress < 0 || $progress > $max) {
- throw new coding_exception(
+ throw new \coding_exception(
'progress() value out of range');
} else if ($progress < $current) {
- throw new coding_Exception(
+ throw new \coding_exception(
'progress() value may not go backwards');
}
$this->currents[key($this->currents)] = $progress;
/**
* Checks max value of current progress section.
*
- * @return int Current max value (may be core_backup_progress::INDETERMINATE)
- * @throws coding_exception If not in a progress section
+ * @return int Current max value (may be \core\progress\base::INDETERMINATE)
+ * @throws \coding_exception If not in a progress section
*/
public function get_current_max() {
$max = end($this->maxes);
if ($max === false) {
- throw new coding_exception('Not inside progress section');
+ throw new \coding_exception('Not inside progress section');
}
return $max;
}
/**
+ * @throws \coding_exception
* @return string Current progress section description
*/
public function get_current_description() {
$description = end($this->descriptions);
if ($description === false) {
- throw new coding_exception('Not inside progress section');
+ throw new \coding_exception('Not inside progress section');
}
return $description;
}
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+namespace core\progress;
+
+defined('MOODLE_INTERNAL') || die();
+
/**
* 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
+ * @package core_progress
* @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 {
+class display extends base {
/**
* @var int Number of wibble states (state0...stateN-1 classes in CSS)
*/
const WIBBLE_STATES = 13;
/**
- * @var progress_bar Current progress bar.
+ * @var \progress_bar Current progress bar.
*/
private $bar;
}
/**
- * By default, the progress section names do not display because (in backup)
- * these are usually untranslated and incomprehensible. To make them
+ * By default, the progress section names do not display because
+ * these will probably be untranslated and incomprehensible. To make them
* display, call this method.
*
* @param bool $displaynames True to display names
*
* Called in constructor and in update_progress if required.
*
- * @throws coding_exception If already started
+ * @throws \coding_exception If already started
*/
public function start_html() {
if ($this->bar) {
- throw new coding_exception('Already started');
+ throw new \coding_exception('Already started');
}
- $this->bar = new progress_bar();
+ $this->bar = new \progress_bar();
$this->bar->create();
- echo html_writer::start_div('wibbler');
+ echo \html_writer::start_div('wibbler');
}
/**
$this->bar = null;
// End wibbler div.
- echo html_writer::end_div();
+ echo \html_writer::end_div();
}
/**
* When progress is updated, updates the bar.
*
- * @see core_backup_progress::update_progress()
+ * @see \core\progress\base::update_progress()
*/
public function update_progress() {
// If finished...
// (up to once per second).
if (time() != $this->lastwibble) {
$this->lastwibble = time();
- echo html_writer::div('', 'wibble state' . $this->currentstate);
+ echo \html_writer::div('', 'wibble state' . $this->currentstate);
// Go on to next colour.
$this->currentstate += $this->direction;
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+namespace core\progress;
+
+defined('MOODLE_INTERNAL') || die();
+
/**
* Progress handler that uses a standard Moodle progress bar to display
- * progress. Same as core_backup_display_progress, but the bar does not
+ * progress. Same as \core\progress\display, but the bar does not
* appear until a certain time has elapsed, and disappears automatically
* after it finishes.
*
* The bar can be re-used, i.e. if you end all sections it will disappear,
* but if you start all sections, a new bar will be output.
*
- * @package core_backup
+ * @package core_progress
* @copyright 2013 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_backup_display_progress_if_slow extends core_backup_display_progress {
+class display_if_slow extends display {
/**
* @var int Waits this many seconds before displaying progress bar
*/
* Starts displaying the progress bar, with optional heading and a special
* div so it can be hidden later.
*
- * @see core_backup_display_progress::start_html()
+ * @see \core\progress\display::start_html()
*/
public function start_html() {
global $OUTPUT;
- $this->id = 'core_backup_display_progress_if_slow' . self::$nextid;
+ $this->id = 'core_progress_display_if_slow' . self::$nextid;
self::$nextid++;
// Containing div includes a CSS class so that it can be themed if required,
// and an id so it can be automatically hidden at end.
- echo html_writer::start_div('core_backup_display_progress_if_slow',
+ echo \html_writer::start_div('core_progress_display_if_slow',
array('id' => $this->id));
// Display optional heading.
* When progress is updated, after a certain time, starts actually displaying
* the progress bar.
*
- * @see core_backup_progress::update_progress()
+ * @see \core\progress\base::update_progress()
*/
public function update_progress() {
// If we haven't started yet, consider starting.
/**
* Finishes parent display then closes div and hides it.
*
- * @see core_backup_display_progress::end_html()
+ * @see \core\progress\display::end_html()
*/
public function end_html() {
parent::end_html();
- echo html_writer::end_div();
- echo html_writer::script('document.getElementById("' . $this->id .
+ echo \html_writer::end_div();
+ echo \html_writer::script('document.getElementById("' . $this->id .
'").style.display = "none"');
}
}
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+namespace core\progress;
+
+defined('MOODLE_INTERNAL') || die();
+
/**
* Progress handler that ignores progress entirely.
*
- * @package core_backup
+ * @package core_progress
* @copyright 2013 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class core_backup_null_progress extends core_backup_progress {
+class null extends base {
public function update_progress() {
// Do nothing.
}
/**
* Unit tests for the progress classes.
*
- * @package core_backup
+ * @package core_progress
* @category phpunit
* @copyright 2013 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
defined('MOODLE_INTERNAL') || die();
-// Include all the needed stuff.
-global $CFG;
-require_once($CFG->dirroot . '/backup/util/progress/core_backup_progress.class.php');
-
/**
* Progress tests.
*/
-class backup_progress_testcase extends basic_testcase {
+class core_progress_testcase extends basic_testcase {
/**
* Tests for basic use with simple numeric progress.
*/
public function test_basic() {
- $progress = new core_backup_mock_progress();
+ $progress = new core_mock_progress();
// Check values of empty progress things.
$this->assertFalse($progress->is_in_progress_section());
core_php_time_limit::get_and_clear_unit_test_data();
$progress->progress(2);
$this->assertTrue($progress->was_update_called());
- $this->assertEquals(array(core_backup_progress::TIME_LIMIT_WITHOUT_PROGRESS),
+ $this->assertEquals(array(\core\progress\base::TIME_LIMIT_WITHOUT_PROGRESS),
core_php_time_limit::get_and_clear_unit_test_data());
// Check the new value.
*/
public function test_nested() {
// Outer progress goes from 0 to 10.
- $progress = new core_backup_mock_progress();
+ $progress = new core_mock_progress();
$progress->start_progress('hello', 10);
// Get up to 4, check position.
* Tests the feature for 'weighting' nested progress.
*/
public function test_nested_weighted() {
- $progress = new core_backup_mock_progress();
+ $progress = new core_mock_progress();
$progress->start_progress('', 10);
// First nested child has 2 units of its own and is worth 1 unit.
$this->assert_min_max(0.4, 0.4, $progress);
// Next indeterminate child is worth 6 units.
- $progress->start_progress('', core_backup_progress::INDETERMINATE, 6);
+ $progress->start_progress('', \core\progress\base::INDETERMINATE, 6);
$progress->step_time();
$progress->progress();
$this->assert_min_max(0.4, 1.0, $progress);
* to be similar.
*/
public function test_realistic() {
- $progress = new core_backup_mock_progress();
+ $progress = new core_mock_progress();
$progress->start_progress('parent', 100);
$progress->start_progress('child', 1);
$progress->progress(1);
* zero entries.
*/
public function test_zero() {
- $progress = new core_backup_mock_progress();
+ $progress = new core_mock_progress();
$progress->start_progress('parent', 100);
$progress->progress(1);
$this->assert_min_max(0.01, 0.01, $progress);
* Tests for any exceptions due to invalid calls.
*/
public function test_exceptions() {
- $progress = new core_backup_mock_progress();
+ $progress = new core_mock_progress();
// Check errors when empty.
try {
// Indeterminate when value expected.
$progress->start_progress('hello', 10);
try {
- $progress->progress(core_backup_progress::INDETERMINATE);
+ $progress->progress(\core\progress\base::INDETERMINATE);
$this->fail();
} catch (coding_exception $e) {
$this->assertEquals(1, preg_match('~expecting value~', $e->getMessage()));
*
* @param number $min Expected min progress
* @param number $max Expected max progress
- * @param core_backup_mock_progress $progress
+ * @param core_mock_progress $progress
*/
- private function assert_min_max($min, $max, core_backup_mock_progress $progress) {
+ private function assert_min_max($min, $max, core_mock_progress $progress) {
$this->assertEquals(array($min, $max),
$progress->get_progress_proportion_range());
}
* Helper class that records when update_progress is called and allows time
* stepping.
*/
-class core_backup_mock_progress extends core_backup_progress {
+class core_mock_progress extends \core\progress\base {
private $updatecalled = false;
private $time = 1;