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? :)
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?
- Page 11(current)
- 2
- Next 10 entries
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
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.
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?
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
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
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?
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.
- Page 11(current)
- 2
- Next 10 entries