Jump to:

10994 Posts in 2728 Topics by 1819 members

All other Modules

SilverStripe Forums » All other Modules » Duplicate files when uploading with filemanager

Discuss all other Modules here.

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

Page: 1 2
Go to End
Author Topic: 2184 Views
  • klikhier
    Avatar
    Community Member
    150 Posts

    Duplicate files when uploading with filemanager Link to this post

    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...

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Duplicate files when uploading with filemanager Link to this post

    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?

  • klikhier
    Avatar
    Community Member
    150 Posts

    Re: Duplicate files when uploading with filemanager Link to this post

    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!

  • klikhier
    Avatar
    Community Member
    150 Posts

    Re: Duplicate files when uploading with filemanager Link to this post

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

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Duplicate files when uploading with filemanager Link to this post

    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?

  • klikhier
    Avatar
    Community Member
    150 Posts

    Re: Duplicate files when uploading with filemanager Link to this post

    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();
    }

  • klikhier
    Avatar
    Community Member
    150 Posts

    Re: Duplicate files when uploading with filemanager Link to this post

    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!

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Duplicate files when uploading with filemanager Link to this post

    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.

    2184 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.