From 57fc14036913dddab05243ab8b77c20facfae5c2 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 6 Mar 2007 03:43:48 +0000 Subject: [PATCH] Made file upload use the Form API instead of the Storage API due to name hacks --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset/File.pm | 8 +++----- lib/WebGUI/Asset/FilePile.pm | 4 ++-- lib/WebGUI/Asset/Wobject/Matrix.pm | 7 ++++++- lib/WebGUI/Operation/Graphics.pm | 7 +++---- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index d2a525daa..00d7b75bb 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -15,6 +15,7 @@ - fix: Fixed the left column template, which still used the RawHeadTags macro. (perlDreamer Consulting, LLC) - Fixed a bad module name in the updated WeatherData asset (perlDreamer Consulting, LLC) + - File and Image handling via Storage.pm (perlDreamer Consulting, LLC) 7.3.11 - Added an option for enabling coverage tests to testCodebase.pl. diff --git a/lib/WebGUI/Asset/File.pm b/lib/WebGUI/Asset/File.pm index 521916718..dc4108687 100644 --- a/lib/WebGUI/Asset/File.pm +++ b/lib/WebGUI/Asset/File.pm @@ -245,13 +245,11 @@ sub processPropertiesFromFormPost { my $self = shift; $self->SUPER::processPropertiesFromFormPost; delete $self->{_storageLocation}; - my $storage = $self->getStorageLocation; - ##The file form element adds a _file to each input name. - ##This thing should really try to use the whole Form API, but that's a major - ##change to this Asset - my $filename = $storage->addFileFromFormPost("file_file",1); + my $fileStorageId = WebGUI::Form::File->new($self->session,{name => 'file'})->getValueFromPost; + my $storage = WebGUI::Storage->get($self->session, $fileStorageId); $storage->setPrivileges($self->get('ownerUserId'), $self->get('groupIdView'), $self->get('groupIdEdit')); + my $filename = $storage->getFiles()->[0]; if (defined $filename && $filename ne $self->get("filename")) { my %data; $data{filename} = $filename; diff --git a/lib/WebGUI/Asset/FilePile.pm b/lib/WebGUI/Asset/FilePile.pm index 2c2214a49..7f3831da9 100644 --- a/lib/WebGUI/Asset/FilePile.pm +++ b/lib/WebGUI/Asset/FilePile.pm @@ -136,10 +136,10 @@ sub edit { #------------------------------------------------------------------- sub editSave { my $self = shift; - my $tempStorage = WebGUI::Storage->create($self->session); ##This is a hack. File uploads should go through the WebGUI::Form::File API - $tempStorage->addFileFromFormPost("file_file"); + my $tempFileStorageId = WebGUI::Form::File->new($self->session,{name => 'file'})->getValueFromPost; + my $tempStorage = WebGUI::Storage->get($self->session, $tempFileStorageId); foreach my $filename (@{$tempStorage->getFiles}) { my $storage = WebGUI::Storage::Image->create($self->session); diff --git a/lib/WebGUI/Asset/Wobject/Matrix.pm b/lib/WebGUI/Asset/Wobject/Matrix.pm index 3fec087c4..8e7a68723 100644 --- a/lib/WebGUI/Asset/Wobject/Matrix.pm +++ b/lib/WebGUI/Asset/Wobject/Matrix.pm @@ -700,13 +700,18 @@ sub www_editListingSave { ##This is a hack. File upload should go throught the WebGUI::Form::File API ##so that future changes don't affect us like this - my $screenshot = $storage->addFileFromFormPost("screenshot_file"); + my $screenshotStorageId = WebGUI::Form::File->new($self->session,{name => 'screenshot'})->getValueFromPost; + my $uploadedScreenshot = WebGUI::Storage->get($self->session, $screenshotStorageId); + my $screenshot = $uploadedScreenshot->addFileFromFormPost("screenshot"); if (defined $screenshot) { $data{filename} = $screenshot; $storage->generateThumbnail($screenshot); + $storage->addFileFromFilesystem($uploadedScreenshot->getPath($screenshot)); } + $uploadedScreenshot->delete; + my $productName = $self->session->form->process("productName"); my $isNew = 0; diff --git a/lib/WebGUI/Operation/Graphics.pm b/lib/WebGUI/Operation/Graphics.pm index b47aa9526..0aba28045 100644 --- a/lib/WebGUI/Operation/Graphics.pm +++ b/lib/WebGUI/Operation/Graphics.pm @@ -260,11 +260,10 @@ sub www_editFontSave { return $session->privilege->adminOnly() unless ($session->user->isInGroup(3)); if ($session->form->process('fid') eq 'new') { - my $storage = WebGUI::Storage->create($session, 'new'); - ##This is a hack. It should use the WebGUI::Form::File API to insulate - ##us from future form name changes. - my $filename = $storage->addFileFromFormPost('fontFile_file'); + my $fileStorageId = WebGUI::Form::File->new($self->session,{name => 'fontFile'})->getValueFromPost; + my $storage = WebGUI::Storage->get($self->session, $fileStorageId); + my $filename = $storage->getFiles()->[0]; if ($filename) { my $font = WebGUI::Image::Font->new($session, 'new');