From e3092f0aa85c7c7e148de94fcab977aeed2c92e4 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Wed, 13 Jun 2007 23:06:44 +0000 Subject: [PATCH] Fixed a bug where due to the lack of a cached Storage object, the assetSize in the db was set wrong. This happened when a File/Image was added, and when it is committed. Editing the Asset would fix it, but once it was committed, the files in the Storage area were not added. List of Changes: 1) Removed setSize from File/Image.pm. It can inherit from File. 2) In Asset::File::processPropertiesFromFormPost, set _storageLocation to the Storage object. Remove the call to setSize since it's done in ->update 3) In Asset::File::setSize, fetch the current storage object via getStorageLocation. 4) In Asset::File::update, move the call to update after the filesystem work. This way changes in the size of the permissions file get accounted for. 5) In Asset::update, call setSize after all changes, regardless of whether or not properties have changed. 6) In Asset::setSize, refactor out the size calculation and update $self's properties cache so that long running scripts have the right size. --- docs/changelog/7.x.x.txt | 2 ++ lib/WebGUI/Asset.pm | 6 ++++-- lib/WebGUI/Asset/File.pm | 6 +++--- lib/WebGUI/Asset/File/Image.pm | 12 ------------ 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index f30cbbe81..766073580 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -35,6 +35,8 @@ - Added a simple Single Sign On mechanism. - Added the SessionId macro. - fix: Package deploy: hidden assets become visible (Yung Han Khoe, United Knowledge) + - fix: Uploaded File Sizes Wrong (perlDreamer Consulting, LLC) + http://www.webgui.org/bugs/tracker/uploaded-file-sizes-wrong#8ao9yNQrxFyJNTUaU7ARPA 7.3.19 diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index ed11042fa..02ae08444 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -1855,8 +1855,10 @@ sub setSize { foreach my $key (keys %{$self->get}) { $sizetest .= $self->get($key); } - $self->session->db->write("update assetData set assetSize=".(length($sizetest)+$extra)." where assetId=".$self->session->db->quote($self->getId)." and revisionDate=".$self->session->db->quote($self->get("revisionDate"))); + my $size = length($sizetest) + $extra; + $self->session->db->write("update assetData set assetSize=".$size." where assetId=".$self->session->db->quote($self->getId)." and revisionDate=".$self->session->db->quote($self->get("revisionDate"))); $self->purgeCache; + $self->{_properties}{assetSize} = $size; } @@ -1907,9 +1909,9 @@ sub update { } if (scalar(@setPairs) > 0) { $self->session->db->write("update ".$definition->{tableName}." set ".join(",",@setPairs)." where assetId=".$self->session->db->quote($self->getId)." and revisionDate=".$self->get("revisionDate")); - $self->setSize; } } + $self->setSize(); $self->purgeCache; } diff --git a/lib/WebGUI/Asset/File.pm b/lib/WebGUI/Asset/File.pm index ef1b2cdc1..9af93573f 100644 --- a/lib/WebGUI/Asset/File.pm +++ b/lib/WebGUI/Asset/File.pm @@ -279,8 +279,8 @@ sub processPropertiesFromFormPost { $data{title} = $filename unless ($session->form->process("title")); $data{menuTitle} = $filename unless ($session->form->process("menuTitle")); $data{url} = $self->getParent->get('url').'/'.$filename unless ($session->form->process("url")); + $self->{_storageLocation} = $storage; $self->update(\%data); - $self->setSize($storage->getFileSize($filename)); } } } @@ -324,7 +324,7 @@ sub purgeRevision { sub setSize { my $self = shift; my $fileSize = shift || 0; - my $storage = $self->{_storageLocation}; + my $storage = $self->getStorageLocation; if (defined $storage) { foreach my $file (@{$storage->getFiles}) { $fileSize += $storage->getFileSize($file); @@ -361,7 +361,6 @@ sub update { edit => $self->get("groupIdEdit"), storageId => $self->get('storageId'), ); - $self->SUPER::update(@_); ##update may have entered a new storageId. Reset the cached one just in case. if ($self->get("storageId") ne $before{storageId}) { $self->setStorageLocation; @@ -369,6 +368,7 @@ sub update { if ($self->get("ownerUserId") ne $before{owner} || $self->get("groupIdEdit") ne $before{edit} || $self->get("groupIdView") ne $before{view}) { $self->getStorageLocation->setPrivileges($self->get("ownerUserId"),$self->get("groupIdView"),$self->get("groupIdEdit")); } + $self->SUPER::update(@_); } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Asset/File/Image.pm b/lib/WebGUI/Asset/File/Image.pm index 0f7d782c1..445a30b87 100644 --- a/lib/WebGUI/Asset/File/Image.pm +++ b/lib/WebGUI/Asset/File/Image.pm @@ -222,18 +222,6 @@ sub processPropertiesFromFormPost { $self->generateThumbnail($self->session->form->process("thumbnailSize")); } -#------------------------------------------------------------------- -sub setSize { - my $self = shift; - my $input = shift; - my $size = 0; - my $storage = $self->{_storageLocation}; - if (defined $storage) { - $size = ($input > $storage->getFileSize($self->get("filename"))) ? $input : $storage->getFileSize($self->get("filename")); - } - return $self->SUPER::setSize($size); -} - #------------------------------------------------------------------- sub setStorageLocation {