2001-08-31 08:19:32 +04:00
|
|
|
# -*- Mode: perl; indent-tabs-mode: nil -*-
|
|
|
|
#
|
|
|
|
# The contents of this file are subject to the Mozilla Public
|
|
|
|
# License Version 1.1 (the "License"); you may not use this file
|
|
|
|
# except in compliance with the License. You may obtain a copy of
|
|
|
|
# the License at http://www.mozilla.org/MPL/
|
|
|
|
#
|
|
|
|
# Software distributed under the License is distributed on an "AS
|
|
|
|
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
# implied. See the License for the specific language governing
|
|
|
|
# rights and limitations under the License.
|
|
|
|
#
|
|
|
|
# The Original Code is the Bugzilla Bug Tracking System.
|
|
|
|
#
|
|
|
|
# The Initial Developer of the Original Code is Netscape Communications
|
|
|
|
# Corporation. Portions created by Netscape are
|
|
|
|
# Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
# Rights Reserved.
|
|
|
|
#
|
|
|
|
# Contributor(s): Terry Weissman <terry@mozilla.org>
|
|
|
|
# Myk Melez <myk@mozilla.org>
|
|
|
|
|
|
|
|
############################################################################
|
|
|
|
# Module Initialization
|
|
|
|
############################################################################
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
2004-03-18 06:57:05 +03:00
|
|
|
package Bugzilla::Attachment;
|
2001-08-31 08:19:32 +04:00
|
|
|
|
|
|
|
# This module requires that its caller have said "require CGI.pl" to import
|
|
|
|
# relevant functions from that script and its companion globals.pl.
|
|
|
|
|
2002-09-28 22:42:54 +04:00
|
|
|
# Use the Flag module to handle flags.
|
|
|
|
use Bugzilla::Flag;
|
2005-02-20 20:03:10 +03:00
|
|
|
use Bugzilla::Config qw(:locations);
|
2005-03-16 01:10:14 +03:00
|
|
|
use Bugzilla::User;
|
2002-09-28 22:42:54 +04:00
|
|
|
|
2001-08-31 08:19:32 +04:00
|
|
|
############################################################################
|
|
|
|
# Functions
|
|
|
|
############################################################################
|
|
|
|
|
2002-09-28 22:42:54 +04:00
|
|
|
sub new {
|
|
|
|
# Returns a hash of information about the attachment with the given ID.
|
|
|
|
|
|
|
|
my ($invocant, $id) = @_;
|
|
|
|
return undef if !$id;
|
|
|
|
my $self = { 'id' => $id };
|
|
|
|
my $class = ref($invocant) || $invocant;
|
|
|
|
bless($self, $class);
|
|
|
|
|
|
|
|
&::PushGlobalSQLState();
|
2003-04-25 09:41:29 +04:00
|
|
|
&::SendSQL("SELECT 1, description, bug_id, isprivate FROM attachments " .
|
2002-09-28 22:42:54 +04:00
|
|
|
"WHERE attach_id = $id");
|
2003-04-25 09:41:29 +04:00
|
|
|
($self->{'exists'},
|
|
|
|
$self->{'summary'},
|
|
|
|
$self->{'bug_id'},
|
|
|
|
$self->{'isprivate'}) = &::FetchSQLData();
|
2002-09-28 22:42:54 +04:00
|
|
|
&::PopGlobalSQLState();
|
|
|
|
|
|
|
|
return $self;
|
|
|
|
}
|
|
|
|
|
2002-03-23 20:58:41 +03:00
|
|
|
sub query
|
2001-08-31 08:19:32 +04:00
|
|
|
{
|
2002-03-23 20:58:41 +03:00
|
|
|
# Retrieves and returns an array of attachment records for a given bug.
|
2005-04-28 06:14:26 +04:00
|
|
|
# This data should be given to attachment/list.html.tmpl in an
|
2002-03-23 20:58:41 +03:00
|
|
|
# "attachments" variable.
|
2001-08-31 08:19:32 +04:00
|
|
|
my ($bugid) = @_;
|
|
|
|
|
2005-02-25 02:37:48 +03:00
|
|
|
my $dbh = Bugzilla->dbh;
|
|
|
|
|
2001-08-31 08:19:32 +04:00
|
|
|
# Retrieve a list of attachments for this bug and write them into an array
|
|
|
|
# of hashes in which each hash represents a single attachment.
|
2005-04-28 06:14:26 +04:00
|
|
|
my $list = $dbh->selectall_arrayref("SELECT attach_id, " .
|
|
|
|
$dbh->sql_date_format('creation_ts', '%Y.%m.%d %H:%i') .
|
|
|
|
", mimetype, description, ispatch,
|
|
|
|
isobsolete, isprivate, LENGTH(thedata)
|
|
|
|
FROM attachments
|
|
|
|
WHERE bug_id = ? ORDER BY attach_id",
|
|
|
|
undef, $bugid);
|
|
|
|
|
2001-08-31 08:19:32 +04:00
|
|
|
my @attachments = ();
|
2005-04-28 06:14:26 +04:00
|
|
|
foreach my $row (@$list) {
|
2001-08-31 08:19:32 +04:00
|
|
|
my %a;
|
2005-04-28 06:14:26 +04:00
|
|
|
($a{'attachid'}, $a{'date'}, $a{'contenttype'},
|
|
|
|
$a{'description'}, $a{'ispatch'}, $a{'isobsolete'},
|
|
|
|
$a{'isprivate'}, $a{'datasize'}) = @$row;
|
2001-08-31 08:19:32 +04:00
|
|
|
|
2002-09-28 22:42:54 +04:00
|
|
|
# Retrieve a list of flags for this attachment.
|
2004-07-06 11:08:02 +04:00
|
|
|
$a{'flags'} = Bugzilla::Flag::match({ 'attach_id' => $a{'attachid'},
|
|
|
|
'is_active' => 1 });
|
2005-02-20 20:03:10 +03:00
|
|
|
|
|
|
|
# A zero size indicates that the attachment is stored locally.
|
|
|
|
if ($a{'datasize'} == 0) {
|
|
|
|
my $attachid = $a{'attachid'};
|
|
|
|
my $hash = ($attachid % 100) + 100;
|
|
|
|
$hash =~ s/.*(\d\d)$/group.$1/;
|
|
|
|
if (open(AH, "$attachdir/$hash/attachment.$attachid")) {
|
|
|
|
$a{'datasize'} = (stat(AH))[7];
|
|
|
|
close(AH);
|
|
|
|
}
|
|
|
|
}
|
2001-08-31 08:19:32 +04:00
|
|
|
push @attachments, \%a;
|
|
|
|
}
|
2005-04-28 06:14:26 +04:00
|
|
|
|
2002-03-23 20:58:41 +03:00
|
|
|
return \@attachments;
|
2001-08-31 08:19:32 +04:00
|
|
|
}
|
2002-02-13 05:27:24 +03:00
|
|
|
|
|
|
|
1;
|