From 76b9562afb08d2484696b12bc8af15c9b8c7f354 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 17 Sep 2020 19:14:06 -0700 Subject: [PATCH] afform_clear() - Fix error when running on non-cached container After switching the tests from an effective policy of `CIVICRM_CONTAINER_CACHE=auto` to an effective policy of `CIVICRM_CONTAINER_CACHE=never`, this started to fail: ``` 1) api_v4_AfformTest::testGetUpdateRevert with data set #0 ('mockPage', array('', '', 'civicrm/mock-page', 'access Foobar')) Symfony\Component\DependencyInjection\Exception\BadMethodCallException: Setting service "angular" for an unknown or non-synthetic service definition on a compiled container is not allowed. /home/me/bknix/build/dmaster/web/sites/all/modules/civicrm/vendor/symfony/dependency-injection/ContainerBuilder.php:532 /home/me/bknix/build/dmaster/web/sites/all/modules/civicrm/ext/afform/core/afform.php:520 /home/me/bknix/build/dmaster/web/sites/all/modules/civicrm/ext/afform/core/Civi/Api4/Afform.php:99 /home/me/bknix/build/dmaster/web/sites/all/modules/civicrm/Civi/Api4/Generic/BasicBatchAction.php:88 /home/me/bknix/build/dmaster/web/sites/all/modules/civicrm/Civi/Api4/Generic/BasicBatchAction.php:68 /home/me/bknix/build/dmaster/web/sites/all/modules/civicrm/Civi/Api4/Provider/ActionObjectProvider.php:68 /home/me/bknix/build/dmaster/web/sites/all/modules/civicrm/Civi/API/Kernel.php:150 /home/me/bknix/build/dmaster/web/sites/all/modules/civicrm/Civi/Api4/Generic/AbstractAction.php:238 /home/me/bknix/build/dmaster/web/sites/all/modules/civicrm/ext/afform/mock/tests/phpunit/api/v4/AfformTest.php:53 /home/me/bknix/extern/phpunit6/phpunit6.phar:570 ``` --- Civi/Angular/Manager.php | 14 ++++++++++++++ ext/afform/core/afform.php | 5 +---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Civi/Angular/Manager.php b/Civi/Angular/Manager.php index 4b21537d3f..a763cf9e71 100644 --- a/Civi/Angular/Manager.php +++ b/Civi/Angular/Manager.php @@ -53,6 +53,20 @@ class Manager { $this->cache = $cache ? $cache : new \CRM_Utils_Cache_ArrayCache([]); } + /** + * Clear out any runtime-cached metadata. + * + * This is useful if, eg, you have recently added or destroyed Angular modules. + * + * @return static + */ + public function clear() { + $this->cache->clear(); + $this->modules = NULL; + $this->changeSets = NULL; + return $this; + } + /** * Get a list of AngularJS modules which should be autoloaded. * diff --git a/ext/afform/core/afform.php b/ext/afform/core/afform.php index 9d445ab6a6..d63c34994f 100644 --- a/ext/afform/core/afform.php +++ b/ext/afform/core/afform.php @@ -514,10 +514,7 @@ function afform_civicrm_permission_check($permission, &$granted, $contactId) { function _afform_clear() { $container = \Civi::container(); $container->get('afform_scanner')->clear(); - - // Civi\Angular\Manager doesn't currently have a way to clear its in-memory - // data, so we just reset the whole object. - $container->set('angular', NULL); + $container->get('angular')->clear(); } /** -- 2.25.1