http://www.mediawiki.org/wiki/Special:Code/MediaWiki/72780

Revision: 72780
Author:   ialex
Date:     2010-09-11 08:23:26 +0000 (Sat, 11 Sep 2010)

Log Message:
-----------
Added DatabaseUpdater::addExtensionUpdate() to let extensions add their own 
updates from the LoadExtensionSchemaUpdates hook.
This uses the same format as the old $wgUpdates, unless callbacks outside the 
DatabaseUpdater instance will recieve it as first parameter.

Modified Paths:
--------------
    trunk/phase3/includes/installer/DatabaseUpdater.php

Modified: trunk/phase3/includes/installer/DatabaseUpdater.php
===================================================================
--- trunk/phase3/includes/installer/DatabaseUpdater.php 2010-09-11 08:22:32 UTC 
(rev 72779)
+++ trunk/phase3/includes/installer/DatabaseUpdater.php 2010-09-11 08:23:26 UTC 
(rev 72780)
@@ -22,6 +22,8 @@
         */
        protected $updates = array();
 
+       protected $extensionUpdates = array();
+
        protected $db;
 
        protected $shared = false;
@@ -78,34 +80,82 @@
                }
        }
 
-       public function getDB() { return $this->db; }
+       /**
+        * Get a database connection to run updates
+        *
+        * @return DatabasBase object
+        */
+       public function getDB() {
+               return $this->db;
+       }
 
+       /**
+        * Add a new update coming from an extension. This should be called by
+        * extensions while executing the LoadExtensionSchemaUpdates hook.
+        *
+        * @param $update Array: the update to run. Format is the following:
+        *                first item is the callback function, it also can be a
+        *                simple string with the name of a function in this 
class,
+        *                following elements are parameters to the function.
+        *                Note that callback functions will recieve this object 
as
+        *                first parameter.
+        */
+       public function addExtensionUpdate( $update ) {
+               $this->extensionUpdates[] = $update;
+       }
+
+       /**
+        * Get the list of extension-defined updates
+        *
+        * @return Array
+        */
+       protected function getExtensionUpdates() {
+               return $this->extensionUpdates;
+       }
+
        public function getPostDatabaseUpdateMaintenance() {
                return $this->postDatabaseUpdateMaintenance;
        }
 
        /**
         * Do all the updates
-        * @param $purge bool Whether to clear the objectcache table after 
updates
+        *
+        * @param $purge Boolean: whether to clear the objectcache table after 
updates
         */
        public function doUpdates( $purge = true ) {
                global $IP, $wgVersion;
                require_once( "$IP/maintenance/updaters.inc" );
-               $this->updates = array_merge( $this->getCoreUpdateList(),
-                       $this->getOldGlobalUpdates() );
-               foreach ( $this->updates as $params ) {
+
+               $this->runUpdates( $this->getCoreUpdateList(), false );
+               $this->runUpdates( $this->getOldGlobalUpdates(), false );
+               $this->runUpdates( $this->getExtensionUpdates(), true );
+
+               $this->setAppliedUpdates( $wgVersion, $this->updates );
+
+               if( $purge ) {
+                       $this->purgeCache();
+               }
+       }
+
+       /**
+        * Helper function for doUpdates()
+        *
+        * @param $updates Array of updates to run
+        * @param $passSelf Boolean: whether to pass this object we calling 
external
+        *                  functions
+        */
+       private function runUpdates( array $updates, $passSelf ) {
+               foreach ( $updates as $params ) {
                        $func = array_shift( $params );
                        if( !is_array( $func ) && method_exists( $this, $func ) 
) {
                                $func = array( $this, $func );
+                       } elseif ( $passSelf ) {
+                               array_unshift( $params, $this );
                        }
                        call_user_func_array( $func, $params );
                        flush();
                }
-               $this->setAppliedUpdates( $wgVersion, $this->updates );
-
-               if( $purge ) {
-                       $this->purgeCache();
-               }
+               $this->updates = array_merge( $this->updates, $updates );
        }
 
        protected function setAppliedUpdates( $version, $updates = array() ) {



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to