1

I am creating a distribution Drupal profile which is bundling CiviCRM and CiviCRM extensions.

Background

Currently, I am having an issue with extensions that CiviCRM settings, for example, Mosaico Extension is using CiviCRM settings for configuration templates, graphic engine etc so after Mosaico extension is completely installed, the Mosaico settings have not been set and you need to flush the system cache.

According to CiviCRM| document https://docs.civicrm.org/dev/en/latest/framework/setting/

Your setting will not be active until you run flush all caches (e.g cv flush or drush cvapi System.flush)

The current version of CiviCRM, Drupal and the extension that are being used.

  • CiviCRM version 5.19.4
  • Drupal version 7.69
  • Mosaico version 2.3

Issue

When I am trying to flush the system cache via CiviCRM API, flush Cache directly via CRM_Extension_System class or calling cleanupCaches on the CRM_Core_config class. None of these is working.

civicrm_api3('System', 'flush');

\CRM_Extension_System::singleton()->getCache()->flush();

$config = \CRM_Core_Config::singleton();
$config->clearModuleList();
$config->cleanupCaches();

Is there a way to flush a system cache and load the configuration during Profile installation?

I have also tried to create settings after the extension is installed and got the error so I understand that the settings are not activated yet.

error when creating settings before the settings are actived

2 Answers 2

1

Haven't done that, but if the focus is on manipulating the content of the settings, then one of these might help:

  1. Try adding calls to Civi::reset() and/or CRM_Core_Config::singleton(TRUE,TRUE) to clear out any statics/singletons/thread-local caches.

    • Civi's headless unit-tests do this (via CiviTestListener). Note that one should only do it while Civi logic is _not_ active in the same thread -- e.g. it's OK to run when PHPUnit is doing setup/teardown because the statics/singletons/caches are essentially inert; but if one did this while running hook_civicrm_config or a Civi page-controller, then some active function on the call-stack may implicitly rely on them, so the behavior would be ill-defined.
  2. Proactively initialize the settings (Civi::setting()->set($key, $value)) before activating the extension. Don't rely on the default values for the settings.

  3. Try working with the SettingsManager (Civi::service('settings_manager')). This has its own flush() operation.

    • Since this is included in System.flush, I don't have high expectations... but it is imaginable that your use-case requires flushing with a different _sequence_ of operations.
0
1

After testing on Tim's suggestion.

  1. It does not work.
  2. Have not tried yet.
  3. It works after calling Civi::service('settings_manager') on the last tasks before install_finished task is called during Drupal installation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.