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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

DOM duplicate images?


Go to End
Reply


16 Posts   3163 Views

Avatar
JonoM

Community Member, 103 Posts

4 August 2011 at 1:46pm

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;

Avatar
schellmax

Community Member, 126 Posts

4 August 2011 at 7:53pm

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

Avatar
benni91

Community Member, 72 Posts

6 February 2012 at 2:07am

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

Avatar
mirkosassetti

Community Member, 20 Posts

6 February 2012 at 10:56pm

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

$managerImages->copyOnImport = false;

Avatar
benni91

Community Member, 72 Posts

6 February 2012 at 11:38pm

Ah ok, thx !

Avatar
tschul

Community Member, 4 Posts

3 March 2012 at 12:30am

Edited: 03/03/2012 3:58am

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

Avatar
JonoM

Community Member, 103 Posts

3 March 2012 at 4:36am

Edited: 03/03/2012 4:39am

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.

Avatar
tschul

Community Member, 4 Posts

5 March 2012 at 11:30am

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?

Go to Top