Merge branch '2014.11-develop' into 2015.11
[tine20] / tine20 / Tinebase / Container.php
index 5fa1d64..891bdd6 100644 (file)
@@ -1106,6 +1106,7 @@ class Tinebase_Container extends Tinebase_Backend_Sql_Abstract
         $tm->commitTransaction($myTransactionId);
         
         return $deletedContainer;
+
         /*
         // move all contained objects to next available personal container and try again to delete container
         $app = Tinebase_Application::getApplicationById($container->application_id);
@@ -1136,7 +1137,6 @@ class Tinebase_Container extends Tinebase_Backend_Sql_Abstract
      */
     public function deleteContainerContents($container, $_ignoreAcl = FALSE)
     {
-        // set records belonging to this container to deleted
         $model = $container->model;
 
         if (empty($model)) {
@@ -1145,9 +1145,6 @@ class Tinebase_Container extends Tinebase_Backend_Sql_Abstract
             return;
         }
 
-        Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__
-            . ' Deleting container contents ...');
-
         $controller = Tinebase_Core::getApplicationInstance($model);
         $filterName = $model . 'Filter';
 
@@ -1155,19 +1152,22 @@ class Tinebase_Container extends Tinebase_Backend_Sql_Abstract
             $acl = $controller->doContainerACLChecks(FALSE);
         }
         if ($controller && class_exists($filterName)) {
-            $filter = new $filterName(array(
-                array(
-                    'field'    => 'container_id',
-                    'operator' => 'equals',
-                    'value'    => intval($container->id)
-                ),
-                array(
-                    'field'    => 'is_deleted',
-                    'operator' => 'equals',
-                    'value'    => 0
-                )),
-                'AND');
-            $controller::getInstance()->deleteByFilter($filter);
+            Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__
+                . ' Delete ' . $model . ' records in container ' . $container->getId());
+
+            $filter = new $filterName(array(array(
+                'field'    => 'container_id',
+                'operator' => 'equals',
+                'value'    => intval($container->id)
+            )), Tinebase_Model_Filter_FilterGroup::CONDITION_AND, array('ignoreAcl' => $_ignoreAcl));
+
+            if ($_ignoreAcl) {
+                $backend = $controller::getInstance()->getBackend();
+                $idsToDelete = $backend->search($filter, null, /* $_onlyIds */ true);
+                $controller::getInstance()->delete($idsToDelete);
+            } else {
+                $controller::getInstance()->deleteByFilter($filter);
+            }
         }
 
         if ($_ignoreAcl === TRUE && method_exists($controller, 'doContainerACLChecks')) {