Answers.Body: <p>Haven't done that, but if the focus is on manipulating the content of the settings, then one of these might help:</p>
  
  <ol>
  <li><p>Try adding calls to <code>Civi::reset()</code> and/or  <code>CRM_Core_Config::singleton(TRUE,TRUE)</code> to clear out any statics/singletons/thread-local caches.</p>
  
  <ul>
  <li><em>Civi's headless unit-tests do this (via <code>CiviTestListener</code>). 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 <code>hook_civicrm_config</code> 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.</em></li>
  </ul></li>
  <li><p>Proactively initialize the settings (<code>Civi::setting()-&gt;set($key, $value)</code>) <em>before</em> activating the extension. Don't rely on the default values for the settings.</p></li>
  <li><p>Try working with the <code>SettingsManager</code> (<code>Civi::service('settings_manager')</code>). This has its own <code>flush()</code> operation.</p>
  
  <ul>
  <li><em>Since this is included in <code>System.flush</code>, I don't have high expectations... but it is imaginable that your use-case requires flushing with a different _sequence_ of operations.</em></li>
  </ul></li>
  </ol>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-10T22:52:19.267Z
Answers.LastActivityDate: 2020-02-10T23:16:50.160Z
Answers.LastEditDate: 2020-02-10T23:16:50.160Z
Answers.UserDisplayName: Tim Otten
Answers.Body: <p>After testing on Tim's suggestion. </p>
  
  <ol>
  <li>It does not work.  </li>
  <li>Have not tried yet.</li>
  <li>It works after calling <code>Civi::service('settings_manager')</code> on the last tasks before install_finished task is called during Drupal installation. </li>
  </ol>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-11T18:37:55.440Z
Answers.LastActivityDate: 2020-02-11T18:37:55.440Z
Answers.UserDisplayName: Erawat Chamanont
Body: <p>I am creating a distribution Drupal profile which is bundling CiviCRM and CiviCRM extensions.</p>
  
  <p><strong>Background</strong></p>
  
  <p>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. </p>
  
  <p>According to CiviCRM| document <a href="https://docs.civicrm.org/dev/en/latest/framework/setting/" rel="nofollow noreferrer">https://docs.civicrm.org/dev/en/latest/framework/setting/</a></p>
  
  <blockquote>
    <p>Your setting will not be active until you run flush all caches (e.g cv
    flush or drush cvapi System.flush)</p>
  </blockquote>
  
  <p>The current version of CiviCRM, Drupal and the extension that are being used.</p>
  
  <ul>
  <li>CiviCRM version 5.19.4 </li>
  <li>Drupal version 7.69 </li>
  <li>Mosaico version 2.3</li>
  </ul>
  
  <p><strong>Issue</strong></p>
  
  <p>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. </p>
  
  <pre><code>civicrm_api3('System', 'flush');
  
  \CRM_Extension_System::singleton()-&gt;getCache()-&gt;flush();
  
  $config = \CRM_Core_Config::singleton();
  $config-&gt;clearModuleList();
  $config-&gt;cleanupCaches();
  </code></pre>
  
  <p>Is there a way to flush a system cache and load the configuration during Profile installation?  </p>
  
  <p>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.</p>
  
  <p><a href="https://i.sstatic.net/uI6TA.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/uI6TA.png" alt="error when creating settings before the settings are actived"></a></p>
  
Tags: <drupal><profile><installation><mosaico>
Title: Flush system cache does not work during installation of Drupal Profile
ThreadText: # Flush system cache does not work during installation of Drupal Profile
  
  (Asked by: username_0 on 2020-02-10)
  
  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.
  
  **Tags:** drupal, profile, installation, mosaico
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2020-02-10. Score: 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.*
  
  
  ---
  
  ### Answer by username_0 on 2020-02-11. Score: 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.
  
  
  ---
  
  