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->getBatchRecords();
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 (array_keys($items) as $key) {
58 $items[$key]['check_permissions'] = TRUE;
59 $this->checkContactPermissions($baoName, $items[$key]);
63 if ($this->getEntityName() !== 'EntityTag' && method_exists($baoName, 'del')) {
64 foreach ($items as $item) {
65 $args = [$item['id']];
66 $bao = call_user_func_array([$baoName, 'del'], $args);
68 $ids[] = ['id' => $item['id']];
71 throw new \
API_Exception("Could not delete {$this->getEntityName()} id {$item['id']}");
76 foreach ($items as $item) {
77 $baoName::deleteRecord($item);
78 $ids[] = ['id' => $item['id']];