Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba

rename $pathBeforeAbs bug when adding a new Image Gallery Page


Go to End


1249 Views

Avatar
slith

Community Member, 7 Posts

12 August 2010 at 9:37pm

Edited: 12/08/2010 10:12pm

I'm running SS 2.4.1 with the latest SVN builds of DataObjectManager, SWFUpload, and Image Gallery.

After creating my initial Image Gallery Page, I tried adding a new Image Gallery Page and Firebug was giving me this error :

ERROR [Warning]: rename(/MYPATH/public_html/assets/image-gallery/New-ImageGalleryPage-2/,/MYPATH/public_html/assets/image-gallery/New-ImageGalleryPage/) [<a href='function.rename'>function.rename</a>]: No such file or directory
IN POST /admin/AddPageOptionsForm
Line 402 in /MYPATH/public_html/sapphire/filesystem/File.php

Without Firebug, I wasn't seeing any error, so it appeared like nothing was happening when I hit "Go" but the page was there if i refreshed my /admin page.

When I hit "Go" a third time it worked fine but since it had already created my second New Image Gallery Page and the "New-ImageGalleryPage-2" directory in assets/image-gallery, it would trigger the error because $pathBeforeAbs was still set to "New-ImageGalleryPage-2"

If I continued adding pages, it would continue incrementing the number after "image-gallery/New-ImageGalleryPage-#", but $pathBeforeAbs was still looking for New-ImageGalleryPage-2.

I got around this problem by running a clean install and then editing sapphire/filesystem/File.php and changing the rename() code on line 402 to first check if $pathBeforeAbs exists.

So on line 402, I changed:

// Rename file or folder
$success = rename($pathBeforeAbs, $pathAfterAbs);
if(!$success) throw new Exception("Cannot move $pathBeforeAbs to $pathAfterAbs");

to

// Rename file or folder
if(file_exists($pathBeforeAbs)){				
       $success = rename($pathBeforeAbs, $pathAfterAbs);
       if(!$success) throw new Exception("Cannot move $pathBeforeAbs to $pathAfterAbs");			
}	

this appears to have fixed the problem... but perhaps there is a better solution for this?