Cleanup to r69187: forgot to safeguard against ul_value or updatelog itself not existing.
authorChad Horohoe <demon@users.mediawiki.org>
Sun, 11 Jul 2010 12:31:44 +0000 (12:31 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Sun, 11 Jul 2010 12:31:44 +0000 (12:31 +0000)
includes/installer/Update.php

index 3192c9e..2fcaeb0 100644 (file)
@@ -9,7 +9,7 @@ class Update {
        // Array of updates to perform on the database
        protected $updates = array();
 
-       // Thing we'll need
+       // Things we'll need
        protected $db, $updater;
 
        public function __construct( $db ) {
@@ -41,6 +41,12 @@ class Update {
        }
 
        protected function loadUpdates() {
+               // If the updatelog table hasn't been upgraded, we can't use the new
+               // style of recording our steps. Run all to be safe
+               if( !$this->canUseNewUpdatelog() ) {
+                       $this->updates = $this->updater->getUpdates();
+                       return;
+               }
                foreach( $this->updater->getUpdates() as $version => $updates ) {
                        $appliedUpdates = $this->getAppliedUpdates( $version );
                        if( !$appliedUpdates || $appliedUpdates != $updates ) {
@@ -49,7 +55,7 @@ class Update {
                }
        }
 
-       private function getAppliedUpdates( $version ) {
+       protected function getAppliedUpdates( $version ) {
                $key = "updatelist-$version";
                $val = $this->db->selectField( 'updatelog', 'ul_value',
                        array( 'ul_key' => $key ), __METHOD__ );
@@ -61,10 +67,27 @@ class Update {
        }
 
        private function setAppliedUpdates( $version, $updates = array() ) {
+               if( !$this->canUseNewUpdatelog() ) {
+                       $this->updates = $this->updater->getUpdates();
+                       return;
+               }
                $key = "updatelist-$version";
                $this->db->delete( 'updatelog', array( 'ul_key' => $key ), __METHOD__ );
                $this->db->insert( 'updatelog',
                        array( 'ul_key' => $key, 'ul_value' => serialize( $updates ) ),
                         __METHOD__ );
        }
+
+       /**
+        * Updatelog was changed in 1.17 to have a ul_value column so we can record
+        * more information about what kind of updates we've done (that's what this
+        * class does). Pre-1.17 wikis won't have this column, and really old wikis
+        * might not even have updatelog at all
+        *
+        * @return boolean
+        */
+       protected function canUseNewUpdatelog() {
+               return $this->db->tableExists( 'updatelog' ) &&
+                       $this->db->fieldExists( 'updatelog', 'ul_value' );
+       }
 }