MediaWiki master
PostgresCreateSchemaTask.php
Go to the documentation of this file.
1<?php
2
4
9
17 public function getName() {
18 return 'schema';
19 }
20
22 public function getDependencies() {
23 return 'user';
24 }
25
26 public function execute(): Status {
27 // Get a connection to the target database
28 $status = $this->getConnection( ITaskContext::CONN_CREATE_SCHEMA );
29 if ( !$status->isOK() ) {
30 return $status;
31 }
32 $conn = $status->getDB();
33 '@phan-var DatabasePostgres $conn';
35 // Create the schema if necessary
36 $schema = $this->getConfigVar( MainConfigNames::DBmwschema );
37 $safeschema = $conn->addIdentifierQuotes( $schema );
38 $safeuser = $conn->addIdentifierQuotes( $this->getConfigVar( MainConfigNames::DBuser ) );
39 if ( !$conn->schemaExists( $schema ) ) {
40 try {
41 $conn->query( "CREATE SCHEMA $safeschema AUTHORIZATION $safeuser", __METHOD__ );
42 } catch ( DBQueryError ) {
43 return Status::newFatal( 'config-install-pg-schema-failed',
44 $this->getOption( 'InstallUser' ), $schema );
45 }
46 }
47
48 return Status::newGood();
49 }
50}
getDependencies()
Get a list of names or aliases of tasks that must be done prior to this task.to override string|strin...
getName()
Get the symbolic name of the task.string
Base class for installer tasks.
Definition Task.php:24
getOption(string $name)
Get an installer option value.
Definition Task.php:190
getConfigVar(string $name)
Get a configuration variable for the wiki being created.
Definition Task.php:180
getConnection(string $type)
Connect to the database for a specified purpose.
Definition Task.php:200
A class containing constants representing the names of configuration variables.
const DBmwschema
Name constant for the DBmwschema setting, for use with Config::get()
const DBuser
Name constant for the DBuser setting, for use with Config::get()
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:44
Postgres database abstraction layer.
Dependency bundle and execution context for installer tasks.