Jump to:

7937 Posts in 1537 Topics by 944 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: 2936 Views
  • JonoM
    Avatar
    Community Member
    103 Posts

    Re: DOM duplicate images? Link to this post

    To mirkosassetti or unclecheese - not sure who added the 'copyOnImport' option but thank you! Much appreciated.

    If anyone finding this thread is wondering how to disable the duplication of assets in a FileDataObjectManager or ImageDataObjectManager you can do it something like this:

    $manager = new ImageDataObjectManager(
       $this,
       'ProjectImages',
       'ProjectImage',
       'Image',
       null,
       'getCMSFields_forPopup'
       
    );
    $manager->copyOnImport = false;

  • schellmax
    Avatar
    Community Member
    126 Posts

    Re: DOM duplicate images? Link to this post

    hey JonoM, thanks for your post. hard to keep track of all the updates.

  • benni91
    Avatar
    Community Member
    72 Posts

    Re: DOM duplicate images? Link to this post

    In wich file is this code? i can't find it :/

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

  • mirkosassetti
    Avatar
    Community Member
    20 Posts

    Re: DOM duplicate images? Link to this post

    It is no longer any need to tweak, the function has been implemented.
    Just set the parameter copyOnImport to false, like:

    $managerImages->copyOnImport = false;

  • benni91
    Avatar
    Community Member
    72 Posts

    Re: DOM duplicate images? Link to this post

    Ah ok, thx !

  • tschul
    Avatar
    Community Member
    4 Posts

    Re: DOM duplicate images? Link to this post

    Thanks a lot for this thread! It took me a couple of months until I got behind this VERY, VERY strange behavior of DOM.
    Thank god you pointed me to this fix. A little heads up at the update process would have been nice.

    After fixing the issue, I have the following problem:
    After having DOM acting up for about 2 months, I have about 1100 files or 19GB of videos, mp3s, images, PDFs duplicated in my assets/my_super_file_structure and a copy of it in assets/uploads.

    In the File database table, these entries are duplicated, too. Example screenshot is found here: http://disi.unitn.it/~stottinger/images/duplicatefiles.png

    Do you have any idea how I could fix this? Paying 20GB extra of webspace for nothing is kind of rough... I am stuck right now.

    thanks a lot for any idea, cheers
    J

  • JonoM
    Avatar
    Community Member
    103 Posts

    Re: DOM duplicate images? Link to this post

    You'd need to somehow change all the references in the database to duplicated files to point to the original files. You could write a script in PHP to go through all your DOM relations and look for the original file in each case (same Name + filesize, different Filename i.e. directory). If it finds it, re-link the original (change the ID in the relationship) and delete the duplicated file. Or actually, add the ID of the duped file to an array so when the process is finished you can delete them - the duped file might be referenced more than once I suppose. You'd also want to flush your image cache as you'd have redundant resized images in there.

  • tschul
    Avatar
    Community Member
    4 Posts

    Re: DOM duplicate images? Link to this post

    Thanks JonoM for your thoughts!
    However, that sounds like worst case. I shall go through all the tables for all the files while keeping a stack of changed relations. Seems very error prone and a lot of work.

    Can't we do something more dirty?

    1.) as I checked so far, the files on the intendent files are not used at all.
    2.) I guess I'd be also happy to change the FILE table that duplicated lines point to the same (intended) file and I delete the duplicated one.

    example:
    before
    ID Name Path
    1 foo.jpg assets/bar/foo.jpg
    2 foo.jpg assets/Uploads/foo.jpg

    After:
    ID Name Path
    1 foo.jpg assets/bar/foo.jpg
    2 foo.jpg assets/bar/foo.jpg

    rm assets/Uploads/foo.jpg
    flush image cache

    not very clean, but without need to change all the the tables... any comments? Do I miss something?

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