/**
* Function to do a 'standard' api get - when the api is only doing a $bao->find then use this.
*
- * @param string $bao_name
+ * @param string|CRM_Core_DAO $bao_name
* Name of BAO.
* @param array $params
* Params from api.
$entity = $entity ?: CRM_Core_DAO_AllCoreTables::getBriefName($bao_name);
$options = _civicrm_api3_get_options_from_params($params);
- $query = new \Civi\API\Api3SelectQuery($entity, CRM_Utils_Array::value('check_permissions', $params, FALSE));
- $query->where = $params;
- if ($options['is_count']) {
- $query->select = ['count_rows'];
+ // Skip query if table doesn't exist yet due to pending upgrade
+ if (!$bao_name::tableHasBeenAdded()) {
+ \Civi::log()->warning("Could not read from {$entity} before table has been added. Upgrade required.", ['civi.tag' => 'upgrade_needed']);
+ $result = [];
}
else {
- $query->select = array_keys(array_filter($options['return']));
- $query->orderBy = $options['sort'];
- $query->isFillUniqueFields = $uniqueFields;
- }
- $query->limit = $options['limit'];
- $query->offset = $options['offset'];
- $query->merge($sql);
- $result = $query->run();
+ $query = new \Civi\API\Api3SelectQuery($entity, $params['check_permissions'] ?? FALSE);
+ $query->where = $params;
+ if ($options['is_count']) {
+ $query->select = ['count_rows'];
+ }
+ else {
+ $query->select = array_keys(array_filter($options['return']));
+ $query->orderBy = $options['sort'];
+ $query->isFillUniqueFields = $uniqueFields;
+ }
+ $query->limit = $options['limit'];
+ $query->offset = $options['offset'];
+ $query->merge($sql);
+ $result = $query->run();
+ }
if ($returnAsSuccess) {
return civicrm_api3_create_success($result, $params, $entity, 'get');