From: Coleman Watts Date: Wed, 12 Aug 2020 20:50:32 +0000 (-0400) Subject: Log warning when attempting to access nonexistant table from api X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=3519db92fd779ef6563deb31483b8bd9294b06af;p=civicrm-core.git Log warning when attempting to access nonexistant table from api --- diff --git a/Civi/Api4/Generic/DAOGetAction.php b/Civi/Api4/Generic/DAOGetAction.php index cbdec8841e..d6a3f10eea 100644 --- a/Civi/Api4/Generic/DAOGetAction.php +++ b/Civi/Api4/Generic/DAOGetAction.php @@ -88,6 +88,7 @@ class DAOGetAction extends AbstractGetAction { // Early return if table doesn't exist yet due to pending upgrade $baoName = $this->getBaoName(); if (!$baoName::tableHasBeenAdded()) { + \Civi::log()->warning("Could not read from {$this->getEntityName()} before table has been added. Upgrade required.", ['civi.tag' => 'upgrade_needed']); return; } diff --git a/api/v3/utils.php b/api/v3/utils.php index 50268a400c..799dc78031 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -1221,7 +1221,7 @@ function formatCheckBoxField(&$checkboxFieldValue, $customFieldLabel, $entity) { /** * 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. @@ -1240,20 +1240,27 @@ function _civicrm_api3_basic_get($bao_name, $params, $returnAsSuccess = TRUE, $e $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');