Add missing condition removal during object deletion
authorMatthias Schmidt <gravatronics@live.com>
Sat, 16 May 2015 08:43:36 +0000 (10:43 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sat, 16 May 2015 08:43:36 +0000 (10:43 +0200)
wcfsetup/install/files/lib/data/ad/AdAction.class.php
wcfsetup/install/files/lib/data/notice/NoticeAction.class.php
wcfsetup/install/files/lib/data/user/group/assignment/UserGroupAssignmentAction.class.php
wcfsetup/install/files/lib/system/condition/ConditionHandler.class.php

index 296451eed09246b2e49b29fadaed3a03625d1947..512eaf1956de63b4e9ec3aeca6103e9a605e8984 100644 (file)
@@ -3,6 +3,7 @@ namespace wcf\data\ad;
 use wcf\data\AbstractDatabaseObjectAction;
 use wcf\data\ISortableAction;
 use wcf\data\IToggleAction;
+use wcf\system\condition\ConditionHandler;
 use wcf\system\exception\UserInputException;
 use wcf\system\WCF;
 
@@ -49,6 +50,15 @@ class AdAction extends AbstractDatabaseObjectAction implements ISortableAction,
                return new Ad($ad->adID);
        }
        
+       /**
+        * @see \wcf\data\IDeleteAction::delete()
+        */
+       public function delete() {
+               ConditionHandler::getInstance()->deleteConditions('com.woltlab.wcf.condition.ad', $this->objectIDs);
+               
+               return parent::delete();
+       }
+       
        /**
         * @see \wcf\data\IToggleAction::toggle()
         */
index 6da91edb50372858f10a8bd4e33a410c8f66ea4c..165ca3a3bc42b1e3ab7b42f9e51aa4787ed4c64a 100644 (file)
@@ -3,6 +3,7 @@ namespace wcf\data\notice;
 use wcf\data\AbstractDatabaseObjectAction;
 use wcf\data\ISortableAction;
 use wcf\data\IToggleAction;
+use wcf\system\condition\ConditionHandler;
 use wcf\system\exception\UserInputException;
 use wcf\system\user\storage\UserStorageHandler;
 use wcf\system\WCF;
@@ -55,6 +56,15 @@ class NoticeAction extends AbstractDatabaseObjectAction implements ISortableActi
                return new Notice($notice->noticeID);
        }
        
+       /**
+        * @see \wcf\data\IDeleteAction::delete()
+        */
+       public function delete() {
+               ConditionHandler::getInstance()->deleteConditions('com.woltlab.wcf.condition.notice', $this->objectIDs);
+               
+               return parent::delete();
+       }
+       
        /**
         * Dismisses a certain notice.
         * 
index 12ef8c8c3f3a1d771001f34a27c2d2e640fbf765..c31bd8f8d908a5f075d1427596627f3d1f34fb5d 100644 (file)
@@ -2,6 +2,7 @@
 namespace wcf\data\user\group\assignment;
 use wcf\data\AbstractDatabaseObjectAction;
 use wcf\data\IToggleAction;
+use wcf\system\condition\ConditionHandler;
 
 /**
  * Executes user group assignment-related actions.
@@ -29,6 +30,15 @@ class UserGroupAssignmentAction extends AbstractDatabaseObjectAction implements
         */
        protected $requireACP = array('create', 'delete', 'toggle', 'update');
        
+       /**
+        * @see \wcf\data\IDeleteAction::delete()
+        */
+       public function delete() {
+               ConditionHandler::getInstance()->deleteConditions('com.woltlab.wcf.condition.userGroupAssignment', $this->objectIDs);
+               
+               return parent::delete();
+       }
+       
        /**
         * @see \wcf\data\IToggleAction::toggle()
         */
index e21140cdfef0ce070e45f837c9bae49d9f08ae8f..2b61e2d2a13fc21863977b29bc43280a3470a996 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 namespace wcf\system\condition;
 use wcf\data\condition\ConditionAction;
+use wcf\data\condition\ConditionList;
 use wcf\data\object\type\ObjectTypeCache;
 use wcf\system\cache\builder\ConditionCacheBuilder;
 use wcf\system\exception\SystemException;
@@ -47,6 +48,39 @@ class ConditionHandler extends SingletonFactory {
                }
        }
        
+       /**
+        * Deletes all conditions of the objects with the given ids.
+        * 
+        * @param       string                  $definitionName
+        * @param       array<integer>          $objectID
+        */
+       public function deleteConditions($definitionName, array $objectID) {
+               if (empty($objectID)) return;
+               
+               $definition = ObjectTypeCache::getInstance()->getDefinitionByName($definitionName);
+               if ($definition === null) {
+                       throw new SystemException("Unknown object type definition with name '".$definitionName."'");
+               }
+               
+               $objectTypes = ObjectTypeCache::getInstance()->getObjectTypes($definitionName);
+               $objectTypeIDs = array();
+               foreach ($objectTypes as $objectType) {
+                       $objectTypeIDs[] = $objectType->objectTypeID;
+               }
+               
+               if (empty($objectTypeIDs)) return;
+               
+               $conditionList = new ConditionList();
+               $conditionList->getConditionBuilder()->add('objectTypeID IN (?)', array($objectTypeIDs));
+               $conditionList->getConditionBuilder()->add('objectID IN (?)', array($objectID));
+               $conditionList->readObjects();
+               
+               if (count($conditionList)) {
+                       $conditionAction = new ConditionAction($conditionList->getObjects(), 'delete');
+                       $conditionAction->executeAction();
+               }
+       }
+       
        /**
         * Returns the conditions for the conditioned object with the given condition
         * object type definition and object id.