From be76e704cfb0f489175928daa474d41293fd3658 Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 20 Apr 2021 15:24:05 +1200 Subject: [PATCH] Save entities created by api v4 to managed This fixes an issue where entities that only have v4 apis were not saving to civicrm_managed because the id was being incorrectly fetched Change-Id: I9b20de6dcc665d22824743b033acbdc889663045 --- CRM/Core/ManagedEntities.php | 4 +++- api/api.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CRM/Core/ManagedEntities.php b/CRM/Core/ManagedEntities.php index 22d9f12f82..442674f2ef 100644 --- a/CRM/Core/ManagedEntities.php +++ b/CRM/Core/ManagedEntities.php @@ -245,7 +245,9 @@ class CRM_Core_ManagedEntities { $dao->module = $todo['module']; $dao->name = $todo['name']; $dao->entity_type = $todo['entity']; - $dao->entity_id = $result['id']; + // A fatal error will result if there is no valid id but if + // this is v4 api we might need to access it via ->first(). + $dao->entity_id = $result['id'] ?? $result->first()['id']; $dao->cleanup = $todo['cleanup'] ?? NULL; $dao->save(); } diff --git a/api/api.php b/api/api.php index be1946db37..3abd532e60 100644 --- a/api/api.php +++ b/api/api.php @@ -16,7 +16,7 @@ * @param array $params * array to be passed to function * - * @return array|int + * @return array|int|Civi\Api4\Generic\Result */ function civicrm_api(string $entity, string $action, array $params) { return \Civi::service('civi_api_kernel')->runSafe($entity, $action, $params); -- 2.25.1