diff --git a/admin/tool/generator/classes/backend.php b/admin/tool/generator/classes/backend.php index e06d0d3cd07..634ef6eeb41 100644 --- a/admin/tool/generator/classes/backend.php +++ b/admin/tool/generator/classes/backend.php @@ -61,16 +61,6 @@ abstract class tool_generator_backend { */ protected $progress; - /** - * @var int Epoch time at which last dot was displayed - */ - protected $lastdot; - - /** - * @var int Epoch time at which last percentage was displayed - */ - protected $lastpercentage; - /** * @var int Epoch time at which current step (current set of dots) started */ @@ -81,6 +71,11 @@ abstract class tool_generator_backend { */ protected $size; + /** + * @var progrss_bar progressbar + */ + protected $progressbar; + /** * Generic generator class * @@ -132,24 +127,14 @@ abstract class tool_generator_backend { if (!$this->progress) { return; } - if (CLI_SCRIPT) { - echo '* '; - } else { - echo html_writer::start_tag('li'); - } - echo get_string('progress_' . $langstring, $module, $a); - if (!$leaveopen) { - if (CLI_SCRIPT) { - echo "\n"; - } else { - echo html_writer::end_tag('li'); - } - } else { - echo ': '; - $this->lastdot = time(); - $this->lastpercentage = $this->lastdot; - $this->starttime = microtime(true); - } + + $this->langstring = $langstring; + $this->module = $module; + $this->aparam = $a; + + $this->starttime = microtime(true); + $this->progressbar = new progress_bar(); + $this->progressbar->create(); } /** @@ -164,24 +149,13 @@ abstract class tool_generator_backend { return; } $now = time(); - if ($now == $this->lastdot) { - return; - } - $this->lastdot = $now; - if (CLI_SCRIPT) { - echo '.'; - } else { - echo ' . '; - } - if ($now - $this->lastpercentage >= 30) { - echo round(100.0 * $number / $total, 1) . '%'; - $this->lastpercentage = $now; - } // Update time limit so PHP doesn't time out. if (!CLI_SCRIPT) { core_php_time_limit::raise(120); } + $status = get_string('progress_' . $this->langstring, $this->module, $number); + $this->progressbar->update($number, $total, $status); } /** @@ -191,11 +165,8 @@ abstract class tool_generator_backend { if (!$this->progress) { return; } - echo get_string('done', 'tool_generator', round(microtime(true) - $this->starttime, 1)); - if (CLI_SCRIPT) { - echo "\n"; - } else { - echo html_writer::end_tag('li'); - } + $status = get_string('progress_' . $this->langstring, $this->module, $this->aparam); + $done = get_string('done', 'tool_generator', round(microtime(true) - $this->starttime, 1)); + $this->progressbar->update_full(100, $status . ' - ' . $done); } } diff --git a/admin/tool/generator/classes/course_backend.php b/admin/tool/generator/classes/course_backend.php index 5117f3ae8b9..5228651f474 100644 --- a/admin/tool/generator/classes/course_backend.php +++ b/admin/tool/generator/classes/course_backend.php @@ -260,6 +260,7 @@ class tool_generator_course_backend extends tool_generator_backend { // Log total time. $this->log('coursecompleted', round(microtime(true) - $entirestart, 1)); + $this->end_log(); if ($this->progress && !CLI_SCRIPT) { echo html_writer::end_tag('ul'); @@ -286,7 +287,9 @@ class tool_generator_course_backend extends tool_generator_backend { $courserecord['summary_format'] = $this->summaryformat; } - return $this->generator->create_course($courserecord, array('createsections' => true)); + $return = $this->generator->create_course($courserecord, array('createsections' => true)); + $this->end_log(); + return $return; } /** @@ -303,6 +306,7 @@ class tool_generator_course_backend extends tool_generator_backend { // Get existing users in order. We will 'fill up holes' in this up to // the required number. $this->log('checkaccounts', $count); + $this->end_log(); $nextnumber = 1; $rs = $DB->get_recordset_select('user', $DB->sql_like('username', '?'), array('tool_generator_%'), 'username', 'id, username');