From d676549aea2519b3092100737bb924438823ef10 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 19 Dec 2019 23:41:10 -0800 Subject: [PATCH] AfformScanner - Simplify cache. Fix CLI/web sync bug. Example bug: 1. Find a packaged (non-overriden) form - e.g. `mockPage` 2. Run `cv api4 Afform.update +w name=mockPage +v permissions='*always allow*' 3. Run `curl http://localhost/civicrm/mock-page` 4. Observe: the page-load fails even though the permissions say it should work The call to `Afform.update` should trigger a cache-clear, but it only fixes on the CLI... because the CLI and web have different runtime IDs. The runtime-id was included preventively in anticipation that oddball multisite arrangements might need to store these things separately. But I think it's overdone, because the runtime-ID factors in things like `SCRIPT_FILENAME` which has no bearing on the whether to use the same cache. Let's KISS and *if* there's any kind of multisite issue, then we can revisit. --- ext/afform/core/CRM/Afform/AfformScanner.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ext/afform/core/CRM/Afform/AfformScanner.php b/ext/afform/core/CRM/Afform/AfformScanner.php index bce6323a63..a6bce85418 100644 --- a/ext/afform/core/CRM/Afform/AfformScanner.php +++ b/ext/afform/core/CRM/Afform/AfformScanner.php @@ -29,7 +29,10 @@ class CRM_Afform_AfformScanner { public function __construct() { // TODO Manage this is a service, and inject the cache service. $this->cache = new CRM_Utils_Cache_SqlGroup([ - 'group' => md5('afform_' . CRM_Core_Config_Runtime::getId() . $this->getSiteLocalPath()), + // Note: If there are edge-case bugs with multisite, consider changing + // the group key - but tread carefully to ensure that (eg) CLI+web workers + // see the same cache. + 'group' => 'afform_scanner', 'prefetch' => FALSE, ]); // $this->cache = new CRM_Utils_Cache_Arraycache([]); -- 2.25.1