[pLog-svn] r3359 - plog/trunk/class/gallery/dao

mark at devel.lifetype.net mark at devel.lifetype.net
Mon May 8 03:55:48 GMT 2006


Author: mark
Date: 2006-05-08 03:55:46 +0000 (Mon, 08 May 2006)
New Revision: 3359

Modified:
   plog/trunk/class/gallery/dao/galleryalbums.class.php
Log:
Apply the patch from tszming in http://bugs.lifetype.net/view.php?id=828.

It can prevent the gallery album falling into a looping situation.

Modified: plog/trunk/class/gallery/dao/galleryalbums.class.php
===================================================================
--- plog/trunk/class/gallery/dao/galleryalbums.class.php	2006-05-08 03:08:05 UTC (rev 3358)
+++ plog/trunk/class/gallery/dao/galleryalbums.class.php	2006-05-08 03:55:46 UTC (rev 3359)
@@ -176,7 +176,26 @@
         	
         	return( $result );
         }
+
+        /**
+         * Returns an array with all the parent album ids of the given album
+         *
+         * @param album The album object whose parents we'd like to get.
+         * @return An array of GalleryAlbum Id
+         */        
+		function getAllParentAlbumIds( $album ) {
+		            
+		    $currentParentId = $album->getParentId();
+		    $parentAlbumsIds = array();
 		
+		    while ( $currentParentId != 0 ) {
+		        $parentAlbumsIds[] = $currentParentId;
+		        $parentAlbum = $this->getAlbum( $currentParentId, -1, false, false );
+		        $currentParentId = $parentAlbum->getParentId();
+		    }
+		    return $parentAlbumsIds;
+		}
+		
         /**
          * Adds an album to the database
          *
@@ -214,6 +233,15 @@
 				return false;
 			}
 			
+			if ($album->getParentId() != 0) {
+			    $parentAlbums = $this->getAllParentAlbumIds( $this->getAlbum( $album->getParentId(), -1, false, false ) ) ;
+			
+			    foreach ( $parentAlbums as $parentAlbum ) {
+			        if ( $parentAlbum == $album->getId() )
+			            return false;
+			    }
+			}
+			
 			// load the previous version of this album
 			$prevVersion = $this->getAlbum( $album->getId());			
 			



More information about the pLog-svn mailing list