Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1162160
session_log_eh.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Sep 20, 4:48 PM
Size
3 KB
Mime Type
text/x-php
Expires
Mon, Sep 22, 4:48 PM (2 h, 50 m)
Engine
blob
Format
Raw Data
Handle
751873
Attached To
rINP In-Portal
session_log_eh.php
View Options
<?php
/**
* @version $Id: session_log_eh.php 15569 2012-10-10 13:29:39Z alex $
* @package In-Portal
* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license GNU/GPL
* In-Portal is Open Source software.
* This means that this software may have been modified pursuant
* the GNU General Public License, and as distributed it includes
* or is derivative of works licensed under the GNU General Public License
* or other free or open source software licenses.
* See http://www.in-portal.org/license for copyright notices and details.
*/
defined
(
'FULL_PATH'
)
or
die
(
'restricted access!'
);
class
SessionLogEventHandler
extends
kDBEventHandler
{
/**
* Opens log for new session
*
* @param kEvent $event
*/
function
OnStartSession
(
$event
)
{
if
(!
$this
->
Application
->
ConfigValue
(
'UseChangeLog'
))
{
// don't use session log when change log is disabled
return
;
}
$object
=
$this
->
Application
->
recallObject
(
$event
->
Prefix
,
null
,
Array
(
'skip_autoload'
=>
1
));
/* @var $object kDBItem */
$fields_hash
=
Array
(
'SessionStart'
=>
adodb_mktime
(),
'IP'
=>
$this
->
Application
->
getClientIp
(),
'PortalUserId'
=>
$this
->
Application
->
RecallVar
(
'user_id'
),
'SessionId'
=>
$this
->
Application
->
GetSID
(),
'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
)
{
$object
=
$this
->
Application
->
recallObject
(
$event
->
Prefix
,
null
,
Array
(
'skip_autoload'
=>
1
));
/* @var $object kDBItem */
$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
);
$object
=
$event
->
getObject
();
/* @var $object kDBItem */
$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
)
{
$temp_handler
=
$this
->
Application
->
recallObject
(
'change-log_TempHandler'
,
'kTempTablesHandler'
);
/* @var $temp_handler kTempTablesHandler */
$temp_handler
->
DeleteItems
(
'change-log'
,
''
,
$related_ids
);
}
}
}
Event Timeline
Log In to Comment