From ff8584d8d9c0d62dabd99f79b42ab9be95739fb7 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 24 Jan 2020 16:04:07 -0500 Subject: [PATCH] APIv4 - don't throw exception when deleting 0 items --- Civi/Api4/Generic/DAODeleteAction.php | 11 +++-------- Civi/Test/Api3TestTrait.php | 4 ++-- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Civi/Api4/Generic/DAODeleteAction.php b/Civi/Api4/Generic/DAODeleteAction.php index 9c2c3cee2278..7398fdf3cb3c 100644 --- a/Civi/Api4/Generic/DAODeleteAction.php +++ b/Civi/Api4/Generic/DAODeleteAction.php @@ -32,19 +32,14 @@ class DAODeleteAction extends AbstractBatchAction { */ public function _run(Result $result) { $defaults = $this->getParamDefaults(); - if ($defaults['where'] && !array_diff_key($this->where, $defaults['where'])) { + if ($defaults['where'] && $this->where === $defaults['where']) { throw new \API_Exception('Cannot delete ' . $this->getEntityName() . ' with no "where" parameter specified'); } $items = $this->getObjects(); - - if (!$items) { - throw new \API_Exception('Cannot delete ' . $this->getEntityName() . ', no records found with ' . $this->whereClauseToString()); + if ($items) { + $result->exchangeArray($this->deleteObjects($items)); } - - $ids = $this->deleteObjects($items); - - $result->exchangeArray($ids); } /** diff --git a/Civi/Test/Api3TestTrait.php b/Civi/Test/Api3TestTrait.php index fe95b3a94761..a0f8e289bc91 100644 --- a/Civi/Test/Api3TestTrait.php +++ b/Civi/Test/Api3TestTrait.php @@ -459,7 +459,7 @@ public function runApi4Legacy($v3Entity, $v3Action, $v3Params = []) { break; case 'delete': - if (!empty($v3Params['id'])) { + if (isset($v3Params['id'])) { $v4Params['where'][] = ['id', '=', $v3Params['id']]; } break; @@ -531,7 +531,7 @@ public function runApi4Legacy($v3Entity, $v3Action, $v3Params = []) { ]; } - if (($v3Action == 'getsingle' || $v3Action == 'getvalue') && count($result) != 1) { + if (($v3Action == 'getsingle' || $v3Action == 'getvalue' || $v3Action == 'delete') && count($result) != 1) { return $onlySuccess ? 0 : [ 'is_error' => 1, 'error_message' => "Expected one $v4Entity but found " . count($result),