From bd7193c7ac5e51c9d3243d557936b2ae5f2e06d2 Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Tue, 26 Apr 2011 14:57:23 +0200 Subject: [PATCH] MDL-27293 report customlang has extra execution time and displays a progress bar during the checkout Initial checkout of strings into the translator table may take a long time. The maximum execution time is increased to one hour and a progress bar is displayed so the user is informed on what is going on. --- admin/report/customlang/index.php | 20 +++++++++++++-- .../customlang/lang/en/report_customlang.php | 4 ++- admin/report/customlang/locallib.php | 25 +++++++++++++++++-- admin/report/customlang/styles.css | 4 +++ 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/admin/report/customlang/index.php b/admin/report/customlang/index.php index 621e15a6c83..86ea785d90c 100644 --- a/admin/report/customlang/index.php +++ b/admin/report/customlang/index.php @@ -24,6 +24,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +define('NO_OUTPUT_BUFFERING', true); // progress bar is used here + require(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php'); require_once($CFG->dirroot.'/'.$CFG->admin.'/report/customlang/locallib.php'); require_once($CFG->libdir.'/adminlib.php'); @@ -45,8 +47,22 @@ if ($action === 'checkout') { if (empty($lng)) { print_error('missingparameter'); } - report_customlang_utils::checkout($lng); - redirect(new moodle_url('/admin/report/customlang/edit.php', array('lng' => $lng))); + + $PAGE->set_cacheable(false); // progress bar is used here + $output = $PAGE->get_renderer('report_customlang'); + echo $output->header(); + echo $output->heading(get_string('pluginname', 'report_customlang')); + $progressbar = new progress_bar(); + $progressbar->create(); // prints the HTML code of the progress bar + + // we may need a bit of extra execution time and memory here + @set_time_limit(HOURSECS); + raise_memory_limit(MEMORY_EXTRA); + report_customlang_utils::checkout($lng, $progressbar); + + echo $output->continue_button(new moodle_url('/admin/report/customlang/edit.php', array('lng' => $lng)), 'get'); + echo $output->footer(); + exit; } if ($action === 'checkin') { diff --git a/admin/report/customlang/lang/en/report_customlang.php b/admin/report/customlang/lang/en/report_customlang.php index d90acaeacc7..6e6c3018ee1 100644 --- a/admin/report/customlang/lang/en/report_customlang.php +++ b/admin/report/customlang/lang/en/report_customlang.php @@ -27,7 +27,9 @@ defined('MOODLE_INTERNAL') || die(); $string['checkin'] = 'Check in strings into disk'; -$string['checkout'] = 'Check out strings into translator'; +$string['checkout'] = 'Check out strings into the translator'; +$string['checkoutdone'] = 'Strings checked out successfully into the translator'; +$string['checkoutinprogress'] = 'Checking out strings into the translator'; $string['confirmcheckin'] = 'You are about to check in modified strings into your local language pack. This will export the customized strings from the translator into the data directory and Moodle will start using the modified strings. Press \'Continue\' button to proceed check in.'; $string['customlang:edit'] = 'Edit local translation'; $string['customlang:view'] = 'View local translation'; diff --git a/admin/report/customlang/locallib.php b/admin/report/customlang/locallib.php index 53ecee13f13..c3aa6ca0d53 100644 --- a/admin/report/customlang/locallib.php +++ b/admin/report/customlang/locallib.php @@ -16,7 +16,7 @@ // along with Moodle. If not, see . /** - * Definition of classes used by Langugae customization admin report + * Definition of classes used by language customization admin report * * @package report * @subpackage customlang @@ -33,6 +33,12 @@ defined('MOODLE_INTERNAL') || die(); */ class report_customlang_utils { + /** + * Rough number of strings that are being processed during a full checkout. + * This is used to estimate the progress of the checkout. + */ + const ROUGH_NUMBER_OF_STRINGS = 16500; + /** @var array cache of {@link self::list_components()} results */ protected static $components = null; @@ -83,8 +89,9 @@ class report_customlang_utils { * This should be executed each time before going to the translation page * * @param string $lang language code to checkout + * @param progress_bar $progressbar optionally, the given progress bar can be updated */ - public static function checkout($lang) { + public static function checkout($lang, progress_bar $progressbar = null) { global $DB; // make sure that all components are registered @@ -107,6 +114,10 @@ class report_customlang_utils { } unset($current); + // initialize the progress counter - stores the number of processed strings + $done = 0; + $strinprogress = get_string('checkoutinprogress', 'report_customlang'); + // reload components and fetch their strings $stringman = get_string_manager(); $components = $DB->get_records('report_customlang_components'); @@ -129,6 +140,12 @@ class report_customlang_utils { $stringlocal = isset($local[$stringid]) ? $local[$stringid] : null; $now = time(); + if (!is_null($progressbar)) { + $done++; + $donepercent = floor(min($done, self::ROUGH_NUMBER_OF_STRINGS) / self::ROUGH_NUMBER_OF_STRINGS * 100); + $progressbar->update_full($donepercent, $strinprogress); + } + if (isset($current[$stringid])) { $needsupdate = false; $currentoriginal = $current[$stringid]->original; @@ -175,6 +192,10 @@ class report_customlang_utils { } } } + + if (!is_null($progressbar)) { + $progressbar->update_full(100, get_string('checkoutdone', 'report_customlang')); + } } /** diff --git a/admin/report/customlang/styles.css b/admin/report/customlang/styles.css index e75f412adf4..e9219724ea0 100644 --- a/admin/report/customlang/styles.css +++ b/admin/report/customlang/styles.css @@ -63,3 +63,7 @@ background-color: #f6f6f6; margin-top: 0.5em; } + +#page-admin-report-customlang-index .continuebutton { + margin-top: 1em; +}