From 6dc2df50f918b8fd419a9f866ce2d63ebf390875 Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Tue, 22 Nov 2011 11:37:36 +0100 Subject: [PATCH 1/2] MDL-30404 Ability to manually purge string caches from the language packs import utility --- admin/tool/langimport/index.php | 22 ++++++++++++++----- .../langimport/lang/en/tool_langimport.php | 4 +++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/admin/tool/langimport/index.php b/admin/tool/langimport/index.php index 964c64ce97c..80d8829865f 100644 --- a/admin/tool/langimport/index.php +++ b/admin/tool/langimport/index.php @@ -35,17 +35,29 @@ require_once($CFG->libdir.'/componentlib.class.php'); admin_externalpage_setup('toollangimport'); -if (!empty($CFG->skiplangupgrade)) { - echo $OUTPUT->header(); - echo $OUTPUT->box(get_string('langimportdisabled', 'tool_langimport')); - echo $OUTPUT->footer(); - die; +if (empty($CFG->langotherroot)) { + throw new moodle_exception('missingcfglangotherroot', 'tool_langimport'); } $mode = optional_param('mode', 0, PARAM_INT); // action $pack = optional_param_array('pack', array(), PARAM_SAFEDIR); // pack to install $uninstalllang = optional_param('uninstalllang', '', PARAM_LANG); // installed pack to uninstall $confirm = optional_param('confirm', 0, PARAM_BOOL); // uninstallation confirmation +$purgecaches = optional_param('purgecaches', false, PARAM_BOOL); // explicit caches reset + +if ($purgecaches) { + require_sesskey(); + get_string_manager()->reset_caches(); + redirect($PAGE->url); +} + +if (!empty($CFG->skiplangupgrade)) { + echo $OUTPUT->header(); + echo $OUTPUT->box(get_string('langimportdisabled', 'tool_langimport')); + echo $OUTPUT->single_button(new moodle_url($PAGE->url, array('purgecaches' => 1)), get_string('purgestringcaches', 'tool_langimport')); + echo $OUTPUT->footer(); + die; +} define('INSTALLATION_OF_SELECTED_LANG', 2); define('DELETION_OF_SELECTED_LANG', 4); diff --git a/admin/tool/langimport/lang/en/tool_langimport.php b/admin/tool/langimport/lang/en/tool_langimport.php index e2fbf511d1a..a5ead161828 100644 --- a/admin/tool/langimport/lang/en/tool_langimport.php +++ b/admin/tool/langimport/lang/en/tool_langimport.php @@ -26,15 +26,17 @@ $string['install'] = 'Install selected language pack'; $string['installedlangs'] = 'Installed language packs'; $string['langimport'] = 'Language import utility'; -$string['langimportdisabled'] = 'Language import feature has been disabled. You have to update your language packs manually at the file-system level.'; +$string['langimportdisabled'] = 'Language import feature has been disabled. You have to update your language packs manually at the file-system level. Do not forget to purge string caches after you do so.'; $string['langpackinstalled'] = 'Language pack {$a} was successfully installed'; $string['langpackremoved'] = 'Language pack was uninstalled'; $string['langpackupdateskipped'] = 'Update of {$a} language pack skipped'; $string['langpackuptodate'] = 'Language pack {$a} is up-to-date'; $string['langupdatecomplete'] = 'Language pack update completed'; +$string['missingcfglangotherroot'] = 'Missing configuration value $CFG->langotherroot'; $string['missinglangparent'] = 'Missing parent language {$a->parent} of {$a->lang}.'; $string['nolangupdateneeded'] = 'All your language packs are up to date, no update is needed'; $string['pluginname'] = 'Language packs'; +$string['purgestringcaches'] = 'Purge string caches'; $string['remotelangnotavailable'] = 'Because Moodle can not connect to download.moodle.org, we are unable to do language pack installation automatically. Please download the appropriate zip file(s) from http://download.moodle.org, copy them to your {$a} directory and unzip them manually.'; $string['uninstall'] = 'Uninstall selected language pack'; $string['uninstallconfirm'] = 'You are about to completely uninstall language pack {$a}, are you sure?'; From 561d547173d478e643aa6b79a1c9c8739a0bfd86 Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Tue, 22 Nov 2011 11:50:54 +0100 Subject: [PATCH 2/2] MDL-30404 All Moodle caches can be now purged from CLI --- admin/cli/purge_caches.php | 53 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 admin/cli/purge_caches.php diff --git a/admin/cli/purge_caches.php b/admin/cli/purge_caches.php new file mode 100644 index 00000000000..f008da2568c --- /dev/null +++ b/admin/cli/purge_caches.php @@ -0,0 +1,53 @@ +. + +/** + * @package core + * @subpackage cli + * @copyright 2011 David Mudrak + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +define('CLI_SCRIPT', true); + +require(dirname(dirname(dirname(__FILE__))).'/config.php'); +require_once($CFG->libdir.'/clilib.php'); + +list($options, $unrecognized) = cli_get_params(array('help' => false), array('h' => 'help')); + +if ($unrecognized) { + $unrecognized = implode("\n ", $unrecognized); + cli_error(get_string('cliunknowoption', 'admin', $unrecognized), 2); +} + +if ($options['help']) { + $help = +"Invalidates all Moodle internal caches + +Options: +-h, --help Print out this help + +Example: +\$sudo -u www-data /usr/bin/php admin/cli/purge_caches.php +"; + + echo $help; + exit(0); +} + +purge_all_caches(); + +exit(0); \ No newline at end of file