Delete title and description language items after category deletion
authorMatthias Schmidt <gravatronics@live.com>
Sun, 11 Jun 2017 08:48:43 +0000 (10:48 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 11 Jun 2017 08:48:43 +0000 (10:48 +0200)
wcfsetup/install/files/lib/data/category/CategoryAction.class.php

index c3a89937351060f7791505447bc0fe42ace381bb..9d0331a015d9f3c95b90ec82936457072c00cd70 100644 (file)
@@ -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);