Form/File will automatically delete empty storage locations, but assets

expect them to stick around.  Add a flag to Form/File.pm to prevent it
from deleting them.  Make sensitive assets use that flag.
This commit is contained in:
Colin Kuskie 2009-07-23 16:50:57 +00:00
parent 69a07bb672
commit bd924e8f88
4 changed files with 23 additions and 7 deletions

View file

@ -27,6 +27,7 @@
- fixed #10664: ThiingyRecord disappeared... sort of
- fixed #10687: i18n Asset_Product::buy_form_options
- fixed #10651: Dashboard Content positions
- fixed #10695: Adding a new article creates a new version tag
7.7.15
- fixed #10629: WebGUI::ProfileField create new field bug

View file

@ -94,7 +94,8 @@ sub definition {
defaultValue=>undef,
maxAttachments=>1,
label=>$i18n->get(7),
deleteFileUrl=>$session->url->page("func=deleteFileConfirm;file=image1;filename=")
deleteFileUrl=>$session->url->page("func=deleteFileConfirm;file=image1;filename="),
persist => 1,
},
image2=>{
tab => "properties",
@ -102,7 +103,8 @@ sub definition {
maxAttachments=>1,
label=>$i18n->get(8),
deleteFileUrl=>$session->url->page("func=deleteFileConfirm;file=image2;filename="),
defaultValue=>undef
defaultValue=>undef,
persist => 1,
},
image3=>{
tab => "properties",
@ -110,7 +112,8 @@ sub definition {
maxAttachments=>1,
label=>$i18n->get(9),
deleteFileUrl=>$session->url->page("func=deleteFileConfirm;file=image3;filename="),
defaultValue=>undef
defaultValue=>undef,
persist => 1,
},
brochure=>{
tab => "properties",
@ -118,7 +121,8 @@ sub definition {
maxAttachments=>1,
label=>$i18n->get(13),
deleteFileUrl=>$session->url->page("func=deleteFileConfirm;file=brochure;filename="),
defaultValue=>undef
defaultValue=>undef,
persist => 1,
},
manual=>{
tab => "properties",
@ -126,7 +130,8 @@ sub definition {
maxAttachments=>1,
label=>$i18n->get(14),
deleteFileUrl=>$session->url->page("func=deleteFileConfirm;file=manual;filename="),
defaultValue=>undef
defaultValue=>undef,
persist => 1,
},
isShippingRequired => {
tab => "shop",
@ -141,7 +146,8 @@ sub definition {
maxAttachments=>1,
label=>$i18n->get(15),
deleteFileUrl=>$session->url->page("func=deleteFileConfirm;file=warranty;filename="),
defaultValue=>undef
defaultValue=>undef,
persist => 1,
},
variantsJSON => {
##Collateral data is stored as JSON in here

View file

@ -125,6 +125,7 @@ sub definition {
fieldType=>"image",
deleteFileUrl=>$session->url->page("func=deleteFile;filename="),
maxAttachments=>2,
persist => 1,
defaultValue=>undef,
label=>$i18n->get("attachments"),
hoverHelp=>$i18n->get("attachments help")

View file

@ -65,6 +65,11 @@ A url that will get a filename appended to it and then links to delete the files
Though not all browsers support it, this will attempt to set the size (or width) of the browse for file field.
=head4 persist
The default behavior of File is to delete empty storage location. However, this causes problems with Assets, which
expect them to stick around. Setting persist => 1 will prevent the deletion.
=cut
sub definition {
@ -83,6 +88,9 @@ sub definition {
},
size=>{
defaultValue=>40
},
persist=>{
defaultValue=>0,
},
});
return $class->SUPER::definition($session, $definition);
@ -195,7 +203,7 @@ sub getValue {
}
$storage->addFileFromFormPost($self->get("name")."_file",1000);
my @files = @{ $storage->getFiles };
if (scalar(@files) < 1) {
if (scalar(@files) < 1 && !$self->get('persist')) {
$storage->delete;
return undef;
}