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

    the log tables can grow really big. Is there an option to automatically shrink/purge/cycle the event logs?

    Olaf
      • 25663 MODX Staff
      • 12,272 Posts
      No ... if you’re using the built in stats in 095 or earlier, you really should consider turning them off. They in fact cause so many problems with even moderately busy sites that it can noticeably and negatively impact webserver performance. (And anecdotally why they were removed in 096... use Google Analytics, AWStats and/or Mint for good alternatives)
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 22098
        • 218 Posts
        no, we’re talking about the event logs and manager logs, not the stats logs

        Olaf
          • 25663 MODX Staff
          • 12,272 Posts
          OK ... no there’s not any current plugin to do that, though that’d be a good one I think assuming the right events are in place (and if they’re not they should be).
            Ryan Thrash, MODX Co-Founder
            Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
            • 22098
            • 218 Posts
            we created a plugin to purge the event and manager logs:

            This is the code to paste into the plugin:

            $number_of_days = isset($no_days) ? $no_days :"";
            
            if ($number_of_days)
            {
              $cut_off_date = time() - ($number_of_days * 24 * 60 * 60);
              $query = "DELETE FROM modx_manager_log WHERE timestamp<'{$cut_off_date}'";
              $modx->db->query($query);
              $query = "DELETE FROM modx_event_log WHERE createdon<'{$cut_off_date}'";
              $modx->db->query($query);
            }
            

            this has to be pasted into the configuration:

            &no_days=Number of Days;text;1


            and it should be triggered at: OnManagerLogin

            This way all events in the manager and event log that are older than the number of days you set in the configuration (default is 1) will be purged from the logs when someone logs into the manager.

            Olaf
              • 2912
              • 315 Posts
              Thats a great plugin and works well... been killing me to clear out the manager actions.

              Thanks! laugh
                BBloke
                • 30223
                • 1,010 Posts
                You’ve hard coded ’modx_’ as the table prefix. You might want to make this plugin a bit more generic. Someone who chooses a different table prefix would get an error if they tried to log in..

                <?php
                $number_of_days = isset($no_days) ? $no_days :"";
                
                if ($number_of_days)
                {
                  $cut_off_date = time() - ($number_of_days * 24 * 60 * 60);
                  $query = "DELETE FROM ". $modx->getFullTableName('manager_log')." WHERE timestamp<'{$cut_off_date}'";
                  $modx->db->query($query);
                  $query = "DELETE FROM ". $modx->getFullTableName('event_log')." WHERE createdon<'{$cut_off_date}'";
                  $modx->db->query($query);
                }
                ?>
                
                  • 22098
                  • 218 Posts
                  that’s what we wanted to do in version 0.2 grin
                  cheers!