[pLog-svn] r5222 - in plog/branches/lifetype-1.2: . templates/wizard

mark at devel.lifetype.net mark at devel.lifetype.net
Thu Mar 29 12:42:43 EDT 2007


Author: mark
Date: 2007-03-29 12:42:43 -0400 (Thu, 29 Mar 2007)
New Revision: 5222

Added:
   plog/branches/lifetype-1.2/templates/wizard/fix120.template
Modified:
   plog/branches/lifetype-1.2/templates/wizard/checks.template
   plog/branches/lifetype-1.2/wizard.php
Log:
Add Fix120 option for user who already upgrade from lifetype 1.1.x to lifetype 1.2.0.

It will fixing those preview images filename for them.

Modified: plog/branches/lifetype-1.2/templates/wizard/checks.template
===================================================================
--- plog/branches/lifetype-1.2/templates/wizard/checks.template	2007-03-29 15:41:52 UTC (rev 5221)
+++ plog/branches/lifetype-1.2/templates/wizard/checks.template	2007-03-29 16:42:43 UTC (rev 5222)
@@ -18,6 +18,11 @@
       system in order to ensure that LifeType can run properly.
       <br/><br/>
       </p>
+	  <img src="imgs/admin/icon_info-16.png" alt="Info" class="wizardInfoIcon" />
+	   <p class="wizardInfoText">
+	  <b>NOTE:</b>If you already upgrade to 1.2.0, there are some changes that need to be done to your resource file name. 
+	  This is a known issue in the upgrade process of LifeType 1.1.x to 1.2.0 that does not convert preview image
+	  file name correctly. In order to have this issue fixed, click <a href="?nextStep=Fix120">here</a> and let the browser window reload.</p>
      </div>
    {/if}
    

Added: plog/branches/lifetype-1.2/templates/wizard/fix120.template
===================================================================
--- plog/branches/lifetype-1.2/templates/wizard/fix120.template	                        (rev 0)
+++ plog/branches/lifetype-1.2/templates/wizard/fix120.template	2007-03-29 16:42:43 UTC (rev 5222)
@@ -0,0 +1,45 @@
+{include file="wizard/header.template" step=4 mode=update title="Changes in Resources"}
+<form name="fix120" method="post" id="update3">
+<fieldset class="inputField">
+<legend>Data Changes</legend>
+{if $viewIsError}
+    <div class="wizardError">
+     <img src="imgs/admin/icon_error-16.png" alt="Error" class="wizardInfoIcon" />
+     <p style="color:red;margin-left:20px;">{$viewErrorMessage}</p>
+     <p>You may choose to ignore this error and continue with the data update process by
+     clicking the "Continue" button below.
+    </div>
+{else}
+   <div class="wizardInfo">
+    <img src="imgs/admin/icon_info-16.png" alt="Info" class="wizardInfoIcon" />
+    <p class="wizardInfoText">
+    {$message}
+    </p>
+   </div> 
+{/if}
+</fieldset>
+<div class="buttons">
+   {if !$complete}
+   <input type="hidden" name="nextStep" value="Fix120"/>
+   {else}
+   {if !$viewIsError}
+   <input type="hidden" name="nextStep" value="Update4"/>   
+   <input type="submit" name="Prev" value="&laquo; Previous"/>   
+   <input type="submit" name="Next" value="Next &raquo;"/>   
+   {/if}
+   {/if}
+   {if $viewIsError}
+     <input type="hidden" name="nextStep" value="Fix120"/>   
+     <input type="submit" name="continue" value="Continue" />
+   {/if}   
+   <input type="hidden" name="page" value="{$nextStep}" />
+   <input type="hidden" name="transformerId" value="{$transformerId}" />
+</div>
+</form>
+{if !$complete  && !$viewIsError}
+ <!-- let's make the document submit itself -->
+ <script type="text/javascript">
+  document.update3.submit();
+ </script>
+{/if}
+{include file="wizard/footer.template"}
\ No newline at end of file

