+--------------------------------------------------------------------+
*/
-/**
- *
- * @package CRM
- * @copyright CiviCRM LLC https://civicrm.org/licensing
- */
-
-
namespace Civi\Api4\Generic;
+use Civi\Api4\Utils\CoreUtil;
+
/**
* Base class for all batch actions (Update, Delete, Replace).
*
protected $where = [];
/**
- * @var array
- */
- private $select;
-
- /**
- * BatchAction constructor.
- * @param string $entityName
- * @param string $actionName
- * @param string|array $select
- * One or more fields to load for each item.
+ * Get a list of records for this batch.
+ *
+ * @return array
*/
- public function __construct($entityName, $actionName, $select = 'id') {
- $this->select = (array) $select;
- parent::__construct($entityName, $actionName);
+ protected function getBatchRecords() {
+ return (array) $this->getBatchAction()->execute();
}
/**
- * @return array
+ * Get an API action object 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 getBatchRecords() {
+ protected function getBatchAction() {
$params = [
'checkPermissions' => $this->checkPermissions,
'where' => $this->where,
'offset' => $this->offset,
];
if (empty($this->reload)) {
- $params['select'] = $this->select;
+ $params['select'] = $this->getSelect();
}
-
- return (array) civicrm_api4($this->getEntityName(), 'get', $params);
+ return \Civi\API\Request::create($this->getEntityName(), 'get', ['version' => 4] + $params);
}
/**
- * @return array
+ * Determines what fields will be returned by getBatchRecords
+ *
+ * Defaults to an entity's primary key(s), typically ['id']
+ *
+ * @return string[]
*/
protected function getSelect() {
- return $this->select;
+ return CoreUtil::getInfoItem($this->getEntityName(), 'primary_key');
}
}