AlephNull has uploaded a new change for review.
https://gerrit.wikimedia.org/r/65301
Change subject: (bug 43571) Fixing fatal error when duplicating VIEWs in MySQL
......................................................................
(bug 43571) Fixing fatal error when duplicating VIEWs in MySQL
Change-Id: I8650baa4b721fe69ea3e1d557dd76745c0c7754e
---
M includes/db/Database.php
M includes/db/DatabaseMysql.php
M tests/phpunit/MediaWikiTestCase.php
3 files changed, 73 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/01/65301/1
diff --git a/includes/db/Database.php b/includes/db/Database.php
index 799e168..14ccfc4 100644
--- a/includes/db/Database.php
+++ b/includes/db/Database.php
@@ -3208,6 +3208,27 @@
}
/**
+ * Lists all the VIEWs in the database
+ *
+ * @param string $prefix Only show VIEWs with this prefix, eg.
unit_test_
+ * @param string $fname Name of calling function
+ * @throws MWException
+ */
+ public function listViews( $prefix = null, $fname = __METHOD__ ) {
+ throw new MWException( 'DatabaseBase::listViews is not
implemented in descendant class' );
+ }
+
+ /**
+ * Differentiates between a TABLE and a VIEW
+ *
+ * @param $name string: Name of the database-structure to test.
+ * @throws MWException
+ */
+ public function isView( $name ) {
+ throw new MWException( 'DatabaseBase::isView is not implemented
in descendant class' );
+ }
+
+ /**
* Convert a timestamp in one of the formats accepted by wfTimestamp()
* to the format used for inserting into timestamp fields in this DBMS.
*
@@ -3748,4 +3769,5 @@
trigger_error( "Transaction idle or pre-commit
callbacks still pending." ); // sanity
}
}
+
}
diff --git a/includes/db/DatabaseMysql.php b/includes/db/DatabaseMysql.php
index ca5a2b4..ca70e0d 100644
--- a/includes/db/DatabaseMysql.php
+++ b/includes/db/DatabaseMysql.php
@@ -917,6 +917,51 @@
return $endArray;
}
+
+ /**
+ * Lists all the VIEWs in the database
+ *
+ * @param string $prefix Only show VIEWs with this prefix, eg.
unit_test_
+ * @param string $fname Name of calling function
+ * @return array
+ */
+ public function listViews( $prefix = null, $fname = __METHOD__ ) {
+
+ // The name of the column containing the name of the VIEW
+ $propertyName = 'Tables_in_' . $this->mDBname;
+
+ // Query for the VIEWS
+ $result = $this->query( 'SHOW FULL TABLES WHERE TABLE_TYPE LIKE
"VIEW"' );
+
+ // Pull out the names
+ $views = array();
+ foreach ( $result as $row ) {
+ $vars = get_object_vars($row);
+ if ( !isSet($vars[$propertyName]) ) {
+ continue;
+ }
+ $view = $vars[$propertyName];
+ if ( !$prefix || strpos( $view, $view ) === 0 ) {
+ array_push( $views, $view );
+ }
+ }
+ return $views;
+ }
+
+ /**
+ * Differentiates between a TABLE and a VIEW.
+ *
+ * @param $name string: Name of the TABLE/VIEW to test
+ * @return bool
+ */
+ public function isView( $name ) {
+ if ( !$name ) {
+ return false;
+ }
+ return in_array( $name, $this->listViews() );
+ }
+
+
/**
* @param $tableName
* @param $fName string
@@ -956,6 +1001,8 @@
return $status;
}
+
+
}
/**
diff --git a/tests/phpunit/MediaWikiTestCase.php
b/tests/phpunit/MediaWikiTestCase.php
index 25ba29e..b2f2888 100644
--- a/tests/phpunit/MediaWikiTestCase.php
+++ b/tests/phpunit/MediaWikiTestCase.php
@@ -536,7 +536,10 @@
public static function listTables( $db ) {
global $wgDBprefix;
- $tables = $db->listTables( $wgDBprefix, __METHOD__ );
+ $tablesAndViews = $db->listTables( $wgDBprefix, __METHOD__ );
+ $views = $db->listViews( $wgDBprefix, __METHOD__ );
+
+ $tables = array_diff( $tablesAndViews, $views );
$tables = array_map( array( __CLASS__, 'unprefixTable' ),
$tables );
// Don't duplicate test tables from the previous fataled run
--
To view, visit https://gerrit.wikimedia.org/r/65301
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8650baa4b721fe69ea3e1d557dd76745c0c7754e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: AlephNull <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits