From 44a3178fc58fcb7a20adcea042f411b3bba8e0f0 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 23 Jun 2021 17:31:40 +1200 Subject: [PATCH] Throw exception when baoName is not found It the BAO name is not found at this point we currently get a fatal error. This makes it more recoverable. The specific case I'm hitting at the moment relates to monolog - the caching of the symfony container means it persists between builds and is accessed before the extension is installed. However the entity is not yet registered. Historically I have hit this fatal in other scenarios but I can't recall the details. --- Civi/Api4/Generic/DAOGetAction.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Civi/Api4/Generic/DAOGetAction.php b/Civi/Api4/Generic/DAOGetAction.php index 07cefdf0c8..f374047486 100644 --- a/Civi/Api4/Generic/DAOGetAction.php +++ b/Civi/Api4/Generic/DAOGetAction.php @@ -78,9 +78,17 @@ class DAOGetAction extends AbstractGetAction { */ protected $having = []; + /** + * @throws \API_Exception + * @throws \CRM_Core_Exception + */ public function _run(Result $result) { // Early return if table doesn't exist yet due to pending upgrade $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"); + } if (!$baoName::tableHasBeenAdded()) { \Civi::log()->warning("Could not read from {$this->getEntityName()} before table has been added. Upgrade required.", ['civi.tag' => 'upgrade_needed']); return; -- 2.25.1