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

Duplicate files when uploading with filemanager


Go to End


12 Posts   3253 Views

Avatar
klikhier

Community Member, 150 Posts

5 June 2009 at 8:47am

Edited: 05/06/2009 8:50am

Hi there,

I'm using the following code in Page.php so that I can use filemanager module to attach images to every page:

  static $has_many = array(
    'Images' => 'Image'
  );
  
  public function getCMSFields() {
    $fields = parent::getCMSFields();

    $manager = new HasManyFileManager(
      $this,
      'Images', // name -> will be used for file grouping
      'Images' // relation name defined in $has_many
    );
 
    // creating tab for the "Files" Manager
    $fields->addFieldToTab('Root.Content.Images', $manager);
    return $fields;
  }	

  public function onBeforeDelete(){
    parent::onBeforeDelete();
    $this->deleteAttachedFiles();
  }

Everything works perfect, except for one thing. All images that I upload are stored in two folders, being /Uploads and /Uploads/AttachedFiles/Images. This doesn't feel right, shouldn't images only be stored in /Uploads/AttachedFiles/Images ?

As there will be a lot of large images on this site, I would really like this solved, because this will cost me twice as much disk space...

Avatar
bummzack

Community Member, 904 Posts

5 June 2009 at 9:50am

Hi

Yes, that sounds strange indeed. I didn't encounter such behavior yet. Can you post the SilverStripe Version you're using, together with other modules you got installed?

Avatar
klikhier

Community Member, 150 Posts

5 June 2009 at 7:25pm

SilverStripe CMS 2.3.1

Modules installed:

- filemanager 0.3.2
- cmsworkflow r78072
- dataobject_manager r137
- swfupload r128
- userforms 0.1.0

I have been checking another SilverStripe project of mine and found that same issues occurs at that site.

Thanks for your help!

Avatar
klikhier

Community Member, 150 Posts

5 June 2009 at 7:27pm

PS. When removing an attached image the file is removed from Uploads/AttachedFiles/Images but NOT from Uploads/

Avatar
bummzack

Community Member, 904 Posts

5 June 2009 at 7:56pm

I don't get this behavior on 2.3.1. But since you're using SWFUpload and DataObjectManager, why not migrate completely to the DataObjectManager?

Avatar
klikhier

Community Member, 150 Posts

5 June 2009 at 8:22pm

Edited: 08/06/2009 6:14am

I will do this, as problems got worse. Very strange.

Just for your info: I removed all pages from mysite/code except for Page.php. Next, I ran a clean install leaving the modules mentioned above in place. Now when going into the CMS and creating a new page I can not delete this page: 'Delete from draft' returns a 'Server error' and the page is NOT deleted. I have narrowed this down and I the problem no longer occurs when removing these lines:

public function onBeforeDelete(){
   parent::onBeforeDelete();
   $this->deleteAttachedFiles();
 }

Avatar
klikhier

Community Member, 150 Posts

9 June 2009 at 10:16am

Dear Banal, could you please have another look.

Am working on a different project with FileManager only (no DataObjectManager module here) and again... files are stored in both the Uploads/ folder and in Uploads/AttachedFiles/Bikers folders. Same issue on different site: duplicate files. What am I doing wrong?

class TeamPage extends Page {
	
	public static $db = array(
	);
	
	public static $has_one = array(
    'Video' => 'File',
    'PreviewImage' => 'Image'
	);

	static $has_many = array(
		'Images' => 'Image'
	);

	static $allowed_children = array(
		'TeamMemberPage',
		'SponsorPage'
	);

	public function getCMSFields() {

		$fields = parent::getCMSFields();

		$manager = new HasManyFileManager(
			$this,
			'Teams', // name -> will be used for file grouping
			'Images' // relation name defined in $has_many
		);
		
		$fields->addFieldToTab('Root.Content.Images', $manager);

	  $fields->addFieldToTab("Root.Content.Video", new FileIFrameField('Video'));
	  $fields->addFieldToTab("Root.Content.Video", new ImageField('PreviewImage', 'Preview Image (shown before video starts)'));

		return $fields;
	}

	/**
	 * Implementation of the onBeforeDelete Method for FileManager
	 */
	public function onBeforeDelete(){
		parent::onBeforeDelete();
		$this->deleteAttachedFiles();
	}

}

Installed modules (SS 2.3.1):

* Blog
* Filemanager
* Googlesitemaps
* Userforms

Pls help!

Avatar
bummzack

Community Member, 904 Posts

9 June 2009 at 9:28pm

Hi klikhier

I was indeed able to reproduce the problem. I fixed the bug in trunk, please get the "Latest trunk build" here: http://silverstripe.org/has-many-file-manager-module/

Hopefully that fixes your problem.

Go to Top