Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1177536
system_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
Wed, Oct 8, 7:40 AM
Size
7 KB
Mime Type
text/x-php
Expires
Fri, Oct 10, 7:40 AM (1 d, 1 h)
Engine
blob
Format
Raw Data
Handle
764121
Attached To
rINP In-Portal
system_log_eh.php
View Options
<?php
/**
* @version $Id: system_log_eh.php 16841 2025-08-31 16:07:02Z alex $
* @package In-Portal
* @copyright Copyright (C) 1997 - 2012 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
SystemLogEventHandler
extends
kDBEventHandler
{
/**
* Filters messages, that require e-mail notification to be sent
*
* @param kEvent $event
* @return void
* @access protected
*/
protected
function
SetCustomQuery
(
kEvent
$event
)
{
parent
::
SetCustomQuery
(
$event
);
/** @var kDBList $object */
$object
=
$event
->
getObject
();
if
(
$event
->
Special
==
'email'
)
{
$unique_id
=
$event
->
getEventParam
(
'unique_id'
);
if
(
$unique_id
!==
false
)
{
$object
->
addFilter
(
'notification_filter'
,
'%1$s.LogNotificationStatus = '
.
kLogger
::
LNS_SENT
);
$object
->
addFilter
(
'unique_filter'
,
'%1$s.LogUniqueId = '
.
$unique_id
);
}
else
{
$object
->
addFilter
(
'notification_filter'
,
'%1$s.LogNotificationStatus = '
.
kLogger
::
LNS_PENDING
);
}
}
}
/**
* [SCHEDULED TASK] Sends delayed notification of system log messages
*
* @param kEvent $event
* @return void
* @access protected
*/
protected
function
OnSendNotifications
(
kEvent
$event
)
{
// initialize list outside of e-mail event with right settings
/** @var kDBList $list */
$list
=
$this
->
Application
->
recallObject
(
$event
->
Prefix
.
'.email'
,
$event
->
Prefix
.
'_List'
,
Array
(
'per_page'
=>
20
));
if
(
!
$list
->
GetRecordsCount
()
)
{
// no messages, that needs to be sent
return
;
}
$notification_email
=
$this
->
Application
->
ConfigValue
(
'SystemLogNotificationEmail'
);
if
(
!
$notification_email
)
{
$this
->
Application
->
removeObject
(
$event
->
Prefix
.
'.email'
);
trigger_error
(
'System Log notification E-mail not specified'
,
E_USER_NOTICE
);
return
;
}
$send_params
=
Array
(
'to_name'
=>
$notification_email
,
'to_email'
=>
$notification_email
,
);
$this
->
Application
->
emailAdmin
(
'SYSTEM.LOG.NOTIFY'
,
null
,
$send_params
);
$this
->
Application
->
removeObject
(
$event
->
Prefix
.
'.email'
);
/** @var kDBItem $object */
$object
=
$event
->
getObject
(
Array
(
'skip_autoload'
=>
true
));
foreach
(
$list
as
$fields_hash
)
{
$object
->
LoadFromHash
(
$fields_hash
);
$object
->
SetDBField
(
'LogNotificationStatus'
,
kLogger
::
LNS_SENT
);
$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
*
* @param kEvent $event Event.
*
* @return void
*/
protected
function
OnRotate
(
kEvent
$event
)
{
$rotation_interval
=
(
int
)
$this
->
Application
->
ConfigValue
(
'SystemLogRotationInterval'
);
// Forever.
if
(
$rotation_interval
===
-
1
)
{
return
;
}
$this
->
deleteRecords
(
'LogTimestamp < '
.
strtotime
(
'-'
.
$rotation_interval
.
' seconds'
));
}
/**
* 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
);
if
(
!
$ids
)
{
break
;
}
$sql
=
'DELETE FROM '
.
$table_name
.
'
WHERE '
.
$id_field
.
' IN ('
.
implode
(
','
,
$ids
)
.
')'
;
$this
->
Conn
->
Query
(
$sql
);
}
}
/**
* Removes old code fragments.
*
* @param kEvent $event Event.
*
* @return void
*/
protected
function
OnRotateCodeFragmentsScheduledTask
(
kEvent
$event
)
{
$id_field
=
$this
->
Application
->
getUnitOption
(
$event
->
Prefix
,
'IDField'
);
$table_name
=
$this
->
Application
->
getUnitOption
(
$event
->
Prefix
,
'TableName'
);
$sql
=
'SELECT LogBacktrace, '
.
$id_field
.
'
FROM '
.
$table_name
.
'
WHERE LogTimestamp < '
.
strtotime
(
'-1 month'
)
.
' AND LogCodeFragmentsRotated = 0
LIMIT 0,500'
;
$records
=
$this
->
Conn
->
GetColIterator
(
$sql
,
$id_field
);
foreach
(
$records
as
$system_log_id
=>
$trace
)
{
if
(
$trace
)
{
$trace
=
unserialize
(
$trace
);
foreach
(
$trace
as
$index
=>
$trace_info
)
{
if
(
array_key_exists
(
'code_fragment'
,
$trace_info
)
)
{
unset
(
$trace
[
$index
][
'code_fragment'
]);
}
}
$trace
=
serialize
(
$trace
);
}
$this
->
Conn
->
doUpdate
(
array
(
'LogBacktrace'
=>
$trace
,
'LogCodeFragment'
=>
null
,
'LogCodeFragmentsRotated'
=>
1
,
),
$table_name
,
$id_field
.
' = '
.
$system_log_id
);
}
}
/**
* Removes old request data.
*
* @param kEvent $event Event.
*
* @return void
*/
protected
function
OnRotateRequestDataScheduledTask
(
kEvent
$event
)
{
$rotation_interval
=
(
int
)
$this
->
Application
->
ConfigValue
(
'SystemLogRequestDataRotationInterval'
);
// Forever.
if
(
$rotation_interval
===
-
1
)
{
return
;
}
$id_field
=
$this
->
Application
->
getUnitOption
(
$event
->
Prefix
,
'IDField'
);
$table_name
=
$this
->
Application
->
getUnitOption
(
$event
->
Prefix
,
'TableName'
);
$where_clause
=
array
(
'LogTimestamp < '
.
strtotime
(
'-'
.
$rotation_interval
.
' seconds'
),
'LogRequestDataRotated = 0'
,
);
$sql
=
'SELECT '
.
$id_field
.
'
FROM '
.
$table_name
.
'
WHERE ('
.
implode
(
') AND ('
,
$where_clause
)
.
')
LIMIT 0,500'
;
$records
=
$this
->
Conn
->
GetColIterator
(
$sql
,
$id_field
);
foreach
(
$records
as
$system_log_id
)
{
$this
->
Conn
->
doUpdate
(
array
(
'LogRequestData'
=>
null
,
'LogSessionData'
=>
null
,
'LogRequestDataRotated'
=>
1
,
),
$table_name
,
$id_field
.
' = '
.
$system_log_id
);
}
}
/**
* Ensures, that used system setting values don't collide.
*
* @param kEvent $event Event.
*
* @return void
*/
protected
function
OnBeforeConfigurationValidatedHook
(
kEvent
$event
)
{
/** @var ConfigurationItem $configuration */
$configuration
=
$event
->
MasterEvent
->
getObject
();
$variable_name
=
$configuration
->
GetDBField
(
'VariableName'
);
if
(
$variable_name
===
'SystemLogRequestDataRotationInterval'
)
{
$request_data_rotation_interval
=
(
int
)
$configuration
->
GetDBField
(
'VariableValue'
);
$global_rotation_interval
=
(
int
)
$this
->
Application
->
ConfigValue
(
'SystemLogRotationInterval'
);
// Not forever.
if
(
$request_data_rotation_interval
!==
-
1
&&
$global_rotation_interval
!==
-
1
&&
$request_data_rotation_interval
>
$global_rotation_interval
)
{
/** @var InpCustomFieldsHelper $custom_fields_helper */
$custom_fields_helper
=
$this
->
Application
->
recallObject
(
'InpCustomFieldsHelper'
);
$options
=
$custom_fields_helper
->
GetValuesHash
(
$configuration
->
GetDBField
(
'ValueList'
));
$configuration
->
SetError
(
'VariableValue'
,
'value_out_of_range'
,
null
,
array
(
'min_value'
=>
'"'
.
reset
(
$options
)
.
'"'
,
'max_value'
=>
'"'
.
$options
[
$global_rotation_interval
]
.
'"'
,
));
}
}
}
}
Event Timeline
Log In to Comment