$orClause = [];
foreach ($orGroup as $key) {
if (!isset($filters[$key])) {
- throw new \CiviCRM_API3_Exception("'$key' specified in OR group but not added to params");
+ throw new \CRM_Core_Exception("'$key' specified in OR group but not added to params");
}
$orClause[] = $filters[$key];
unset($filters[$key]);
* @return array
* structured response data (per civicrm_api3_create_success)
* @see civicrm_api3_create_success
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public function invoke($apiRequest);
* @inheritDoc
* @param array $apiRequest
* @return array
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public function invoke($apiRequest) {
if (strtolower($apiRequest['entity']) == 'entity' && $apiRequest['action'] == 'get') {
}
// We shouldn't get here because onApiResolve() checks $this->actions
- throw new \API_Exception("Unsupported action (" . $apiRequest['entity'] . '.' . $apiRequest['action'] . ']');
+ throw new \CRM_Core_Exception("Unsupported action (" . $apiRequest['entity'] . '.' . $apiRequest['action'] . ']');
}
/**
* The full description of the API request.
* @return array
* Formatted API result
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public function doCreate($apiRequest) {
if (isset($apiRequest['params']['id'])) {
}
if (!isset($this->records[$id])) {
- throw new \API_Exception("Invalid ID: $id");
+ throw new \CRM_Core_Exception("Invalid ID: $id");
}
foreach ($this->fields as $field) {
* The full description of the API request.
* @return array
* Formatted API result
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public function doGet($apiRequest) {
return _civicrm_api3_basic_array_get($apiRequest['entity'], $apiRequest['params'], $this->records, 'id', $this->fields);
* The full description of the API request.
* @return array
* Formatted API result
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public function doDelete($apiRequest) {
$id = @$apiRequest['params']['id'];
public function getEntityNames($version) {
// return $version == $this->version ? [$this->entity] : [];
- throw new \API_Exception("Not support: WrappingProvider::getEntityNames()");
+ throw new \CRM_Core_Exception("Not support: WrappingProvider::getEntityNames()");
}
public function getActionNames($version, $entity) {
// return $version == $this->version && $this->entity == $entity ? [$this->action] : [];
- throw new \API_Exception("Not support: WrappingProvider::getActionNames()");
+ throw new \CRM_Core_Exception("Not support: WrappingProvider::getActionNames()");
}
}
* Build & execute the query and return results array
*
* @return array|int
- * @throws \API_Exception
* @throws \CRM_Core_Exception
* @throws \Exception
*/
*
* @return array|null
* Returns the table and field name for adding this field to a SELECT or WHERE clause
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
* @throws \Civi\API\Exception\UnauthorizedException
*/
protected function addFkField($fkFieldName, $side) {
/**
* Orders the query by one or more fields
*
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
* @throws \Civi\API\Exception\UnauthorizedException
*/
protected function buildOrderBy() {
}
}
else {
- throw new \API_Exception("Unknown field specified for sort. Cannot order by '$item'");
+ throw new \CRM_Core_Exception("Unknown field specified for sort. Cannot order by '$item'");
}
}
}
* @param \Civi\API\Event\PrepareEvent $event
* API preparation event.
*
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public function onApiPrepare(\Civi\API\Event\PrepareEvent $event) {
$apiRequest = $event->getApiRequest();
/**
* @param \Civi\API\Event\AuthorizeEvent $event
* API authorization event.
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
* @throws \Civi\API\Exception\UnauthorizedException
*/
public function onApiAuthorize(\Civi\API\Event\AuthorizeEvent $event) {
if (/*!$isTrusted */
empty($apiRequest['params']['id']) && empty($apiRequest['params']['entity_table'])
) {
- throw new \API_Exception("Mandatory key(s) missing from params array: 'id' or 'entity_table'");
+ throw new \CRM_Core_Exception("Mandatory key(s) missing from params array: 'id' or 'entity_table'");
}
if (isset($apiRequest['params']['id'])) {
return;
}
elseif ($isValidId) {
- throw new \API_Exception("Failed to match record to related entity");
+ throw new \CRM_Core_Exception("Failed to match record to related entity");
}
elseif (!$isValidId && strtolower($apiRequest['action']) == 'get') {
// The matches will be an empty set; doesn't make a difference if we
return;
}
- throw new \API_Exception("Failed to run permission check");
+ throw new \CRM_Core_Exception("Failed to run permission check");
}
}
* @param array $apiRequest
* The full API request.
* @throws \Exception
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
* @throws \Civi\API\Exception\UnauthorizedException
*/
public function authorizeDelegate($action, $entityTable, $entityId, $apiRequest) {
$entity = $this->getDelegatedEntityName($entityTable);
if (!$entity) {
- throw new \API_Exception("Failed to run permission check: Unrecognized target entity table ($entityTable)");
+ throw new \CRM_Core_Exception("Failed to run permission check: Unrecognized target entity table ($entityTable)");
}
if (!$entityId) {
throw new \Civi\API\Exception\UnauthorizedException("Authorization failed on ($entity): Missing entity_id");
* The saved FK.
* @param array $apiRequest
* The full API request.
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public function preventReassignment($fileId, $entityTable, $entityId, $apiRequest) {
if (strtolower($apiRequest['action']) == 'create' && $fileId && !$this->isTrusted($apiRequest)) {
// TODO: no change in field_name?
if (isset($apiRequest['params']['entity_table']) && $entityTable != $apiRequest['params']['entity_table']) {
- throw new \API_Exception("Cannot modify entity_table");
+ throw new \CRM_Core_Exception("Cannot modify entity_table");
}
if (isset($apiRequest['params']['entity_id']) && $entityId != $apiRequest['params']['entity_id']) {
- throw new \API_Exception("Cannot modify entity_id");
+ throw new \CRM_Core_Exception("Cannot modify entity_id");
}
}
}
* @param \Civi\API\Event\Event $event
* API preparation event.
*
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public function onApiPrepare(\Civi\API\Event\Event $event) {
$apiRequest = $event->getApiRequest();
*
* @param \Civi\API\Event\Event $event
*
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public function onApiRespond(\Civi\API\Event\Event $event) {
$apiRequest = $event->getApiRequest();
* API result.
* @return array
* Modified API result.
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public function filter($apiRequest, $apiResult) {
if ($this->fields === '*') {
return $apiResult;
}
}
- throw new \API_Exception(sprintf('Filtering failed for %s.%s. Unrecognized result format.', $apiRequest['entity'], $apiRequest['action']));
+ throw new \CRM_Core_Exception(sprintf('Filtering failed for %s.%s. Unrecognized result format.', $apiRequest['entity'], $apiRequest['action']));
}
/**
$geocodingClassName = \CRM_Utils_GeocodeProvider::getUsableClassName();
$geocodingProvider = \CRM_Utils_GeocodeProvider::getConfiguredProvider();
if (!is_callable([$geocodingProvider, 'getCoordinates'])) {
- throw new \API_Exception('Geocoding provider does not support getCoordinates');
+ throw new \CRM_Core_Exception('Geocoding provider does not support getCoordinates');
}
$coord = $geocodingClassName::getCoordinates($this->address);
if (isset($coord['geo_code_1'], $coord['geo_code_2'])) {
$result[] = $coord;
}
elseif (!empty($coord['geo_code_error'])) {
- throw new \API_Exception('Geocoding failed. ' . $coord['geo_code_error']);
+ throw new \CRM_Core_Exception('Geocoding failed. ' . $coord['geo_code_error']);
}
}
/**
* @param $items
* @return array
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
protected function deleteObjects($items) {
foreach ($items as $item) {
if (!\CRM_Contact_BAO_Contact::deleteContact($item['id'], FALSE, !$this->useTrash, $this->checkPermissions)) {
- throw new \API_Exception("Could not delete {$this->getEntityName()} id {$item['id']}");
+ throw new \CRM_Core_Exception("Could not delete {$this->getEntityName()} id {$item['id']}");
}
$ids[] = ['id' => $item['id']];
}
if (strpos($this->dedupeRule, '.Unsupervised') || strpos($this->dedupeRule, '.Supervised')) {
[$contactType, $ruleType] = explode('.', $this->dedupeRule);
if (!empty($item['contact_type']) && $contactType !== $item['contact_type']) {
- throw new \API_Exception('Mismatched contact type.');
+ throw new \CRM_Core_Exception('Mismatched contact type.');
}
$item['contact_type'] = $contactType;
$dedupeParams['rule'] = $ruleType;
->addSelect('id', 'contact_type')
->execute()->single();
if (!empty($item['contact_type']) && $ruleGroup['contact_type'] !== $item['contact_type']) {
- throw new \API_Exception('Mismatched contact type.');
+ throw new \CRM_Core_Exception('Mismatched contact type.');
}
$item['contact_type'] = $ruleGroup['contact_type'];
$dedupeParams['rule_group_id'] = $ruleGroup['id'];
*
* @param array $entityValues
* @param array $dedupeParams
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
private function transformCustomParams(array &$entityValues, array &$dedupeParams) {
foreach ($entityValues as $name => $value) {
$isBatch = $queue instanceof \CRM_Queue_Queue_BatchQueueInterface;
$limit = $queue->getSpec('batch_limit') ?: 1;
if ($limit > 1 && !$isBatch) {
- throw new \API_Exception(sprintf('Queue "%s" (%s) does not support batching.', $queue->getName(), get_class($queue)));
+ throw new \CRM_Core_Exception(sprintf('Queue "%s" (%s) does not support batching.', $queue->getName(), get_class($queue)));
// Note 1: Simply looping over `claimItem()` is unlikley to help the consumer b/c
// drivers like Sql+Memory are linear+blocking.
// Note 2: The default is batch_limit=1. So someone has specifically chosen an invalid configuration...
protected function queue(): \CRM_Queue_Queue {
if (empty($this->queue)) {
- throw new \API_Exception('Missing required parameter: $queue');
+ throw new \CRM_Core_Exception('Missing required parameter: $queue');
}
return \Civi::queue($this->queue);
}
$queue = \Civi::queue($this->items[0]['queue']);
$ids = \CRM_Utils_Array::collect('id', $this->items);
if (count($ids) > 1 && !($queue instanceof \CRM_Queue_Queue_BatchQueueInterface)) {
- throw new \API_Exception("runItems: Error: Running multiple items requires BatchQueueInterface");
+ throw new \CRM_Core_Exception("runItems: Error: Running multiple items requires BatchQueueInterface");
}
if (count($ids) > 1) {
$items = $queue->fetchItems($ids);
: [$queue->claimItem()];
}
else {
- throw new \API_Exception("runItems: Requires either 'queue' or 'item'.");
+ throw new \CRM_Core_Exception("runItems: Requires either 'queue' or 'item'.");
}
if (empty($items)) {
$outcomes = [];
\CRM_Utils_Hook::queueRun($queue, $items, $outcomes);
if (empty($outcomes)) {
- throw new \API_Exception(sprintf('Failed to run queue items (name=%s, runner=%s, itemCount=%d, outcomeCount=%d)',
+ throw new \CRM_Core_Exception(sprintf('Failed to run queue items (name=%s, runner=%s, itemCount=%d, outcomeCount=%d)',
$queue->getName(), $queue->getSpec('runner'), count($items), count($outcomes)));
}
foreach ($items as $itemPos => $item) {
private function validateItemStubs(): void {
$queueNames = [];
if (!isset($this->items[0])) {
- throw new \API_Exception("Queue items must be given as numeric array.");
+ throw new \CRM_Core_Exception("Queue items must be given as numeric array.");
}
foreach ($this->items as $item) {
if (empty($item['queue'])) {
- throw new \API_Exception("Queue item requires property 'queue'.");
+ throw new \CRM_Core_Exception("Queue item requires property 'queue'.");
}
if (empty($item['id'])) {
- throw new \API_Exception("Queue item requires property 'id'.");
+ throw new \CRM_Core_Exception("Queue item requires property 'id'.");
}
$queueNames[$item['queue']] = 1;
}
if (count($queueNames) > 1) {
- throw new \API_Exception("Queue items cannot be mixed. Found queues: " . implode(', ', array_keys($queueNames)));
+ throw new \CRM_Core_Exception("Queue items cannot be mixed. Found queues: " . implode(', ', array_keys($queueNames)));
}
}
*
* @param int $domain
* @return array
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
protected function validateSettings($domain) {
$meta = \Civi\Core\SettingsMetadata::getMetadata([], $domain);
}, isset($this->values) ? array_keys($this->values) : $this->select);
$invalid = array_diff($names, array_keys($meta));
if ($invalid) {
- throw new \API_Exception("Unknown settings for domain $domain: " . implode(', ', $invalid));
+ throw new \CRM_Core_Exception("Unknown settings for domain $domain: " . implode(', ', $invalid));
}
if (isset($this->values)) {
foreach ($this->values as $name => $value) {
$domains = Domain::get(FALSE)->addSelect('id')->execute()->column('id');
$invalid = array_diff($this->domainId, $domains);
if ($invalid) {
- throw new \API_Exception('Invalid domain id: ' . implode(', ', $invalid));
+ throw new \CRM_Core_Exception('Invalid domain id: ' . implode(', ', $invalid));
}
}
else {
/**
* @param \Civi\Api4\Generic\Result $result
*
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
* @throws \Civi\Crypto\Exception\CryptoException
*/
public function _run(Result $result) {
if (empty($this->tag)) {
- throw new \API_Exception("Missing required argument: tag");
+ throw new \CRM_Core_Exception("Missing required argument: tag");
}
// Track log of changes in memory.
* @param string $customGroup
* @param bool $checkPermissions
* @return Action\CustomValue\Get
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public static function get($customGroup, $checkPermissions = TRUE) {
return (new Action\CustomValue\Get($customGroup, __FUNCTION__))
* @param string $customGroup
* @param bool $checkPermissions
* @return Action\CustomValue\GetFields
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public static function getFields($customGroup = NULL, $checkPermissions = TRUE) {
return (new Action\CustomValue\GetFields($customGroup, __FUNCTION__))
* @param string $customGroup
* @param bool $checkPermissions
* @return Action\CustomValue\Save
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public static function save($customGroup, $checkPermissions = TRUE) {
return (new Action\CustomValue\Save($customGroup, __FUNCTION__))
* @param string $customGroup
* @param bool $checkPermissions
* @return Action\CustomValue\Create
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public static function create($customGroup, $checkPermissions = TRUE) {
return (new Action\CustomValue\Create($customGroup, __FUNCTION__))
* @param string $customGroup
* @param bool $checkPermissions
* @return Action\CustomValue\Update
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public static function update($customGroup, $checkPermissions = TRUE) {
return (new Action\CustomValue\Update($customGroup, __FUNCTION__))
* @param string $customGroup
* @param bool $checkPermissions
* @return Action\CustomValue\Delete
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public static function delete($customGroup, $checkPermissions = TRUE) {
return (new Action\CustomValue\Delete($customGroup, __FUNCTION__))
* @param string $customGroup
* @param bool $checkPermissions
* @return Generic\BasicReplaceAction
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public static function replace($customGroup, $checkPermissions = TRUE) {
return (new Generic\BasicReplaceAction("Custom_$customGroup", __FUNCTION__))
* @param string $customGroup
* @param bool $checkPermissions
* @return Action\GetActions
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public static function getActions($customGroup = NULL, $checkPermissions = TRUE) {
return (new Action\GetActions("Custom_$customGroup", __FUNCTION__))
$value = $apiRequest->$getParam();
// Required fields
if (!empty($info['required']) && (!$value && $value !== 0 && $value !== '0')) {
- throw new \API_Exception('Parameter "' . $param . '" is required.');
+ throw new \CRM_Core_Exception('Parameter "' . $param . '" is required.');
}
if (!empty($info['type']) && !self::checkType($value, $info['type'])) {
- throw new \API_Exception('Parameter "' . $param . '" is not of the correct type. Expecting ' . implode(' or ', $info['type']) . '.');
+ throw new \CRM_Core_Exception('Parameter "' . $param . '" is not of the correct type. Expecting ' . implode(' or ', $info['type']) . '.');
}
if (!empty($info['deprecated']) && isset($value)) {
\CRM_Core_Error::deprecatedWarning('APIv4 ' . $apiRequest->getEntityName() . ".$param parameter is deprecated.");
* @param $value
* @param $types
* @return bool
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public static function checkType($value, $types) {
if ($value === NULL) {
return TRUE;
default:
- throw new \API_Exception('Unknown parameter type: ' . $type);
+ throw new \CRM_Core_Exception('Unknown parameter type: ' . $type);
}
}
return FALSE;
/**
* Convert the list of errors an exception.
*
- * @return \API_Exception
+ * @return \CRM_Core_Exception
*/
public function toException() {
// We should probably have a better way to report the errors in a structured/list format.
- return new \API_Exception(ts('Found %1 error(s) in submitted %2 record(s) of type "%3": %4', [
+ return new \CRM_Core_Exception(ts('Found %1 error(s) in submitted %2 record(s) of type "%3": %4', [
1 => count($this->errors),
2 => count(array_unique(array_column($this->errors, 'record'))),
3 => $this->getEntityName(),
*
* @param string $entityName
* @param string $actionName
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public function __construct($entityName, $actionName) {
// If a namespaced class name is passed in
* @throws \Exception
*/
public function __set($name, $value) {
- throw new \API_Exception('Unknown api parameter');
+ throw new \CRM_Core_Exception('Unknown api parameter');
}
/**
* @param int $val
* @return $this
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public function setVersion($val) {
if ($val !== 4 && $val !== '4') {
- throw new \API_Exception('Cannot modify api version');
+ throw new \CRM_Core_Exception('Cannot modify api version');
}
return $this;
}
* @param $name
* @param $arguments
* @return static|mixed
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public function __call($name, $arguments) {
$param = lcfirst(substr($name, 3));
if (!$param || $param[0] == '_') {
- throw new \API_Exception('Unknown api parameter: ' . $name);
+ throw new \CRM_Core_Exception('Unknown api parameter: ' . $name);
}
$mode = substr($name, 0, 3);
if ($this->paramExists($param)) {
return $this;
}
}
- throw new \API_Exception('Unknown api parameter: ' . $name);
+ throw new \CRM_Core_Exception('Unknown api parameter: ' . $name);
}
/**
* This is basically the outer wrapper for api v4.
*
* @return \Civi\Api4\Generic\Result
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
* @throws \Civi\API\Exception\UnauthorizedException
*/
public function execute() {
*/
public function offsetSet($offset, $value): void {
if (in_array($offset, ['entity', 'action', 'entityName', 'actionName', 'params', 'version', 'id'])) {
- throw new \API_Exception('Cannot modify api4 state via array access');
+ throw new \CRM_Core_Exception('Cannot modify api4 state via array access');
}
if ($offset == 'check_permissions') {
$this->setCheckPermissions($value);
*/
public function offsetUnset($offset): void {
if (in_array($offset, ['entity', 'action', 'entityName', 'actionName', 'params', 'check_permissions', 'version', 'id'])) {
- throw new \API_Exception('Cannot modify api4 state via array access');
+ throw new \CRM_Core_Exception('Cannot modify api4 state via array access');
}
unset($this->_arrayStorage[$offset]);
}
* This is because we DON'T want the wrapper to check permissions as this is an internal op.
* @see \Civi\Api4\Action\Contact\GetFields
*
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
* @return array
*/
public function entityFields() {
*
* @param $values
* @return array
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
protected function checkRequiredFields($values) {
$unmatched = [];
* Replaces pseudoconstants in input values
*
* @param array $record
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
protected function formatWriteValues(&$record) {
$optionFields = [];
* @param array $vars
* Variable name => value
* @return bool
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
* @throws \Exception
*/
protected function evaluateCondition($expr, $vars) {
if (strpos($expr, '}') !== FALSE || strpos($expr, '{') !== FALSE) {
- throw new \API_Exception('Illegal character in expression');
+ throw new \CRM_Core_Exception('Illegal character in expression');
}
$tpl = "{if $expr}1{else}0{/if}";
return (bool) trim(\CRM_Core_Smarty::singleton()->fetchWith('string:' . $tpl, $vars));
}
/**
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
* @throws \Civi\API\Exception\UnauthorizedException
*/
protected function validateValues() {
- // FIXME: There should be a protocol to report a full list of errors... Perhaps a subclass of API_Exception?
+ // FIXME: There should be a protocol to report a full list of errors... Perhaps a subclass of CRM_Core_Exception?
$unmatched = $this->checkRequiredFields($this->getValues());
if ($unmatched) {
- throw new \API_Exception("Mandatory values missing from Api4 {$this->getEntityName()}::{$this->getActionName()}: " . implode(", ", $unmatched), "mandatory_missing", ["fields" => $unmatched]);
+ throw new \CRM_Core_Exception("Mandatory values missing from Api4 {$this->getEntityName()}::{$this->getActionName()}: " . implode(", ", $unmatched), "mandatory_missing", ["fields" => $unmatched]);
}
if ($this->checkPermissions && !CoreUtil::checkAccessRecord($this, $this->getValues(), \CRM_Core_Session::getLoggedInContactID() ?: 0)) {
* Note: it will skip adding field defaults when fetching records by id,
* or if that field has already been added to the where clause.
*
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
protected function setDefaultWhereClause() {
if (!$this->_itemsToGet('id')) {
* @param string $op
* @param mixed $value
* @return $this
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public function addWhere(string $fieldName, string $op, $value = NULL) {
if (!in_array($op, CoreUtil::getOperators())) {
- throw new \API_Exception('Unsupported operator');
+ throw new \CRM_Core_Exception('Unsupported operator');
}
$this->where[] = [$fieldName, $op, $value];
return $this;
* Either a nested array of arguments, or a variable number of arguments passed to this function.
*
* @return $this
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public function addClause(string $operator, $condition1) {
if (!is_array($condition1[0])) {
protected $reload = FALSE;
/**
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
* @throws \Civi\API\Exception\UnauthorizedException
*/
protected function validateValues() {
$idField = CoreUtil::getIdFieldName($this->getEntityName());
- // FIXME: There should be a protocol to report a full list of errors... Perhaps a subclass of API_Exception?
+ // FIXME: There should be a protocol to report a full list of errors... Perhaps a subclass of CRM_Core_Exception?
$unmatched = [];
foreach ($this->records as $record) {
if (empty($record[$idField])) {
}
}
if ($unmatched) {
- throw new \API_Exception("Mandatory values missing from Api4 {$this->getEntityName()}::{$this->getActionName()}: " . implode(", ", $unmatched), "mandatory_missing", ["fields" => $unmatched]);
+ throw new \CRM_Core_Exception("Mandatory values missing from Api4 {$this->getEntityName()}::{$this->getActionName()}: " . implode(", ", $unmatched), "mandatory_missing", ["fields" => $unmatched]);
}
if ($this->checkPermissions) {
// Require WHERE if we didn't get primary keys from values
if (!$this->where) {
- throw new \API_Exception('Parameter "where" is required unless primary keys are supplied in values.');
+ throw new \CRM_Core_Exception('Parameter "where" is required unless primary keys are supplied in values.');
}
// Update a single record by primary key (if this entity has a single primary key)
}
/**
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
protected function validateValues() {
- // FIXME: There should be a protocol to report a full list of errors... Perhaps a subclass of API_Exception?
+ // FIXME: There should be a protocol to report a full list of errors... Perhaps a subclass of CRM_Core_Exception?
$e = new ValidateValuesEvent($this, [$this->values], new \CRM_Utils_LazyArray(function () {
$existing = $this->getBatchAction()->setSelect(['*'])->execute();
$result = [];
* Evaluate :pseudoconstant suffix expressions and replace raw values with option values
*
* @param $records
- * @throws \API_Exception
* @throws \CRM_Core_Exception
*/
protected function formatRawValues(&$records) {
/**
* @param array $items
* @return array
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
protected function updateRecords(array $items): array {
return array_map([$this, 'writeRecord'], $items);
}
/**
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
protected function validateValues() {
$idField = CoreUtil::getIdFieldName($this->getEntityName());
if (!empty($this->values[$idField])) {
- throw new \API_Exception("Cannot pass $idField to Create action. Use Update action instead.");
+ throw new \CRM_Core_Exception("Cannot pass $idField to Create action. Use Update action instead.");
}
parent::validateValues();
}
public function _run(Result $result) {
$defaults = $this->getParamDefaults();
if ($defaults['where'] && $this->where === $defaults['where']) {
- throw new \API_Exception('Cannot delete ' . $this->getEntityName() . ' with no "where" parameter specified');
+ throw new \CRM_Core_Exception('Cannot delete ' . $this->getEntityName() . ' with no "where" parameter specified');
}
$items = $this->getBatchRecords();
/**
* @param $items
* @return array
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
protected function deleteObjects($items) {
$idField = CoreUtil::getIdFieldName($this->getEntityName());
$result[] = [$idField => $item[$idField]];
}
else {
- throw new \API_Exception("Could not delete {$this->getEntityName()} $idField {$item[$idField]}");
+ throw new \CRM_Core_Exception("Could not delete {$this->getEntityName()} $idField {$item[$idField]}");
}
}
}
protected $translationMode;
/**
- * @throws \API_Exception
* @throws \CRM_Core_Exception
*/
public function _run(Result $result) {
$baoName = $this->getBaoName();
if (!$baoName) {
// In some cases (eg. site spin-up) the code may attempt to call the api before the entity name is registered.
- throw new \API_Exception("BAO for {$this->getEntityName()} is not available. This could be a load-order issue");
+ throw new \CRM_Core_Exception("BAO for {$this->getEntityName()} is not available. This could be a load-order issue");
}
if (!$baoName::tableHasBeenAdded()) {
\Civi::log()->warning("Could not read from {$this->getEntityName()} before table has been added. Upgrade required.", ['civi.tag' => 'upgrade_needed']);
* @param mixed $value
* @param bool $isExpression
* @return $this
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public function addWhere(string $fieldName, string $op, $value = NULL, bool $isExpression = FALSE) {
if (!in_array($op, CoreUtil::getOperators())) {
- throw new \API_Exception('Unsupported operator');
+ throw new \CRM_Core_Exception('Unsupported operator');
}
$this->where[] = [$fieldName, $op, $value, $isExpression];
return $this;
* @param string $op
* @param mixed $value
* @return $this
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public function addHaving(string $expr, string $op, $value = NULL) {
if (!in_array($op, CoreUtil::getOperators())) {
- throw new \API_Exception('Unsupported operator');
+ throw new \CRM_Core_Exception('Unsupported operator');
}
$this->having[] = [$expr, $op, $value];
return $this;
* @param string $fieldName
* @param array $fields
* @return array|null
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
private function getFkFieldSpec($fieldName, $fields) {
$fieldPath = explode('.', $fieldName);
*
* Normally this would involve calling getFields... but this IS getFields.
*
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
private function formatValues() {
foreach (array_keys($this->values) as $key) {
/**
* @param array $items
* @return array
- * @throws \API_Exception
* @throws \CRM_Core_Exception
*/
protected function updateRecords(array $items): array {
*/
private function exportRecord(string $entityType, int $entityId, Result $result, $parentName = NULL, $excludeFields = []) {
if (isset($this->exportedEntities[$entityType][$entityId])) {
- throw new \API_Exception("Circular reference detected: attempted to export $entityType id $entityId multiple times.");
+ throw new \CRM_Core_Exception("Circular reference detected: attempted to export $entityType id $entityId multiple times.");
}
$this->exportedEntities[$entityType][$entityId] = TRUE;
$select = $pseudofields = [];
* If there are too many or too few results, then throw an exception.
*
* @return array
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public function single() {
return \CRM_Utils_Array::single($this, "{$this->entity} record");
*
* @param string $key
* @return $this
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public function indexBy($key) {
$this->indexedBy = $key;
}
}
if (!$newResults) {
- throw new \API_Exception("Key $key not found in api results");
+ throw new \CRM_Core_Exception("Key $key not found in api results");
}
$this->exchangeArray($newResults);
}
*/
public function countMatched() :int {
if (!isset($this->matchedCount)) {
- throw new \API_Exception("countMatched can only be used if there was no limit set or if row_count was included in the select fields.");
+ throw new \CRM_Core_Exception("countMatched can only be used if there was no limit set or if row_count was included in the select fields.");
}
return $this->matchedCount;
}
*
* @return array
* The records after being written to the DB (e.g. including newly assigned "id").
- * @throws \API_Exception
* @throws \CRM_Core_Exception
*/
protected function writeObjects($items) {
foreach ($this->write($items) as $index => $dao) {
if (!$dao) {
$errMessage = sprintf('%s write operation failed', $this->getEntityName());
- throw new \API_Exception($errMessage);
+ throw new \CRM_Core_Exception($errMessage);
}
$result[] = $this->baoToArray($dao, $items[$index]);
}
* @param array $params
* @param int $entityId
*
- * @throws \API_Exception
* @throws \CRM_Core_Exception
*/
protected function formatCustomParams(&$params, $entityId) {
require_once 'api/v3/utils.php';
$value = \_civicrm_api3_resolve_contactID($value);
if ('unknown-user' === $value) {
- throw new \API_Exception("\"{$field['name']}\" \"{$value}\" cannot be resolved to a contact ID", 2002, ['error_field' => $field['name'], "type" => "integer"]);
+ throw new \CRM_Core_Exception("\"{$field['name']}\" \"{$value}\" cannot be resolved to a contact ID", 2002, ['error_field' => $field['name'], "type" => "integer"]);
}
}
return $item;
}
else {
- throw new \API_Exception('Cannot revert ' . $action->getEntityName() . ' with id ' . $item['id']);
+ throw new \CRM_Core_Exception('Cannot revert ' . $action->getEntityName() . ' with id ' . $item['id']);
}
}))->setCheckPermissions($checkPermissions);
}
/**
* If SavedSearch is supplied as a string, this will load it as an array
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
* @throws \Civi\API\Exception\UnauthorizedException
*/
protected function loadSavedSearch() {
* It ignores those containing special characters like dots or parentheses,
* they are handled separately in Api4SelectQuery.
*
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
protected function expandSelectClauseWildcards() {
if (!$this->select) {
* @param $request
* @param $row
* @return array|\Civi\Api4\Generic\Result|null
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
protected function runChain($request, $row) {
[$entity, $action, $params, $index] = $request;
* Builds main final sql statement after initialization.
*
* @return string
- * @throws \API_Exception
* @throws \CRM_Core_Exception
*/
public function getSql() {
/**
* @return int
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public function getCount() {
$this->buildWhereClause();
/**
* @param array $select
* Array of select expressions; defaults to $this->getSelect
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
protected function buildSelectClause($select = NULL) {
// Use default if select not provided, exclude row_count which is handled elsewhere
if ($valid) {
$alias = $expr->getAlias();
if ($alias != $expr->getExpr() && isset($this->apiFieldSpec[$alias])) {
- throw new \API_Exception('Cannot use existing field name as alias');
+ throw new \CRM_Core_Exception('Cannot use existing field name as alias');
}
$this->selectAliases[$alias] = $expr->getExpr();
$this->query->select($expr->render($this) . " AS `$alias`");
protected function buildOrderBy() {
foreach ($this->getOrderBy() as $item => $dir) {
if ($dir !== 'ASC' && $dir !== 'DESC') {
- throw new \API_Exception("Invalid sort direction. Cannot order by $item $dir");
+ throw new \CRM_Core_Exception("Invalid sort direction. Cannot order by $item $dir");
}
try {
}
}
// If the expression could not be rendered, it might be a field alias
- catch (\API_Exception $e) {
+ catch (\CRM_Core_Exception $e) {
// Silently ignore fields the user lacks permission to see
if (is_a($e, 'Civi\API\Exception\UnauthorizedException')) {
$this->debug('unauthorized_fields', $item);
$column = '`' . $item . '`';
}
else {
- throw new \API_Exception("Invalid field '{$item}'");
+ throw new \CRM_Core_Exception("Invalid field '{$item}'");
}
}
* @param int $depth
* @return string SQL where clause
*
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
* @uses composeClause() to generate the SQL etc.
*/
protected function treeWalkClauses($clause, $type, $depth = 0) {
* WHERE|HAVING|ON
* @param int $depth
* @return string SQL
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
* @throws \Exception
*/
public function composeClause(array $clause, string $type, int $depth) {
[$expr, $operator, $value] = array_pad($clause, 3, NULL);
$isExpression = $clause[3] ?? FALSE;
if (!in_array($operator, CoreUtil::getOperators(), TRUE)) {
- throw new \API_Exception('Illegal operator');
+ throw new \CRM_Core_Exception('Illegal operator');
}
// For WHERE clause, expr must be the name of a field.
throw new UnauthorizedException("Unauthorized field '$expr'");
}
else {
- throw new \API_Exception("Invalid expression in HAVING clause: '$expr'. Must use a value from SELECT clause.");
+ throw new \CRM_Core_Exception("Invalid expression in HAVING clause: '$expr'. Must use a value from SELECT clause.");
}
}
$fieldAlias = '`' . $fieldAlias . '`';
$sqlClause = $this->createSQLClause($fieldAlias, $operator, $value, $field, $depth);
if ($sqlClause === NULL) {
- throw new \API_Exception("Invalid value in $type clause for '$expr'");
+ throw new \CRM_Core_Exception("Invalid value in $type clause for '$expr'");
}
return $sqlClause;
}
*/
protected function createSQLClause($fieldAlias, $operator, $value, $field, int $depth) {
if (!empty($field['operators']) && !in_array($operator, $field['operators'], TRUE)) {
- throw new \API_Exception('Illegal operator for ' . $field['name']);
+ throw new \CRM_Core_Exception('Illegal operator for ' . $field['name']);
}
// Some fields use a callback to generate their sql
if (!empty($field['sql_filters'])) {
* @param string $expr
* @param array $allowedTypes
* @return SqlExpression
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
protected function getExpression(string $expr, $allowedTypes = NULL) {
$sqlExpr = SqlExpression::convert($expr, FALSE, $allowedTypes);
* In strict mode, this will throw an exception if the field doesn't exist
*
* @return array|null
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public function getField($expr, $strict = FALSE) {
// If the expression contains a pseudoconstant filter like activity_type_id:label,
$this->debug($field === FALSE ? 'unauthorized_fields' : 'undefined_fields', $fieldName);
}
if ($strict && $field === NULL) {
- throw new \API_Exception("Invalid field '$fieldName'");
+ throw new \CRM_Core_Exception("Invalid field '$fieldName'");
}
if ($strict && $field === FALSE) {
throw new UnauthorizedException("Unauthorized field '$fieldName'");
/**
* Join onto other entities as specified by the api call.
*
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
* @throws \Civi\API\Exception\NotImplementedException
*/
private function addExplicitJoins() {
// Ensure alias is a safe string, and supply default if not given
$alias = $alias ?: strtolower($entity);
if ($alias === self::MAIN_TABLE_ALIAS || !preg_match('/^[-\w]{1,256}$/', $alias)) {
- throw new \API_Exception('Illegal join alias: "' . $alias . '"');
+ throw new \CRM_Core_Exception('Illegal join alias: "' . $alias . '"');
}
// First item in the array is a boolean indicating if the join is required (aka INNER or LEFT).
// The rest are join conditions.
$side = $side ? 'INNER' : 'LEFT';
}
if (!in_array($side, ['INNER', 'LEFT', 'EXCLUDE'])) {
- throw new \API_Exception("Illegal value for join side: '$side'.");
+ throw new \CRM_Core_Exception("Illegal value for join side: '$side'.");
}
if ($side === 'EXCLUDE') {
$side = 'LEFT';
* @param string $joinEntity
* @param string $alias
* @param string $side
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
protected function addBridgeJoin($joinTree, $joinEntity, $alias, $side) {
$bridgeEntity = array_shift($joinTree);
* @param string $bridgeEntity
* @param string $joinEntity
* @return array
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
private function getBridgeRefs(string $bridgeEntity, string $joinEntity): array {
$bridges = CoreUtil::getInfoItem($bridgeEntity, 'bridge') ?? [];
}
}
}
- throw new \API_Exception("Unable to join $bridgeEntity to $joinEntity");
+ throw new \CRM_Core_Exception("Unable to join $bridgeEntity to $joinEntity");
}
/**
* @param string $bridgeEntity
* @param string $side
* @return string[]
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
private function getBridgeJoinConditions(array &$joinTree, $baseRef, string $alias, string $bridgeAlias, string $bridgeEntity, string $side): array {
$bridgeConditions = [];
// If no bridge conditions were specified, link it to the base entity
if (!$bridgeConditions) {
if (!in_array($this->getEntity(), $baseRef->getTargetEntities())) {
- throw new \API_Exception("Unable to join $bridgeEntity to " . $this->getEntity());
+ throw new \CRM_Core_Exception("Unable to join $bridgeEntity to " . $this->getEntity());
}
$bridgeConditions[] = "`$bridgeAlias`.`{$baseRef->getReferenceKey()}` = a.`{$baseRef->getTargetKey()}`";
if ($baseRef->getTypeColumn()) {
try {
$joinPath = $joiner->getPath($explicitJoin['table'] ?? $this->getFrom(), $pathArray);
}
- catch (\API_Exception $e) {
+ catch (\CRM_Core_Exception $e) {
if (!empty($explicitJoin['bridge'])) {
// Try looking up custom field in bridge entity instead
try {
$useBridgeTable = TRUE;
$joinPath = $joiner->getPath(CoreUtil::getTableName($explicitJoin['bridge']), $pathArray);
}
- catch (\API_Exception $e) {
+ catch (\CRM_Core_Exception $e) {
return;
}
}
* @param bool $parseAlias
* @param array $mustBe
* @return SqlExpression
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public static function convert(string $expression, $parseAlias = FALSE, $mustBe = []) {
$as = $parseAlias ? strrpos($expression, ' AS ') : FALSE;
elseif ($bracketPos && $lastChar === ')') {
$fnName = substr($expr, 0, $bracketPos);
if ($fnName !== strtoupper($fnName)) {
- throw new \API_Exception('Sql function must be uppercase.');
+ throw new \CRM_Core_Exception('Sql function must be uppercase.');
}
$className = 'SqlFunction' . $fnName;
}
}
$className = __NAMESPACE__ . '\\' . $className;
if (!class_exists($className)) {
- throw new \API_Exception('Unable to parse sql expression: ' . $expression);
+ throw new \CRM_Core_Exception('Unable to parse sql expression: ' . $expression);
}
$sqlExpression = new $className($expr, $alias);
if ($mustBe) {
return $sqlExpression;
}
}
- throw new \API_Exception('Illegal sql expression.');
+ throw new \CRM_Core_Exception('Illegal sql expression.');
}
return $sqlExpression;
}
* @param array $mustBe
* @param int $max
* @return SqlExpression[]
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
protected function captureExpressions(string &$arg, array $mustBe, int $max) {
$captured = [];
protected function initialize() {
if ($this->alias && $this->alias !== $this->expr) {
- throw new \API_Exception("Aliasing field names is not allowed, only expressions can have an alias.");
+ throw new \CRM_Core_Exception("Aliasing field names is not allowed, only expressions can have an alias.");
}
$this->fields[] = $this->expr;
}
continue;
}
if (!$prefix && !$param['optional']) {
- throw new \API_Exception("Missing param $name for SQL function " . static::getName());
+ throw new \CRM_Core_Exception("Missing param $name for SQL function " . static::getName());
}
}
elseif ($param['flag_before']) {
count($exprs) < $param['min_expr'] &&
!(!$exprs && $param['optional'])
) {
- throw new \API_Exception("Too few arguments to param $name for SQL function " . static::getName());
+ throw new \CRM_Core_Exception("Too few arguments to param $name for SQL function " . static::getName());
}
$this->args[$idx]['expr'] = $exprs;
}
}
if (trim($arg)) {
- throw new \API_Exception("Too many arguments given for SQL function " . static::getName());
+ throw new \CRM_Core_Exception("Too many arguments given for SQL function " . static::getName());
}
}
*
* @param $extends
* @return string
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
* @throws \Civi\API\Exception\UnauthorizedException
*/
public static function getEntityFromExtends($extends) {
* @param array $joinPath
*
* @return \Civi\Api4\Service\Schema\Joinable\Joinable[]
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public function getPath(string $baseTable, array $joinPath) {
$cacheKey = sprintf('%s.%s', $baseTable, implode('.', $joinPath));
$link = $this->schemaMap->getLink($baseTable, $targetAlias);
if (!$link) {
- throw new \API_Exception(sprintf('Cannot join %s to %s', $baseTable, $targetAlias));
+ throw new \CRM_Core_Exception(sprintf('Cannot join %s to %s', $baseTable, $targetAlias));
}
else {
$fullPath[$targetAlias] = $link;
*
* @return \Civi\Api4\Service\Schema\Joinable\Joinable|NULL
* Link to the target table
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public function getLink($baseTableName, $targetTableAlias): ?Joinable\Joinable {
$table = $this->getTableByName($baseTableName);
if (!$table) {
- throw new \API_Exception("Table $baseTableName not found");
+ throw new \CRM_Core_Exception("Table $baseTableName not found");
}
foreach ($table->getTableLinks() as $link) {
*
* @param string $entity
* @param \Civi\Api4\Service\Spec\RequestSpec $spec
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
* @see \CRM_Core_SelectValues::customGroupExtends
*/
private function addCustomFields($entity, RequestSpec $spec) {
* @param string $entityName
*
* @return array
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
private function getDAOFields(string $entityName): array {
$bao = CoreUtil::getBAOFromApiName($entityName);
if (!$bao) {
- throw new \API_Exception('Entity not loaded: ' . $entityName);
+ throw new \CRM_Core_Exception('Entity not loaded: ' . $entityName);
}
return $bao::getSupportedFields();
}
* @param int|string $userID
* Contact ID of the user we are testing,. 0 for the anonymous user.
* @return bool
- * @throws \API_Exception
* @throws \CRM_Core_Exception
* @throws \Civi\API\Exception\NotImplementedException
* @throws \Civi\API\Exception\UnauthorizedException
* Contact ID of the user we are testing, or 0 for the anonymous user.
*
* @return bool
- * @throws \API_Exception
* @throws \CRM_Core_Exception
*/
public static function checkAccessDelegated(string $entityName, string $actionName, array $record, int $userID) {
*
* @param array $params
* @param array $fields
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public static function formatWriteParams(&$params, $fields) {
foreach ($fields as $name => $field) {
* @param array $fieldSpec
* @param string|null $operator (only for 'get' actions)
* @param null $index (for recursive loops)
- * @throws \API_Exception
* @throws \CRM_Core_Exception
*/
public static function formatInputValue(&$value, ?string $fieldName, array $fieldSpec, &$operator = NULL, $index = NULL) {
if ($fk === 'Contact' && !is_numeric($value)) {
$value = \_civicrm_api3_resolve_contactID($value);
if ('unknown-user' === $value) {
- throw new \API_Exception("\"{$fieldSpec['name']}\" \"{$value}\" cannot be resolved to a contact ID", 2002, ['error_field' => $fieldSpec['name'], "type" => "integer"]);
+ throw new \CRM_Core_Exception("\"{$fieldSpec['name']}\" \"{$value}\" cannot be resolved to a contact ID", 2002, ['error_field' => $fieldSpec['name'], "type" => "integer"]);
}
}
return date($format, strtotime($value ?? ''));
}
if (isset($index) && !strstr($operator, 'BETWEEN')) {
- throw new \API_Exception("Relative dates cannot be in an array using the $operator operator.");
+ throw new \CRM_Core_Exception("Relative dates cannot be in an array using the $operator operator.");
}
[$dateFrom, $dateTo] = \CRM_Utils_Date::getFromTo($value);
switch ($operator) {
return self::formatDateValue($format, $index ? $dateTo : $dateFrom);
default:
- throw new \API_Exception("Relative dates cannot be used with the $operator operator.");
+ throw new \CRM_Core_Exception("Relative dates cannot be used with the $operator operator.");
}
}
* @param array $fields
* @param string $action
* @param array $selectAliases
- * @throws \API_Exception
* @throws \CRM_Core_Exception
*/
public static function formatOutputValues(&$results, $fields, $action = 'get', $selectAliases = []) {
* Other values for this object
* @param string $action
* @return array
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public static function getPseudoconstantList(array $field, string $fieldAlias, $params = [], $action = 'get') {
[$fieldPath, $valueType] = explode(':', $fieldAlias);
// For create actions, only unique identifiers can be used.
// For get actions any valid suffix is ok.
if (($action === 'create' && !$context) || !in_array($valueType, self::$pseudoConstantSuffixes, TRUE)) {
- throw new \API_Exception('Illegal expression');
+ throw new \CRM_Core_Exception('Illegal expression');
}
$baoName = $context ? CoreUtil::getBAOFromApiName($field['entity']) : NULL;
// Use BAO::buildOptions if possible
if (is_array($options)) {
return $options;
}
- throw new \API_Exception("No option list found for '{$field['name']}'");
+ throw new \CRM_Core_Exception("No option list found for '{$field['name']}'");
}
/**
*
* @param \Civi\CCase\Event\CaseChangeEvent $event
*
- * @throws \CiviCRM_API3_Exception
+ * @throws \CRM_Core_Exception
* @return void
*/
public function onCaseChange(\Civi\CCase\Event\CaseChangeEvent $event) {
*
* @return \CRM_Core_Payment
*
- * @throws \CiviCRM_API3_Exception|\CRM_Core_Exception
+ * @throws \CRM_Core_Exception
*/
public function getById($id) {
if (isset($this->cache[$id])) {
* @param bool $is_test
*
* @return \CRM_Core_Payment|NULL
- * @throws \CiviCRM_API3_Exception
+ * @throws \CRM_Core_Exception
*/
public function getByName($name, $is_test) {
$processor = civicrm_api3('payment_processor', 'getsingle', ['name' => $name, 'is_test' => $is_test]);
* @param string $className
*
* @return \Civi\Payment\CRM_Core_Payment|NULL
- * @throws \CiviCRM_API3_Exception
+ * @throws \CRM_Core_Exception
*/
public function getByClass($className) {
return $this->getByProcessor([
try {
$result = $this->civicrm_api($entity, $action, $params);
}
- catch (\API_Exception $e) {
+ catch (\CRM_Core_Exception $e) {
// api v4 call failed and threw an exception.
return [];
}
* @param $v3Action
* @param array $v3Params
* @return array|int
- * @throws \API_Exception
- * @throws \CiviCRM_API3_Exception
+ * @throws \CRM_Core_Exception
* @throws \Exception
*/
public function runApi4Legacy($v3Entity, $v3Action, $v3Params = []) {
* @param array $result
* @param bool $sequential
* @return array
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
protected function runApi4LegacyChain($key, $params, $mainEntity, $result, $sequential) {
// Handle an array of multiple calls using recursion
/**
* @return \Civi\Api4\Generic\AbstractGetAction
- * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
protected function findExamples(): \Civi\Api4\Generic\AbstractGetAction {
return \Civi\Api4\ExampleData::get(0)