Index: branches/5.3.x/core/units/logs/session_logs/session_log_eh.php =================================================================== diff -u -N -r15928 -r16329 --- branches/5.3.x/core/units/logs/session_logs/session_log_eh.php (.../session_log_eh.php) (revision 15928) +++ branches/5.3.x/core/units/logs/session_logs/session_log_eh.php (.../session_log_eh.php) (revision 16329) @@ -1,6 +1,6 @@ Application->ConfigValue('SessionLogRotationInterval'); + + if ( $rotation_interval === -1 ) { + // Forever. + return; + } + + $session_log_temp_handler = $this->getTempTablesHandler($event->getPrefixSpecial(), $event); + $change_log_temp_handler = $this->getTempTablesHandler('change-log', $event); + + $limit = 100; + $session_log_config = $event->getUnitConfig(); + $session_log_select_sql = ' SELECT ' . $session_log_config->getIDField() . ' + FROM ' . $session_log_config->getTableName() . ' + WHERE ' . TIMENOW . ' - SessionEnd > ' . $rotation_interval . ' + LIMIT 0,' . $limit; + $change_log_config = $this->Application->getUnitConfig('change-log'); + + do { + $session_log_ids = $this->Conn->GetCol($session_log_select_sql); + + if ( !$session_log_ids ) { + break; + } + + $change_log_select_sql = ' SELECT ' . $change_log_config->getIDField() . ' + FROM ' . $change_log_config->getTableName() . ' + WHERE SessionLogId IN (' . implode(',', $session_log_ids) . ') + LIMIT 0,' . $limit; + + do { + $change_log_ids = $this->Conn->GetCol($change_log_select_sql); + + if ( $change_log_ids ) { + $change_log_temp_handler->DeleteItems('change-log', '', $change_log_ids); + } + } while ( count($change_log_ids) == $limit ); + + $session_log_temp_handler->DeleteItems($event->Prefix, $event->Special, $session_log_ids); + } while ( count($session_log_ids) == $limit ); + } + + /** + * Get temp tables handler instance. + * + * @param string $prefix_special Prefix, special. + * @param kEvent $event Event. + * + * @return kTempTablesHandler + */ + public function getTempTablesHandler($prefix_special, kEvent $event) + { + return $this->Application->recallObject( + $prefix_special . '_TempHandler', + 'kTempTablesHandler', + array('parent_event' => $event) + ); + } + + }