[REF] Replace the deprecated system_rebuild_module_data function with equivilant...
[civicrm-core.git] / Civi / Api4 / Generic / DAODeleteAction.php
index 3e0135f8991cbcb291f5aaf1c9f625edebba5417..e9f4c36d90bbf85b804e29dd2b6fe159e3d20a2e 100644 (file)
@@ -14,8 +14,6 @@
  *
  * @package CRM
  * @copyright CiviCRM LLC https://civicrm.org/licensing
- * $Id$
- *
  */
 
 
@@ -38,7 +36,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 +52,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 +72,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;