[pLog-svn] r1837 - in plog/branches/plog-1.0.1/class: file gallery/dao

oscar at devel.plogworld.net oscar at devel.plogworld.net
Thu Apr 14 20:50:51 GMT 2005


Author: oscar
Date: 2005-04-14 20:50:51 +0000 (Thu, 14 Apr 2005)
New Revision: 1837

Modified:
   plog/branches/plog-1.0.1/class/file/file.class.php
   plog/branches/plog-1.0.1/class/file/fileuploads.class.php
   plog/branches/plog-1.0.1/class/gallery/dao/galleryresources.class.php
Log:
this should solve issue 429, successfully tested by posting binary files via xmlrpc and via the resource center.

Modified: plog/branches/plog-1.0.1/class/file/file.class.php
===================================================================
--- plog/branches/plog-1.0.1/class/file/file.class.php	2005-04-14 17:30:17 UTC (rev 1836)
+++ plog/branches/plog-1.0.1/class/file/file.class.php	2005-04-14 20:50:51 UTC (rev 1837)
@@ -3,8 +3,9 @@
     /**
      * \defgroup File
 	 *
-	 * The File module provides some classes to deal with files. The File class is the most
-	 * useful once, since provides OOP wrappers around some PHP functions that work with files.
+	 * The File module provides some classes to deal with files. The File class
+	 * is the most useful once, since provides OOP wrappers around some PHP
+	 * functions that work with files.
      */
 
 
@@ -28,7 +29,8 @@
 		 var $_mode;
 		 
 		 /**
-		  * Creates an object of this type, but the file is not automaticaly opened
+		  * Creates an object of this type, but the file is not automaticaly 
+		  * opened
 		  *
 		  * @param fileName The name of the file
 		  */
@@ -69,7 +71,8 @@
 		 
 		 /**
 		  * Reads the whole file and put it into an array, where every position
-		  * of the array is a line of the file (new-line characters not included)
+		  * of the array is a line of the file (new-line characters not
+		  * included)
 		  *
 		  * @return An array where every position is a line from the file.
 		  */
@@ -88,8 +91,8 @@
 		 /**
 		  * Reads bytes from the currently opened file
 		  *
-		  * @param size Amount of bytes we'd like to read from the file. It is set
-		  * to 4096 by default.
+		  * @param size Amount of bytes we'd like to read from the file. It is 
+		  * set to 4096 by default.
 		  * @return Returns the read contents
 		  */
 		 function read( $size = 4096 )
@@ -156,9 +159,9 @@
 		  * Returns true wether the file is a directory. See
 		  * http://fi.php.net/manual/en/function.is-dir.php for more details.
 		  *
-		  * @param file The filename we're trying to check. If omitted, the current file
-		  * will be used (note that this function can be used as static as long as the
-		  * file parameter is provided)
+		  * @param file The filename we're trying to check. If omitted, the
+		  * current file will be used (note that this function can be used as
+		  * static as long as the file parameter is provided)
 		  * @return Returns true if the file is a directory.
 		  */
 		 function isDir( $file = null )
@@ -171,11 +174,12 @@
 		 
 		 /**
 		  * Returns true if the file is writable by the current user.
-		  * See http://fi.php.net/manual/en/function.is-writable.php for more details.
+		  * See http://fi.php.net/manual/en/function.is-writable.php for more 
+		  * details.
 		  *
-		  * @param file The filename we're trying to check. If omitted, the current file
-		  * will be used (note that this function can be used as static as long as the
-		  * file parameter is provided)
+		  * @param file The filename we're trying to check. If omitted, the
+		  * current file will be used (note that this function can be used as
+		  * static as long as the file parameter is provided)
 		  * @return Returns true if the file is writable, or false otherwise.
 		  */
 		 function isWritable( $file = null )
@@ -187,10 +191,11 @@
 		 }
 		 
 		 /**
-		  * returns true if the file is readable. Can be used as static if a filename is provided
+		  * returns true if the file is readable. Can be used as static if a
+		  * filename is provided
 		  *
-		  * @param if provided, this method can be used as an static method and it will check for
-		  * the readability status of the file
+		  * @param if provided, this method can be used as an static method and
+		  * it will check for the readability status of the file
 		  * @return true if readable or false otherwise
 		  */
 		 function isReadable( $file = null )
