summaryrefslogtreecommitdiffstats
path: root/Bugzilla
diff options
context:
space:
mode:
authormyk%mozilla.org <>2004-02-06 03:14:01 +0100
committermyk%mozilla.org <>2004-02-06 03:14:01 +0100
commit0b01a89cc8901ad0217455563c58b26c10f6dad7 (patch)
treecfe49edaeff34420a1f8f1747002d16ed6baf550 /Bugzilla
parent038bb59e90b8e253e8b61a219c606638f63855c6 (diff)
downloadbugzilla-0b01a89cc8901ad0217455563c58b26c10f6dad7.tar.gz
bugzilla-0b01a89cc8901ad0217455563c58b26c10f6dad7.tar.xz
Fix for bug 127995: shows the size of attachments in the show bug and attachment interfaces.
Patch by Dave Swegen <dswegen@software.plasmon.com> r=myk a=myk
Diffstat (limited to 'Bugzilla')
-rw-r--r--Bugzilla/Attachment.pm7
-rw-r--r--Bugzilla/Template.pm24
2 files changed, 28 insertions, 3 deletions
diff --git a/Bugzilla/Attachment.pm b/Bugzilla/Attachment.pm
index ea5cd531c..84979d3ea 100644
--- a/Bugzilla/Attachment.pm
+++ b/Bugzilla/Attachment.pm
@@ -77,7 +77,8 @@ sub query
# of hashes in which each hash represents a single attachment.
&::SendSQL("
SELECT attach_id, DATE_FORMAT(creation_ts, '%Y.%m.%d %H:%i'),
- mimetype, description, ispatch, isobsolete, isprivate, submitter_id
+ mimetype, description, ispatch, isobsolete, isprivate,
+ submitter_id, LENGTH(thedata)
FROM attachments WHERE bug_id = $bugid ORDER BY attach_id
");
my @attachments = ();
@@ -85,8 +86,8 @@ sub query
my %a;
my $submitter_id;
($a{'attachid'}, $a{'date'}, $a{'contenttype'}, $a{'description'},
- $a{'ispatch'}, $a{'isobsolete'}, $a{'isprivate'}, $submitter_id)
- = &::FetchSQLData();
+ $a{'ispatch'}, $a{'isobsolete'}, $a{'isprivate'}, $submitter_id,
+ $a{'datasize'}) = &::FetchSQLData();
# Retrieve a list of flags for this attachment.
$a{'flags'} = Bugzilla::Flag::match({ 'attach_id' => $a{'attachid'} });
diff --git a/Bugzilla/Template.pm b/Bugzilla/Template.pm
index d370627d3..c123154bb 100644
--- a/Bugzilla/Template.pm
+++ b/Bugzilla/Template.pm
@@ -258,6 +258,30 @@ sub create {
return $var;
} ,
+ # Format a filesize in bytes to a human readable value
+ unitconvert => sub
+ {
+ my ($data) = @_;
+ my $retval = "";
+ my %units = (
+ 'KB' => 1024,
+ 'MB' => 1024 * 1024,
+ 'GB' => 1024 * 1024 * 1024,
+ );
+
+ if ($data < 1024) {
+ return "$data bytes";
+ }
+ else {
+ my $u;
+ foreach $u ('GB', 'MB', 'KB') {
+ if ($data >= $units{$u}) {
+ return sprintf("%.2f %s", $data/$units{$u}, $u);
+ }
+ }
+ }
+ },
+
# Format a time for display (more info in Bugzilla::Util)
time => \&Bugzilla::Util::format_time,