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.

All other Modules /

Discuss all other Modules here.

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

Image Gallery issue: Replacing pictures in albums


Go to End


15 Posts   4993 Views

Avatar
creatormarius

Community Member, 11 Posts

1 June 2010 at 6:52pm

to the trackers : code updated - there were a few bugs. Hopefully these are all resolved now. I'm able to replace images successfully now into the album folder they should be in. Still testing, but looks ok.

I still wish to implement a new uploader class so that core does not have to be hacked - anyone with experience on how to do this, please let me know.

Avatar
creatormarius

Community Member, 11 Posts

14 June 2010 at 9:47pm

Another hole plugged: When deleting images from the gallery and subsequently loading a similar named image the file uploads and displays fine on the front end (with the previously posted hacks) but not in admin - it turns out the old image caches are not deleted on update.
Updated code as follows:
Sapphire/Core/model/IMAGE.PHP > Image_Uploader Class > save > after $image = new $imageClass(); Add/replace:
//**marius hack to save replaced files correctly
if ($owner->class == 'ImageGalleryItem') {
$album = DataObject::get_by_id("ImageGalleryAlbum", $this->linkedObj->AlbumID);
$folder = DataObject::get_by_id("File", $album->FolderID);
$path = substr(str_replace('assets/','',$folder->Filename), 0, -1) ;
$u = new Upload();
$u->loadIntoFile($data['Upload'],$image,$path);
$image->deleteFormattedImages(); //called in loaduploaded..
$owner->$fieldName = $u->file->ID;
} else {
//** end marius hack
// Assuming its a decendant of File
$image->loadUploaded($data['Upload']);
$owner->$fieldName = $image->ID;
}

Then in ImageGalleryImage.PHP > ImageGalleryImageClass: ADD:
public function deleteFormattedImages() {
/* marius hack - to clean up image_gallery cache files */
$folder = DataObject::get_by_id("Folder", $this->ParentID);
$files = glob(Director::baseFolder().'/'.$folder->Filename."_resampled/*-$this->Name");
foreach($files as $file) {unlink($file);}
parent::deleteFormattedImages();
}

Avatar
pinkp

Community Member, 182 Posts

17 June 2010 at 10:27am

Are these hacks needed for SS 2.4?

They areas you suggest adding the Hacks to don't seem to exist in 2.4? have they already been added...?

Im working on a site with ImageGallery r400 & SS2.4 and SOME images are braking and just showing the little paper broken link picture... The file locations look good but the files are not actually there. How can I fix this it is SO frustrating.

Thanks.

Avatar
creatormarius

Community Member, 11 Posts

17 June 2010 at 2:27pm

Sorry, I started building before 2.4 was released.

I will update this posts with the correct version information later today.

Your best bet is to get some help from the developer - if that was possible - since even if you're pretty good at PHP there're quite a few hoops to jump through before you can put a spanner to the works. It helps that SS is very well structured and OOPed, but the documentation for the inner workings is sorely lacking (unless I'm looking in the wrong places!).

Unfortunately the developer of ImageGallery is probably too busy to maintain it and, quite rightly perhaps, only seems interested in things happening in the current release. I had quite a fun time (*NOT*) stepping through code to solve my issues - with no help from the developer or the 'community'.

If your copies are up-to-date then perhaps the developer will take note and suggest some fixes. Might be good to post the steps you take to reproduce the problem.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

17 June 2010 at 3:22pm

For the record, I'm always up for making improvements to my modules, but when that requires hacking the core, I tend to stay away. Indeed, I do always have a lot my plate, so if there's a patch that has been created, or one that just needs a little help, I'm happy to oblige, but I just need to make sure my hours are allocated wisely, and not on exploratory hacking.

Thanks to all of you guys for your hard work and support of my work!

Avatar
creatormarius

Community Member, 11 Posts

17 June 2010 at 4:05pm

I did offer to collaborate on writing a fix / patch for the bugs described in this post that does not require hacking core... however the implementation was a bit above my station at the time and requires an intimate understanding of how SS handles forms etc. Basically the the image uploader class needs extending (with the hack above) and also a number of other changes such as rules for the redirector for another class of image uploads.

So for the record, I offer again to collaborate with anyone interested in fixing this the right way.

PS: It's interesting that in core the uploader uses a deprecated technique... it even says so in the code... that's the real root of the problem.

Avatar
Neuman

Community Member, 2 Posts

8 August 2010 at 4:52am

Edited: 08/08/2010 5:04am

For SS 2.4 I got around the problem by editing the ImageGalleryItem.php class.
In the getCMSFields_forPopup method I replaced this:

$fields->push(new ImageField('Image'));

with this:
$album_folder = $this->Album()->Folder()->FileName;
$upload_folder = substr_replace(str_replace(ASSETS_DIR.'/','',$album_folder),"", -1);
$fields->push(new ImageField('Image','','','','',$upload_folder));

Hope that helps some.

Go to Top