Merge "RecentChange: Use constants for the $noudp parameter of save()"
[lhc/web/wiklou.git] / includes / db / CloneDatabase.php
index 2b394b6..edb54ae 100644 (file)
@@ -2,9 +2,6 @@
 /**
  * Helper class for making a copy of the database, mostly for unit testing.
  *
- * Copyright © 2010 Chad Horohoe <chad@anyonecanedit.org>
- * https://www.mediawiki.org/
- *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
@@ -24,6 +21,7 @@
  * @ingroup Database
  */
 use MediaWiki\MediaWikiServices;
+use Wikimedia\Rdbms\IMaintainableDatabase;
 
 class CloneDatabase {
        /** @var string Table prefix for cloning */
@@ -45,8 +43,6 @@ class CloneDatabase {
        private $db;
 
        /**
-        * Constructor
-        *
         * @param IMaintainableDatabase $db A database subclass
         * @param array $tablesToClone An array of tables to clone, unprefixed
         * @param string $newTablePrefix Prefix to assign to the tables
@@ -54,12 +50,12 @@ class CloneDatabase {
         * @param bool $dropCurrentTables
         */
        public function __construct( IMaintainableDatabase $db, array $tablesToClone,
-               $newTablePrefix, $oldTablePrefix = '', $dropCurrentTables = true
+               $newTablePrefix, $oldTablePrefix = null, $dropCurrentTables = true
        ) {
                $this->db = $db;
                $this->tablesToClone = $tablesToClone;
                $this->newTablePrefix = $newTablePrefix;
-               $this->oldTablePrefix = $oldTablePrefix ? $oldTablePrefix : $this->db->tablePrefix();
+               $this->oldTablePrefix = $oldTablePrefix !== null ? $oldTablePrefix : $this->db->tablePrefix();
                $this->dropCurrentTables = $dropCurrentTables;
        }
 
@@ -79,7 +75,7 @@ class CloneDatabase {
                foreach ( $this->tablesToClone as $tbl ) {
                        if ( $wgSharedDB && in_array( $tbl, $wgSharedTables, true ) ) {
                                // Shared tables don't work properly when cloning due to
-                               // how prefixes are handled (bug 65654)
+                               // how prefixes are handled (T67654)
                                throw new RuntimeException( "Cannot clone shared table $tbl." );
                        }
                        # Clean up from previous aborted run.  So that table escaping
@@ -92,8 +88,10 @@ class CloneDatabase {
                        self::changePrefix( $this->newTablePrefix );
                        $newTableName = $this->db->tableName( $tbl, 'raw' );
 
+                       // Postgres: Temp tables are automatically deleted upon end of session
+                       //           Same Temp table name hides existing table for current session
                        if ( $this->dropCurrentTables
-                               && !in_array( $this->db->getType(), [ 'postgres', 'oracle' ] )
+                               && !in_array( $this->db->getType(), [ 'oracle' ] )
                        ) {
                                if ( $oldTableName === $newTableName ) {
                                        // Last ditch check to avoid data loss