We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    I’ve been trying to figure out exactly what the active_users table is for. Apparently it keeps a record of all users both web and manager from the first time they log in. Some of the fields I can understand what they are, but the id field I can’t figure out. Also, all web users apparently get an action of 998 no matter what they are doing. It seems to me that there could be an update to set action to 8 (indicating log out) when a web user logs out, even though it really doesn’t matter, but then the reporting scripts will report a log out status.

    What I don’t quite understand is why these records don’t get cleared out after a certain length of time. I even found a couple of web users that I had deleted, then re-created much later, still there.

    Does anyone else feel that a bit more responsive logging of web users might be useful? I know there is a timestamp so last activity can be determined, but that still doesn’t give any clue as to the actual current status of the web user.

    OK, I figured out that the id field is the document id the user is currently on. So the only thing left is to change the web user’s action to indicate a logout, and since 8 is already used for manager users and won’t conflict with the document id, I would like to propose simply adding a line to the weblogin.processor.inc.php file immediately before clearing the session, around line 131:

                // update status in active_users table
                $modx->db->update("action = 8",$modx->getFullTableName('active_users'),"internalKey = -".$_SESSION['webInternalKey']);
    
      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
      • 1764
      • 680 Posts
      Sounds good to me.

      But do we really need this at all? I’m not sure exactly what it is used for either. I’d think the manager log table would be the place for recording login and logout times. My assumtion is the table is used for the Who’s Online tab on the homepage. I wonder if it wouldn’t be better to implement this as a module/plugin.

      With that in mind. I’d love to see us have customizable "homepages" for the manager. Each user could select what tabs and links they wanted on their login page. Modules could be shown in tabs similar to the tabs on the homepage now.
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        The active_users table is used in the Manager to determine if someone is editing a resource, thus locking the resource.
        Removing locks just truncates this table. Which kind of invalidates its use for keeping track of web users online. That should be changed to just remove the entries for manager users.

        I’m inclined to feel that the entry should be removed on logout, with occasional checks and removeal of entries that are inactive for x amount of time (could be set in the system admin sections).

        But making this an optional plugin for tracking web users would be great; it would give the option of speeding things up a bit since the user’s actions won’t be logged.
          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