Make the indexName functions more obviously laid out
[lhc/web/wiklou.git] / includes / libs / rdbms / database / DatabaseMysqlBase.php
index 61ba498..4b3a644 100644 (file)
@@ -23,6 +23,7 @@
 use Wikimedia\Rdbms\DBMasterPos;
 use Wikimedia\Rdbms\MySQLMasterPos;
 use Wikimedia\Rdbms\MySQLField;
+use Wikimedia\Rdbms\ResultWrapper;
 
 /**
  * Database abstraction object for MySQL.
@@ -820,7 +821,8 @@ abstract class DatabaseMysqlBase extends Database {
 
                $row = $res ? $this->fetchRow( $res ) : false;
                if ( !$row ) {
-                       throw new DBExpectedError( $this, "Failed to query MASTER_POS_WAIT()" );
+                       throw new DBExpectedError( $this,
+                               "MASTER_POS_WAIT() or MASTER_GTID_WAIT() failed: {$this->lastError()}" );
                }
 
                // Result can be NULL (error), -1 (timeout), or 0+ per the MySQL manual
@@ -1333,4 +1335,25 @@ abstract class DatabaseMysqlBase extends Database {
        public function isView( $name, $prefix = null ) {
                return in_array( $name, $this->listViews( $prefix ) );
        }
+
+       /**
+        * Allows for index remapping in queries where this is not consistent across DBMS
+        *
+        * @param string $index
+        * @return string
+        */
+       protected function indexName( $index ) {
+               // Backwards-compatibility hack
+               $renamed = [
+                       'ar_usertext_timestamp' => 'usertext_timestamp',
+                       'un_user_id' => 'user_id',
+                       'un_user_ip' => 'user_ip',
+               ];
+
+               if ( isset( $renamed[$index] ) ) {
+                       return $renamed[$index];
+               } else {
+                       return $index;
+               }
+       }
 }