#!/usr/bin/php5 -q fetchOneCell())) { echo "Orphaned sessions: found $count orphaned sessions. Please fix that.\n"; } } /** * Purges session events without a valid session. */ function purgeOrphanedEvents() { XDB::execute( "DELETE e FROM log_events AS e LEFT JOIN log_sessions AS s ON (s.id = e.session) WHERE s.id IS NULL"); $affectedRows = XDB::affectedRows(); echo "Orphaned events: removed $affectedRows events.\n"; } // Remove expired sessions. // For normal user, we only keep 12 months of data (and at least the last two sessions). // For administrator, we also keep data for 12 months, but with a backlog of at least 20 sessions. // For disabled users, we keep data for 5 years, and with a backlog of at least 2 sessions. // For other users, no data are discarded. discardExpiredSessions('user', 12, 2); discardExpiredSessions('admin', 12, 20); discardExpiredSessions('disabled', 60, 2); // Purge orphaned entries; events are purged automatically, sessions require explicit // action from the administrator. checkOrphanedSessions(); purgeOrphanedEvents(); // Many rows have been removed from the two logger tables. Let's optimize them. XDB::execute("OPTIMIZE TABLE log_events"); XDB::execute("OPTIMIZE TABLE log_sessions"); // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>