[pLog-svn] r5987 - plog/branches/lifetype-1.2/class/gallery/dao
oscar at devel.lifetype.net
oscar at devel.lifetype.net
Mon Oct 15 16:31:33 EDT 2007
Author: oscar
Date: 2007-10-15 16:31:33 -0400 (Mon, 15 Oct 2007)
New Revision: 5987
Modified:
plog/branches/lifetype-1.2/class/gallery/dao/galleryresource.class.php
plog/branches/lifetype-1.2/class/gallery/dao/galleryresources.class.php
plog/branches/lifetype-1.2/class/gallery/dao/galleryresourcestorage.class.php
Log:
Implemented feature request http://bugs.lifetype.net/view.php?id=1405 -- Added method GalleryResource::setOwnerId(), which turned out to be a bit more complicated than expected because when changing the owner id of a resource we also need to move the file and its thumbnails (if any) around.
Modified: plog/branches/lifetype-1.2/class/gallery/dao/galleryresource.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/gallery/dao/galleryresource.class.php 2007-10-15 20:30:16 UTC (rev 5986)
+++ plog/branches/lifetype-1.2/class/gallery/dao/galleryresource.class.php 2007-10-15 20:31:33 UTC (rev 5987)
@@ -262,6 +262,16 @@
}
/**
+ * Sets the identifier of the owner of this resource
+ *
+ * @param ownerId The identifier of the owner
+ */
+ function setOwnerId( $ownerId )
+ {
+ $this->_ownerId = $ownerId;
+ }
+
+ /**
* Sets the GalleryAlbum object to which this file belongs
*/
function setAlbum( $album )
Modified: plog/branches/lifetype-1.2/class/gallery/dao/galleryresources.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/gallery/dao/galleryresources.class.php 2007-10-15 20:30:16 UTC (rev 5986)
+++ plog/branches/lifetype-1.2/class/gallery/dao/galleryresources.class.php 2007-10-15 20:31:33 UTC (rev 5987)
@@ -758,6 +758,7 @@
$this->_cache->removeData( $resource->getFileName(), CACHE_RESOURCES_BY_NAME );
// and update the album counters... must substract 1 from the previous album
// and must add one to the new album
+ lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryalbums.class.php" );
$albums = new GalleryAlbums();
$album = $resource->getAlbum();
$album->setNumResources( $album->getNumResources() + 1 );
@@ -766,7 +767,17 @@
// update the counters of the previous album
$prevAlbum = $prevVersion->getAlbum();
$prevAlbum->setNumResources( $prevAlbum->getNumResources() - 1 );
- $albums->updateAlbum( $prevAlbum );
+ $albums->updateAlbum( $prevAlbum );
+
+ // was the the owner id changed, compared to the old version? because if it was, then
+ // we also need to move the file and the thumbnails
+ if( $resource->getOwnerId() != $prevVersion->getOwnerId()) {
+ lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryresourcestorage.class.php" );
+ $storage = new GalleryResourceStorage();
+ if (!$storage->moveFile( $prevVersion, $resource )) {
+ return false;
+ }
+ }
}
return( $result );
Modified: plog/branches/lifetype-1.2/class/gallery/dao/galleryresourcestorage.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/gallery/dao/galleryresourcestorage.class.php 2007-10-15 20:30:16 UTC (rev 5986)
+++ plog/branches/lifetype-1.2/class/gallery/dao/galleryresourcestorage.class.php 2007-10-15 20:31:33 UTC (rev 5987)
@@ -394,5 +394,64 @@
$resourcePath = $this->getUserFolder( $resource->getOwnerId()).$fileName;
return $resourcePath;
}
- }
-?>
+
+
+ /**
+ * Moves a file from one owner folder to another if the owner was modified.
+ *
+ * @param prevVersion A GalleryResource object
+ * @param resource A GalleryResource object
+ * @return True if successfull or if no move were needed.
+ */
+ function moveFile( $prevVersion, $resource )
+ {
+ $prevOwnerId = $prevVersion->getOwnerId();
+ $newOwnerId = $resource->getOwnerId();
+
+ if ($newOwnerId == $prevOwnerId) {
+ // No need to move
+ return true;
+ }
+
+ // check that the folders exist
+ if( !$this->_checkUserStorageFolder( $prevOwnerId ))
+ return false;
+ if( !$this->_checkUserStorageFolder( $newOwnerId ))
+ return false;
+
+ // move the main file
+ $fileName = $this->getUserFolder( $prevOwnerId ) . $resource->getFileName();
+ $destFile = $this->getUserFolder( $newOwnerId ) . $resource->getFileName();
+ $res = File::rename( $fileName, $destFile );
+ if( !$res )
+ return false;
+
+ // check that the permissions are correct
+ File::chMod( $destFile, 0755 );
+
+ // move the preview
+ $fileName = $this->getPreviewsFolder( $prevOwnerId ) . $resource->getPreviewFileName();
+ $destFile = $this->getPreviewsFolder( $newOwnerId ) . $resource->getPreviewFileName();
+ $res = File::rename( $fileName, $destFile );
+ if( !$res )
+ return false;
+
+ // check that the permissions are correct
+ File::chMod( $destFile, 0755 );
+
+ // move the medium size preview
+ $fileName = $this->getMediumSizePreviewsFolder( $prevOwnerId ) . $resource->getMediumSizePreviewFileName();
+ $destFile = $this->getMediumSizePreviewsFolder( $newOwnerId ) . $resource->getMediumSizePreviewFileName();
+ $res = File::rename( $fileName, $destFile );
+
+ if( !$res )
+ return false;
+
+ // check that the permissions are correct
+ File::chMod( $destFile, 0755 );
+
+ return true;
+ }
+ }
+?>
+
\ No newline at end of file
More information about the pLog-svn
mailing list