#892 - Error attaching an existing folder to an ImageField

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@47941 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Andrew O'Neil 2008-01-13 22:51:03 +00:00
parent 6afd4655de
commit e87b76b305

View File

@ -645,7 +645,7 @@ class Image_Uploader extends Controller {
}
$owner = DataObject::get_by_id($data['Class'], $data['ID']);
$fieldName = $data['Field'] . 'ID';
if($data['ImageSource'] == 'existing') {
if(!$data['ExistingFile']) {
// No image has been selected
@ -658,6 +658,14 @@ class Image_Uploader extends Controller {
// Edit the class name, if applicable
$existingFile = DataObject::get_by_id("File", $data['ExistingFile']);
$desiredClass = $owner->has_one($data['Field']);
// Unless specifically asked, we don't want the user to be able
// to select a folder
if(is_a($existingFile, 'Folder') && $desiredClass != 'Folder') {
Director::redirectBack();
return;
}
if(!is_a($existingFile, $desiredClass)) {
$existingFile->ClassName = $desiredClass;
$existingFile->write();