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.

Customising the CMS /

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

stop overwriting files with setReplaceFile(false)


Go to End


4 Posts   980 Views

Avatar
mi32dogs

Community Member, 75 Posts

21 March 2015 at 4:43am

Hi

I have a question, I’m building a press release section with a data object in 3.1. I want to upload pdf files with the function that if the file already exist that he not overwrite it but just add a number to it.
I see there is a setting “setReplaceFile” that would do that, but whatever I do it does not seem to work.

Any tips on how to get this to work?

This is what I have so far

public function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab('Root.Main', DateField::create('Date','Date of Press Release')
      ->setConfig('showcalendar', true));
    $fields->addFieldToTab('Root.Main', TextField::create('Headline','Headline'));
    $fields->addFieldToTab('Root.Main', HtmlEditorField::create('Excerpt')->setDescription('Add something like the first paragraph of the press release'));
    $fields->addFieldToTab('Root.Main', $PressReleases = UploadField::create('PressRelease','PressRelease file (PDF only)'));

    $PressReleases
      ->setFolderName('ShowPro/press/PressRelease')
      ->getValidator()->setAllowedExtensions(array('pdf'));
    $PressReleases->getUpload()->setReplaceFile(false);
    return $fields;
  }

Avatar
Nightjar

Community Member, 28 Posts

21 March 2015 at 9:31am

This topic is probably well solved by now, but just to perhaps suggest for future users (and in case it isn't solved), you might be interested in something like the DMS module.
http://addons.silverstripe.org/add-ons/silverstripe/dms

It handles document versioning amongst other things (such as binding a document to a page, which sounds rather useful in your case).

Avatar
mi32dogs

Community Member, 75 Posts

22 March 2015 at 9:18am

Do you mean that this is a known bug but has not been fixed yet?

Avatar
mi32dogs

Community Member, 75 Posts

22 March 2015 at 9:25am

OK, figured it out and for anybody else with the same problem you also have to set "setOverwriteWarning(false)" otherwise it will not work