From: Aaron Schulz Date: Tue, 20 Jun 2017 23:29:56 +0000 (-0700) Subject: Factor out new qualifiedTableComponents() Database method X-Git-Tag: 1.31.0-rc.0~2935^2 X-Git-Url: http://git.cyclocoop.org/%22.%24image2.%22?a=commitdiff_plain;h=0b51d17dbc8b90bbb4fdfa19f2b28a2778c17f77;p=lhc%2Fweb%2Fwiklou.git Factor out new qualifiedTableComponents() Database method Change-Id: Ib453a5a8e0cf8bb1b77e65eb6f9569819d4eb5b2 --- diff --git a/includes/libs/rdbms/database/Database.php b/includes/libs/rdbms/database/Database.php index 9e91592a52..afeffb3048 100644 --- a/includes/libs/rdbms/database/Database.php +++ b/includes/libs/rdbms/database/Database.php @@ -1802,8 +1802,31 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware } # Split database and table into proper variables. - # We reverse the explode so that database.table and table both output - # the correct table. + list( $database, $schema, $prefix, $table ) = $this->qualifiedTableComponents( $name ); + + # Quote $table and apply the prefix if not quoted. + # $tableName might be empty if this is called from Database::replaceVars() + $tableName = "{$prefix}{$table}"; + if ( $format === 'quoted' + && !$this->isQuotedIdentifier( $tableName ) + && $tableName !== '' + ) { + $tableName = $this->addIdentifierQuotes( $tableName ); + } + + # Quote $schema and $database and merge them with the table name if needed + $tableName = $this->prependDatabaseOrSchema( $schema, $tableName, $format ); + $tableName = $this->prependDatabaseOrSchema( $database, $tableName, $format ); + + return $tableName; + } + + /** + * @param string $name Table name + * @return array (DB name, schema name, table prefix, table name) + */ + protected function qualifiedTableComponents( $name ) { + # We reverse the explode so that database.table and table both output the correct table. $dbDetails = explode( '.', $name, 3 ); if ( count( $dbDetails ) == 3 ) { list( $database, $schema, $table ) = $dbDetails; @@ -1833,21 +1856,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware } } - # Quote $table and apply the prefix if not quoted. - # $tableName might be empty if this is called from Database::replaceVars() - $tableName = "{$prefix}{$table}"; - if ( $format === 'quoted' - && !$this->isQuotedIdentifier( $tableName ) - && $tableName !== '' - ) { - $tableName = $this->addIdentifierQuotes( $tableName ); - } - - # Quote $schema and $database and merge them with the table name if needed - $tableName = $this->prependDatabaseOrSchema( $schema, $tableName, $format ); - $tableName = $this->prependDatabaseOrSchema( $database, $tableName, $format ); - - return $tableName; + return [ $database, $schema, $prefix, $table ]; } /**