Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/units/logs/system_logs/system_log_eh.php
Show First 20 Lines • Show All 83 Lines • ▼ Show 20 Line(s) | |||||
foreach ($list as $fields_hash) { | foreach ($list as $fields_hash) { | ||||
$object->LoadFromHash($fields_hash); | $object->LoadFromHash($fields_hash); | ||||
$object->SetDBField('LogNotificationStatus', kLogger::LNS_SENT); | $object->SetDBField('LogNotificationStatus', kLogger::LNS_SENT); | ||||
$object->Update(); | $object->Update(); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Deletes all selected items. | |||||
* | |||||
* @param kEvent $event Event. | |||||
* | |||||
* @return void | |||||
*/ | |||||
protected function OnMassDelete(kEvent $event) | |||||
{ | |||||
$ids = $this->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 | * [SCHEDULED TASK] Will remove old system logs | ||||
* | * | ||||
* @param kEvent $event | * @param kEvent $event Event. | ||||
* | |||||
* @return void | * @return void | ||||
* @access protected | |||||
*/ | */ | ||||
protected function OnRotate(kEvent $event) | protected function OnRotate(kEvent $event) | ||||
{ | { | ||||
$rotation_interval = (int)$this->Application->ConfigValue('SystemLogRotationInterval'); | $rotation_interval = (int)$this->Application->ConfigValue('SystemLogRotationInterval'); | ||||
// Forever. | |||||
if ( $rotation_interval === -1 ) { | if ( $rotation_interval === -1 ) { | ||||
// forever | |||||
return; | return; | ||||
} | } | ||||
$sql = 'SELECT ' . $this->Application->getUnitOption($event->Prefix, 'IDField') . ' | $this->deleteRecords('LogTimestamp < ' . strtotime('-' . $rotation_interval . ' seconds')); | ||||
FROM ' . $this->Application->getUnitOption($event->Prefix, 'TableName') . ' | } | ||||
WHERE ' . TIMENOW . ' - LogTimestamp > ' . $rotation_interval . ' | |||||
LIMIT 0,50'; | /** | ||||
* 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'); | |||||
$sql = 'SELECT ' . $id_field . ' | |||||
FROM ' . $table_name . ' | |||||
WHERE ' . $where_clause . ' | |||||
LIMIT 0,500'; | |||||
while ( true ) { | |||||
$ids = $this->Conn->GetCol($sql); | $ids = $this->Conn->GetCol($sql); | ||||
if ( $ids ) { | if ( !$ids ) { | ||||
/** @var kTempTablesHandler $temp_handler */ | break; | ||||
$temp_handler = $this->Application->recallObject($event->getPrefixSpecial() . '_TempHandler', 'kTempTablesHandler', Array ('parent_event' => $event)); | } | ||||
$temp_handler->DeleteItems($event->Prefix, $event->Special, $ids); | $sql = 'DELETE FROM ' . $table_name . ' | ||||
WHERE ' . $id_field . ' IN (' . implode(',', $ids) . ')'; | |||||
$this->Conn->Query($sql); | |||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Removes old code fragments. | * Removes old code fragments. | ||||
* | * | ||||
* @param kEvent $event Event. | * @param kEvent $event Event. | ||||
* | * | ||||
Show All 39 Lines |