We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 46718
    • 39 Posts
    Hello MODX'ers,

    I've got a script that checks MODX users against an external API and marks them as active or inactive based on the response.

    I can successfully set the user active state both with the MODX API and in the database directly, but neither method displays the change in the MODX manager by making the "Active" checkbox checked or unchecked respectively. This means the only way to really check the user's active state is by looking in the database.

    To be clear, the user login does respect the active state set in the database, but the display in the MODX manager does not get updated.

    I'm wondering if there is some user cache that I need to clear after saving the user in order for it to display in the manager.

    Here is the simple code I am using to set the user active state:
    $userid = 1;
    $user = $modx->getObject('modUser', $userid);
      if($user){
        $user->set('active', 1);
        if($user->save() == false){
          $modx->log(modX::LOG_LEVEL_ERROR,'$user active state not saved for user id: '.$userid);
        }
      }
    


    This is in MODX 2.5.8 hosted with MODX Cloud.

    Thanks for any help!
    - Roger

    This question has been answered by BobRay. See the first response.

      • 3749
      • 24,544 Posts
      As far as I can tell, data on individual users is not cached at all. You could verify that by adding this code at the end, which will clear the entire cache:

      $cm = $modx->getCacheManager();
      $cm->refresh();
      


      If the active checkbox is still not updated, it's not a MODX cache issue. Don't forget to remove that code, since it will slow down your site considerably.


      I wonder if it might be your browser cache. See if adding a bogus query parameter to your URL makes a difference.

      https://bobsguides.com/mgnr/?a=security/user/update&id=1&bogusparam=12


        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
      • discuss.answer
        • 3749
        • 24,544 Posts
        I had another thought.

        Try this:

        if($user->save(true) == false){



          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
          • 46718
          • 39 Posts
          Quote from: BobRay at Oct 17, 2017, 04:02 PM
          I had another thought.

          Try this:

          if($user->save(true) == false){




          Thanks, @BobRay you're my hero!
            • 3749
            • 24,544 Posts
            Thanks for the kind words. smiley

            That argument sets the cacheFlag for the xPDOObject's save() method. It affects the xPDO cache layer, not the MODX cache. The save() code always confuses me, but I think setting it to true says to cache the results, but mark them as modified. You can also send an integer that determines how long the object remains in the cache.

            Are you running some external cache like memcached, wincache, or APC?

              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
              • 46718
              • 39 Posts
              Nope, just normal MODX cache.
                • 3749
                • 24,544 Posts
                Ah ... just looked at the xPDO cachemanager class.

                In that case it creates cache files. They're in the temp directory, which is why I couldn't find them.

                  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
                  • 46718
                  • 39 Posts
                  Ok, good because I looked all over the /core/cache folder, thought I was going crazy.

                  Me too. wink [ed. note: BobRay last edited this post 6 years, 6 months ago.]