@@ -204,8 +209,8 @@
 		 }
 		 
 		 /**
-		  * removes a file. Can be used as static if a filename is provided. Otherwise it will
-		  * remove the file that was given in the constructor
+		  * removes a file. Can be used as static if a filename is provided. 
+		  * Otherwise it will remove the file that was given in the constructor
 		  *
 		  * @param optionally, name of the file to delete
 		  * @return True if successful or false otherwise
@@ -243,9 +248,10 @@
 				return File::delete( $dirName );
 			}
 				
-			// Glob::myGlob is easier to use than Glob::glob, specially when we're
-			// relying on the native version... This improved version will automatically
-			// ignore things like "." and ".." for us, making it much easier!
+			// Glob::myGlob is easier to use than Glob::glob, specially when 
+			// we're relying on the native version... This improved version 
+			// will automatically ignore things like "." and ".." for us, 
+			// making it much easier!
 			$files = Glob::myGlob( $dirName, "*" );
 			foreach( $files as $file ) {
 				if( File::isDir( $file )) {
@@ -266,15 +272,17 @@
 		 }
 		 
 		 /**
-       	  * Creates a new folder. If the folder name is /a/b/c and neither /a or /a/b exist, this
-		  * method will take care of creating the whole folder structure automatically.
+       	  * Creates a new folder. If the folder name is /a/b/c and neither 
+       	  * /a or /a/b exist, this method will take care of creating the 
+       	  * whole folder structure automatically.
 		  *
 		  * @static
 		  * @param dirName The name of the new folder
 		  * @param mode Attributes that will be given to the folder
 		  * @return Returns true if no problem or false otherwise.
 		  */
-		 function createDir( $dirName, $mode = FILE_DEFAULT_DIRECTORY_CREATION_MODE )
+		 function createDir( $dirName, 
+		                     $mode = FILE_DEFAULT_DIRECTORY_CREATION_MODE )
 		 {
              if(File::exists($dirName)) return true;
 
@@ -312,8 +320,9 @@
 		 /**
 		  * Returns the size of the file.
 		  *
-		  * @param string fileName An optional parameter specifying the name of the file. If omitted,
-		  * we will use the file that we have currently opened. Please note that this function can
+		  * @param string fileName An optional parameter specifying the name 
+		  * of the file. If omitted, we will use the file that we have 
+		  * currently opened. Please note that this function can
 		  * be used as static if a file name is specified.
 		  * @return An integer specifying the size of the file.
 		  */
@@ -329,31 +338,49 @@
 				 return $size;
 		 }
 		 
-		 /**
-			 * renames a file
-		  *
-		  * http://www.php.net/manual/en/function.rename.php
-		  *
-		  * This function can be used as static if inFile and outFile are both not
-		  * empty. if outFile is empty, then the internal file of the current object
-		  * will be used as the input file and the first parameter of this method
-		  * will become the destination file name.
-		  *
-		  * @param inFile Original file
-		  * @param outFile Destination file.
-		  * @return Returns true if file was renamed ok or false otherwise.
-		  */
-		 function rename( $inFile, $outFile = null )
-		 {
-			 // check how many parameters we have
-			 if( $outFile == null ) {
-				 $outFile = $inFile;
-				 $inFile  = $this->_fileName;
-			 }
-			 
-			 // and rename everything
-			 return rename( $inFile, $outFile );
-		 }
+         /**
+          * renames a file
+          *
+          * http://www.php.net/manual/en/function.rename.php
+          *
+          * This function can be used as static if inFile and outFile are both 
+          * not empty. if outFile is empty, then the internal file of the
+          * current object will be used as the input file and the first 
+          * parameter of this method will become the destination file name.
+          *
+          * @param inFile Original file
+          * @param outFile Destination file.
+          * @return Returns true if file was renamed ok or false otherwise.
+          */
+          function rename( $inFile, $outFile = null )
+          {
+              // check how many parameters we have
+              if( $outFile == null ) {
+                  $outFile = $inFile;
+                  $inFile  = $this->_fileName;
+              }
+            
+              // In order to work around the bug in php versions older
+              // than 4.3.3, where rename will not work across different
+              // partitions, this will be a copy and delete of the original file
+            
+              // copy the file to the new location
+              if (!copy($inFile, $outFile)) {
+                  // The copy failed, return false
+                  return FALSE;
+              }
+            
+              // Now delete the old file
+              // NOTICE, we are not checking the error here.  It is possible 
+              // the the original file will remain and the copy will exist.
+              //
+              // One way to potentially fix this is to look at the result of
+              // unlink, and then delete the copy if unlink returned FALSE, 
+              // but this call to unlink could just as easily fail
+              unlink( $inFile );
+            
+              return TRUE;
+          }
 		 
 		 /**
 		  * copies a file from one place to another.
@@ -373,7 +400,8 @@
 		  * changes the permissions of a file, via PHP's chmod() function
 		  *
 		  * @param inFile The name of the file whose mode we'd like to change
-		  * @param mode The new mode, or if none provided, it will default to 0644
+		  * @param mode The new mode, or if none provided, it will default 
+		  * to 0644
 		  * @return true if successful or false otherwise 
 		  * @static
 		  */
