29use Wikimedia\AtEase\AtEase;
94 private $cachedConnType;
119 if ( version_compare( $serverVersion, static::$minimumVersion ) < 0 ) {
120 return Status::newFatal(
121 static::$notMinimumVersionMessage, static::$minimumVersion, $serverVersion
125 return Status::newGood();
144 return Status::newGood();
180 if ( $type === self::CONN_DONT_KNOW ) {
181 if ( $this->cachedConnType ) {
182 $type = $this->cachedConnType;
187 if ( $this->cachedConn ) {
188 if ( $this->cachedConnType === $type ) {
191 return $this->
changeConnType( $this->cachedConn, $this->cachedConnType, $type );
195 if ( $status->isOK() ) {
196 $this->cachedConn = $status->getDB();
197 $this->cachedConnType = $type;
199 $this->db = $this->cachedConn;
201 if ( $type === self::CONN_CREATE_SCHEMA || $type === self::CONN_CREATE_TABLES ) {
218 if ( !$status->isOK() ) {
219 throw new RuntimeException( __METHOD__ .
': unexpected DB connection error' );
221 return $status->getDB();
249 if ( $storedType === self::CONN_CREATE_DATABASE ) {
250 if ( $newType === self::CONN_CREATE_SCHEMA || $newType === self::CONN_CREATE_TABLES ) {
253 $this->getVar(
'wgDBname' ),
254 $this->getVar(
'wgDBmwschema' ),
255 $this->getVar(
'wgDBprefix' ) ??
''
258 $storedType = self::CONN_CREATE_SCHEMA;
262 if ( $newType === self::CONN_CREATE_TABLES && $storedType === self::CONN_CREATE_SCHEMA ) {
263 $status = $this->changeConnTypeFromSchemaToTables( $conn );
264 if ( $status->isOK() ) {
265 $storedType = self::CONN_CREATE_TABLES;
290 private function applySourceFile( $conn, $sqlFile ) {
291 $status = Status::newGood();
293 $conn->doAtomicSection( __METHOD__,
294 static function ( $conn ) use ( $sqlFile ) {
295 $conn->sourceFile( $sqlFile );
297 IDatabase::ATOMIC_CANCELABLE
299 }
catch ( DBQueryError $e ) {
300 $status->fatal(
"config-install-tables-failed", $e->getMessage() );
311 $status = $this->getConnection( self::CONN_CREATE_TABLES );
312 if ( !$status->isOK() ) {
315 $conn = $status->getDB();
316 if ( $conn->tableExists(
'archive', __METHOD__ ) ) {
317 $status->warning(
"config-install-tables-exist" );
320 $status = $this->applySourceFile( $conn,
321 $this->getSqlFilePath(
'tables-generated.sql' ) );
322 if ( !$status->isOK() ) {
325 $status->merge( $this->applySourceFile( $conn,
326 $this->getSqlFilePath(
'tables.sql' ) ) );
337 $this->definitelyGetConnection( self::CONN_CREATE_TABLES ) );
338 $updater->insertInitialUpdateKeys();
339 return Status::newGood();
349 private function getSqlFilePath(
string $filename ) {
352 $dbmsSpecificFilePath =
"$IP/maintenance/" . $this->getName() .
"/$filename";
353 if ( file_exists( $dbmsSpecificFilePath ) ) {
354 return $dbmsSpecificFilePath;
356 return "$IP/maintenance/$filename";
365 $status = $this->getConnection( self::CONN_CREATE_TABLES );
366 if ( !$status->isOK() ) {
372 $updater->setAutoExtensionHookContainer( $this->parent->getAutoExtensionHookContainer() );
373 $updater->doUpdates( [
'extensions' ] );
419 return $this->globalNames;
428 $this->parent = $parent;
439 return extension_loaded( $name );
448 return wfMessage(
'config-type-' . $this->getName() )->text();
458 foreach ( $this->getGlobalNames() as $var ) {
459 if ( isset( $GLOBALS[$var] ) ) {
460 $defaults[$var] = $GLOBALS[$var];
471 return $this->internalDefaults;
480 public function getVar( $var, $default =
null ) {
481 $defaults = $this->getGlobalDefaults();
482 $internal = $this->getInternalDefaults();
483 if ( isset( $defaults[$var] ) ) {
484 $default = $defaults[$var];
485 } elseif ( isset( $internal[$var] ) ) {
486 $default = $internal[$var];
489 return $this->parent->getVar( $var, $default );
497 public function setVar( $name, $value ) {
498 $this->parent->setVar( $name, $value );
516 $status = $this->getConnection( self::CONN_CREATE_SCHEMA );
517 if ( !$status->isOK() ) {
520 $db = $status->getDB();
531 $status = $this->getConnection( self::CONN_CREATE_TABLES );
532 if ( !$status->isOK() ) {
535 $conn = $status->getDB();
537 $row = $conn->newSelectQueryBuilder()
539 ->from(
'interwiki' )
540 ->caller( __METHOD__ )->fetchRow();
542 $status->warning(
'config-install-interwiki-exists' );
547 AtEase::suppressWarnings();
548 $rows = file(
"$IP/maintenance/interwiki.list",
549 FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
550 AtEase::restoreWarnings();
552 return Status::newFatal(
'config-install-interwiki-list' );
554 $insert = $conn->newInsertQueryBuilder()
555 ->insertInto(
'interwiki' );
556 foreach ( $rows as $row ) {
557 $row = preg_replace(
'/^\s*([^#]*?)\s*(#.*)?$/',
'\\1', $row );
564 [
'iw_prefix',
'iw_url',
'iw_local',
'iw_api',
'iw_wikiid' ],
569 $insert->caller( __METHOD__ )->execute();
571 return Status::newGood();
587 ( $schema !==
'' ) ? $schema :
null,
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
if(!defined( 'MEDIAWIKI')) if(ini_get('mbstring.func_overload')) if(!defined( 'MW_ENTRY_POINT')) global $IP
Environment checks.
Class to handle database/schema/prefix specifications for IDatabase.