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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

DOM duplicate images?


Go to End


16 Posts   5626 Views

Avatar
mirkosassetti

Community Member, 20 Posts

10 February 2011 at 6:06am

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? :)

Avatar
tmkp

Community Member, 42 Posts

10 February 2011 at 11:29am

Edited: 10/02/2011 11:55am

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

Avatar
mirkosassetti

Community Member, 20 Posts

17 February 2011 at 4:01am

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.

Avatar
davidm2010

Community Member, 107 Posts

17 March 2011 at 6:26am

Edited: 18/03/2011 5:08am

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?

Avatar
schellmax

Community Member, 126 Posts

28 March 2011 at 10:34pm

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

Avatar
JonoM

Community Member, 130 Posts

17 April 2011 at 1:32pm

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

Avatar
micahsheets

Community Member, 165 Posts

20 June 2011 at 2:41pm

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?

Avatar
mirkosassetti

Community Member, 20 Posts

20 June 2011 at 8:22pm

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.

Go to Top