Permalink
Browse files

MDL-27293 report customlang has extra execution time and displays a p…

…rogress 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.
  • Loading branch information...
1 parent 77e4a16 commit bd7193c7ac5e51c9d3243d557936b2ae5f2e06d2 @mudrd8mz mudrd8mz committed Apr 26, 2011
@@ -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 (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') {
@@ -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';
@@ -16,7 +16,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
- * 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 @@
*/
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 @@ public static function list_components() {
* 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 @@ public static function checkout($lang) {
}
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 @@ public static function checkout($lang) {
$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 @@ public static function checkout($lang) {
}
}
}
+
+ if (!is_null($progressbar)) {
+ $progressbar->update_full(100, get_string('checkoutdone', 'report_customlang'));
+ }
}
/**
@@ -63,3 +63,7 @@
background-color: #f6f6f6;
margin-top: 0.5em;
}
+
+#page-admin-report-customlang-index .continuebutton {
+ margin-top: 1em;
+}

0 comments on commit bd7193c

Please sign in to comment.