Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F804090
D165.id468.diff
No One
Temporary
Actions
View 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, Feb 26, 9:05 AM
Size
9 KB
Mime Type
text/x-diff
Expires
Thu, Feb 27, 9:05 AM (1 h, 1 m)
Engine
blob
Format
Raw Data
Handle
576804
Attached To
D165: INP-1510 Allow rotation of "Session Log" and "Changes Log"
D165.id468.diff
View Options
Index: branches/5.3.x/core/install/english.lang
===================================================================
--- branches/5.3.x/core/install/english.lang
+++ branches/5.3.x/core/install/english.lang
@@ -208,6 +208,7 @@
<PHRASE Label="la_config_SessionBrowserSignatureCheck" Module="Core" Type="1">U2Vzc2lvbiBTZWN1cml0eSBDaGVjayBiYXNlZCBvbiBCcm93c2VyIFNpZ25hdHVyZQ==</PHRASE>
<PHRASE Label="la_config_SessionCookieDomains" Module="Core" Type="1">U2Vzc2lvbiBDb29raWUgRG9tYWlucyAoc2luZ2xlIGRvbWFpbiBwZXIgbGluZSk=</PHRASE>
<PHRASE Label="la_config_SessionIPAddressCheck" Module="Core" Type="1">U2Vzc2lvbiBTZWN1cml0eSBDaGVjayBiYXNlZCBvbiBJUA==</PHRASE>
+ <PHRASE Label="la_config_SessionLogRotationInterval" Module="Core" Type="1">S2VlcCAiU2Vzc2lvbiBMb2ciIGZvcg==</PHRASE>
<PHRASE Label="la_config_SiteNameSubTitle" Module="Core" Type="1">V2Vic2l0ZSBTdWJ0aXRsZQ==</PHRASE>
<PHRASE Label="la_config_site_zone" Module="Core" Type="1">VGltZSB6b25lIG9mIHRoZSBzaXRl</PHRASE>
<PHRASE Label="la_config_SoftMaintenanceTemplate" Module="Core" Type="1" Hint="VGhpcyB0ZW1wbGF0ZSB3aWxsIGJlIHNob3duIHRvIHRoZSBGcm9udCBFbmQgdXNlcnMgd2hlbiBTb2Z0IE1haW50ZW5hbmNlIG1vZGUgaXMgYWN0aXZlLg==">VGVtcGxhdGUgZm9yIFNvZnQgTWFpbnRlbmFuY2U=</PHRASE>
@@ -923,6 +924,7 @@
<PHRASE Label="la_opt_Failed" Module="Core" Type="1">RmFpbGVk</PHRASE>
<PHRASE Label="la_opt_February" Module="Core" Type="1">RmVicnVhcnk=</PHRASE>
<PHRASE Label="la_opt_FirstName" Module="Core" Type="1">Rmlyc3QgTmFtZQ==</PHRASE>
+ <PHRASE Label="la_opt_FiveYears" Module="Core" Type="1">NSB5ZWFycw==</PHRASE>
<PHRASE Label="la_opt_Friday" Module="Core" Type="1">RnJpZGF5</PHRASE>
<PHRASE Label="la_opt_Group" Module="Core" Type="1">R3JvdXA=</PHRASE>
<PHRASE Label="la_opt_GuestsOnly" Module="Core" Type="1">R3Vlc3RzIE9ubHk=</PHRASE>
@@ -994,10 +996,12 @@
<PHRASE Label="la_opt_Tab" Module="Core" Type="1">VGFi</PHRASE>
<PHRASE Label="la_opt_Template" Module="Core" Type="1">VGVtcGxhdGU=</PHRASE>
<PHRASE Label="la_opt_ThreeMonths" Module="Core" Type="1">MyBtb250aHM=</PHRASE>
+ <PHRASE Label="la_opt_ThreeYears" Module="Core" Type="1">MyB5ZWFycw==</PHRASE>
<PHRASE Label="la_opt_Thursday" Module="Core" Type="1">VGh1cnNkYXk=</PHRASE>
<PHRASE Label="la_opt_Title" Module="Core" Type="1">VGl0bGU=</PHRASE>
<PHRASE Label="la_opt_Tuesday" Module="Core" Type="1">VHVlc2RheQ==</PHRASE>
<PHRASE Label="la_opt_TwoWeeks" Module="Core" Type="1">MiB3ZWVrcw==</PHRASE>
+ <PHRASE Label="la_opt_TwoYears" Module="Core" Type="1">MiB5ZWFycw==</PHRASE>
<PHRASE Label="la_opt_User" Module="Core" Type="1">VXNlcg==</PHRASE>
<PHRASE Label="la_opt_UserEmailActivation" Module="Core" Type="1">RW1haWwgQWN0aXZhdGlvbg==</PHRASE>
<PHRASE Label="la_opt_UserInstantRegistration" Module="Core" Type="1">SW1tZWRpYXRlIA==</PHRASE>
Index: branches/5.3.x/core/install/install_data.sql
===================================================================
--- branches/5.3.x/core/install/install_data.sql
+++ branches/5.3.x/core/install/install_data.sql
@@ -106,6 +106,7 @@
INSERT INTO SystemSettings VALUES(DEFAULT, 'EmailLogRotationInterval', '2419200', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsLogs', 'la_config_EmailLogRotationInterval', 'select', NULL, '86400=la_opt_OneDay||604800=la_opt_OneWeek||1209600=la_opt_TwoWeeks||2419200=la_opt_OneMonth||7257600=la_opt_ThreeMonths||29030400=la_opt_OneYear||-1=la_opt_EmailLogKeepForever', 65.02, 0, 0, 'hint:la_config_EmailLogRotationInterval');
INSERT INTO SystemSettings VALUES(DEFAULT, 'SystemLogRotationInterval', '2419200', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsLogs', 'la_config_SystemLogRotationInterval', 'select', NULL, '86400=la_opt_OneDay||604800=la_opt_OneWeek||1209600=la_opt_TwoWeeks||2419200=la_opt_OneMonth||7257600=la_opt_ThreeMonths||29030400=la_opt_OneYear||-1=la_opt_SystemLogKeepForever', 65.03, 0, 1, 'hint:la_config_SystemLogRotationInterval');
INSERT INTO SystemSettings VALUES(DEFAULT, 'SystemLogNotificationEmail', '', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsLogs', 'la_config_SystemLogNotificationEmail', 'text', 'a:5:{s:4:"type";s:6:"string";s:9:"formatter";s:10:"kFormatter";s:6:"regexp";s:85:"/^([-a-zA-Z0-9!\\#$%&*+\\/=?^_`{|}~.]+@[a-zA-Z0-9]{1}[-.a-zA-Z0-9_]*\\.[a-zA-Z]{2,6})$/i";s:10:"error_msgs";a:1:{s:14:"invalid_format";s:18:"!la_invalid_email!";}s:7:"default";s:0:"";}', NULL, 65.04, 0, 1, 'hint:la_config_SystemLogNotificationEmail');
+INSERT INTO SystemSettings VALUES(DEFAULT, 'SessionLogRotationInterval', '2629800', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsLogs', 'la_config_SessionLogRotationInterval', 'select', '', '86400=la_opt_OneDay||604800=la_opt_OneWeek||1209600=la_opt_TwoWeeks||2629800=la_opt_OneMonth||7889400=la_opt_ThreeMonths||31557600=la_opt_OneYear||63115200=la_opt_TwoYears||94672800=la_opt_ThreeYears||157788000=la_opt_FiveYears||-1=la_opt_EmailLogKeepForever', 65.05, 0, 1, NULL);
INSERT INTO SystemSettings VALUES(DEFAULT, 'CSVExportDelimiter', '1', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsCSVExport', 'la_config_CSVExportDelimiter', 'select', NULL, '0=la_opt_Tab||1=la_opt_Comma||2=la_opt_Semicolon||3=la_opt_Space||4=la_opt_Colon', 70.01, 0, 1, NULL);
INSERT INTO SystemSettings VALUES(DEFAULT, 'CSVExportEnclosure', '0', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsCSVExport', 'la_config_CSVExportEnclosure', 'radio', NULL, '0=la_Doublequotes||1=la_Quotes', 70.02, 0, 1, NULL);
INSERT INTO SystemSettings VALUES(DEFAULT, 'CSVExportSeparator', '0', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsCSVExport', 'la_config_CSVExportSeparator', 'radio', NULL, '0=la_Linux||1=la_Windows', 70.03, 0, 1, NULL);
Index: branches/5.3.x/core/install/upgrades.sql
===================================================================
--- branches/5.3.x/core/install/upgrades.sql
+++ branches/5.3.x/core/install/upgrades.sql
@@ -3037,3 +3037,5 @@
ALTER TABLE SiteDomains
ADD `Status` TINYINT NOT NULL DEFAULT '1' AFTER Priority,
ADD INDEX (`Status`);
+
+INSERT INTO SystemSettings VALUES(DEFAULT, 'SessionLogRotationInterval', '2629800', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsLogs', 'la_config_SessionLogRotationInterval', 'select', '', '86400=la_opt_OneDay||604800=la_opt_OneWeek||1209600=la_opt_TwoWeeks||2629800=la_opt_OneMonth||7889400=la_opt_ThreeMonths||31557600=la_opt_OneYear||63115200=la_opt_TwoYears||94672800=la_opt_ThreeYears||157788000=la_opt_FiveYears||-1=la_opt_EmailLogKeepForever', 65.05, 0, 1, NULL);
Index: branches/5.3.x/core/units/logs/session_logs/session_log_eh.php
===================================================================
--- branches/5.3.x/core/units/logs/session_logs/session_log_eh.php
+++ branches/5.3.x/core/units/logs/session_logs/session_log_eh.php
@@ -129,4 +129,72 @@
}
}
- }
\ No newline at end of file
+ /**
+ * [SCHEDULED TASK] Will remove old session logs
+ *
+ * @param kEvent $event Event.
+ *
+ * @return void
+ */
+ protected function OnRotate(kEvent $event)
+ {
+ $rotation_interval = (int)$this->Application->ConfigValue('SessionLogRotationInterval');
+
+ if ( $rotation_interval === -1 ) {
+ // Forever.
+ return;
+ }
+
+ $session_log_temp_handler = $this->getTempTablesHandler($event->getPrefixSpecial(), $event);
+ $change_log_temp_handler = $this->getTempTablesHandler('change-log', $event);
+
+ $limit = 100;
+ $session_log_config = $event->getUnitConfig();
+ $session_log_select_sql = ' SELECT ' . $session_log_config->getIDField() . '
+ FROM ' . $session_log_config->getTableName() . '
+ WHERE ' . TIMENOW . ' - SessionEnd > ' . $rotation_interval . '
+ LIMIT 0,' . $limit;
+ $change_log_config = $this->Application->getUnitConfig('change-log');
+
+ do {
+ $session_log_ids = $this->Conn->GetCol($session_log_select_sql);
+
+ if ( !$session_log_ids ) {
+ break;
+ }
+
+ $change_log_select_sql = ' SELECT ' . $change_log_config->getIDField() . '
+ FROM ' . $change_log_config->getTableName() . '
+ WHERE SessionLogId IN (' . implode(',', $session_log_ids) . ')
+ LIMIT 0,' . $limit;
+
+ do {
+ $change_log_ids = $this->Conn->GetCol($change_log_select_sql);
+
+ if ( $change_log_ids ) {
+ $change_log_temp_handler->DeleteItems('change-log', '', $change_log_ids);
+ }
+ } while ( count($change_log_ids) == $limit );
+
+ $session_log_temp_handler->DeleteItems($event->Prefix, $event->Special, $session_log_ids);
+ } while ( count($session_log_ids) == $limit );
+ }
+
+ /**
+ * Get temp tables handler instance.
+ *
+ * @param string $prefix_special Prefix, special.
+ * @param kEvent $event Event.
+ *
+ * @return kTempTablesHandler
+ */
+ public function getTempTablesHandler($prefix_special, kEvent $event)
+ {
+ return $this->Application->recallObject(
+ $prefix_special . '_TempHandler',
+ 'kTempTablesHandler',
+ array('parent_event' => $event)
+ );
+ }
+
+ }
Index: branches/5.3.x/core/units/logs/session_logs/session_logs_config.php
===================================================================
--- branches/5.3.x/core/units/logs/session_logs/session_logs_config.php
+++ branches/5.3.x/core/units/logs/session_logs/session_logs_config.php
@@ -55,6 +55,10 @@
5 => 'mode',
),
+ 'ScheduledTasks' => array(
+ 'rotate_session_logs' => array('EventName' => 'OnRotate', 'RunSchedule' => '0 0 * * *'),
+ ),
+
'IDField' => 'SessionLogId',
'StatusField' => Array ('Status'),
@@ -150,4 +154,4 @@
),
),
),
-);
\ No newline at end of file
+);
Event Timeline
Log In to Comment