r79828 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79827‎ | r79828 | r79829 >
Date:18:24, 7 January 2011
Author:demon
Status:deferred (Comments)
Tags:
Comment:
Move over some initial_setup() for Postgres (THIS IS BROKEN, NEEDS REVIEW/WORK FROM POSTGRES GUYS!!)
* Ported canCreateAccounts() check
* Moved creation of new user to setupUser()
* Moved DB creation (still needs schema stuff) to setupDatabase() where it belongs
* Added ts2 setup

TODO:
* UI for non-admin account (like MysqlInstaller::getSettingsForm) and maybe move ts2 and other "optional" settings there
* Schema creation/setup
Modified paths:
  • /trunk/phase3/includes/installer/Installer.i18n.php (modified) (history)
  • /trunk/phase3/includes/installer/MysqlInstaller.php (modified) (history)
  • /trunk/phase3/includes/installer/PostgresInstaller.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/installer/Installer.i18n.php
@@ -452,6 +452,9 @@
453453 Make sure that the user "$1" can write to the schema "$2".',
454454 'config-install-pg-commit' => 'Committing changes',
455455 'config-pg-no-plpgsql' => 'You need to install the language PL/pgSQL in the database $1',
 456+ 'config-install-pg-ts2' => 'Checking for tsearch2',
 457+ 'config-install-pg-ts2-failed' => "'''FAILED''' tsearch2 must be installed in the database $1
 458+Please read [http://www.devx.com/opensource/Article/21674/0/page/2 these instructions] or ask on #postgresql on irc.freenode.net</li>\n",
456459 'config-install-user' => 'Creating database user',
457460 'config-install-user-failed' => 'Granting permission to user "$1" failed: $2',
458461 'config-install-tables' => 'Creating tables',
Index: trunk/phase3/includes/installer/MysqlInstaller.php
@@ -410,7 +410,7 @@
411411 $conn = $status->value;
412412 $dbName = $this->getVar( 'wgDBname' );
413413 if( !$conn->selectDB( $dbName ) ) {
414 - $conn->query( "CREATE DATABASE `$dbName`", __METHOD__ );
 414+ $conn->query( "CREATE DATABASE " . $conn->addIdentifierQuotes( $dbName ), __METHOD__ );
415415 $conn->selectDB( $dbName );
416416 }
417417 return $status;
Index: trunk/phase3/includes/installer/PostgresInstaller.php
@@ -25,6 +25,7 @@
2626 );
2727
2828 var $minimumVersion = '8.1';
 29+ private $ts2MaxVersion = '8.3'; // Doing ts2 is not necessary in PG > 8.3
2930
3031 function getName() {
3132 return 'postgres';
@@ -99,7 +100,7 @@
100101 $this->getVar( 'wgDBserver' ),
101102 $this->getVar( '_InstallUser' ),
102103 $this->getVar( '_InstallPassword' ),
103 - $this->getVar( 'wgDBname' ) );
 104+ false );
104105 $status->value = $this->db;
105106 } catch ( DBConnectionError $e ) {
106107 $status->fatal( 'config-connection-error', $e->getMessage() );
@@ -107,13 +108,50 @@
108109 return $status;
109110 }
110111
 112+ protected function canCreateAccounts() {
 113+ $status = $this->getConnection();
 114+ if ( !$status->isOK() ) {
 115+ return false;
 116+ }
 117+ $conn = $status->value;
 118+
 119+ $superuser = $this->getVar( '_InstallUser' );
 120+
 121+ $rights = $conn->query( 'pg_catalog.pg_user',
 122+ 'SELECT
 123+ CASE WHEN usesuper IS TRUE THEN
 124+ CASE WHEN usecreatedb IS TRUE THEN 3 ELSE 1 END
 125+ ELSE CASE WHEN usecreatedb IS TRUE THEN 2 ELSE 0 END
 126+ END AS rights',
 127+ array( 'usename' => $superuser ), __METHOD__
 128+ );
 129+
 130+ if( !$rights ) {
 131+ return false;
 132+ }
 133+
 134+ if( $rights != 1 && $rights != 3 ) {
 135+ return false;
 136+ }
 137+
 138+ return true;
 139+ }
 140+