@@ -385,8 +413,10 @@
 		 /**
 		  * returns true if the file exists.
 		  *
-		  * Can be used as an static method if a file name is provided as a parameter
-		  * @param fileName optinally, name of the file whose existance we'd like to check
+		  * Can be used as an static method if a file name is provided as a
+		  *  parameter
+		  * @param fileName optinally, name of the file whose existance we'd
+		  * like to check
 		  * @return true if successful or false otherwise
 		  */
 		 function exists( $fileName = null ) 

Modified: plog/branches/plog-1.0.1/class/file/fileuploads.class.php
===================================================================
--- plog/branches/plog-1.0.1/class/file/fileuploads.class.php	2005-04-14 17:30:17 UTC (rev 1836)
+++ plog/branches/plog-1.0.1/class/file/fileuploads.class.php	2005-04-14 20:50:51 UTC (rev 1837)
@@ -102,7 +102,7 @@
                 array_push( $uploads, $upload );
             }
 
-            return $uploads;
+            return $uploads;
         }
         
         /**
@@ -120,22 +120,7 @@
                 return FALSE;
             }
             
-            // Now copy the file to the new location
-            if (!copy($filename, $destination)) {
-                // The copy failed, return false
-                return FALSE;
-            }
-            
-            // Now delete the old file
-            // NOTICE, we are not checking the error here.  It is possible 
-            // the the original file will remain and the copy will exist.
-            //
-            // One way to potentially fix this is to look at the result of unlink, and 
-            // then delete the copy if unlink returned FALSE, but this call to unlink 
-            // could just as easily fail
-            unlink( $filename );
-            
-            return TRUE;
-         }
+            return File::rename( $filename, $destination );
+         }
     }
 ?>

Modified: plog/branches/plog-1.0.1/class/gallery/dao/galleryresources.class.php
===================================================================
--- plog/branches/plog-1.0.1/class/gallery/dao/galleryresources.class.php	2005-04-14 17:30:17 UTC (rev 1836)
+++ plog/branches/plog-1.0.1/class/gallery/dao/galleryresources.class.php	2005-04-14 20:50:51 UTC (rev 1837)
@@ -524,7 +524,7 @@
         {
             // check if quotas are enabled, and if this file would make us go
             // over the quota
-            if( GalleryResourceQuotas::isBlogOverResourceQuota( $ownerId, File::getSize( $filePath ))) {
+            if( GalleryResourceQuotas::isBlogOverResourceQuota( $ownerId, File::getSize( $fullFilePath ))) {
                 return GALLERY_ERROR_QUOTA_EXCEEDED;
             }
             
@@ -552,7 +552,8 @@
             // and finally move the file to the right place in disk
             // move the file to disk
             $storage = new GalleryResourceStorage();
-            $resFile = $storage->storeFile( $resourceId, $ownerId, $fullFilePath );
+            $resFile = $storage->storeFile( $resourceId, $ownerId, $fullFilePath,
+                                            RESOURCE_STORAGE_STORE_MOVE );
             
             // if the file cannot be read, we will also remove the record from the
             // database so that we don't screw up




More information about the pLog-svn mailing list