4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
10 +--------------------------------------------------------------------+
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
22 namespace Civi\Api4\Generic
;
25 * Delete one or more $ENTITIES.
27 * $ENTITIES are deleted based on criteria specified in `where` parameter (required).
29 class DAODeleteAction
extends AbstractBatchAction
{
30 use Traits\DAOActionTrait
;
33 * Batch delete function
35 public function _run(Result
$result) {
36 $defaults = $this->getParamDefaults();
37 if ($defaults['where'] && $this->where
=== $defaults['where']) {
38 throw new \
API_Exception('Cannot delete ' . $this->getEntityName() . ' with no "where" parameter specified');
41 $items = $this->getObjects();
43 $result->exchangeArray($this->deleteObjects($items));
50 * @throws \API_Exception
52 protected function deleteObjects($items) {
54 $baoName = $this->getBaoName();
56 if ($this->getCheckPermissions()) {
57 foreach ($items as $item) {
58 $this->checkContactPermissions($baoName, $item);
62 if ($this->getEntityName() !== 'EntityTag' && method_exists($baoName, 'del')) {
63 foreach ($items as $item) {
64 $args = [$item['id']];
65 $bao = call_user_func_array([$baoName, 'del'], $args);
67 $ids[] = ['id' => $item['id']];
70 throw new \
API_Exception("Could not delete {$this->getEntityName()} id {$item['id']}");
75 foreach ($items as $item) {
76 $bao = new $baoName();
77 $bao->id
= $item['id'];
79 $action_result = $bao->delete();
81 $ids[] = ['id' => $item['id']];
84 throw new \
API_Exception("Could not delete {$this->getEntityName()} id {$item['id']}");