From d6f190fbd2d9476a10a2ff6896b99bfd6ef1bed7 Mon Sep 17 00:00:00 2001 From: eileen Date: Sat, 5 Jan 2019 11:24:20 +1300 Subject: [PATCH] dev/core#643 fix for double delete attempt when chained with getsingle --- Civi/API/Provider/MagicFunctionProvider.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Civi/API/Provider/MagicFunctionProvider.php b/Civi/API/Provider/MagicFunctionProvider.php index 207b5991cc..1b44dd931a 100644 --- a/Civi/API/Provider/MagicFunctionProvider.php +++ b/Civi/API/Provider/MagicFunctionProvider.php @@ -83,7 +83,18 @@ class MagicFunctionProvider implements EventSubscriberInterface, ProviderInterfa // Unlike normal API implementations, generic implementations require explicit // knowledge of the entity and action (as well as $params). Bundle up these bits // into a convenient data structure. + if ($apiRequest['action'] === 'getsingle') { + // strip any api nested parts here as otherwise chaining may happen twice + // see https://lab.civicrm.org/dev/core/issues/643 + // testCreateBAODefaults fails without this. + foreach ($apiRequest['params'] as $key => $param) { + if ($key !== 'api.has_parent' && substr($key, 0, 4) === 'api.' || substr($key, 0, 4) === 'api_') { + unset($apiRequest['params'][$key]); + } + } + } $result = $function($apiRequest); + } elseif ($apiRequest['function'] && !$apiRequest['is_generic']) { $result = $function($apiRequest['params']); -- 2.25.1