Merge ".mailmap: Correct two contributor names"
[mediawiki.git] / includes / installer / NetworkedDatabaseCreator.php
blobcc27dc9a4b5ff4f1781e65bdfb516b5e630d6340
1 <?php
3 namespace MediaWiki\Installer;
5 use MediaWiki\Installer\Task\ITaskContext;
6 use MediaWiki\Status\Status;
7 use Wikimedia\Rdbms\DatabaseDomain;
8 use Wikimedia\Rdbms\IDatabase;
9 use Wikimedia\Rdbms\ILoadBalancer;
11 /**
12 * Common code for MySQL and PostgreSQL, which are similar due to the fact that
13 * databases can be created by getting a connection to a network service.
15 * SQLite does not inherit this because its connection handles can't operate on
16 * databases other than the one you originally connected to.
18 abstract class NetworkedDatabaseCreator extends DatabaseCreator {
19 public function existsLocally( $database ) {
20 $connStatus = $this->context->getConnection( ITaskContext::CONN_CREATE_DATABASE );
21 if ( !$connStatus->isOK() ) {
22 return false;
24 return $this->existsInConnection( $connStatus->getDB(), $database );
27 public function existsInLoadBalancer( ILoadBalancer $loadBalancer, $database ) {
28 $conn = $loadBalancer->getConnection( DB_PRIMARY, [], DatabaseDomain::newUnspecified()->getId() );
29 return $this->existsInConnection( $conn, $database );
32 public function createLocally( $database ): Status {
33 $connStatus = $this->context->getConnection( ITaskContext::CONN_CREATE_DATABASE );
34 if ( !$connStatus->isOK() ) {
35 return $connStatus;
37 $conn = $connStatus->getDB();
38 return $this->createInConnection( $conn, $database );
41 public function createInLoadBalancer( ILoadBalancer $loadBalancer, $database ): Status {
42 $conn = $loadBalancer->getConnection( DB_PRIMARY, [], DatabaseDomain::newUnspecified()->getId() );
43 return $this->createInConnection( $conn, $database );
46 /**
47 * Determine whether a database exists on a connection
49 * @param IDatabase $conn
50 * @param string $database
51 * @return bool
53 abstract protected function existsInConnection( IDatabase $conn, $database );
55 /**
56 * Create a database on a connection
58 * @param IDatabase $conn
59 * @param string $database
60 * @return Status
62 abstract protected function createInConnection( IDatabase $conn, $database ): Status;