Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F776022
D503.id1313.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
Thu, Feb 6, 4:38 PM
Size
5 KB
Mime Type
text/x-diff
Expires
Fri, Feb 7, 4:38 PM (7 m, 10 s)
Engine
blob
Format
Raw Data
Handle
558509
Attached To
D503: INP-1893 Denormalize "ChangeLogs" database table
D503.id1313.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/units/helpers/ChangeLogHelper.php
===================================================================
--- core/units/helpers/ChangeLogHelper.php
+++ core/units/helpers/ChangeLogHelper.php
@@ -279,10 +279,8 @@
return;
}
- $add_fields = array(
- 'PortalUserId' => $this->Application->RecallVar('user_id'),
- 'SessionLogId' => $session_log_id,
- );
+ $user_id = $this->Application->RecallVar('user_id');
+ $add_fields = $this->getAddFields($session_log_id, $user_id);
$change_log_table = $this->Application->getUnitOption('change-log', 'TableName');
@@ -301,6 +299,59 @@
}
/**
+ * Provides additional fields for change log record
+ *
+ * @param integer $session_log_id Session Log ID.
+ * @param integer $user_id User ID.
+ *
+ * @return array
+ */
+ protected function getAddFields($session_log_id, $user_id)
+ {
+ static $cache = array();
+
+ $cache_key = $session_log_id . ':' . $user_id;
+
+ if ( isset($cache[$cache_key]) ) {
+ return $cache[$cache_key];
+ }
+
+ $cache[$cache_key] = array(
+ 'PortalUserId' => $user_id,
+ 'SessionLogId' => $session_log_id,
+ );
+ $cache[$cache_key] += $this->getUserFields($user_id);
+
+ return $cache[$cache_key];
+ }
+
+ /**
+ * Returns user fields.
+ *
+ * @param integer $user_id User ID.
+ *
+ * @return array
+ */
+ protected function getUserFields($user_id)
+ {
+ if ( $user_id == USER_ROOT ) {
+ return array(
+ 'UserLogin' => 'root',
+ );
+ }
+
+ $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);
+
+ return $user_data !== false ? $user_data : array();
+ }
+
+ /**
* Returns change log session variable name.
*
* @param string $main_prefix Main prefix.
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,20 +82,15 @@
)
),
- '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 (
'ChangeLogId' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0),
'PortalUserId' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0),
+ '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' => ''),
'SessionLogId' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0),
'Action' => Array (
'type' => 'int', 'formatter' => 'kOptionsFormatter',
@@ -126,13 +120,6 @@
'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' => ''),
- ),
-
'Grids' => Array (
'Default' => Array (
'Icons' => Array ('default' => 'icon16_item.png'),
Event Timeline
Log In to Comment