Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Uploadfield doesn't save into inherited Image Classes #341

merged 4 commits into from Apr 19, 2012


None yet
2 participants

mateusz commented Apr 18, 2012

Ref: http://open.silverstripe.org/ticket/7140

Fixes the original issue, plus adds support to relationAutoSetting, adds comments, removes one unnecessary write.

@halkyon halkyon commented on an outdated diff Apr 18, 2012

if (!$return['error']) {
+ $fileObject = null;
+ if ($this->relationAutoSetting) {
+ // Search for classes that can hold the uploaded files by reflecting on the relations. Has one has priority.
+ $foundClasses = array_filter(array($record->has_one($name), $record->has_many($name), $record->many_many($name)));

halkyon Apr 18, 2012


Getting the object on the relationship should probably be done somewhere else, like in DataObject, rather than UploadField doing the discovery itself.
I can't recall if we already have something that does this or not. @sminnee?


mateusz commented Apr 18, 2012

Yeah, now that I look at it, maybe better to call $record->$name, and then try to get the relationship class from there. Will look into it tomorrow.

mateusz added some commits Apr 18, 2012

BUGFIX: fixed asserts and file cleanup
DataObject::get_one returns false if not found, so better check for
object. Also, the directory would not be cleaned, so on the subsequent
run the files could end up having suffixes.

missed this one
BUGFIX: make UploadField aware of relations to derived classes (os7140)
UploadField was relying entirely on the File::get_class_for_file_extension to
select a class, so it could only create File or Image objects. This
would break the relationships based on derived objects. Also make it
respect the FileField::relationAutoSetting.

mateusz commented Apr 19, 2012

Fixed for many-many relationships: now will just traverse the relationship and make out the class from the received object.

halkyon added a commit that referenced this pull request Apr 19, 2012

Merge pull request #341 from mateusz/uploadfield-hasone
Uploadfield doesn't save into inherited Image Classes

@halkyon halkyon merged commit b8faa41 into silverstripe:master Apr 19, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment