Refactor installation into parent class, shouldn't be up to children to implement...
authorChad Horohoe <demon@users.mediawiki.org>
Tue, 6 Jul 2010 18:31:55 +0000 (18:31 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Tue, 6 Jul 2010 18:31:55 +0000 (18:31 +0000)
includes/installer/Installer.php
includes/installer/WebInstaller.php

index 2492b23..798533a 100644 (file)
@@ -853,6 +853,35 @@ abstract class Installer {
                return $this->installSteps;
        }
 
+       /**
+        * Actually perform the installation
+        * @param Array $startCB A callback array for the beginning of each step
+        * @param Array $endCB A callback array for the end of each step
+        * @return Array of Status objects
+        */
+       public function performInstallation( $startCB, $endCB ) {
+               $installResults = array();
+               foreach( $this->getInstallSteps() as $stepObj ) {
+                       $step = is_array( $stepObj ) ? $stepObj['name'] : $stepObj;
+                       call_user_func_array( $startCB, array( $step ) );
+                       $status = null;
+
+                       # Call our working function
+                       if ( is_array( $step ) ) {
+                               # A custom callaback
+                               $callback = $stepObj['callback'];
+                               $status = call_user_func_array( $callback, array() );
+                       } else {
+                               # Boring implicitly named callback
+                               $func = 'install' . ucfirst( $step );
+                               $status = $this->{$func}();
+                       }
+                       call_user_func_array( $endCB, array( $step, $status ) );
+                       $installResults[$step] = $status;
+               }
+               return $installResults;
+       }
+
        public function installExtensions() {
                global $wgHooks, $wgAutoloadClasses;
                $exts = $this->getVar( '_Extensions' );
index bbdbb7f..09f3c18 100644 (file)
@@ -1577,42 +1577,26 @@ class WebInstaller_Install extends WebInstallerPage {
                }
                $this->startForm();
                $this->addHTML("<ul>");
-               foreach( $this->parent->getInstallSteps() as $stepObj ) {
-                       $step = is_array( $stepObj ) ? $stepObj['name'] : $stepObj;
-                       $this->startStage( "config-install-$step" );
-                       $status = null;
-
-                       # Call our working function
-                       if ( is_array( $step ) ) {
-                               # A custom callaback
-                               $callback = $stepObj['callback'];
-                               $status = call_user_func_array( $callback, array() );
-                       } else {
-                               # Boring implicitly named callback
-                               $func = 'install' . ucfirst( $step );
-                               $status = $this->parent->{$func}();
-                       }
-
-                       $ok = $status->isGood();
-                       if ( !$ok ) {
-                               $this->parent->showStatusBox( $status );
-                       }
-                       $this->endStage( $ok );
-               }
+               $this->parent->performInstallation(
+                       array( $this, 'startStage'), 
+                       array( $this, 'endStage' )
+               );
                $this->addHTML("</ul>");
                $this->endForm();
                return true;
 
        }
 
-       private function startStage( $msg ) {
-               $this->addHTML( "<li>" . wfMsgHtml( $msg ) . wfMsg( 'ellipsis') );
+       public function startStage( $step ) {
+               $this->addHTML( "<li>" . wfMsgHtml( "config-install-$step" ) . wfMsg( 'ellipsis') );
        }
 
-       private function endStage( $success = true ) {
+       public function endStage( $step, $status ) {
+               $success = $status->isGood();
                $msg = $success ? 'config-install-step-done' : 'config-install-step-failed';
                $html = wfMsgHtml( 'word-separator' ) . wfMsgHtml( $msg );
                if ( !$success ) {
+                       $this->parent->showStatusBox( $status );
                        $html = "<span class=\"error\">$html</span>";
                }
                $this->addHTML( $html . "</li>\n" );