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
20 namespace Civi\Api4\Generic
;
23 * Delete one or more $ENTITIES.
25 * $ENTITIES are deleted based on criteria specified in `where` parameter (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->getBatchRecords();
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 (array_keys($items) as $key) {
56 $items[$key]['check_permissions'] = TRUE;
57 $this->checkContactPermissions($baoName, $items[$key]);
61 if ($this->getEntityName() !== 'EntityTag' && method_exists($baoName, 'del')) {
62 foreach ($items as $item) {
63 $args = [$item['id']];
64 $bao = call_user_func_array([$baoName, 'del'], $args);
66 $ids[] = ['id' => $item['id']];
69 throw new \
API_Exception("Could not delete {$this->getEntityName()} id {$item['id']}");
74 foreach ($items as $item) {
75 $baoName::deleteRecord($item);
76 $ids[] = ['id' => $item['id']];