We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 43568
    • 9 Posts
    hi,

    I created an individual user setting ('css_prefix' -> [[++css_prefix]]) to have different templates in frontend.
    When I let the user login to the frontend, the value shows the stored value.
    without login or users without this setting show the system-wide value of this setting.
    so far, so good.

    but:
    when I change the user-specific setting (Manage | Users | Update User | Settings), the change is NOT reflected in the frontend!
    after logout/login in the frontend, the value shows the new value.
    without any user logged in (so the system setting is used), the frontend shows all value-changes AT ONCE (even without clearing
    the cache)!

    I tried to write an uncached Snippet, too
    [[!_getSystemSetting? &setting=`css_prefix`]] -> return ($modx->config[$setting])
    but it does not show the correct/current value!

    is this a bug ?

    TIA

    Marc

    modx 2.5.5-pl [ed. note: ucnet last edited this post 7 years, 1 month ago.]
      • 3749
      • 24,544 Posts
      I don't think it's a bug. $modx->config comes from the cache.

      If you want an immediate, uncached value for the setting tag, I think this would do it:

      [[!++css_prefix]]


      It should also work to clear the cache in the Manager, but it seems to me that sometimes it doesn't -- I'm not sure it clears the user settings.

      Clearing the cache manually by deleting all files in the core/cache directory is quaranteed to work. I'm almost sure that CacheClear extra would also do it, but I'm not positive..
        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
        • 43568
        • 9 Posts
        Hi Bob,

        thx for your reply.

        Quote from: BobRay at Mar 01, 2017, 09:00 PM
        I don't think it's a bug. $modx->config comes from the cache.

        is there an uncached-property like
        $modx->_config
        available ?

        Quote from: BobRay at Mar 01, 2017, 09:00 PM
        If you want an immediate, uncached value for the setting tag, I think this would do it:

        [[!++css_prefix]]

        I checked it today with an uncached tag
        [[!++css_prefix]
        , but it's the same result!
        changing the value (user setting!) in the backend does not reflect the new value, except after logout/login.
        :-(

        Quote from: BobRay at Mar 01, 2017, 09:00 PM
        It should also work to clear the cache in the Manager, but it seems to me that sometimes it doesn't -- I'm not sure it clears the user settings.

        this does not help, ether.

        because changing the setting at context-level and even and system-level does reflect the change immediatly, I think this is kind of a weird caching-thing or even kind of a (caching-)bug.

        I would dive into this if someone could assist in pointing me to the right code-details...

        Marc
          • 3749
          • 24,544 Posts
          It could be a browser cache issue.

          Once you've deleted the core/cache files, all settings will come from the database.

          The process is very straightforward, MODX gets the System Settings, then merges in the Context Settings, then User Group Settings, then User Settings. In each case, any matching new values overwrite the existing ones.

          I'm not sure if there is a $modx->_config value, but if there is, I'm pretty sure it would match $modx->config. MODX would never get both a cached and uncached value for a setting.

          Worst-case, you can do this (assuming that it's not a browser cache issue):

          [[!getSetting? &key=`css_prefix`]]


          /* getSetting snippet */
          
          $key = $modx->getOption('key', $scriptProperties, '', true);
          if (!empty($key)) {
              $setting = $modx->getObject('modUserSetting', array('key' => $key), false);
              if ($setting) {
                  $output = $setting->get('value');
              } else {
                  $output = 'Could not get setting object';
              }
          } else {
              $output = 'No Key';
          }


          [P.S.] On second thought, maybe it is kind of a bug.


          [ed. note: BobRay last edited this post 7 years, 1 month ago.]
            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
            • 43568
            • 9 Posts

            Quote from: BobRay at Mar 03, 2017, 05:17 AM
            It could be a browser cache issue.

            sorry, this isn't the case.

            Quote from: BobRay at Mar 03, 2017, 05:17 AM
            Once you've deleted the core/cache files, all settings will come from the database.

            this doesn't help ether!
            I removed alls files from core/cache, still same value!

            I did not find any user-specific settings cached there (?).

            Quote from: BobRay at Mar 03, 2017, 05:17 AM
            The process is very straightforward, MODX gets the System Settings, then merges in the Context Settings, then User Group Settings, then User Settings. In each case, any matching new values overwrite the existing ones.

            yes, that's what I expect.

            BTW: I can't save any user-group-settings for '(anonymous)'-group ?!

            Quote from: BobRay at Mar 03, 2017, 05:17 AM
            Worst-case, you can do this (assuming that it's not a browser cache issue):

            this works fine, as it always retrieves the 'modUserSetting' (after fixing your small typo ;-) $output = 'No Key'); )


            It looks like user-settings are just once retrieved on login and not updated.

            can anyone confirm this behaviour ?

            Where do I find the code where $modx->config[] is filled/updated ?

            thanks,

            Marc
              • 3749
              • 24,544 Posts
              I'm glad that worked for you (typo fixed above).

              Out of curiosity, would you look in the core/cache directory and see if there is a user settings cache? If so, see if it changes when you edit a user setting, save it, and clear the cache.

              I'm not sure where the config is loaded, but I suspect that as soon as someone logs in, the user settings are set and attached to the user object, and not changed until the next login.

              You could try a snippet with this code:

              $mod-log(modX::LOG_LEVEL_ERROR, 'User Object: ' . print_r( (array) $modx->user, true));


              You could also write a PHP script that instantiates MODX, and sets the $modx->user object, then debug it in a text editor and look at the user part of the $modx object.

              If either one works, you'll probably be wading through a ton of code.
              [ed. note: BobRay last edited this post 7 years, 1 month ago.]
                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
                • 43568
                • 9 Posts
                Quote from: BobRay at Mar 05, 2017, 05:02 AM
                Out of curiosity, would you look in the core/cache directory and see if there is a user settings cache? If so, see if it changes when you edit a user setting, save it, and clear the cache.

                there is NO user settings cache or even any file that contains my setting (beside system-settings/config.cache.php and context-settings/).

                Quote from: BobRay at Mar 05, 2017, 05:02 AM
                I'm not sure where the config is loaded, but I suspect that as soon as someone logs in, the user settings are set and attached to the user object, and not changed until the next login.

                that's exactly what I think that happens.
                and I'm not sure if it's just a feature (like internal automatic user-settings-caching).
                acl's aren't cached there even they are attached to the user-object(?) as well.
                from my point of view, these settings could (better: should) be updated on a change while the user is still logged in!

                not to call it a bug, but better a feature-should-get-updated-request ?

                thanks so far - I will keep the object-review on my 2do-list.
                :-)

                Marc
                  • 3749
                  • 24,544 Posts
                  It's always a trade-off. If you insert too much cache/setting clearing, it slows down the Manager. There are often dependencies far beyond the object in question. If a user settings changes, for example, the display of a cached chunk, snippet, or resource, may no longer be correct unless they too are cleared. Clearing all that makes the Manager very slow, not to mention all the front-end users getting slow page-loads because the stuff is no longer cached.
                    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
                    • 43568
                    • 9 Posts
                    Quote from: BobRay at Mar 07, 2017, 09:36 PM
                    It's always a trade-off.

                    yes, you'r right.
                    but from my point of view, user-settings don't change that often (but when it my be important). changing them should be the same as clearing the cache (or saving a chunk, that also clears the cache).
                    anyway, thanks a lot for your support. for now, I stay with checking the user-setting explicitly (with your snippet ;-))
                    let's see what comes next 8-)

                    Marc