MDL-39319 langimport: Able to delete more languages at once

This commit is contained in:
Martin Mastny 2015-05-27 17:03:02 +08:00
parent 0c6faf4b51
commit 6ddf92c774
3 changed files with 26 additions and 16 deletions

View File

@ -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;
}
}

View File

@ -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')));

View File

@ -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 <a href="https://download.moodle.org/langpack/">download.moodle.org/langpack</a>, 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';