Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » DOM duplicate images?

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2
Go to End
Author Topic: 2932 Views
  • mirkosassetti
    Avatar
    Community Member
    20 Posts

    DOM duplicate images? Link to this post

    Recently I came across this behavior: i have all the images i need for a galley in a folder, by example "Uploads/myimage/"; with DOM and Uploadify, when i import images from that folder, they are copied (duplicated) in the folder "Uploads/". Later i discover that if i set the same upload folder, so "Uploads/myimage/", images aren't copied.
    Digging trough the DOM sources i found the code doing that on class FileDataObjectManager, function saveImportForm().
    I can not imagine why this thing is done, but i'm curious.
    In any case, I think it would be useful to implement a way to disable this behavior.
    What do you think?

  • tmkp
    Avatar
    Community Member
    42 Posts

    Re: DOM duplicate images? Link to this post

    Hi,

    I was just about to post a similar issue.

    I set up a basic GalleryPage with ImageDataObjectManager/Uploadify and created a GalleryImage Dataobject to hold the actual Images and Captions, relationships are set and all is working well.

    Now, if I use the IDOM Popup to upload images and try to upload to any other folder than the default "assets/Uploads/", the images will end up in both /Uploads/ AND the folder I selected. The GalleryImage Dataobject links up to the copy in /Uploads/ though.

    Code is as follows

    class GalleryPage extends Page {

       static $has_many = array (
          'Images' => 'GalleryImage',
       );

       function getCMSFields() {
          $f = parent::getCMSFields();

          $manager = new ImageDataObjectManager(
             $this,
             'Images',
             'GalleryImage',
             'Image',
             array(
                'Text' => 'Bildunterschrift'
             ),
             'getCMSFields_forPopup'
          );

          $f->addFieldToTab("Root.Content.Bilder-Gallerie",$manager);

          return $f;
       }

    }

    <?php
    class GalleryImage extends DataObject {

       static $db = array (
          'Text' => 'Text'
       );

       public static $has_one = array (
          "Image" => "Image",
          "GalleryPage" => "GalleryPage",
       );

       public function getCMSFields_forPopup() {
          return new FieldSet(
             new FileIFrameField("Image"),
             new TextField("Text")
          );
       }

    }

    Anyone else having problems with this?

    Thanks in advance, and great work on the modules Uncle Cheese. Haven't been back here in while, but I love the new features.

    -------

    EDIT: Using 2.4.5, DOM r540, Uploadify r534

  • mirkosassetti
    Avatar
    Community Member
    20 Posts

    Re: DOM duplicate images? Link to this post

    Correction.
    The function saveImportForm() i think is for when not using Uploadify.
    For the installation with Uploadify the function is saveUploadifyForm().
    For now i solved the duplication behaviour by commentig the lines as below:

    public function saveUploadifyForm($data, $form)
       {
          if(!isset($data['UploadedFiles']) || !is_array($data['UploadedFiles'])) {
             return Director::redirectBack();
          }
          
          $file_class = $this->fileClassName;
          $do_class = $this->sourceClass();
          $idxfield = $this->fileFieldName."ID";
          $fff = $this->fileFieldName;
          $dataobject_ids = array();
          if($this->hasDataObject) {
             foreach($data['UploadedFiles'] as $id) {
                if($file = DataObject::get_by_id("File", (int) $id)) {
    //               $upload_folder = $form->Fields()->fieldByName('UploadedFiles')->uploadFolder;
    //               $folder_id = Folder::findOrMake($upload_folder)->ID;
    //               if($file->ParentID != $folder_id) {
    //                  $new_file_path = $this->uploadFolder.'/'.$file->Name;
    //                  copy($file->getFullPath(), BASE_PATH.'/'.ASSETS_DIR.'/'.$new_file_path);
    //                  $clone = new $file_class();
    //                  $clone->Filename = $new_file_path;
    //                  $clone->ParentID = $folder_id;                  
    //                  $clone->write();
    //                  $id = $clone->ID;
    //               }
                   
                   $obj = new $do_class();         
                   $obj->$idxfield = $id;
                   $ownerID = $this->getParentIdName($this->getParentClass(), $this->sourceClass());
                   $obj->$ownerID = $this->controllerID;
                   $this->updateDataObject($obj);
                   $obj->write();
                   $obj->$fff()->write();
                   $dataobject_ids[] = $obj->ID;
                }
             }
             $_POST['uploaded_files'] = $dataobject_ids;
             foreach($_POST['uploaded_files'] as $id) {
             }
          }   
          else {
             foreach($data['UploadedFiles'] as $id) {
                if($file = DataObject::get_by_id("File", (int) $id)) {
                   $ownerID = $this->getParentIdName($this->getParentClass(), $this->sourceClass());
                   $file->$ownerID = $this->controllerID;
                   $file->write();
                }
             }
          }      

    $form = $this->EditUploadedForm();
          return $this->customise(array(
           'String' => is_string($form),
             'DetailForm' => $form
          ))->renderWith($this->templatePopup);
       }

    All seem to works fine.

  • davidm2010
    Avatar
    Community Member
    107 Posts

    Re: DOM duplicate images? Link to this post

    I made the changes as indicated and I am getting a URL error in Image Gallery when I add title and information. Have you tried this with the latest Image Gallery (34f64c0) from GITHUB?

  • schellmax
    Avatar
    Community Member
    126 Posts

    Re: DOM duplicate images? Link to this post

    file duplication didn't make much sense to me, too, so i commented out the lines in FileDataObjectManager as @mirkokassetti suggested. works for me, thanks for sharing

  • JonoM
    Avatar
    Community Member
    103 Posts

    Re: DOM duplicate images? Link to this post

    I have to agree - for me file duplication doesn't make any sense, just makes a mess in the assets folder. Any chance of changing this behaviour in the module Uncle Cheese? If a file already exists why make another copy of it? Cheers

  • micahsheets
    Avatar
    Community Member
    164 Posts

    Re: DOM duplicate images? Link to this post

    I am having this same issue with SS 2.4.5 and the DOM that is downloadable form the SS site. In IDOM uploadify window I can select in a dropdown a different folder than Uploads. When I upload an image, I find it in both my Assets/Gallery/ and in Assets/Uploads/. And when I am presented the window for editing the newly created dataobject that the image was attached to I can see that the image in Assets/Uploads is the one that got attached to my dataobject. so the act of selecting a folder in uploadify's dropdown is completely useless. Is there possible a problem with the dataobject I am managing with IDOM?

  • mirkosassetti
    Avatar
    Community Member
    20 Posts

    Re: DOM duplicate images? Link to this post

    No, this isn't an issue but a "feature", it's coded.
    I'm testing a modified version of DOM with a parameter to disable the duplication. When i'm sure that it works, i try to submit it to UncleCheese for inclusion in master.

    2932 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.