Index: branches/5.2.x/core/units/logs/system_logs/system_log_eh.php =================================================================== diff -u -N -r16754 -r16755 --- branches/5.2.x/core/units/logs/system_logs/system_log_eh.php (.../system_log_eh.php) (revision 16754) +++ branches/5.2.x/core/units/logs/system_logs/system_log_eh.php (.../system_log_eh.php) (revision 16755) @@ -1,6 +1,6 @@ StoreSelectedIDs($event); + $this->clearSelectedIDs($event); + + if ( !$ids ) { + return; + } + + $this->deleteRecords( + $this->Application->getUnitOption($event->Prefix, 'IDField') . ' IN (' . implode(',', $ids) . ')' + ); + } + + /** + * Deletes all records from table + * + * @param kEvent $event Event. + * + * @return void + */ + protected function OnDeleteAll(kEvent $event) + { + $this->deleteRecords('TRUE'); + } + + /** * [SCHEDULED TASK] Will remove old system logs * - * @param kEvent $event + * @param kEvent $event Event. + * * @return void - * @access protected */ protected function OnRotate(kEvent $event) { $rotation_interval = (int)$this->Application->ConfigValue('SystemLogRotationInterval'); + // Forever. if ( $rotation_interval === -1 ) { - // forever return; } - $sql = 'SELECT ' . $this->Application->getUnitOption($event->Prefix, 'IDField') . ' - FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' - WHERE ' . TIMENOW . ' - LogTimestamp > ' . $rotation_interval . ' - LIMIT 0,50'; - $ids = $this->Conn->GetCol($sql); + $this->deleteRecords('LogTimestamp < ' . strtotime('-' . $rotation_interval . ' seconds')); + } - if ( $ids ) { - /** @var kTempTablesHandler $temp_handler */ - $temp_handler = $this->Application->recallObject($event->getPrefixSpecial() . '_TempHandler', 'kTempTablesHandler', Array ('parent_event' => $event)); + /** + * Deletes records & connected records by a WHERE clause. + * + * @param string $where_clause Where clause. + * + * @return void + */ + protected function deleteRecords($where_clause) + { + $id_field = $this->Application->getUnitOption($this->Prefix, 'IDField'); + $table_name = $this->Application->getUnitOption($this->Prefix, 'TableName'); - $temp_handler->DeleteItems($event->Prefix, $event->Special, $ids); + $sql = 'SELECT ' . $id_field . ' + FROM ' . $table_name . ' + WHERE ' . $where_clause . ' + LIMIT 0,500'; + + while ( true ) { + $ids = $this->Conn->GetCol($sql); + + if ( !$ids ) { + break; + } + + $sql = 'DELETE FROM ' . $table_name . ' + WHERE ' . $id_field . ' IN (' . implode(',', $ids) . ')'; + $this->Conn->Query($sql); } }