From 6ddf92c7749d88818a6def5a807d298b19dc867e Mon Sep 17 00:00:00 2001 From: Martin Mastny Date: Wed, 27 May 2015 17:03:02 +0800 Subject: [PATCH] MDL-39319 langimport: Able to delete more languages at once --- admin/tool/langimport/classes/controller.php | 2 +- admin/tool/langimport/index.php | 35 ++++++++++++------- .../langimport/lang/en/tool_langimport.php | 5 +-- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/admin/tool/langimport/classes/controller.php b/admin/tool/langimport/classes/controller.php index d3eee5887bc..bf43258ae89 100644 --- a/admin/tool/langimport/classes/controller.php +++ b/admin/tool/langimport/classes/controller.php @@ -128,7 +128,7 @@ class controller { event\langpack_removed::event_with_langcode($lang)->trigger(); return true; } else { // Nothing deleted, possibly due to permission error. - $this->errors[] = 'An error has occurred, language pack is not completely uninstalled, please check file permissions'; + $this->errors[] = get_string('langpacknotremoved', 'tool_langimport', $lang); return false; } } diff --git a/admin/tool/langimport/index.php b/admin/tool/langimport/index.php index b49dbd3a74e..27fd584001f 100644 --- a/admin/tool/langimport/index.php +++ b/admin/tool/langimport/index.php @@ -37,11 +37,11 @@ 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 +$mode = optional_param('mode', 0, PARAM_INT); // action +$pack = optional_param_array('pack', array(), PARAM_SAFEDIR); // pack to install +$uninstalllang = optional_param_array('uninstalllang', array(), PARAM_LANG);// installed pack to uninstall +$confirmtounistall = optional_param('confirmtouninstall', '', PARAM_ALPHAEXT); // uninstallation confirmation +$purgecaches = optional_param('purgecaches', false, PARAM_BOOL); // explicit caches reset if ($purgecaches) { require_sesskey(); @@ -70,21 +70,30 @@ if (($mode == INSTALLATION_OF_SELECTED_LANG) and confirm_sesskey() and !empty($p $controller->install_languagepacks($pack); } -if ($mode == DELETION_OF_SELECTED_LANG and !empty($uninstalllang)) { - if ($uninstalllang == 'en') { +if ($mode == DELETION_OF_SELECTED_LANG and (!empty($uninstalllang) or !empty($confirmtounistall))) { + // Actually deleting languages, languages to delete are passed as GET parameter as string + // ...need to populate them to array. + if (empty($uninstalllang)) { + $uninstalllang = explode('-', $confirmtounistall); + } + + if (in_array('en', $uninstalllang)) { // TODO. $controller->errors[] = 'English language pack can not be uninstalled'; - } else if (!$confirm and confirm_sesskey()) { + } else if (empty($confirmtounistall) and confirm_sesskey()) { // User chose langs to be deleted, show confirmation. echo $OUTPUT->header(); - echo $OUTPUT->confirm(get_string('uninstallconfirm', 'tool_langimport', $uninstalllang), - 'index.php?mode='.DELETION_OF_SELECTED_LANG.'&uninstalllang='.$uninstalllang.'&confirm=1', + echo $OUTPUT->confirm(get_string('uninstallconfirm', 'tool_langimport', implode(', ', $uninstalllang)), + 'index.php?mode='.DELETION_OF_SELECTED_LANG.'&confirmtouninstall='.implode('-', $uninstalllang), 'index.php'); echo $OUTPUT->footer(); die; - } else if (confirm_sesskey()) { - $controller->uninstall_language($uninstalllang); + } else if (confirm_sesskey()) { // Deleting languages. + foreach ($uninstalllang as $ulang) { + $controller->uninstall_language($ulang); + } + } } @@ -158,7 +167,7 @@ echo html_writer::start_tag('form', array('id' => 'uninstallform', 'action' => $ echo html_writer::start_tag('fieldset'); echo html_writer::label(get_string('installedlangs', 'tool_langimport'), 'menuuninstalllang'); echo html_writer::empty_tag('br'); -echo html_writer::select($installedlangs, 'uninstalllang', '', false, array('size' => 15)); +echo html_writer::select($installedlangs, 'uninstalllang[]', '', false, array('size' => 15, 'multiple' => 'multiple')); echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())); echo html_writer::empty_tag('br'); echo html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('uninstall', 'tool_langimport'))); diff --git a/admin/tool/langimport/lang/en/tool_langimport.php b/admin/tool/langimport/lang/en/tool_langimport.php index fba12f9def0..a8c97fca6bf 100644 --- a/admin/tool/langimport/lang/en/tool_langimport.php +++ b/admin/tool/langimport/lang/en/tool_langimport.php @@ -30,6 +30,7 @@ $string['langimportdisabled'] = 'Language import feature has been disabled. You $string['langpackinstalled'] = 'Language pack \'{$a}\' was successfully installed'; $string['langpackinstalledevent'] = 'Language pack installed'; $string['langpackremoved'] = 'Language pack \'{$a}\' was uninstalled'; +$string['langpacknotremoved'] = 'An error has occurred, language pack \'{$a}\' is not completely uninstalled, please check file permissions'; $string['langpackremovedevent'] = 'Language pack uninstalled'; $string['langpackupdateskipped'] = 'Update of \'{$a}\' language pack skipped'; $string['langpackuptodate'] = 'Language pack \'{$a}\' is up-to-date'; @@ -42,7 +43,7 @@ $string['nolangupdateneeded'] = 'All your language packs are up to date, no upda $string['pluginname'] = 'Language packs'; $string['purgestringcaches'] = 'Purge string caches'; $string['remotelangnotavailable'] = 'Because Moodle cannot connect to download.moodle.org, it is not possible for language packs to be installed automatically. Please download the appropriate ZIP file(s) from download.moodle.org/langpack, 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?'; +$string['uninstall'] = 'Uninstall selected language packs'; +$string['uninstallconfirm'] = 'You are about to completely uninstall these language packs: {$a}. Are you sure?'; $string['updatelangs'] = 'Update all installed language packs'; -- 2.43.0