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 items, based on criteria specified in Where param (required).
27 class DAODeleteAction
extends AbstractBatchAction
{
28 use Traits\DAOActionTrait
;
31 * Batch delete function
33 public function _run(Result
$result) {
34 $defaults = $this->getParamDefaults();
35 if ($defaults['where'] && $this->where
=== $defaults['where']) {
36 throw new \
API_Exception('Cannot delete ' . $this->getEntityName() . ' with no "where" parameter specified');
39 $items = $this->getObjects();
41 $result->exchangeArray($this->deleteObjects($items));
48 * @throws \API_Exception
50 protected function deleteObjects($items) {
52 $baoName = $this->getBaoName();
54 if ($this->getCheckPermissions()) {
55 foreach ($items as $item) {
56 $this->checkContactPermissions($baoName, $item);
60 if ($this->getEntityName() !== 'EntityTag' && method_exists($baoName, 'del')) {
61 foreach ($items as $item) {
62 $args = [$item['id']];
63 $bao = call_user_func_array([$baoName, 'del'], $args);
65 $ids[] = ['id' => $item['id']];
68 throw new \
API_Exception("Could not delete {$this->getEntityName()} id {$item['id']}");
73 foreach ($items as $item) {
74 $bao = new $baoName();
75 $bao->id
= $item['id'];
77 $action_result = $bao->delete();
79 $ids[] = ['id' => $item['id']];
82 throw new \
API_Exception("Could not delete {$this->getEntityName()} id {$item['id']}");