X-Git-Url: https://git.cyclocoop.org/%27.%24link.%27?a=blobdiff_plain;f=includes%2Fdb%2FMWLBFactory.php;h=79f787dba4b73e26b5d7af782ab57cf9c02516e4;hb=c91a71c5f608675df6205a945bdc4be29d81d21e;hp=560733200f3082273c2d447f9be96a83a3fcb30e;hpb=d444b2c0b40087a87fb74914be89041b09d8593b;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/db/MWLBFactory.php b/includes/db/MWLBFactory.php index 560733200f..79f787dba4 100644 --- a/includes/db/MWLBFactory.php +++ b/includes/db/MWLBFactory.php @@ -23,6 +23,7 @@ use MediaWiki\Logger\LoggerFactory; use MediaWiki\MediaWikiServices; +use Wikimedia\Rdbms\LBFactory; use Wikimedia\Rdbms\DatabaseDomain; /** @@ -30,6 +31,10 @@ use Wikimedia\Rdbms\DatabaseDomain; * @ingroup Database */ abstract class MWLBFactory { + + /** @var array Cache of already-logged deprecation messages */ + private static $loggedDeprecations = []; + /** * @param array $lbConf Config for LBFactory::__construct() * @param Config $mainConfig Main config object from MediaWikiServices @@ -56,6 +61,7 @@ abstract class MWLBFactory { 'connLogger' => LoggerFactory::getInstance( 'DBConnection' ), 'perfLogger' => LoggerFactory::getInstance( 'DBPerformance' ), 'errorLogger' => [ MWExceptionHandler::class, 'logException' ], + 'deprecationLogger' => [ static::class, 'logDeprecation' ], 'cliMode' => $wgCommandLineMode, 'hostname' => wfHostname(), 'readOnlyReason' => $readOnlyMode->getReason(), @@ -64,7 +70,7 @@ abstract class MWLBFactory { // When making changes here, remember to also specify MediaWiki-specific options // for Database classes in the relevant Installer subclass. // Such as MysqlInstaller::openConnection and PostgresInstaller::openConnectionWithParams. - if ( $lbConf['class'] === 'LBFactorySimple' ) { + if ( $lbConf['class'] === Wikimedia\Rdbms\LBFactorySimple::class ) { if ( isset( $lbConf['servers'] ) ) { // Server array is already explicitly configured; leave alone } elseif ( is_array( $mainConfig->get( 'DBservers' ) ) ) { @@ -132,7 +138,7 @@ abstract class MWLBFactory { if ( !isset( $lbConf['externalClusters'] ) ) { $lbConf['externalClusters'] = $mainConfig->get( 'ExternalServers' ); } - } elseif ( $lbConf['class'] === 'LBFactoryMulti' ) { + } elseif ( $lbConf['class'] === Wikimedia\Rdbms\LBFactoryMulti::class ) { if ( isset( $lbConf['serverTemplate'] ) ) { if ( in_array( $lbConf['serverTemplate']['type'], $typesWithSchema, true ) ) { $lbConf['serverTemplate']['schema'] = $mainConfig->get( 'DBmwschema' ); @@ -201,4 +207,46 @@ abstract class MWLBFactory { return $class; } + + public static function setSchemaAliases( LBFactory $lbFactory, Config $config ) { + if ( $config->get( 'DBtype' ) === 'mysql' ) { + /** + * When SQLite indexes were introduced in r45764, it was noted that + * SQLite requires index names to be unique within the whole database, + * not just within a schema. As discussed in CR r45819, to avoid the + * need for a schema change on existing installations, the indexes + * were implicitly mapped from the new names to the old names. + * + * This mapping can be removed if DB patches are introduced to alter + * the relevant tables in existing installations. Note that because + * this index mapping applies to table creation, even new installations + * of MySQL have the old names (except for installations created during + * a period where this mapping was inappropriately removed, see + * T154872). + */ + $lbFactory->setIndexAliases( [ + 'ar_usertext_timestamp' => 'usertext_timestamp', + 'un_user_id' => 'user_id', + 'un_user_ip' => 'user_ip', + ] ); + } + } + + /** + * Log a database deprecation warning + * @param string $msg Deprecation message + */ + public static function logDeprecation( $msg ) { + global $wgDevelopmentWarnings; + + if ( isset( self::$loggedDeprecations[$msg] ) ) { + return; + } + self::$loggedDeprecations[$msg] = true; + + if ( $wgDevelopmentWarnings ) { + trigger_error( $msg, E_USER_DEPRECATED ); + } + wfDebugLog( 'deprecated', $msg, 'private' ); + } }