+ /**
+ * Clones the External Store database(s) for testing
+ *
+ * @param string $testPrefix Prefix for test tables
+ */
+ protected static function setupExternalStoreTestDBs( $testPrefix ) {
+ $connections = self::getExternalStoreDatabaseConnections();
+ foreach ( $connections as $dbw ) {
+ // Hack: cloneTableStructure sets $wgDBprefix to the unit test
+ // prefix,. Even though listTables now uses tablePrefix, that
+ // itself is populated from $wgDBprefix by default.
+
+ // We have to set it back, or we won't find the original 'blobs'
+ // table to copy.
+
+ $dbw->tablePrefix( self::$oldTablePrefix );
+ self::setupDatabaseWithTestPrefix( $dbw, $testPrefix );
+ }
+ }
+
+ /**
+ * Gets master database connections for all of the ExternalStoreDB
+ * stores configured in $wgDefaultExternalStore.
+ *
+ * @return array Array of DatabaseBase master connections
+ */
+
+ protected static function getExternalStoreDatabaseConnections() {
+ global $wgDefaultExternalStore;
+
+ $externalStoreDB = ExternalStore::getStoreObject( 'DB' );
+ $defaultArray = (array) $wgDefaultExternalStore;
+ $dbws = [];
+ foreach ( $defaultArray as $url ) {
+ if ( strpos( $url, 'DB://' ) === 0 ) {
+ list( $proto, $cluster ) = explode( '://', $url, 2 );
+ $dbw = $externalStoreDB->getMaster( $cluster );
+ $dbws[] = $dbw;
+ }
+ }
+
+ return $dbws;
+ }
+
+ /**
+ * Check whether ExternalStoreDB is being used
+ *
+ * @return bool True if it's being used
+ */
+ protected static function isUsingExternalStoreDB() {
+ global $wgDefaultExternalStore;
+ if ( !$wgDefaultExternalStore ) {
+ return false;
+ }
+
+ $defaultArray = (array) $wgDefaultExternalStore;
+ foreach ( $defaultArray as $url ) {
+ if ( strpos( $url, 'DB://' ) === 0 ) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+