We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24629
    • 370 Posts
    Hi i have a snippet that allows me to set a user active or inactive. it seems to work allright.
    But i'm faced with the strange situation where a user is INACTIVE on the userslist (/manager/?a=security/user) but ACTIVE on theyre detail page (/manager/?a=security/user/update&id=24) and vice versa
    How is this possible??? i'm viewing this with browser caching off. I also checked the data in the database as well
    I tried this in Chrome and Firefox and both show the same anomaly.

    Is it possible the userslist is cached by modx somehow?

    RDG
      • 3749
      • 24,544 Posts
      How are you getting the active status and how are you displaying it?
        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
        • 24629
        • 370 Posts
        Hi BobRay,

        here are 4 screendumps taken at the same moment. 2 from the manager and 1 from phpmyadmin and 1 from my custom usermanager. it shows that, allthough the TESTuser is active=0 in the database. the manager shows the user active in the userLIST and the userDETAIL page.
        I use a snippet to get a list on my custom usermanager (the simplified version)
        
        $c = $modx->newQuery('modUser');
        $c->where(array('primary_group' => '3'));
        $c->sortby('username', 'ASC');
        $users = $modx->getCollection('modUser', $c, false);
        
         foreach ($users as $user) {
                    $bgcolor = ($bgcolor == "#ffffff") ? "#f9f9f9" : "#ffffff";
                    $o .= $modx->getChunk('row-user-list', array('id' => $user->get('id')
                    , 'username' => $user->get('username')
                    , 'active' => $user->get('active')
                    , 'bgcolor' => $bgcolor));
                }
        
        


        I'm using a small AJAX call on the custom usermanager to a snippet to set the user active or incative:
        $o = '';
        
        if (isset($_REQUEST['id']) && isset($_REQUEST['active'])) {
            $id = (isset($_REQUEST['id'])) ? $_REQUEST['id'] : '';
            $active = (isset($_REQUEST['active'])) ? $_REQUEST['active'] : '';
            $a = ($active == 'false') ? 0 : 1;
            $user = $modx->getObject('modUser', $id, false);
            $user->set('active', $a);
            if (!$user->save()) {
                $o .= 'ERROR: Could not save user.';
            }else{
                $o .= 'OK: save user.';
            }
        }
        return $o;
        

        The snippet seems to work fine because i can see in the database the active field changing its the the pages (espescialy the userlist in the MODX manager) that don't 'refresh'
        I hav a feeling the
        $users = $modx->getCollection('modUser', $c, false);
        gets cached somehow

        RDG

        PS im setting active and inactive on my custom usermanager [ed. note: rdaneeel last edited this post 11 years, 11 months ago.]
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          If I edit the database directly, as soon as I refresh the Manager page, either by reloading in the browser or clicking the Users menu item again, it does show the difference in the status.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 24629
            • 370 Posts
            Hi,
            I also checked the response from the server in Charles when asking for /manager/?a=security/user and the connectors/index.php sends the faulty data in JSON. so even while the DB has an active = 0 the response is:
            {
            		"id": 59,
            		"username": "TESTuser",
            		"class_key": "modUser",
            		"active": true,
            		"remote_key": null,
            		"remote_data": null,
            		"hash_class": "hashing.modPBKDF2",
            		"primary_group": 3,
            		"session_stale": null,
            		"sudo": false,
            		"fullname": "test",
            		"email": "[email protected]",
            		"blocked": false,
            		"cls": "pupdate premove pcopy"
            	}
            
            


            Any ideas why?

            RDG
              • 24629
              • 370 Posts
              Hi,

              I also asked my ISP and they got back to me just now. Seems there is some caching happening on the server. Also caching in Chrome (although turned off in Devtools) still likes to cache so it seems.
              Server caching has been changed and for now all seems stable. thanks for your time.

              RDG