AfformScanner - Simplify cache. Fix CLI/web sync bug.
authorTim Otten <totten@civicrm.org>
Fri, 20 Dec 2019 07:41:10 +0000 (23:41 -0800)
committerCiviCRM <info@civicrm.org>
Wed, 16 Sep 2020 02:13:20 +0000 (19:13 -0700)
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

index bce6323a63d3c5966604fe185a112a687f9299aa..a6bce85418b236c134b9a8ae391222d0b89efbc2 100644 (file)
@@ -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([]);