Merge "tests: stop updating the search engine"
[lhc/web/wiklou.git] / includes / libs / rdbms / database / Database.php
index ba63432..3d35d76 100644 (file)
@@ -898,7 +898,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
 
                if ( false === $ret ) {
                        # Deadlocks cause the entire transaction to abort, not just the statement.
-                       # http://dev.mysql.com/doc/refman/5.7/en/innodb-error-handling.html
+                       # https://dev.mysql.com/doc/refman/5.7/en/innodb-error-handling.html
                        # https://www.postgresql.org/docs/9.1/static/explicit-locking.html
                        if ( $this->wasDeadlock() ) {
                                if ( $this->explicitTrxActive() || $priorWritesPending ) {
@@ -1721,9 +1721,9 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                } elseif ( count( $dbDetails ) == 2 ) {
                        list( $database, $table ) = $dbDetails;
                        # We don't want any prefix added in this case
+                       $prefix = '';
                        # In dbs that support it, $database may actually be the schema
                        # but that doesn't affect any of the functionality here
-                       $prefix = '';
                        $schema = '';
                } else {
                        list( $table ) = $dbDetails;
@@ -1745,29 +1745,35 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                # Quote $table and apply the prefix if not quoted.
                # $tableName might be empty if this is called from Database::replaceVars()
                $tableName = "{$prefix}{$table}";
-               if ( $format == 'quoted'
-                       && !$this->isQuotedIdentifier( $tableName ) && $tableName !== ''
+               if ( $format === 'quoted'
+                       && !$this->isQuotedIdentifier( $tableName )
+                       && $tableName !== ''
                ) {
                        $tableName = $this->addIdentifierQuotes( $tableName );
                }
 
-               # Quote $schema and merge it with the table name if needed
-               if ( strlen( $schema ) ) {
-                       if ( $format == 'quoted' && !$this->isQuotedIdentifier( $schema ) ) {
-                               $schema = $this->addIdentifierQuotes( $schema );
-                       }
-                       $tableName = $schema . '.' . $tableName;
-               }
+               # Quote $schema and $database and merge them with the table name if needed
+               $tableName = $this->prependDatabaseOrSchema( $schema, $tableName, $format );
+               $tableName = $this->prependDatabaseOrSchema( $database, $tableName, $format );
+
+               return $tableName;
+       }
 
-               # Quote $database and merge it with the table name if needed
-               if ( $database !== '' ) {
-                       if ( $format == 'quoted' && !$this->isQuotedIdentifier( $database ) ) {
-                               $database = $this->addIdentifierQuotes( $database );
+       /**
+        * @param string|null $namespace Database or schema
+        * @param string $relation Name of table, view, sequence, etc...
+        * @param string $format One of (raw, quoted)
+        * @return string Relation name with quoted and merged $namespace as needed
+        */
+       private function prependDatabaseOrSchema( $namespace, $relation, $format ) {
+               if ( strlen( $namespace ) ) {
+                       if ( $format === 'quoted' && !$this->isQuotedIdentifier( $namespace ) ) {
+                               $namespace = $this->addIdentifierQuotes( $namespace );
                        }
-                       $tableName = $database . '.' . $tableName;
+                       $relation = $namespace . '.' . $relation;
                }
 
-               return $tableName;
+               return $relation;
        }
 
        public function tableNames() {