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.

All other Modules /

Discuss all other Modules here.

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

Uploadify import image removes image from other page


Go to End


10 Posts   3347 Views

Avatar
klikhier

Community Member, 150 Posts

12 November 2010 at 1:11am

Edited: 12/11/2010 1:14am

UncleCheese,

I ran into the following situation today on SS2.4.2 and the latest Uploadify (I think r510):

Photo.php

<?php
class Photo extends Image {

	static $has_one = array (
		'Page' => 'Page'
	);

}
?>

Page.php


...

	public static $has_many = array(
		'Photos' => 'Photo'
	);

...

		$fields->addFieldToTab('Root.Content.'._t('CMS.PHOTOS','Photos'), $miuf = new MultipleImageUploadField('Photos',_t('CMS.CONTENT_PHOTOS','Content photos')));

...

Situation:

1. In CMS open page 'home' and upload new image using uploadify
2. Check front-end: image perfectly visible
3. Back in CMS open page 'about us' and import the same image using 'Choose existing'
4. Check front-end: image perfectly visible, BUT no longer on page 'home'. Also in CMS the image is gone on page 'home'

Avatar
UncleCheese

Forum Moderator, 4102 Posts

12 November 2010 at 3:38am

That's funny. I literally just discovered this bug yesterday, just hours before you posted it.

Yeah, it's a tricky one. The "choose existing" functionality for a multiple file upload field would have to be based on a many_many rather than a has_many.

The other solution is to copy the files on import -- like DOM does. That way you don't break any relationships.

It's a major drag, either way. Neither is a clean solution.

--------------------
SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com

Avatar
klikhier

Community Member, 150 Posts

12 November 2010 at 5:23am

Ok thanks for you quick response!!!

What would be the quickest fix. Could you lead me/show me where to find/provide me with the code to copy files like done in DOM?

Avatar
klikhier

Community Member, 150 Posts

10 March 2011 at 4:11am

Hi Uncle Cheese. Is it possible/ease to setup a multiple file upload field with a many_many relationship or does this involve some serious coding? All this to prevent images disappearing from other pages when adding them (choose existing) to a new page.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

10 March 2011 at 4:27am

Yes.. thank you for reminding me. There's a patch floating around this forum that updates Uploadify to use many_many..

If you find it, please post it here.. I'll keep looking. Hopefully whoever wrote it can submit a pull request and we can get that into Github.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

10 March 2011 at 5:16am

Found the patch and applied it.

https://github.com/unclecheese/Uploadify

Avatar
klikhier

Community Member, 150 Posts

10 March 2011 at 7:43am

Edited: 10/03/2011 7:54am

Thanks Uncle Cheese,

I've set it up like this:

// mysite/code/Photo.php

class Photo extends Image {
 
  static $belongs_many_many = array (
    'Pages' => 'Page'
  );

} 

// mysite/code/Page.php


...

  public static $many_many = array(
    'Photos' => 'Photo'
  );

...

  $fields->addFieldToTab("Root.Content.Photos", new MultipleImageUploadField('Photos','&nbsp;'));

Works like a charm...

Avatar
UncleCheese

Forum Moderator, 4102 Posts

10 March 2011 at 8:48am

Great! Thanks for being the first to test it.

Go to Top