From 8ecaced6fc3f1b92f01ec99ffae06ebc67c30b4b Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Thu, 25 Feb 2021 14:02:04 +0100 Subject: [PATCH] Default languages (de/en) can no longer be deleted Closes #3969 --- .../install/files/acp/templates/languageList.tpl | 2 +- .../files/lib/data/language/Language.class.php | 10 ++++++++++ .../lib/data/language/LanguageAction.class.php | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/acp/templates/languageList.tpl b/wcfsetup/install/files/acp/templates/languageList.tpl index 82edbb9963..9df2e9a218 100644 --- a/wcfsetup/install/files/acp/templates/languageList.tpl +++ b/wcfsetup/install/files/acp/templates/languageList.tpl @@ -68,7 +68,7 @@ - {if !$language->isDefault} + {if $language->isDeletable()} {else} diff --git a/wcfsetup/install/files/lib/data/language/Language.class.php b/wcfsetup/install/files/lib/data/language/Language.class.php index 2020ee92d8..e0a5a16c2a 100644 --- a/wcfsetup/install/files/lib/data/language/Language.class.php +++ b/wcfsetup/install/files/lib/data/language/Language.class.php @@ -295,4 +295,14 @@ class Language extends DatabaseObject { $this->packageID = PACKAGE_ID; } + + /** + * Returns true if this language can be deleted. + * + * @since 5.4 + */ + public function isDeletable(): bool + { + return !$this->isDefault && $this->languageCode !== 'de' && $this->languageCode !== 'en'; + } } diff --git a/wcfsetup/install/files/lib/data/language/LanguageAction.class.php b/wcfsetup/install/files/lib/data/language/LanguageAction.class.php index 9673f9bd40..b589b2fce6 100644 --- a/wcfsetup/install/files/lib/data/language/LanguageAction.class.php +++ b/wcfsetup/install/files/lib/data/language/LanguageAction.class.php @@ -90,4 +90,18 @@ class LanguageAction extends AbstractDatabaseObjectAction implements IToggleActi } } } + + /** + * @inheritDoc + */ + public function validateDelete() + { + parent::validateDelete(); + + foreach ($this->getObjects() as $language) { + if (!$language->isDeletable()) { + throw new UserInputException('objectIDs'); + } + } + } } -- 2.20.1