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 +--------------------------------------------------------------------+
13 namespace Civi\Api4\Generic
;
15 use Civi\Api4\Utils\CoreUtil
;
18 * Base class for all batch actions (Update, Delete, Replace).
20 * This differs from the AbstractQuery class in that the "Where" clause is required.
22 * @package Civi\Api4\Generic
24 abstract class AbstractBatchAction
extends AbstractQueryAction
{
27 * Criteria for selecting $ENTITIES to process.
32 protected $where = [];
35 * Get a list of records for this batch.
39 protected function getBatchRecords() {
40 return (array) $this->getBatchAction()->execute();
44 * Get an API action object which resolves the list of records for this batch.
46 * This is similar to `getBatchRecords()`, but you may further refine the
47 * API call (e.g. selecting different fields or data-pages) before executing.
49 * @return \Civi\Api4\Generic\AbstractGetAction
51 protected function getBatchAction() {
53 'checkPermissions' => $this->checkPermissions
,
54 'where' => $this->where
,
55 'orderBy' => $this->orderBy
,
56 'limit' => $this->limit
,
57 'offset' => $this->offset
,
59 if (empty($this->reload
)) {
60 $params['select'] = $this->getSelect();
62 return \Civi\API\Request
::create($this->getEntityName(), 'get', ['version' => 4] +
$params);
66 * Determines what fields will be returned by getBatchRecords
68 * Defaults to an entity's primary key(s), typically ['id']
72 protected function getSelect() {
73 return CoreUtil
::getInfoItem($this->getEntityName(), 'primary_key');