Modified: plog/branches/lifetype-1.2/wizard.php
===================================================================
--- plog/branches/lifetype-1.2/wizard.php	2007-03-29 15:41:52 UTC (rev 5221)
+++ plog/branches/lifetype-1.2/wizard.php	2007-03-29 16:42:43 UTC (rev 5222)
@@ -90,6 +90,7 @@
     $_actionMap["Update1"] = "UpdateStepOne";
     $_actionMap["Update2"] = "UpdateStepTwo";
     $_actionMap["Update3"] = "UpdateStepThree";
+    $_actionMap["Fix120"] = "Fix120StepOne";
 
 
     /**
@@ -1806,7 +1807,6 @@
 	                    }
 					}
 				}
-
 				
 				// if it's an image, we also need to process the previews
 				if( $row["resource_type"] == "1" ) {
@@ -1843,8 +1843,6 @@
 	                    }
 					}
 				}
-				
-				
 
                 $this->updatedRecords++;
             }
@@ -1854,9 +1852,8 @@
         }        
     }
 
-
     /**
-     * processes all resource files and renames the files to their "real" names
+     * processes all resource files and renames the files to their "encoded" names
      */
     class ResourcesEncodedFileNameDataTransformer extends DatabaseDataTransformer
     {
@@ -1901,9 +1898,6 @@
 				$fileName = $galleryFolder.$row["owner_id"]."/".$row["owner_id"]."-".$row["id"].".".$fileExt;
 				$destFileName = $galleryFolder.$row["owner_id"]."/".$row["owner_id"]."-".$row["id"].".".strtolower($fileExt);
 				
-                    //print( "Renaming file: $fileName --- $destFileName<br/>" );
-
-                    // skip the rename if we already did it
 				if( $fileName != $destFileName ) {
 					if( File::exists( $fileName )) {
 		                if( !File::exists( $destFileName)) {
@@ -1922,6 +1916,96 @@
         }        
     }
 
+    /**
+     * processes all resource files that we did not convert correctly in 1.2.0
+     */
+    class ResourcesFix120FileNameDataTransformer extends DatabaseDataTransformer
+    {
+        function getNumSteps()
+        {
+            return( parent::getNumSteps( "gallery_resources" ));
+        }
+    
+        function perform()
+        {
+            $this->message = "Fixing resource files with original file naming rule (step %s of %s)<br/>";        
+        
+            $query1 = "SELECT id, owner_id, file_name, resource_type, thumbnail_format FROM ".$this->dbPrefix."gallery_resources";
+
+			$config =& Config::getConfig();
+			$galleryFolder = $config->getValue( "resources_folder" );
+
+            // total number of comments
+            $res1 = $this->Execute( $query1, $this->page, $this->itemsPerPage );
+            if( !$res1 ) {
+                $this->message .= "Error performing loading resource data";
+                return false;
+            }
+            if( $res1->RecordCount() == 0 ) {
+				$this->message .= "No more records to process";
+				return( true );            
+            }
+            $numComments = Array();
+            while( $row = $res1->FetchRow()) {
+				//
+				// process each one of the rows and rename the main file
+				//
+				
+				// get the file extension
+				if(( $extPos = strrpos( $row["file_name"], "." )) !== false ) {					
+					$fileExt = substr( $row["file_name"], $extPos+1, strlen( $row["file_name"] ));
+				}
+				else {
+					$fileExt = "";
+				}
+
+				// Only convert the preview file name if the file extension does not lower case
+				if( strtolower( $fileExt ) != $fileExt ) {
+					// if it's an image, we also need to process the previews
+					if( $row["resource_type"] == "1" ) {
+						// calculate the extension of the preview file, depending on how it was saved
+						if( $row["thumbnail_format"] == "same" ) {
+							$previewExt = strtolower( $fileExt );
+							$destFileName = $row["file_name"];
+						}
+						else {
+							$previewExt = $row["thumbnail_format"];
+							// remove the old extension and put the new one in place
+							//print("file name = ".$row["file_name"]." - file ext = $fileExt - previewExt = $previewExt" );
+							$destFileName = str_replace( $fileExt, $previewExt, $row["file_name"] );
+						}
+							
+						// file names for the preview and medium preview
+						$previewFileName = $galleryFolder.$row["owner_id"]."/previews/".$row["owner_id"]."-".$row["id"].".".$previewExt;
+						$medPreviewFileName = $galleryFolder.$row["owner_id"]."/previews-med/".$row["owner_id"]."-".$row["id"].".".$previewExt;					
+						// destination file names for the preview and medium preview
+						$destPreviewFileName = $galleryFolder.$row["owner_id"]."/previews/".$destFileName;
+						$destMedPreviewFileName = $galleryFolder.$row["owner_id"]."/previews-med/".$destFileName;
+						
+						//print(" -- renaming preview: $previewFileName -- $destPreviewFileName<br/>");
+						//print(" -- renaming medium preview: $medPreviewFileName -- $destMedPreviewFileName<br/>");					
+						
+						if( File::exists( $previewFileName )) {
+	                    	if( !File::exists( $destPreviewFileName)) {
+	                        	File::rename( $previewFileName, $destPreviewFileName );
+	                    	}
+						}
+						if( File::exists( $medPreviewFileName )) {
+		                    if( !File::exists( $destMedPreviewFileName)) {
+		                        File::rename( $medPreviewFileName, $destMedPreviewFileName );
+		                    }
+						}
+					}
+				}
+
+                $this->updatedRecords++;
+            }
+            $res1->Close();
+            $this->message .= "{$this->updatedRecords} resource files updated, ".$this->getTotalProcessedRecords()." processed so far (".$this->getPercentProcessed()."%)<br/>";
+            return true;        
+        }        
+    }    
+
 	// Dummy Transformer
 	class DummyDataTransformer extends DatabaseDataTransformer
 	{
@@ -2107,9 +2191,132 @@
 
             return true;
         }
+    }
 
-    }    
+	// Fix those resources that we did not convert correctly in 1.2.0
+    class Fix120StepOne extends WizardPagedAction
+    {
+        var $message;  
+        var $currentTransformerId;
+        var $totalTransformers;
+    
+        function Fix120StepOne( $actionInfo, $httpRequest )
+        {
+            $this->WizardPagedAction( $actionInfo, $httpRequest );
+            
+            /**
+             * array with the data transformers that will be run
+             */
+            $this->transformers = Array(
+				"ResourcesFix120FileNameDataTransformer",
+				"DummyDataTransformer"
+            );
 
+            $this->currentTransformerId = $this->getTransformerIdFromRequest();
+            $this->totalTransformers = count( $this->transformers ) - 1;
+        }
+        
+        /**
+         * 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;
+            $message = sprintf( $message, $this->currentTransformerId + 1, $this->totalTransformers );
+            
+            //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/>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( "fix120" );
+                    // 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( "fix120" );
+                        // 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!
+						// delete the contents of the temporary folder
+						include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
+						$config =& Config::getConfig();
+						$tmpFolder = $config->getValue( "temp_folder", TEMP_FOLDER );
+                        WizardTools::cleanTmpFolder();
+
+                        // User upgrade LifeType from 1.1.x to 1.2.0, they have to use "original_file_name",
+                        // becasue there is no option for user to choose he want to use encoded file name
+                        // or original file name.
+                        // save the resources naming rule to config table
+						$config->saveValue( "resources_naming_rule", "original_file_name" );
+
+                        $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
@@ -2121,4 +2328,4 @@
     //// main part ////
     $controller = new Controller( $_actionMap, "nextStep" );
     $controller->process( HttpVars::getRequest());
-?>
+?>
\ No newline at end of file



More information about the pLog-svn mailing list