[pLog-svn] r4123 - plog/branches/lifetype-1.1.1

oscar at devel.lifetype.net oscar at devel.lifetype.net
Thu Oct 12 08:03:34 GMT 2006


Author: oscar
Date: 2006-10-12 08:03:33 +0000 (Thu, 12 Oct 2006)
New Revision: 4123

Modified:
   plog/branches/lifetype-1.1.1/wizard.php
Log:
fix for issue 1079 (http://bugs.lifetype.net/view.php?id=1079) -- we forgot to set the file_size field of resources when upgrading from 1.0 to 1.1.


Modified: plog/branches/lifetype-1.1.1/wizard.php
===================================================================
--- plog/branches/lifetype-1.1.1/wizard.php	2006-10-11 22:07:38 UTC (rev 4122)
+++ plog/branches/lifetype-1.1.1/wizard.php	2006-10-12 08:03:33 UTC (rev 4123)
@@ -85,6 +85,7 @@
     $_actionMap["Update1"] = "UpdateStepOne";
     $_actionMap["Update2"] = "UpdateStepTwo";
     $_actionMap["Update3"] = "UpdateStepThree";
+	$_actionMap["Fix111"] = "UpdateFix111";
 
 
     /**
@@ -2247,7 +2248,57 @@
             return true;        
         }
     }
+
+    /**
+     * populates the site_admin field in the users table
+     */
+    class ResourceSizeDataTransformer extends DatabaseDataTransformer
+    {
+        function getNumSteps()
+        {
+            return( parent::getNumSteps( "gallery_resources" ));
+        }
     
+        function perform()
+        {
+            $this->message = "<b>Updating gallery resources</b><br/><br/>";        
+        
+            $query1 = "SELECT id, metadata FROM ".$this->dbPrefix."gallery_resources";
+
+            // total number of comments
+            $res1 = $this->Execute( $query1, $this->page, $this->itemsPerPage );
+            if( !$res1 ) {
+                $this->message .= "Error performing changes to the gallery resources table!";
+                return false;
+            }
+            if( $res1->RecordCount() == 0 ) {
+				$this->message .= "No more records to process";
+				return( true );            
+            }
+            $numComments = Array();
+            while( $row = $res1->FetchRow()) {
+                $resId = $row["id"];
+				$fileSize = 0;
+				if( isset( $row["metadata"] )) {
+					$metadata = unserialize( $row["metadata"] );
+					if( is_array( $metadata )) {
+						$fileSize = $metadata["filesize"];
+					}
+				}
+                $update = "UPDATE ".$this->dbPrefix."gallery_resources SET file_size = $fileSize WHERE id = ".Db::qstr($resId);
+                $result = $this->Execute( $update );
+                if( !$result ) {
+                    $this->message .= "Error updating resource with id {$resId}<br/>";
+                }
+                else
+                    $this->updatedRecords++;
+            }
+            $res1->Close();
+            $this->message .= "{$this->updatedRecords} resources updated, ".$this->getTotalProcessedRecords()." processed so far (".$this->getPercentProcessed()."%)<br/>";
+            return true;        
+        }                
+    }
+    
     /**
      * This class is basically now a "data transformer runner", because now it works
      * like class that executes data transformers, collects their results and refreshes
@@ -2294,7 +2345,8 @@
                 "LinkCategoriesDataTransformer",
                 "CommentsDataTransformer",
                 "AlbumsDataTransformer",
-                "PostSchemaDataTransformer"
+                "PostSchemaDataTransformer",
+				"ResourceSizeDataTransformer"
             );
             
             $this->currentTransformerId = $this->getTransformerIdFromRequest();
@@ -2389,6 +2441,110 @@
 
     }    
 
+	class UpdateFix111 extends WizardPagedAction
+	{
+		function UpdateFix111( $actionInfo, $httpRequest )
+		{
+			$this->WizardPagedAction( $actionInfo, $httpRequest );
+
+            /**
+             * array with the data transformers that will be run
+             */
+            $this->transformers = Array(
+				"ResourceSizeDataTransformer"
+            );
+
+            $this->currentTransformerId = $this->getTransformerIdFromRequest();
+        }
+
+        /**
+         * gets the id of the transformer from the request. If it is not available, it
+         * will return the id of the first transformer available (which is '0')
+         *
+         * @private
+         */
+        function getTransformerIdFromRequest()
+        {    	
+			$id = HttpVars::getRequestValue( "transformerId" );
+			$val = new IntegerValidator();
+			if( !$val->validate( $id ))
+				$id = 0;
+
+			return $id;        
+        }        
+
+       function perform()
+       {
+            $step = $this->getPageFromRequest();
+
+            // get the current transformer class so that we can continue where we left
+            $transformerClass = $this->transformers[$this->currentTransformerId];                              
+            $transformer = new $transformerClass( $step );
+            $result = $transformer->perform();
+            $complete = $transformer->isComplete();
+            $message = $transformer->message;
+
+            //print("transformer = $transformerClass<br/>");
+
+            // error during processing and the processor is configured
+            // to fail on error   
+            if( !$result && $transformer->failOnError ) {
+                //print("Error in step = $step<br/>");
+                $this->_view = new WizardView( "update3" );
+                // current and next step
+                $this->_view->setValue( "currentStep", $step );
+                $this->_view->setValue( "nextStep", $step+1 );                
+                // whether this transformer is ready
+                $this->_view->setValue( "complete", $complete );
+                // transformer id
+                $this->_view->setValue( "transformerId", $this->currentTransformerId );            
+                $this->_view->setValue( "error", true );
+                if( $transformer->DbError() != "" ) {
+                    $message .= "<br/><br/>The database error message was: ".$transformer->DbError()."<br/>";
+                }
+
+                $this->_view->setErrorMessage( $message );
+            }                
+            else {
+                if( !$complete ) {
+                    //print("it's not complete! step = $step<br/>");
+                    $this->_view = new WizardView( "update3" );
+                    // current and next step
+                    $this->_view->setValue( "currentStep", $step );
+                    $this->_view->setValue( "nextStep", $step+1 );                
+                    // whether this transformer is ready
+                    $this->_view->setValue( "complete", $complete );
+                    // transformer id
+                    $this->_view->setValue( "transformerId", $this->currentTransformerId );
+                }            
+                else {
+                    // have we already been through all transformers?
+                    //print("transformer complete! - num transformers = ".count($this->transformers)."<br/>");
+                    $moreTransformers = ( $this->currentTransformerId+1 < count( $this->transformers ));
+                    if( $moreTransformers ) {
+                        //print("Starting new transformer!<br/>");
+                        $this->_view = new WizardView( "update3" );
+                        // current and next step
+                        $this->_view->setValue( "currentStep", 0 );
+                        $this->_view->setValue( "nextStep", 1 );  
+                        // whether this transformer is ready
+                        $this->_view->setValue( "complete", false );
+                        // transformer id
+                        $this->_view->setValue( "transformerId", $this->currentTransformerId+1 );
+                    }
+                    else {
+                        // no more data to transform, we can finalize the installation!
+                        $this->_view = new WizardView( "update4" );
+                    }
+                }
+            }
+
+            $this->_view->setValue( "message", $message );            
+
+            return true;
+		}
+	}
+
     // check if the "./tmp" folder is writable by us, otherwise
     // throw an error before the user gets countless errors
     // from Smarty



More information about the pLog-svn mailing list