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.
This commit is contained in:
Colin Kuskie 2007-06-13 23:06:44 +00:00
parent fc2736e553
commit e3092f0aa8
4 changed files with 9 additions and 17 deletions

View file

@ -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

View file

@ -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;
}

View file

@ -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(@_);
}
#-------------------------------------------------------------------

View file

@ -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 {