Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F802477
D503.id1306.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
Mon, Feb 24, 5:29 AM
Size
4 KB
Mime Type
text/x-diff
Expires
Tue, Feb 25, 5:29 AM (15 h, 56 m)
Engine
blob
Format
Raw Data
Handle
575391
Attached To
D503: INP-1893 Denormalize "ChangeLogs" database table
D503.id1306.diff
View Options
Index: core/install/install_schema.sql
===================================================================
--- core/install/install_schema.sql
+++ core/install/install_schema.sql
@@ -676,6 +676,10 @@
CREATE TABLE ChangeLogs (
ChangeLogId bigint(20) NOT NULL AUTO_INCREMENT,
PortalUserId int(11) NOT NULL DEFAULT '0',
+ UserLogin varchar(255) NOT NULL DEFAULT '',
+ UserFirstName varchar(255) NOT NULL DEFAULT '',
+ UserLastName varchar(255) NOT NULL DEFAULT '',
+ UserEmail varchar(255) NOT NULL DEFAULT '',
SessionLogId int(11) NOT NULL DEFAULT '0',
`Action` tinyint(4) NOT NULL DEFAULT '0',
OccuredOn int(11) DEFAULT NULL,
Index: core/install/upgrades.sql
===================================================================
--- core/install/upgrades.sql
+++ core/install/upgrades.sql
@@ -2986,3 +2986,15 @@
UPDATE UserSessionLogs SET SessionKey = SessionId;
ALTER TABLE CurlLog CHANGE `SessionKey` `SessionKey` char(64) NOT NULL DEFAULT '';
ALTER TABLE SystemLog CHANGE `LogSessionKey` `LogSessionKey` char(64) NOT NULL DEFAULT '';
+
+ALTER TABLE ChangeLogs ADD UserEmail varchar(255) NOT NULL DEFAULT '' AFTER PortalUserId;
+ALTER TABLE ChangeLogs ADD UserLastName varchar(255) NOT NULL DEFAULT '' AFTER PortalUserId;
+ALTER TABLE ChangeLogs ADD UserFirstName varchar(255) NOT NULL DEFAULT '' AFTER PortalUserId;
+ALTER TABLE ChangeLogs ADD UserLogin varchar(255) NOT NULL DEFAULT '' AFTER PortalUserId;
+UPDATE ChangeLogs SET UserLogin = 'root' WHERE PortalUserId = -1;
+UPDATE ChangeLogs l
+JOIN <%TABLE_PREFIX%>Users u ON u.PortalUserId = l.PortalUserId
+SET l.UserLogin = u.Username,
+ l.UserFirstName = u.FirstName,
+ l.UserLastName = u.LastName,
+ l.UserEmail = u.Email;
Index: core/kernel/db/db_event_handler.php
===================================================================
--- core/kernel/db/db_event_handler.php
+++ core/kernel/db/db_event_handler.php
@@ -2061,10 +2061,7 @@
return ;
}
- $add_fields = Array (
- 'PortalUserId' => $this->Application->RecallVar('user_id'),
- 'SessionLogId' => $sesion_log_id,
- );
+ $add_fields = $this->getChangeLogAddFields($sesion_log_id);
$change_log_table = $this->Application->getUnitOption('change-log', 'TableName');
@@ -2083,6 +2080,50 @@
}
/**
+ * Provides additional fields for change log record
+ *
+ * @param integer $session_log_id Session Log ID.
+ *
+ * @return array
+ */
+ protected function getChangeLogAddFields($session_log_id)
+ {
+ static $cache = array();
+
+ $user_id = $this->Application->RecallVar('user_id');
+
+ if ( isset($cache[$user_id]) ) {
+ return $cache[$user_id];
+ }
+
+ $cache[$user_id] = array(
+ 'PortalUserId' => $user_id,
+ 'SessionLogId' => $session_log_id,
+ );
+
+ if ( $user_id == USER_ROOT ) {
+ $user_data = array(
+ 'UserLogin' => 'root',
+ );
+ $cache[$user_id] += $user_data;
+
+ return $cache[$user_id];
+ }
+
+ $sql = 'SELECT Username AS UserLogin, FirstName AS UserFirstName,
+ LastName AS UserLastName, Email AS UserEmail
+ FROM ' . TABLE_PREFIX . 'Users
+ WHERE PortalUserId = ' . $user_id;
+ $user_data = $this->Conn->GetRow($sql);
+
+ if ( $user_data !== false ) {
+ $cache[$user_id] += $user_data;
+ }
+
+ return $cache[$user_id];
+ }
+
+ /**
* Cancels edit
* Removes all temp tables and clears selected ids
*
Index: core/units/logs/change_logs/change_logs_config.php
===================================================================
--- core/units/logs/change_logs/change_logs_config.php
+++ core/units/logs/change_logs/change_logs_config.php
@@ -73,8 +73,7 @@
'ListSQLs' => Array (
'' => ' SELECT %1$s.* %2$s
- FROM %1$s
- LEFT JOIN '.TABLE_PREFIX.'Users AS u ON u.PortalUserId = %1$s.PortalUserId',
+ FROM %1$s',
),
'ListSortings' => Array (
@@ -83,15 +82,6 @@
)
),
- 'CalculatedFields' => Array (
- '' => Array (
- 'UserLogin' => 'IF(%1$s.PortalUserId = ' . USER_ROOT . ', \'root\', u.Username)',
- 'UserFirstName' => 'u.FirstName',
- 'UserLastName' => 'u.LastName',
- 'UserEmail' => 'u.Email',
- ),
- ),
-
'ForceDontLogChanges' => true,
'Fields' => Array (
@@ -124,13 +114,10 @@
'max_len' => 255, 'not_null' => 1, 'default' => ''
),
'MasterId' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0),
- ),
-
- 'VirtualFields' => Array (
- 'UserLogin' => Array ('type' => 'string', 'default' => ''),
- 'UserFirstName' => Array ('type' => 'string', 'default' => ''),
- 'UserLastName' => Array ('type' => 'string', 'default' => ''),
- 'UserEmail' => Array ('type' => 'string', 'default' => ''),
+ 'UserLogin' => array('type' => 'string', 'not_null' => 1, 'default' => ''),
+ 'UserFirstName' => array('type' => 'string', 'not_null' => 1, 'default' => ''),
+ 'UserLastName' => array('type' => 'string', 'not_null' => 1, 'default' => ''),
+ 'UserEmail' => array('type' => 'string', 'not_null' => 1, 'default' => ''),
),
'Grids' => Array (
Event Timeline
Log In to Comment