From bd924e8f8822917fa5c664e2726cc8e8b3a13cea Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Thu, 23 Jul 2009 16:50:57 +0000 Subject: [PATCH] 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. --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset/Sku/Product.pm | 18 ++++++++++++------ lib/WebGUI/Asset/Wobject/Article.pm | 1 + lib/WebGUI/Form/File.pm | 10 +++++++++- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 459584f4b..c7e53d8f3 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -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 diff --git a/lib/WebGUI/Asset/Sku/Product.pm b/lib/WebGUI/Asset/Sku/Product.pm index 86c52364c..aeed8fe39 100644 --- a/lib/WebGUI/Asset/Sku/Product.pm +++ b/lib/WebGUI/Asset/Sku/Product.pm @@ -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 diff --git a/lib/WebGUI/Asset/Wobject/Article.pm b/lib/WebGUI/Asset/Wobject/Article.pm index b74a6456b..938320c07 100644 --- a/lib/WebGUI/Asset/Wobject/Article.pm +++ b/lib/WebGUI/Asset/Wobject/Article.pm @@ -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") diff --git a/lib/WebGUI/Form/File.pm b/lib/WebGUI/Form/File.pm index 8a123b798..279ffd624 100644 --- a/lib/WebGUI/Form/File.pm +++ b/lib/WebGUI/Form/File.pm @@ -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; }