Merge "Postgres updater fixes to make update.php able to run"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Sat, 29 Oct 2016 01:31:01 +0000 (01:31 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Sat, 29 Oct 2016 01:31:01 +0000 (01:31 +0000)
1  2 
includes/libs/rdbms/database/DatabasePostgres.php

@@@ -152,6 -152,8 +152,8 @@@ class DatabasePostgres extends Databas
                }
  
                $this->determineCoreSchema( $this->mSchema );
+               // The schema to be used is now in the search path; no need for explicit qualification
+               $this->mSchema = null;
  
                return $this->mConn;
        }
@@@ -768,19 -770,33 +770,33 @@@ __INDEXATTR__
        }
  
        function tableName( $name, $format = 'quoted' ) {
-               # Replace reserved words with better ones
-               switch ( $name ) {
-                       case 'user':
-                               return $this->realTableName( 'mwuser', $format );
-                       case 'text':
-                               return $this->realTableName( 'pagecontent', $format );
-                       default:
-                               return $this->realTableName( $name, $format );
+               // Replace reserved words with better ones
+               $name = $this->remappedTableName( $name );
+               return parent::tableName( $name, $format );
+       }
+       /**
+        * @param string $name
+        * @return string Value of $name or remapped name if $name is a reserved keyword
+        * @TODO: dependency inject these...
+        */
+       public function remappedTableName( $name ) {
+               if ( $name === 'user' ) {
+                       return 'mwuser';
+               } elseif ( $name === 'text' ) {
+                       return 'pagecontent';
                }
+               return $name;
        }
  
-       /* Don't cheat on installer */
-       function realTableName( $name, $format = 'quoted' ) {
+       /**
+        * @param string $name
+        * @param string $format
+        * @return string Qualified and encoded (if requested) table name
+        */
+       public function realTableName( $name, $format = 'quoted' ) {
                return parent::tableName( $name, $format );
        }
  
                if ( $schema === false ) {
                        $schema = $this->getCoreSchema();
                }
-               $table = $this->realTableName( $table, 'raw' );
                $etable = $this->addQuotes( $table );
                $eschema = $this->addQuotes( $schema );
                $sql = "SELECT 1 FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n "
         * @return bool
         */
        function schemaExists( $schema ) {
 -              $exists = $this->selectField( '"pg_catalog"."pg_namespace"', 1,
 -                      [ 'nspname' => $schema ], __METHOD__ );
 +              if ( !strlen( $schema ) ) {
 +                      return false; // short-circuit
 +              }
 +
 +              $exists = $this->selectField(
 +                      '"pg_catalog"."pg_namespace"', 1, [ 'nspname' => $schema ], __METHOD__ );
  
                return (bool)$exists;
        }