Page MenuHomeIn-Portal Phabricator

D503.id1303.diff
No OneTemporary

File Metadata

Created
Sun, Feb 23, 1:56 PM

D503.id1303.diff

Index: core/install/install_schema.sql
===================================================================
--- core/install/install_schema.sql
+++ core/install/install_schema.sql
@@ -684,6 +684,10 @@
Changes text,
MasterPrefix varchar(255) NOT NULL DEFAULT '',
MasterId bigint(20) 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 '',
PRIMARY KEY (ChangeLogId),
KEY PortalUserId (PortalUserId),
KEY SessionLogId (SessionLogId),
Index: core/install/upgrades.php
===================================================================
--- core/install/upgrades.php
+++ core/install/upgrades.php
@@ -2370,6 +2370,7 @@
if ( $mode === 'after' ) {
$this->migrateExportUserPresets();
$this->changeSessionKeyFormat();
+ $this->migrateChangeLogsUserFields();
}
if ( $mode != 'before' ) {
@@ -2548,6 +2549,23 @@
}
/**
+ * Copy necessary user data to the new ChangeLogs table columns
+ *
+ * @return void
+ */
+ protected function migrateChangeLogsUserFields()
+ {
+ $sql = 'UPDATE ' . TABLE_PREFIX . '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';
+ $this->Conn->Query($sql);
+ }
+
+ /**
* Replaces session key with session id in the given table name fragment.
*
* @param string $table_name_fragment Table name fragment.
Index: core/install/upgrades.sql
===================================================================
--- core/install/upgrades.sql
+++ core/install/upgrades.sql
@@ -2986,3 +2986,9 @@
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 UserLogin varchar(255) NOT NULL DEFAULT '';
+ALTER TABLE ChangeLogs ADD UserFirstName varchar(255) NOT NULL DEFAULT '';
+ALTER TABLE ChangeLogs ADD UserLastName varchar(255) NOT NULL DEFAULT '';
+ALTER TABLE ChangeLogs ADD UserEmail varchar(255) NOT NULL DEFAULT '';
+UPDATE ChangeLogs SET UserLogin = 'root' WHERE PortalUserId = -1;
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,60 @@
}
/**
+ * Provides additional fields for change log record
+ *
+ * @param integer $session_log_id Ssession 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',
+ 'UserFirstName' => '',
+ 'UserLastName' => '',
+ 'UserEmail' => '',
+ );
+ $cache[$user_id] = array_merge($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 ) {
+ $user_data = array(
+ 'UserLogin' => '',
+ 'UserFirstName' => '',
+ 'UserLastName' => '',
+ 'UserEmail' => '',
+ );
+ }
+
+ $cache[$user_id] = array_merge($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