r79094 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79093‎ | r79094 | r79095 >
Date:01:19, 28 December 2010
Author:demon
Status:ok
Tags:
Comment:
Followup r79093: Move DROP TABLE code to Database classes and properly rename back to original table prefix in destroyDatabase()
Modified paths:
  • /trunk/phase3/includes/db/CloneDatabase.php (modified) (history)
  • /trunk/phase3/includes/db/Database.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseMysql.php (modified) (history)
  • /trunk/phase3/tests/parser/parserTest.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/parser/parserTest.inc
@@ -54,6 +54,12 @@
5555 private $db;
5656
5757 /**
 58+ * Database clone helper
 59+ * @var CloneDatabase
 60+ */
 61+ private $dbClone;
 62+
 63+ /**
5864 * string $oldTablePrefix Original table prefix
5965 */
6066 private $oldTablePrefix;
@@ -852,7 +858,7 @@
853859 }
854860 $this->teardownUploadDir( $this->uploadDir );
855861
856 - $this->db->tablePrefix( $this->oldTablePrefix );
 862+ $this->dbClone->destroy();
857863 $this->databaseSetupDone = false;
858864
859865 if ( $this->useTemporaryTables ) {
Index: trunk/phase3/includes/db/DatabaseMysql.php
@@ -531,6 +531,13 @@
532532 $this->query( $query, $fname );
533533 }
534534
 535+ public function dropTable( $tableName, $fName = 'DatabaseMysql::dropTable' ) {
 536+ if( !$this->tableExists( $tableName ) ) {
 537+ return false;
 538+ }
 539+ return $this->query( "DROP TABLE IF EXISTS " . $this->tableName( $tableName ), $fName );
 540+ }
 541+
535542 }
536543
537544 /**
Index: trunk/phase3/includes/db/Database.php
@@ -2640,6 +2640,20 @@
26412641 }
26422642
26432643 /**
 2644+ * Delete a table
 2645+ */
 2646+ public function dropTable( $tableName, $method = 'DatabaseBase::dropTable' ) {
 2647+ if( !$this->tableExists( $tableName, $method ) ) {
 2648+ return false;
 2649+ }
 2650+ $sql = "DROP TABLE " . $this->tableName( $tableName );
 2651+ if( $this->cascadingDeletes() ) {
 2652+ $sql .= " CASCADE";
 2653+ }
 2654+ return $this->query( $sql );
 2655+ }
 2656+
 2657+ /**
26442658 * Get search engine class. All subclasses of this need to implement this
26452659 * if they wish to use searching.
26462660 *
Index: trunk/phase3/includes/db/CloneDatabase.php
@@ -95,16 +95,7 @@
9696 $newTableName = $this->db->tableName( $tbl );
9797
9898 if( $this->dropCurrentTables ) {
99 - if ( $this->db->getType() == 'mysql' && $this->db->tableExists( $tbl ) ) {
100 - $this->db->query( "DROP TABLE IF EXISTS $newTableName" );
101 - } elseif ( in_array( $this->db->getType(), array( 'postgres', 'oracle' ) ) ) {
102 - /* DROPs wouldn't work due to Foreign Key Constraints (bug 14990, r58669)
103 - * Use "DROP TABLE IF EXISTS $newTableName CASCADE" for postgres? That
104 - * syntax would also work for mysql.
105 - */
106 - } elseif ( $this->db->tableExists( $tbl ) ) {
107 - $this->db->query( "DROP TABLE $newTableName" );
108 - }
 99+ $this->db->dropTable( $newTableName, __METHOD__ );
109100 }
110101
111102 # Create new table
@@ -113,6 +104,20 @@
114105 }
115106
116107 /**
 108+ * Change the prefix back to the original.
 109+ * @param $dropTables bool Optionally drop the tables we created
 110+ */
 111+ public function destroy( $dropTables = false ) {
 112+ if( $dropTables ) {
 113+ $this->changePrefix( $this->newTablePrefix );
 114+ foreach( $this->tablesToClone as $tbl ) {
 115+ $this->db->dropTable( $tbl );
 116+ }
 117+ }
 118+ $this->changePrefix( $this->oldTablePrefix );
 119+ }
 120+
 121+ /**
117122 * Change the table prefix on all open DB connections/
118123 */
119124 protected function changePrefix( $prefix ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r79095Nitpick r79094: fix var namesdemon01:22, 28 December 2010
r79138Followup to r79094, PG handles temporary tables correctly so you dont need to...overlordq22:26, 28 December 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r79093Refactor table cloning code into its own class so it can maybe be used by thi...demon00:44, 28 December 2010

Status & tagging log