Hello everybody.
We have been having similar issues with the image_gallery module as described here, even though we encountered it while trying to import previously uploaded files to an image gallery.
Environment:
SilverStripe: 2.4.2
DataObjectManager: r511
ImageGallery: r511
Uploadify: r511
Problem:
When importing files already uploaded to SilverStripe to an ImageGalleryPage album, it will fail with a similar error message and stack trace as described by Chip Designs in the first post.
Steps to reproduce:
1. Create a new ImageGalleryPage, choose the default album.
2. Click "Add images to $AlbumName".
3. Select the "choose existing"-tab in the uploadify field.
4. Select one or more existing images and click the "Import"-button.
5. Press the "Continue"-button.
6. Observe that the import fails with (roughly) the same error message as described in this thread.
Likely cause:
ImageGallery requires that all images which is handles is of the type ImageGalleryImage, however, when an existing image is imported it will be of type Image. When ImageGallery then tries to retrieve the Image through the ImageGalleryItem has_one-relation it will get an "empty" ImageGalleryImage-object since the ID points to an Image and not an ImageGalleryImage.
Manually changing the ClassName of the given Image to ImageGalleryImage will solve the problem.
Suggested solution:
The ugly "make-it-work"-solution we are using right now simply adds some extra handling to ImageGalleryItem::onBeforeWrite() which will change the given Image to an ImageGalleryImage and write the changes. This will fix the import problem since it ensures that the given Image has the correct type.
A better solution would probably be to get rid of ImageGallaryImage as a DataObject altogether and instead use a DataObjectDecorator for Image. Since all methods on ImageGalleryImage seems to use publicly available methods and features on Image, it should be implementable as a Decorator. If it works it should allow for ImageGallery to handle normal Images, which should remove the problem once and for all.
Patch: http://gist.github.com/646912
Edit: Added a link to the patch.
Edit 2: Changed the description of the better solution a little.
Edit 3: It seems like the first patch version was not working properly, it should be fixed now.