Fix callbacks for the final time so it actually works per documentation.
authorChad Horohoe <demon@users.mediawiki.org>
Tue, 11 Jan 2011 15:02:59 +0000 (15:02 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Tue, 11 Jan 2011 15:02:59 +0000 (15:02 +0000)
Other minor postgres fixes

includes/installer/CoreInstaller.php
includes/installer/Installer.i18n.php
includes/installer/PostgresInstaller.php

index bc72f39..2300d57 100644 (file)
@@ -345,42 +345,34 @@ abstract class CoreInstaller extends Installer {
                        array( 'name' => 'sysop',      'callback' => array( $this, 'createSysop' ) ),
                        array( 'name' => 'mainpage',   'callback' => array( $this, 'createMainpage' ) ),
                );
-               if( count( $this->getVar( '_Extensions' ) ) ) {
-                       array_unshift( $coreInstallSteps,
-                               array( 'name' => 'extensions', 'callback' => array( $this, 'includeExtensions' ) )
-                       );
-               }
-               $this->installSteps = $coreInstallSteps;
-               foreach( $this->extraInstallSteps as $step ) {
-                       // Put the step at the beginning
-                       if( !strval( $step['position' ] ) ) {
-                               array_unshift( $this->installSteps, $step['callback'] );
-                               continue;
-                       } else {
-                               // Walk the $coreInstallSteps array to see if we can modify
-                               // $this->installSteps with a callback that wants to attach after
-                               // a given step
-                               array_walk( 
-                                       $coreInstallSteps,
-                                       array( $this, 'installStepCallback' ),
-                                       $step
+
+               // Build the array of install steps starting from the core install list,
+               // then adding any callbacks that wanted to attach after a given step
+               foreach( $coreInstallSteps as $step ) {
+                       $this->installSteps[] = $step;
+                       if( isset( $this->extraInstallSteps[ $step['name'] ] ) ) {
+                               $this->installSteps = array_merge(
+                                       $this->installSteps,
+                                       $this->extraInstallSteps[ $step['name'] ]
                                );
                        }
                }
-               return $this->installSteps;
-       }
 
-       /**
-        * Callback for getInstallSteps() - used for finding if a given $insertableStep
-        * should be inserted after the current $coreStep in question
-        */
-       private function installStepCallback( $coreStep, $key, $insertableStep ) {
-               if( $coreStep['name'] == $insertableStep['position'] ) {
-                       $front = array_slice( $this->installSteps, 0, $key + 1 );
-                       $front[] = $insertableStep['callback'];
-                       $back = array_slice( $this->installSteps, $key + 1 );
-                       $this->installSteps = array_merge( $front, $back );
+               // Prepend any steps that want to be at the beginning
+               if( isset( $this->extraInstallSteps['BEGINNING'] ) ) {
+                       $this->installSteps = array_merge(
+                               $this->extraInstallSteps['BEGINNING'],
+                               $this->installSteps
+                       );
                }
+
+               // Extensions should always go first, chance to tie into hooks and such
+               if( count( $this->getVar( '_Extensions' ) ) ) {
+                       array_unshift( $this->installSteps,
+                               array( 'name' => 'extensions', 'callback' => array( $this, 'includeExtensions' ) )
+                       );
+               }
+               return $this->installSteps;
        }
 
        /**
@@ -593,9 +585,7 @@ abstract class CoreInstaller extends Installer {
         *    array( 'name' => 'some-unique-name', 'callback' => array( $obj, 'function' ) );
         * @param $findStep String the step to find. Omit to put the step at the beginning
         */
-       public function addInstallStep( $callback, $findStep = '' ) {
-               $this->extraInstallSteps[] = array(
-                       'position' => $findStep, 'callback' => $callback
-               );
+       public function addInstallStep( $callback, $findStep = 'BEGINNING' ) {
+               $this->extraInstallSteps[$findStep][] = $callback;
        }
 }
index 2e83f08..e500113 100644 (file)
@@ -451,6 +451,7 @@ Please proceed to the next page.",
        'config-install-pg-schema-failed' => 'Tables creation failed.
 Make sure that the user "$1" can write to the schema "$2".',
        'config-install-pg-commit'        => 'Committing changes',
+       'config-pg-plpgsql'               => 'Checking for language PL/pgSQL',
        'config-pg-no-plpgsql'            => 'You need to install the language PL/pgSQL in the database $1',
        'config-install-pg-ts2'           => 'Checking for tsearch2',
        'config-install-pg-ts2-failed'    => "'''FAILED''' tsearch2 must be installed in the database $1.
index a811dff..51b04dc 100644 (file)
@@ -201,9 +201,14 @@ class PostgresInstaller extends DatabaseInstaller {
                        'name' => 'pg-ts2',
                        'callback' => array( $this, 'setupTs2' ),
                );
+               $plpgCB = array(
+                       'name' => 'pg-plpgsql',
+                       'callback' => array( $this, 'setupPLpgSQL' ),
+               );
                $this->parent->addInstallStep( $commitCB, 'interwiki' );
                $this->parent->addInstallStep( $userCB );
-               $this->parent->addInstallStep( $ts2CB, 'setupDatabase' );
+               $this->parent->addInstallStep( $ts2CB, 'database' );
+               $this->parent->addInstallStep( $plpgCB, 'database' );
        }
 
        function setupDatabase() {
@@ -269,6 +274,11 @@ class PostgresInstaller extends DatabaseInstaller {
         * @return Status
         */
        function setupTs2() {
+               $status = $this->getConnection();
+               if ( !$status->isOK() ) {
+                       return $status;
+               }
+
                if( version_compare( $this->db->getServerVersion(), $this->ts2MaxVersion, '<' ) ) {
                        if ( !$this->db->tableExists( 'pg_ts_cfg', $wgDBts2schema ) ) {
                                return Status::newFatal( 
@@ -335,23 +345,28 @@ class PostgresInstaller extends DatabaseInstaller {
                $wgDBpassword = $this->getVar( '_InstallPassword' );
        }
 
-       private function setupPLpgSQL() {
-               $rows = $this->numRows( 
+       public function setupPLpgSQL() {
+               $status = $this->getConnection();
+               if ( !$status->isOK() ) {
+                       return $status;
+               }
+
+               $rows = $this->db->numRows(
                        $this->db->query( "SELECT 1 FROM pg_catalog.pg_language WHERE lanname = 'plpgsql'" )
                );
                if ( $rows < 1 ) {
                        // plpgsql is not installed, but if we have a pg_pltemplate table, we should be able to create it
                        $SQL = "SELECT 1 FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON (n.oid = c.relnamespace) ".
                                "WHERE relname = 'pg_pltemplate' AND nspname='pg_catalog'";
-                       $rows = $this->numRows( $this->db->query( $SQL ) );
-                       global $wgDBname;
+                       $rows = $this->db->numRows( $this->db->query( $SQL ) );
+                       $dbName = $this->getVar( 'wgDBname' );
                        if ( $rows >= 1 ) {
                                $result = $this->db->query( 'CREATE LANGUAGE plpgsql' );
                                if ( !$result ) {
-                                       return Status::newFatal( 'config-pg-no-plpgsql', $wgDBname );
+                                       return Status::newFatal( 'config-pg-no-plpgsql', $dbName );
                                }
                        } else {
-                               return Status::newFatal( 'config-pg-no-plpgsql', $wgDBname );
+                               return Status::newFatal( 'config-pg-no-plpgsql', $dbName );
                        }
                }
                return Status::newGood();