From: Aaron Schulz Date: Sun, 18 Sep 2016 03:39:28 +0000 (-0700) Subject: Remove wf* function and global variable usage from DatabaseSqlite X-Git-Tag: 1.31.0-rc.0~5492^2 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dcompta/operations/modifier.php?a=commitdiff_plain;h=47e816c69c197fec86c344256d81d7c8f781b880;p=lhc%2Fweb%2Fwiklou.git Remove wf* function and global variable usage from DatabaseSqlite Change-Id: I81753621ecd1e7e3b099243b4c4d0f3428bf9ae2 --- diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index 7a34b3ab18..7cd62ce918 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -57,6 +57,9 @@ return [ if ( $class === 'LBFactorySimple' ) { if ( is_array( $mainConfig->get( 'DBservers' ) ) ) { foreach ( $mainConfig->get( 'DBservers' ) as $i => $server ) { + if ( $server['type'] === 'sqlite' ) { + $server += [ 'dbDirectory' => $mainConfig->get( 'SQLiteDataDir' ) ]; + } $lbConf['servers'][$i] = $server + [ 'schema' => $mainConfig->get( 'DBmwschema' ), 'tablePrefix' => $mainConfig->get( 'DBprefix' ), @@ -70,22 +73,25 @@ return [ $flags |= $mainConfig->get( 'DebugDumpSql' ) ? DBO_DEBUG : 0; $flags |= $mainConfig->get( 'DBssl' ) ? DBO_SSL : 0; $flags |= $mainConfig->get( 'DBcompress' ) ? DBO_COMPRESS : 0; - $lbConf['servers'] = [ - [ - 'host' => $mainConfig->get( 'DBserver' ), - 'user' => $mainConfig->get( 'DBuser' ), - 'password' => $mainConfig->get( 'DBpassword' ), - 'dbname' => $mainConfig->get( 'DBname' ), - 'schema' => $mainConfig->get( 'DBmwschema' ), - 'tablePrefix' => $mainConfig->get( 'DBprefix' ), - 'type' => $mainConfig->get( 'DBtype' ), - 'load' => 1, - 'flags' => $flags, - 'sqlMode' => $mainConfig->get( 'SQLMode' ), - 'utf8Mode' => $mainConfig->get( 'DBmysql5' ) - ] + $server = [ + 'host' => $mainConfig->get( 'DBserver' ), + 'user' => $mainConfig->get( 'DBuser' ), + 'password' => $mainConfig->get( 'DBpassword' ), + 'dbname' => $mainConfig->get( 'DBname' ), + 'schema' => $mainConfig->get( 'DBmwschema' ), + 'tablePrefix' => $mainConfig->get( 'DBprefix' ), + 'type' => $mainConfig->get( 'DBtype' ), + 'load' => 1, + 'flags' => $flags, + 'sqlMode' => $mainConfig->get( 'SQLMode' ), + 'utf8Mode' => $mainConfig->get( 'DBmysql5' ) ]; + if ( $server['type'] === 'sqlite' ) { + $server[ 'dbDirectory'] = $mainConfig->get( 'SQLiteDataDir' ); + } + $lbConf['servers'] = [ $server ]; } + $lbConf['externalServers'] = $mainConfig->get( 'ExternalServers' ); } diff --git a/includes/db/DatabaseSqlite.php b/includes/db/DatabaseSqlite.php index a52c2edf1a..11acde78f6 100644 --- a/includes/db/DatabaseSqlite.php +++ b/includes/db/DatabaseSqlite.php @@ -59,10 +59,6 @@ class DatabaseSqlite extends DatabaseBase { * @param array $p */ function __construct( array $p ) { - global $wgSQLiteDataDir; - - $this->dbDir = isset( $p['dbDirectory'] ) ? $p['dbDirectory'] : $wgSQLiteDataDir; - if ( isset( $p['dbFilePath'] ) ) { parent::__construct( $p ); // Standalone .sqlite file mode. @@ -70,7 +66,10 @@ class DatabaseSqlite extends DatabaseBase { // which is derived from the file path in this case. $this->openFile( $p['dbFilePath'] ); $lockDomain = md5( $p['dbFilePath'] ); + } elseif ( !isset( $p['dbDirectory'] ) ) { + throw new InvalidArgumentException( "Need 'dbDirectory' or 'dbFilePath' parameter." ); } else { + $this->dbDir = $p['dbDirectory']; $this->mDBname = $p['dbname']; $lockDomain = $this->mDBname; // Stock wiki mode using standard file names per DB. @@ -95,7 +94,7 @@ class DatabaseSqlite extends DatabaseBase { !in_array( $this->trxMode, [ 'DEFERRED', 'IMMEDIATE', 'EXCLUSIVE' ] ) ) { $this->trxMode = null; - wfWarn( "Invalid SQLite transaction mode provided." ); + $this->queryLogger->warning( "Invalid SQLite transaction mode provided." ); } $this->lockMgr = new FSLockManager( [ @@ -183,7 +182,7 @@ class DatabaseSqlite extends DatabaseBase { } if ( !$this->mConn ) { - wfDebug( "DB connection error: $err\n" ); + $this->queryLogger->debug( "DB connection error: $err\n" ); throw new DBConnectionError( $this, $err ); } @@ -725,15 +724,6 @@ class DatabaseSqlite extends DatabaseBase { return $ver; } - /** - * @return string User-friendly database information - */ - public function getServerInfo() { - return wfMessage( self::getFulltextSearchModule() - ? 'sqlite-has-fts' - : 'sqlite-no-fts', $this->getServerVersion() )->text(); - } - /** * Get information about a given field * Returns false if the field does not exist. @@ -811,12 +801,11 @@ class DatabaseSqlite extends DatabaseBase { // There is an additional bug regarding sorting this data after insert // on older versions of sqlite shipped with ubuntu 12.04 // https://phabricator.wikimedia.org/T74367 - wfDebugLog( - __CLASS__, + $this->queryLogger->debug( __FUNCTION__ . - ': Quoting value containing null byte. ' . - 'For consistency all binary data should have been ' . - 'first processed with self::encodeBlob()' + ': Quoting value containing null byte. ' . + 'For consistency all binary data should have been ' . + 'first processed with self::encodeBlob()' ); return "x'" . bin2hex( $s ) . "'"; } else { @@ -977,7 +966,8 @@ class DatabaseSqlite extends DatabaseBase { ); if ( $temporary ) { if ( preg_match( '/^\\s*CREATE\\s+VIRTUAL\\s+TABLE\b/i', $sql ) ) { - wfDebug( "Table $oldName is virtual, can't create a temporary duplicate.\n" ); + $this->queryLogger->debug( + "Table $oldName is virtual, can't create a temporary duplicate.\n" ); } else { $sql = str_replace( 'CREATE TABLE', 'CREATE TEMPORARY TABLE', $sql ); } diff --git a/languages/i18n/en.json b/languages/i18n/en.json index a8dd10378a..67e649148b 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -3793,8 +3793,6 @@ "htmlform-user-not-exists": "$1 does not exist.", "htmlform-user-not-valid": "$1 isn't a valid username.", "rawmessage": "$1", - "sqlite-has-fts": "$1 with full-text search support", - "sqlite-no-fts": "$1 without full-text search support", "logentry-delete-delete": "$1 {{GENDER:$2|deleted}} page $3", "logentry-delete-restore": "$1 {{GENDER:$2|restored}} page $3", "logentry-delete-event": "$1 {{GENDER:$2|changed}} visibility of {{PLURAL:$5|a log event|$5 log events}} on $3: $4", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index fbf95cc359..163b613247 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -3977,8 +3977,6 @@ "htmlform-user-not-exists": "Error message shown if a user with the name provided by the user does not exist. $1 is the username.", "htmlform-user-not-valid": "Error message shown if the name provided by the user isn't a valid username. $1 is the username.", "rawmessage": "{{notranslate}} Used to pass arbitrary text as a message specifier array", - "sqlite-has-fts": "Shown on [[Special:Version]].\nParameters:\n* $1 - version", - "sqlite-no-fts": "Shown on [[Special:Version]].\nParameters:\n* $1 - version", "logentry-delete-delete": "{{Logentry|[[Special:Log/delete]]}}", "logentry-delete-restore": "{{Logentry|[[Special:Log/delete]]}}", "logentry-delete-event": "{{Logentry|[[Special:Log/delete]]}}\n{{Logentryparam}}\n* $5 - count of affected log events",