Application->ConfigValue('UseChangeLog') ) { // Don't use session log when installing OR change log is disabled. return; } /** @var kDBItem $object */ $object = $this->Application->recallObject($event->Prefix, null, Array ('skip_autoload' => 1)); $fields_hash = Array ( 'SessionStart' => adodb_mktime(), 'IP' => $this->Application->getClientIp(), 'PortalUserId' => $this->Application->RecallVar('user_id'), 'SessionId' => $this->Application->GetSID(Session::PURPOSE_REFERENCE), 'SessionKey' => $this->Application->GetSID(Session::PURPOSE_STORAGE), 'Status' => SESSION_LOG_ACTIVE, ); $object->SetDBFieldsFromHash($fields_hash); $object->UpdateFormattersSubFields(); if ($object->Create()) { $this->Application->StoreVar('_SessionLogId_', $object->GetID()); } } /** * Closes log for current session * * @param kEvent $event */ function OnEndSession($event) { /** @var kDBItem $object */ $object = $this->Application->recallObject($event->Prefix, null, Array ('skip_autoload' => 1)); $object->Load($this->Application->RecallVar('_SessionLogId_')); if (!$object->isLoaded()) { return ; } $fields_hash = Array ( 'SessionEnd' => adodb_mktime(), 'Status' => SESSION_LOG_LOGGED_OUT, ); $object->SetDBFieldsFromHash($fields_hash); $object->UpdateFormattersSubFields(); $object->Update(); } /** * Apply custom processing to item * * @param kEvent $event * @param string $type * @return void * @access protected */ protected function customProcessing(kEvent $event, $type) { if ( $event->Name == 'OnMassDelete' && $type == 'before' ) { $ids = $event->getEventParam('ids'); if ( $ids ) { $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField'); $table_name = $this->Application->getUnitOption($event->Prefix, 'TableName'); $sql = 'SELECT ' . $id_field . ' FROM ' . $table_name . ' WHERE ' . $id_field . ' IN (' . implode(',', $ids) . ') AND Status <> ' . SESSION_LOG_ACTIVE; $allowed_ids = $this->Conn->GetCol($sql); $event->setEventParam('ids', $allowed_ids); } } } /** * Delete changes, related to deleted session * * @param kEvent $event * @return void * @access protected */ protected function OnAfterItemDelete(kEvent $event) { parent::OnAfterItemDelete($event); /** @var kDBItem $object */ $object = $event->getObject(); $sql = 'SELECT ' . $this->Application->getUnitOption('change-log', 'IDField') . ' FROM ' . $this->Application->getUnitOption('change-log', 'TableName') . ' WHERE SessionLogId = ' . $object->GetID(); $related_ids = $this->Conn->GetCol($sql); if ( $related_ids ) { /** @var kTempTablesHandler $temp_handler */ $temp_handler = $this->Application->recallObject('change-log_TempHandler', 'kTempTablesHandler'); $temp_handler->DeleteItems('change-log', '', $related_ids); } } }