From 8047edec7bea76c2ed4e8e32684f8069fa60a7b6 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 19 May 2021 16:45:51 -0700 Subject: [PATCH] (REF) APIv4 BatchAction - Split 'getBatchRecords()' in two The original form (`getBatchRecords()`) still returns an array of items. The alternate form (`getBatchAction()`) returns an API call for fetching the batchs - but this API call may be further refined (e.g. selecting different fields or data-pages). --- Civi/Api4/Generic/AbstractBatchAction.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Civi/Api4/Generic/AbstractBatchAction.php b/Civi/Api4/Generic/AbstractBatchAction.php index 7a0e6e8c19..f0701590f1 100644 --- a/Civi/Api4/Generic/AbstractBatchAction.php +++ b/Civi/Api4/Generic/AbstractBatchAction.php @@ -54,9 +54,23 @@ abstract class AbstractBatchAction extends AbstractQueryAction { } /** + * Get a list of records for this batch. + * * @return array */ protected function getBatchRecords() { + return (array) $this->getBatchAction()->execute(); + } + + /** + * Get a query which resolves the list of records for this batch. + * + * This is similar to `getBatchRecords()`, but you may further refine the + * API call (e.g. selecting different fields or data-pages) before executing. + * + * @return \Civi\Api4\Generic\AbstractGetAction + */ + protected function getBatchAction() { $params = [ 'checkPermissions' => $this->checkPermissions, 'where' => $this->where, @@ -67,8 +81,7 @@ abstract class AbstractBatchAction extends AbstractQueryAction { if (empty($this->reload)) { $params['select'] = $this->select; } - - return (array) civicrm_api4($this->getEntityName(), 'get', $params); + return \Civi\API\Request::create($this->getEntityName(), 'get', ['version' => 4] + $params); } /** -- 2.25.1