[pLog-svn] r5221 - plog/branches/lifetype-1.2

mark at devel.lifetype.net mark at devel.lifetype.net
Thu Mar 29 11:41:52 EDT 2007


Author: mark
Date: 2007-03-29 11:41:52 -0400 (Thu, 29 Mar 2007)
New Revision: 5221

Modified:
   plog/branches/lifetype-1.2/wizard.php
Log:
1. Add ResourcesEncodedFileNameDataTransformer for "encoded_file_name" option. We still need to convert the filename to lowercase...

2. Add a dummy transformers, let the last message can show on the screen when upgrade complete.

Modified: plog/branches/lifetype-1.2/wizard.php
===================================================================
--- plog/branches/lifetype-1.2/wizard.php	2007-03-29 11:55:13 UTC (rev 5220)
+++ plog/branches/lifetype-1.2/wizard.php	2007-03-29 15:41:52 UTC (rev 5221)
@@ -1753,7 +1753,7 @@
     /**
      * processes all resource files and renames the files to their "real" names
      */
-    class ResourcesDataTransformer extends DatabaseDataTransformer
+    class ResourcesOriginalFileNameDataTransformer extends DatabaseDataTransformer
     {
         function getNumSteps()
         {
@@ -1762,7 +1762,7 @@
     
         function perform()
         {
-            $this->message = "Updating resource files (step %s of %s)<br/>";        
+            $this->message = "Updating 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";
 
@@ -1853,7 +1853,89 @@
             return true;        
         }        
     }
+
+
+    /**
+     * processes all resource files and renames the files to their "real" names
+     */
+    class ResourcesEncodedFileNameDataTransformer extends DatabaseDataTransformer
+    {
+        function getNumSteps()
+        {
+            return( parent::getNumSteps( "gallery_resources" ));
+        }
+    
+        function perform()
+        {
+            $this->message = "Updating resource files with encoded 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 = "";
+				}
+								
+				$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)) {
+		                    if( !File::rename( $fileName, $destFileName )) {
+		                        $this->message .= "Error updating resource file with id ".$row["id"].", while attempting to rename file from $fileName to $destFileName<br/>";
+		                    }
+						}
+					}
+				}	
+
+                $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
+	{
+		function getNumSteps()
+		{
+			return( 0 );
+		}
+		
+		function perform()
+		{
+			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
@@ -1906,6 +1988,8 @@
 					"AdminUserPermissionsDataTransformer",
 					"UserPermissionsDataTransformer",
 					"ConfigDataTransformer",
+					"ResourcesEncodedFileNameDataTransformer",
+					"DummyDataTransformer"
 	            );
 	        }
 	        else {
@@ -1915,12 +1999,13 @@
 					"AdminUserPermissionsDataTransformer",
 					"UserPermissionsDataTransformer",
 					"ConfigDataTransformer",
-					"ResourcesDataTransformer"
+					"ResourcesOriginalFileNameDataTransformer",
+					"DummyDataTransformer"
 	            );
 	    	}
 
             $this->currentTransformerId = $this->getTransformerIdFromRequest();
-            $this->totalTransformers = count( $this->transformers );
+            $this->totalTransformers = count( $this->transformers ) - 1;
         }
         
         /**
@@ -1967,8 +2052,8 @@
                 // transformer id
                 $this->_view->setValue( "transformerId", $this->currentTransformerId );            
                 $this->_view->setValue( "error", true );
-                if( $transformer->ErrorMsg() != "" ) {
-                    $message .= "<br/>The database error message was: ".$transformer->ErrorMsg()."<br/>";
+                if( $transformer->DbError() != "" ) {
+                    $message .= "<br/>The database error message was: ".$transformer->DbError()."<br/>";
                 }
 
                 $this->_view->setErrorMessage( $message );



More information about the pLog-svn mailing list