X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Finstaller%2FPostgresInstaller.php;h=3ac2b3a8d270fc193ef6636e954e6e16d81234be;hb=a2697d7d14b951dd7e3f6e292c9bed4bcffef1b6;hp=7c4a6a802e90fd5278899bc1803b08d1cdfa8984;hpb=6bc96793072f60bb37610986ff9d13df07685aaf;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/installer/PostgresInstaller.php b/includes/installer/PostgresInstaller.php index 7c4a6a802e..3ac2b3a8d2 100644 --- a/includes/installer/PostgresInstaller.php +++ b/includes/installer/PostgresInstaller.php @@ -2,6 +2,21 @@ /** * PostgreSQL-specific installer. * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * * @file * @ingroup Deployment */ @@ -45,7 +60,7 @@ class PostgresInstaller extends DatabaseInstaller { $this->getTextBox( 'wgDBserver', 'config-db-host', array(), $this->parent->getHelpBox( 'config-db-host-help' ) ) . $this->getTextBox( 'wgDBport', 'config-db-port' ) . Html::openElement( 'fieldset' ) . - Html::element( 'legend', array(), wfMsg( 'config-db-wiki-settings' ) ) . + Html::element( 'legend', array(), wfMessage( 'config-db-wiki-settings' )->text() ) . $this->getTextBox( 'wgDBname', 'config-db-name', array(), $this->parent->getHelpBox( 'config-db-name-help' ) ) . $this->getTextBox( 'wgDBmwschema', 'config-db-schema', array(), $this->parent->getHelpBox( 'config-db-schema-help' ) ) . Html::closeElement( 'fieldset' ) . @@ -80,6 +95,9 @@ class PostgresInstaller extends DatabaseInstaller { if ( !$status->isOK() ) { return $status; } + /** + * @var $conn DatabaseBase + */ $conn = $status->value; // Check version @@ -107,9 +125,9 @@ class PostgresInstaller extends DatabaseInstaller { /** * Open a PG connection with given parameters - * @param $user User name - * @param $password Password - * @param $dbName Database name + * @param $user string User name + * @param $password string Password + * @param $dbName string Database name * @return Status */ protected function openConnectionWithParams( $user, $password, $dbName ) { @@ -139,9 +157,12 @@ class PostgresInstaller extends DatabaseInstaller { $status = $this->openPgConnection( $type ); if ( $status->isOK() ) { + /** + * @var $conn DatabaseBase + */ $conn = $status->value; $conn->clearFlag( DBO_TRX ); - $conn->commit(); + $conn->commit( __METHOD__ ); $this->pgConns[$type] = $conn; } return $status; @@ -162,14 +183,14 @@ class PostgresInstaller extends DatabaseInstaller { * separate connection for this allows us to avoid accidental cross-module * dependencies. * - * @param $type The type of connection to get: + * @param $type string The type of connection to get: * - create-db: A connection for creating DBs, suitable for pre- * installation. * - create-schema: A connection to the new DB, for creating schemas and * other similar objects in the new DB. * - create-tables: A connection with a role suitable for creating tables. * - * @return A Status object. On success, a connection object will be in the + * @return Status object. On success, a connection object will be in the * value member. */ protected function openPgConnection( $type ) { @@ -186,6 +207,9 @@ class PostgresInstaller extends DatabaseInstaller { case 'create-tables': $status = $this->openPgConnection( 'create-schema' ); if ( $status->isOK() ) { + /** + * @var $conn DatabaseBase + */ $conn = $status->value; $safeRole = $conn->addIdentifierQuotes( $this->getVar( 'wgDBuser' ) ); $conn->query( "SET ROLE $safeRole" ); @@ -204,6 +228,7 @@ class PostgresInstaller extends DatabaseInstaller { if ( !in_array( $this->getVar( 'wgDBname' ), $dbs ) ) { array_unshift( $dbs, $this->getVar( 'wgDBname' ) ); } + $conn = false; $status = Status::newGood(); foreach ( $dbs as $db ) { try { @@ -233,6 +258,9 @@ class PostgresInstaller extends DatabaseInstaller { if ( !$status->isOK() ) { return false; } + /** + * @var $conn DatabaseBase + */ $conn = $status->value; $superuser = $this->getVar( '_InstallUser' ); @@ -331,6 +359,7 @@ class PostgresInstaller extends DatabaseInstaller { /** * Returns true if the install user is able to create objects owned * by the web user, false otherwise. + * @return bool */ protected function canCreateObjectsForWebUser() { if ( $this->isSuperUser() ) { @@ -352,10 +381,11 @@ class PostgresInstaller extends DatabaseInstaller { /** * Recursive helper for canCreateObjectsForWebUser(). - * @param $conn Database object - * @param $targetMember Role ID of the member to look for - * @param $group Role ID of the group to look for - * @param $maxDepth Maximum recursive search depth + * @param $conn DatabaseBase object + * @param $targetMember int Role ID of the member to look for + * @param $group int Role ID of the group to look for + * @param $maxDepth int Maximum recursive search depth + * @return bool */ protected function isRoleMember( $conn, $targetMember, $group, $maxDepth ) { if ( $targetMember === $group ) { @@ -383,6 +413,10 @@ class PostgresInstaller extends DatabaseInstaller { } public function preInstall() { + $createDbAccount = array( + 'name' => 'user', + 'callback' => array( $this, 'setupUser' ), + ); $commitCB = array( 'name' => 'pg-commit', 'callback' => array( $this, 'commitChanges' ), @@ -395,15 +429,13 @@ class PostgresInstaller extends DatabaseInstaller { 'name' => 'schema', 'callback' => array( $this, 'setupSchema' ) ); + + if( $this->getVar( '_CreateDBAccount' ) ) { + $this->parent->addInstallStep( $createDbAccount, 'database' ); + } $this->parent->addInstallStep( $commitCB, 'interwiki' ); $this->parent->addInstallStep( $plpgCB, 'database' ); $this->parent->addInstallStep( $schemaCB, 'database' ); - if( $this->getVar( '_CreateDBAccount' ) ) { - $this->parent->addInstallStep( array( - 'name' => 'user', - 'callback' => array( $this, 'setupUser' ), - ) ); - } } function setupDatabase() { @@ -414,10 +446,6 @@ class PostgresInstaller extends DatabaseInstaller { $conn = $status->value; $dbName = $this->getVar( 'wgDBname' ); - $schema = $this->getVar( 'wgDBmwschema' ); - $user = $this->getVar( 'wgDBuser' ); - $safeschema = $conn->addIdentifierQuotes( $schema ); - $safeuser = $conn->addIdentifierQuotes( $user ); $exists = $conn->selectField( '"pg_catalog"."pg_database"', '1', array( 'datname' => $dbName ), __METHOD__ ); @@ -449,19 +477,13 @@ class PostgresInstaller extends DatabaseInstaller { } } - // If we created a user, alter it now to search the new schema by default - if ( $this->getVar( '_CreateDBAccount' ) ) { - $conn->query( "ALTER ROLE $safeuser SET search_path = $safeschema, public", - __METHOD__ ); - } - // Select the new schema in the current connection - $conn->query( "SET search_path = $safeschema" ); + $conn->determineCoreSchema( $schema ); return Status::newGood(); } function commitChanges() { - $this->db->query( 'COMMIT' ); + $this->db->commit( __METHOD__ ); return Status::newGood(); } @@ -476,10 +498,8 @@ class PostgresInstaller extends DatabaseInstaller { } $conn = $status->value; - $schema = $this->getVar( 'wgDBmwschema' ); $safeuser = $conn->addIdentifierQuotes( $this->getVar( 'wgDBuser' ) ); $safepass = $conn->addQuotes( $this->getVar( 'wgDBpassword' ) ); - $safeschema = $conn->addIdentifierQuotes( $schema ); // Check if the user already exists $userExists = $conn->roleExists( $this->getVar( 'wgDBuser' ) ); @@ -530,10 +550,15 @@ class PostgresInstaller extends DatabaseInstaller { if ( !$status->isOK() ) { return $status; } + + /** + * @var $conn DatabaseBase + */ $conn = $status->value; - if( $conn->tableExists( 'user' ) ) { + if( $conn->tableExists( 'archive' ) ) { $status->warning( 'config-install-tables-exist' ); + $this->enableLB(); return $status; } @@ -565,6 +590,9 @@ class PostgresInstaller extends DatabaseInstaller { if ( !$status->isOK() ) { return $status; } + /** + * @var $conn DatabaseBase + */ $conn = $status->value; $exists = $conn->selectField( '"pg_catalog"."pg_language"', 1,