111141 public function preInstall() {
112 - # Add our user callback to installSteps, right before the tables are created.
113 - $callback = array(
 142+ $commitCB = array(
114143 'name' => 'pg-commit',
115144 'callback' => array( $this, 'commitChanges' ),
116145 );
117 - $this->parent->addInstallStep( $callback, 'interwiki' );
 146+ $userCB = array(
 147+ 'name' => 'user',
 148+ 'callback' => array( $this, 'setupUser' ),
 149+ );
 150+ $ts2CB = array(
 151+ 'name' => 'pg-ts2',
 152+ 'callback' => array( $this, 'setupTs2' ),
 153+ );
 154+ $this->parent->addInstallStep( $commitCB, 'interwiki' );
 155+ $this->parent->addInstallStep( $userCB );
118156 }
119157
120158 function setupDatabase() {
@@ -137,16 +175,65 @@
138176 $this->getVar( 'wgDBuser'), $schema );
139177 }
140178 $conn->query( "DROP TABLE $safeschema.$ctest" );
141 -
 179+
 180+ $dbName = $this->getVar( 'wgDBname' );
 181+ if( !$conn->selectDB( $dbName ) ) {
 182+ $safedb = $conn->addIdentifierQuotes( $dbName );
 183+ $safeuser = $conn->addQuotes( $this->getVar( 'wgDBuser' ) );
 184+ $conn->query( "CREATE DATABASE $safedb OWNER $safeuser", __METHOD__ );
 185+ $conn->selectDB( $dbName );
 186+ }
142187 return $status;
143188 }
144189
 190+ /**
 191+ * Ts2 isn't needed in newer versions of Postgres, so wrap it in a nice big
 192+ * version check and skip it if we're new. Maybe we can bump $minimumVersion
 193+ * one day and render this obsolete :)
 194+ *
 195+ * @return Status
 196+ */
 197+ function setupTs2() {
 198+ if( version_compare( $this->db->getServerVersion(), $this->ts2MaxVersion, '<' ) ) {
 199+ if ( !$this->db->tableExists( 'pg_ts_cfg', $wgDBts2schema ) ) {
 200+ return Status::newFatal( 'config-install-pg-ts2-failed' );
 201+ }
 202+ $safeuser = $this->db->addQuotes( $this->getVar( 'wgDBuser' ) );
 203+ foreach ( array( 'cfg', 'cfgmap', 'dict', 'parser' ) as $table ) {
 204+ $sql = "GRANT SELECT ON pg_ts_$table TO $safeuser";
 205+ $this->db->query( $sql, __METHOD__ );
 206+ }
 207+ }
 208+ return Status::newGood();
 209+ }
 210+
145211 function commitChanges() {
146212 $this->db->query( 'COMMIT' );
147 -
148213 return Status::newGood();
149214 }
150215
 216+ function setupUser() {
 217+ if ( !$this->getVar( '_CreateDBAccount' ) ) {
 218+ return Status::newGood();
 219+ }
 220+
 221+ $status = $this->getConnection();
 222+ if ( !$status->isOK() ) {
 223+ return $status;
 224+ }
 225+
 226+ $db = $this->getVar( 'wgDBname' );
 227+ $this->db->selectDB( $db );
 228+ $safeuser = $this->db->addQuotes( $this->getVar( 'wgDBuser' ) );
 229+ $safepass = $this->db->addQuotes( $this->getVar( 'wgDBpassword' ) );
 230+ $res = $this->db->query( "CREATE USER $safeuser NOCREATEDB PASSWORD $safepass", __METHOD__ );
 231+ if ( $res !== true ) {
 232+ $status->fatal( 'config-install-user-failed', $this->getVar( 'wgDBuser' ) );
 233+ }
 234+
 235+ return $status;
 236+ }
 237+
151238 function getLocalSettings() {
152239 $port = $this->getVar( 'wgDBport' );
153240 $schema = $this->getVar( 'wgDBmwschema' );

Follow-up revisions

RevisionCommit summaryAuthorDate
r79837Follow-up r79828: Add dotraymond19:51, 7 January 2011
r80124Fix undefined variable from r79828demon21:28, 12 January 2011
r81182MFT a bunch of installer fixes. r80238, r80128, r80124, r80083, r80080, r800...demon01:59, 29 January 2011

Comments

#Comment by Raymond (talk | contribs)   19:09, 7 January 2011

In 'config-install-pg-ts2-failed' is a closing </li>. Where is the opening tag?

#Comment by 😂 (talk | contribs)   19:41, 7 January 2011

There wasn't one, copy+paste error from DatabasePostgres. Fixed in r79834.

#Comment by Platonides (talk | contribs)   00:33, 12 January 2011

if ( !$this->db->tableExists( 'pg_ts_cfg', $wgDBts2schema ) ) {

You need a global $wgDBts2schema;

#Comment by 😂 (talk | contribs)   00:36, 12 January 2011

To be safe, it's best to do $this->getVar()

#Comment by 😂 (talk | contribs)   21:29, 12 January 2011

Fixed in r80124.

Status & tagging log