From: Tim Otten Date: Thu, 16 Jul 2020 09:33:07 +0000 (-0700) Subject: EventCart - Resolve BAO identity and uncommitted DAO changes X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=915274c81b977d7f50e721edbd612ffd75b78490;p=civicrm-core.git EventCart - Resolve BAO identity and uncommitted DAO changes Overview -------- This fixes a recent issue in which `setup.sh` is producing local-only changes to the `Cart` and `EventInCart` DAO files. To reduce ambiguity, I'm rephrasing the normal "Before/After" and giving a 3-step evolution/history. Evolution --------- (1) Traditionally, the `Cart`/`EventInCart` entities have both BAO+DAO in main source-tree. (2) With #17743 (685bf3d218a9dad7e90d24aec165c63df12c1f67), the BAO moved away. But then we get some detritus in the code-tree whenever you run `setup.sh`. (3) With this patch, we don't get the detritus anymore. Technical Details ----------------- When I ran `setup.sh -g`, it produced local modifications like this: ``` diff --git a/CRM/Event/Cart/DAO/Cart.php b/CRM/Event/Cart/DAO/Cart.php index 4683add13d..3a7f721dc1 100644 --- a/CRM/Event/Cart/DAO/Cart.php +++ b/CRM/Event/Cart/DAO/Cart.php @@ -94,7 +94,7 @@ class CRM_Event_Cart_DAO_Cart extends CRM_Core_DAO { 'where' => 'civicrm_event_carts.id', 'table_name' => 'civicrm_event_carts', 'entity' => 'Cart', - 'bao' => 'CRM_Event_Cart_BAO_Cart', + 'bao' => 'CRM_Event_Cart_DAO_Cart', 'localizable' => 0, 'add' => '4.1', ], ``` (Let's ignore the cyclic dependency in this design - that's a messier/pre-existing problem.) That metadata is inaccurate. The `bao` should point to the BAO, sinec the BAO does exist. It's inaccurate because the BAO exists in a different location. This patch allows you override the file-existence check -- saying, "this entity will use BAO's even though they're not in the file-location you might normally expect." --- diff --git a/CRM/Core/CodeGen/Specification.php b/CRM/Core/CodeGen/Specification.php index 67d057f096..0f4678d74a 100644 --- a/CRM/Core/CodeGen/Specification.php +++ b/CRM/Core/CodeGen/Specification.php @@ -192,6 +192,7 @@ class CRM_Core_CodeGen_Specification { $sourceFile = "xml/schema/{$base}/{$klass}.xml"; $daoPath = "{$base}/DAO/"; $baoPath = __DIR__ . '/../../../' . str_replace(' ', '', "{$base}/BAO/"); + $useBao = $this->value('useBao', $tableXML, file_exists($baoPath . $klass . '.php')); $pre = str_replace('/', '_', $daoPath); $this->classNames[$name] = $pre . $klass; @@ -213,7 +214,7 @@ class CRM_Core_CodeGen_Specification { 'icon' => $tableXML->icon ?? NULL, 'labelName' => substr($name, 8), 'className' => $this->classNames[$name], - 'bao' => (file_exists($baoPath . $klass . '.php') ? str_replace('DAO', 'BAO', $this->classNames[$name]) : $this->classNames[$name]), + 'bao' => ($useBao ? str_replace('DAO', 'BAO', $this->classNames[$name]) : $this->classNames[$name]), 'entity' => $klass, 'attributes_simple' => trim($database['tableAttributes_simple']), 'attributes_modern' => trim($database['tableAttributes_modern']), diff --git a/xml/schema/Event/Cart/Cart.xml b/xml/schema/Event/Cart/Cart.xml index 35a96bfb3a..48c4ae3fd2 100644 --- a/xml/schema/Event/Cart/Cart.xml +++ b/xml/schema/Event/Cart/Cart.xml @@ -3,6 +3,7 @@ CRM/Event/CartCart + 1civicrm_event_carts id diff --git a/xml/schema/Event/Cart/EventInCart.xml b/xml/schema/Event/Cart/EventInCart.xml index 6fd487202d..f8ac8d506b 100644 --- a/xml/schema/Event/Cart/EventInCart.xml +++ b/xml/schema/Event/Cart/EventInCart.xml @@ -3,6 +3,7 @@
CRM/Event/CartEventInCart + 1civicrm_events_in_carts id