Jump to:

10930 Posts in 2613 Topics by 1810 members

All other Modules

SilverStripe Forums » All other Modules » Image Gallery issue: Replacing pictures in albums

Discuss all other Modules here.

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

Page: 1 2
Go to End
Author Topic: 2875 Views
  • creatormarius
    Avatar
    Community Member
    11 Posts

    Re: Image Gallery issue: Replacing pictures in albums Link to this post

    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.

  • creatormarius
    Avatar
    Community Member
    11 Posts

    Re: Image Gallery issue: Replacing pictures in albums Link to this post

    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();
       }

  • pinkp
    Avatar
    Community Member
    168 Posts

    Re: Image Gallery issue: Replacing pictures in albums Link to this post

    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.

  • creatormarius
    Avatar
    Community Member
    11 Posts

    Re: Image Gallery issue: Replacing pictures in albums Link to this post

    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.

  • UncleCheese
    Avatar
    4085 Posts

    Re: Image Gallery issue: Replacing pictures in albums Link to this post

    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!

  • creatormarius
    Avatar
    Community Member
    11 Posts

    Re: Image Gallery issue: Replacing pictures in albums Link to this post

    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.

  • Neuman
    Avatar
    Community Member
    2 Posts

    Re: Image Gallery issue: Replacing pictures in albums Link to this post

    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.

    2875 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.