MediaWiki master
NetworkedDatabaseCreator.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Installer;
4
10
19 public function existsLocally( $database ) {
20 $connStatus = $this->context->getConnection( ITaskContext::CONN_CREATE_DATABASE );
21 if ( !$connStatus->isOK() ) {
22 return false;
23 }
24 return $this->existsInConnection( $connStatus->getDB(), $database );
25 }
26
27 public function existsInLoadBalancer( ILoadBalancer $loadBalancer, $database ) {
28 $conn = $loadBalancer->getConnection( DB_PRIMARY, [], DatabaseDomain::newUnspecified()->getId() );
29 return $this->existsInConnection( $conn, $database );
30 }
31
32 public function createLocally( $database ): Status {
33 $connStatus = $this->context->getConnection( ITaskContext::CONN_CREATE_DATABASE );
34 if ( !$connStatus->isOK() ) {
35 return $connStatus;
36 }
37 $conn = $connStatus->getDB();
38 return $this->createInConnection( $conn, $database );
39 }
40
41 public function createInLoadBalancer( ILoadBalancer $loadBalancer, $database ): Status {
42 $conn = $loadBalancer->getConnection( DB_PRIMARY, [], DatabaseDomain::newUnspecified()->getId() );
43 return $this->createInConnection( $conn, $database );
44 }
45
53 abstract protected function existsInConnection( IDatabase $conn, $database );
54
62 abstract protected function createInConnection( IDatabase $conn, $database ): Status;
63}
Helper for creating databases.
Common code for MySQL and PostgreSQL, which are similar due to the fact that databases can be created...
createInLoadBalancer(ILoadBalancer $loadBalancer, $database)
Create a database in the specified LoadBalancer which may be for an external cluster.
existsLocally( $database)
Check if a database exists on the local cluster or context.
createInConnection(IDatabase $conn, $database)
Create a database on a connection.
existsInConnection(IDatabase $conn, $database)
Determine whether a database exists on a connection.
createLocally( $database)
Create a database in the local cluster or install context.
existsInLoadBalancer(ILoadBalancer $loadBalancer, $database)
Check if a database exists in the specified LoadBalancer which may be for an external cluster.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:54
Class to handle database/schema/prefix specifications for IDatabase.
Dependency bundle and execution context for installer tasks.
Interface to a relational database.
Definition IDatabase.php:45
This class is a delegate to ILBFactory for a given database cluster.
getConnection( $i, $groups=[], $domain=false, $flags=0)
Get a lazy-connecting database handle for a specific or virtual (DB_PRIMARY/DB_REPLICA) server index.
const DB_PRIMARY
Definition defines.php:28