We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 47190
    • 4 Posts
    I am trying to set a system with a custom plugin via a variable passed through the URL.

    I have done this successfully BUT I also need to clear the cache when this fires otherwise I get the cached setting when I use the placeholder [[++theme_name]] and that is where I am running into trouble...

    Currently running MODX 2.3.0.

    Here is my plugin code: (fires OnWebPageInit)

    <?php
    $theme = isset($_GET['theme']) ? $_GET['theme'] : ''  ;
    
    $clearss =  array( 'system_settings' => array() );
    $modx->cacheManager-> refresh($clearss);
    
    $Setting = $modx->getObject('modSystemSetting', 'theme_name');
    $Setting->set('value', $theme);
    $Setting->save();
    


    This changes my system setting properly.

    Here is a link to the page and how I am passing the variable : http://modx.immarketing.net/?theme=theme1

    Any advice as to how I can get my system_settings cache to clear? It would be great if I could just clear that one setting.

      • 3749
      • 24,544 Posts
      I may have this wrong (the docs are kind of sketchy), but I think this might do it:

      $cm = $modx->getCacheManager();
      $cm->refresh(array('system_settings'=>array()));
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 47190
        • 4 Posts
        Quote from: BobRay at Jul 25, 2014, 07:01 PM
        I may have this wrong (the docs are kind of sketchy), but I think this might do it:

        $cm = $modx->getCacheManager();
        $cm->refresh(array('system_settings'=>array()));

        Thanks BobRay // but this didn't do the trick. I'm going to keep digging!
          • 3749
          • 24,544 Posts
          Assuming that you're not using a custom cache of some kind, you should be able to just unlink the file:

          unlink(MODX_CORE_PATH . 'cache/system_settings/config.cache.php');


          If it's for the current request, you could also try:

          $modx->setOption('theme_name', $theme);
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 47190
            • 4 Posts
            Thanks BobRay,

            Where would I put the coded to unlink the SS config Cache?

            Quote from: BobRay at Jul 28, 2014, 11:50 PM
            Assuming that you're not using a custom cache of some kind, you should be able to just unlink the file:

            unlink(MODX_CORE_PATH . 'cache/system_settings/config.cache.php');


            If it's for the current request, you could also try:

            $modx->setOption('theme_name', $theme);
              • 3749
              • 24,544 Posts
              At the end of the plugin, just before the return statement and it should definitely have a return at the end).
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting