[pLog-svn] r4411 - plog/trunk

Oscar Renalias oscar at renalias.net
Tue Dec 19 23:53:38 GMT 2006


So after these changes and revs 4412 and 4413, LT 1.2 is capable of  
working with resources uploaded in previous versions of LT while  
keeping old URLs available (by catching them and generating HTTP  
redirects to the new ones)

I've already asked about this a couple of times but some extra  
testing would be very much appreciated. If you have some spare time,  
please consider giving this a try (if possible with "real" data and  
files)

On 20 Dec 2006, at 00:48, oscar at devel.lifetype.net wrote:

> Author: oscar
> Date: 2006-12-19 22:48:32 +0000 (Tue, 19 Dec 2006)
> New Revision: 4411
>
> Modified:
>    plog/trunk/wizard.php
> Log:
> this should take care of renaming all resource files back to their  
> "original" names. It's only been tested with "normal" file names,  
> i.e. no strange characters such as accented vowels, umlauts or non- 
> latin characters. Some testing in those areas would be good...
>
>
> Modified: plog/trunk/wizard.php
> ===================================================================
> --- plog/trunk/wizard.php	2006-12-19 21:13:09 UTC (rev 4410)
> +++ plog/trunk/wizard.php	2006-12-19 22:48:32 UTC (rev 4411)
> @@ -1137,7 +1137,7 @@
>  					// if it's an admin permission, add it
>  					$p = new UserPermission( $userId, 0, $perm->getId());
>  					$userPerms->grantPermission( $p );
> -					print("granting permission: ".$perm->getName()."<br/>");
> +					//print("granting permission: ".$perm->getName()."<br/>");
>  				}
>  			}
>
> @@ -1664,7 +1664,7 @@
>  				if( $row["permission_id"] != 3) {
>  					foreach( $allPerms as $perm ) {
>  						if( !$perm->isAdminOnlyPermission() && !in_array( $perm- 
> >getName(), $blogOwnerOnlyPerms )) {
> -							print( "granting perm: ".$perm->getName()." - user: ".$row 
> ["user_id"]." - blog id: ".$row["blog_id"]."<br/>");							
> +							//print( "granting perm: ".$perm->getName()." - user: ".$row 
> ["user_id"]." - blog id: ".$row["blog_id"]."<br/>");							
>  							$perm = new UserPermission( $row["user_id"], $row 
> ["blog_id"], $perm->getId());
>  							$userPermissions->grantPermission( $perm );
>  						}
> @@ -1740,14 +1740,17 @@
>
>          function perform()
>          {
> -            $this->message = "<b>Updating users (step 2 of 2)</ 
> b><br/><br/>";
> +            $this->message = "<b>Updating resource files (step 3  
> of 3)</b><br/><br/>";
>
> -            $query1 = "SELECT DISTINCT user_id FROM ".$this- 
> >dbPrefix."users_permissions WHERE permission_id = 1";
> +            $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 changes to the  
> users table";
> +                $this->message .= "Error performing loading  
> resource data";
>                  return false;
>              }
>              if( $res1->RecordCount() == 0 ) {
> @@ -1756,21 +1759,65 @@
>              }
>              $numComments = Array();
>              while( $row = $res1->FetchRow()) {
> -                $userId = $row["user_id"];
> -                $update = "UPDATE ".$this->dbPrefix."users SET  
> site_admin = 1 WHERE id = ".Db::qstr($userId);
> -                $result = $this->Execute( $update );
> -                if( !$result ) {
> -                    $this->message .= "Error updating user with id  
> {$userId}<br/>";
> -                }
> -                else
> -                    $this->updatedRecords++;
> +				//
> +				// 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 
> ["file_name"];
> +				
> +				print( "Renaming file: $fileName --- $destFileName<br/>" );
> +				
> +				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/>";
> +				}
> +				
> +
> +				
> +				// 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 = $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/>");					
> +					
> +					File::rename( $previewFileName, $destPreviewFileName );
> +					File::rename( $medPreviewFileName, $destMedPreviewFileName );
> +				}
> +				
> +				
> +
> +                $this->updatedRecords++;
>              }
>              $res1->Close();
> -            $this->message .= "{$this->updatedRecords} users  
> updated, ".$this->getTotalProcessedRecords()." processed so far (". 
> $this->getPercentProcessed()."%)<br/>";
> +            $this->message .= "{$this->updatedRecords} resource  
> files updated, ".$this->getTotalProcessedRecords()." processed so  
> far (".$this->getPercentProcessed()."%)<br/>";
>              return true;
> -        }
> -
> -
> +        }
>      }
>
>      /**
> @@ -1812,8 +1859,8 @@
>               */
>              $this->transformers = Array(
>  				"AdminUserPermissionsDataTransformer",
> -				"UserPermissionsDataTransformer" /*,
> -				"ResourcesDataTransformer"*/
> +				"UserPermissionsDataTransformer",
> +				"ResourcesDataTransformer"
>              );
>
>              $this->currentTransformerId = $this- 
> >getTransformerIdFromRequest();
>
> _______________________________________________
> pLog-svn mailing list
> pLog-svn at devel.lifetype.net
> http://devel.lifetype.net/mailman/listinfo/plog-svn
>



More information about the pLog-svn mailing list