Merge "Fix 'Tags' padding to keep it farther from the edge and document the source...
[lhc/web/wiklou.git] / includes / libs / rdbms / ChronologyProtector.php
index 099f172..b0dc10e 100644 (file)
@@ -43,6 +43,8 @@ class ChronologyProtector implements LoggerAwareInterface {
        protected $key;
        /** @var string Hash of client parameters */
        protected $clientId;
+       /** @var string[] Map of client information fields for logging */
+       protected $clientLogInfo;
        /** @var int|null Expected minimum index of the last write to the position store */
        protected $waitForPosIndex;
        /** @var int Max seconds to wait on positions to appear */
@@ -70,15 +72,24 @@ class ChronologyProtector implements LoggerAwareInterface {
 
        /**
         * @param BagOStuff $store
-        * @param array[] $client Map of (ip: <IP>, agent: <user-agent>)
+        * @param array[] $client Map of (ip: <IP>, agent: <user-agent> [, clientId: <hash>] )
         * @param int|null $posIndex Write counter index [optional]
         * @since 1.27
         */
        public function __construct( BagOStuff $store, array $client, $posIndex = null ) {
                $this->store = $store;
-               $this->clientId = md5( $client['ip'] . "\n" . $client['agent'] );
+               $this->clientId = isset( $client['clientId'] )
+                       ? $client['clientId']
+                       : md5( $client['ip'] . "\n" . $client['agent'] );
                $this->key = $store->makeGlobalKey( __CLASS__, $this->clientId, 'v2' );
                $this->waitForPosIndex = $posIndex;
+
+               $this->clientLogInfo = [
+                       'clientIP' => $client['ip'],
+                       'clientAgent' => $client['agent'],
+                       'clientId' => $client['clientId'] ?? null
+               ];
+
                $this->logger = new NullLogger();
        }
 
@@ -86,6 +97,14 @@ class ChronologyProtector implements LoggerAwareInterface {
                $this->logger = $logger;
        }
 
+       /**
+        * @return string Client ID hash
+        * @since 1.32
+        */
+       public function getClientId() {
+               return $this->clientId;
+       }
+
        /**
         * @param bool $enabled Whether to no-op all method calls
         * @since 1.27
@@ -298,7 +317,7 @@ class ChronologyProtector implements LoggerAwareInterface {
                                                [
                                                        'cpPosIndex' => $this->waitForPosIndex,
                                                        'waitTimeMs' => $waitedMs
-                                               ]
+                                               ] + $this->clientLogInfo
                                        );
                                } else {
                                        $this->logger->warning(
@@ -307,7 +326,7 @@ class ChronologyProtector implements LoggerAwareInterface {
                                                        'cpPosIndex' => $this->waitForPosIndex,
                                                        'indexReached' => $indexReached,
                                                        'waitTimeMs' => $waitedMs
-                                               ]
+                                               ] + $this->clientLogInfo
                                        );
                                }
                        } else {