From: Matthias Schmidt Date: Sun, 11 Jun 2017 08:48:43 +0000 (+0200) Subject: Delete title and description language items after category deletion X-Git-Tag: 2.1.16~8 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=9c3f3eb27993679a6889e552ff93933c33ce83fc;p=GitHub%2FWoltLab%2FWCF.git Delete title and description language items after category deletion --- diff --git a/wcfsetup/install/files/lib/data/category/CategoryAction.class.php b/wcfsetup/install/files/lib/data/category/CategoryAction.class.php index c3a8993735..9d0331a015 100644 --- a/wcfsetup/install/files/lib/data/category/CategoryAction.class.php +++ b/wcfsetup/install/files/lib/data/category/CategoryAction.class.php @@ -4,7 +4,9 @@ use wcf\data\AbstractDatabaseObjectAction; use wcf\data\ISortableAction; use wcf\data\IToggleAction; use wcf\data\IToggleContainerAction; +use wcf\data\language\item\LanguageItemAction; use wcf\system\category\CategoryHandler; +use wcf\system\database\util\PreparedStatementConditionBuilder; use wcf\system\exception\PermissionDeniedException; use wcf\system\exception\SystemException; use wcf\system\exception\UserInputException; @@ -39,6 +41,39 @@ class CategoryAction extends AbstractDatabaseObjectAction implements ISortableAc public function delete() { $returnValue = parent::delete(); + // delete language items + if (!empty($this->objects)) { + // identify i18n labels + $languageVariables = array(); + foreach ($this->objects as $category) { + if ($category->title === $category->getProcessor()->getI18nLangVarPrefix() . '.title.category' . $category->categoryID) { + $languageVariables[] = $category->title; + } + if ($category->description === $category->getProcessor()->getI18nLangVarPrefix() . '.description.category' . $category->categoryID) { + $languageVariables[] = $category->description; + } + } + + // remove language variables + if (!empty($languageVariables)) { + $conditions = new PreparedStatementConditionBuilder(); + $conditions->add('languageItem IN (?)', array($languageVariables)); + + $sql = "SELECT languageItemID + FROM wcf".WCF_N."_language_item + ".$conditions; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute($conditions->getParameters()); + $languageItemIDs = array(); + while ($row = $statement->fetchArray()) { + $languageItemIDs[] = $row['languageItemID']; + } + + $objectAction = new LanguageItemAction($languageItemIDs, 'delete'); + $objectAction->executeAction(); + } + } + // call category types foreach ($this->objects as $categoryEditor) { $categoryEditor->getProcessor()->afterDeletion($categoryEditor);