Permalink
Browse files

Introducing new clean-texts CLI script

  • Loading branch information...
1 parent 0bd8c3e commit d5f742e62fad9ec3d2ac321f7674b5814d3a62e4 @mudrd8mz mudrd8mz committed May 23, 2012
Showing with 93 additions and 0 deletions.
  1. +68 −0 cli/clean-texts.php
  2. +25 −0 simpletest/testmlanglib.php
View
@@ -0,0 +1,68 @@
+<?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/>.
+
+/**
+ * Applies {@link mlang_component::clean_texts()} to all components
+ *
+ * @package local_amos
+ * @copyright 2012 David Mudrak <david.mudrak@gmail.com>
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+define('CLI_SCRIPT', true);
+
+require_once(dirname(dirname(dirname(dirname(__FILE__)))) . '/config.php');
+require_once($CFG->dirroot . '/local/amos/cli/config.php');
+require_once($CFG->dirroot . '/local/amos/mlanglib.php');
+require_once($CFG->libdir . '/clilib.php');
+
+cli_separator();
+fputs(STDOUT, date('Y-m-d H:i', time()));
+fputs(STDOUT, " CLEAN TEXTS JOB STARTED\n");
+
+$stage = new mlang_stage();
+
+$tree = mlang_tools::components_tree();
+foreach ($tree as $vercode => $languages) {
+ if ($vercode <= mlang_version::MOODLE_19) {
+ continue;
+ }
+ $version = mlang_version::by_code($vercode);
+ foreach ($languages as $langcode => $components) {
+ if ($langcode == 'en') {
+ continue;
+ }
+ foreach ($components as $componentname => $ignored) {
+ $component = mlang_component::from_snapshot($componentname, $langcode, $version);
+ $component->clean_texts();
+ $stage->add($component);
+ $stage->rebase();
+ if ($stage->has_component()) {
+ $stage->commit('Cleaning strings debris and format', array('source' => 'bot', 'userinfo' => 'AMOS-bot <amos@moodle.org>'), true);
+ fputs(STDOUT, $version->label.' '.$langcode.' '.$componentname.' committed '.date('Y-m-d H:i', time()).PHP_EOL);
+ } else {
+ fputs(STDOUT, $version->label.' '.$langcode.' '.$componentname.' no change '.date('Y-m-d H:i', time()).PHP_EOL);
+ }
+ $stage->clear();
+ $component->clear();
+ unset($component);
+ }
+ }
+}
+
+fputs(STDOUT, date('Y-m-d H:i', time()));
+fputs(STDOUT, " CLEAN TEXTS JOB DONE\n");
@@ -807,9 +807,34 @@ public function test_clean_text() {
$component = new mlang_component('doodle', 'xx', mlang_version::by_branch('MOODLE_20_STABLE'));
$component->add_string(new mlang_string('first', "Line\n\n\n\n\n\n\nline"));
$component->add_string(new mlang_string('second', 'This \really \$a sucks. Yes {$a}, it {$a->does}'));
+ $component->add_string(new mlang_string('third', "Multi line \n trailing "));
$component->clean_texts();
$this->assertEqual("Line\n\n\nline", $component->get_string('first')->text); // two blank lines allowed in format 2
$this->assertEqual('This really $a sucks. Yes {$a}, it {$a->does}', $component->get_string('second')->text);
+ $this->assertEqual("Multi line\n trailing", $component->get_string('third')->text);
+ $component->clear();
+ unset($component);
+ }
+
+ public function test_clean_texts_rebase() {
+ $stage = new mlang_stage();
+ $component = new mlang_component('doodle', 'xx', mlang_version::by_branch('MOODLE_20_STABLE'));
+ $component->add_string(new mlang_string('multiline', "Multi line \n trailing "));
+ $stage->add($component);
+ $stage->commit('Initial commit', array('source' => 'unittest'));
+ $component->clear();
+
+ $component = mlang_component::from_snapshot('doodle', 'xx', mlang_version::by_branch('MOODLE_20_STABLE'));
+ $this->assertTrue($component->has_string('multiline'));
+ $this->assertEqual("Multi line \n trailing ", $component->get_string('multiline')->text);
+ $component->clean_texts();
+ $stage->add($component);
+ $stage->commit('Cleaned', array('source' => 'unittest'));
+ $component->clear();
+
+ $component = mlang_component::from_snapshot('doodle', 'xx', mlang_version::by_branch('MOODLE_20_STABLE'));
+ $this->assertTrue($component->has_string('multiline'));
+ $this->assertEqual("Multi line\n trailing", $component->get_string('multiline')->text);
$component->clear();
unset($component);
}

0 comments on commit d5f742e

Please sign in to comment.