APIv4 - Support pseudoconstant lookups
[civicrm-core.git] / Civi / Api4 / Generic / DAODeleteAction.php
index 3e0135f8991cbcb291f5aaf1c9f625edebba5417..666e702993a1e78823cc90d769c291480f68e12f 100644 (file)
@@ -38,7 +38,7 @@ class DAODeleteAction extends AbstractBatchAction {
       throw new \API_Exception('Cannot delete ' . $this->getEntityName() . ' with no "where" parameter specified');
     }
 
-    $items = $this->getObjects();
+    $items = $this->getBatchRecords();
     if ($items) {
       $result->exchangeArray($this->deleteObjects($items));
     }
@@ -54,8 +54,9 @@ class DAODeleteAction extends AbstractBatchAction {
     $baoName = $this->getBaoName();
 
     if ($this->getCheckPermissions()) {
-      foreach ($items as $item) {
-        $this->checkContactPermissions($baoName, $item);
+      foreach (array_keys($items) as $key) {
+        $items[$key]['check_permissions'] = TRUE;
+        $this->checkContactPermissions($baoName, $items[$key]);
       }
     }
 
@@ -73,16 +74,8 @@ class DAODeleteAction extends AbstractBatchAction {
     }
     else {
       foreach ($items as $item) {
-        $bao = new $baoName();
-        $bao->id = $item['id'];
-        // delete it
-        $action_result = $bao->delete();
-        if ($action_result) {
-          $ids[] = ['id' => $item['id']];
-        }
-        else {
-          throw new \API_Exception("Could not delete {$this->getEntityName()} id {$item['id']}");
-        }
+        $baoName::deleteRecord($item);
+        $ids[] = ['id' => $item['id']];
       }
     }
     return $ids;