Commit 2f7a7d31 authored by Frédéric Buclin's avatar Frédéric Buclin

Bug 360231: importxml.pl ignores the maxattachmentsize and maxlocalattachment…

Bug 360231: importxml.pl ignores the maxattachmentsize and maxlocalattachment parameters when importing attachments r=dkl a=justdave
parent 7eed51a8
...@@ -54,6 +54,7 @@ use lib qw(. lib); ...@@ -54,6 +54,7 @@ use lib qw(. lib);
use Bugzilla; use Bugzilla;
use Bugzilla::Object; use Bugzilla::Object;
use Bugzilla::Bug; use Bugzilla::Bug;
use Bugzilla::Attachment;
use Bugzilla::Product; use Bugzilla::Product;
use Bugzilla::Version; use Bugzilla::Version;
use Bugzilla::Component; use Bugzilla::Component;
...@@ -1053,6 +1054,7 @@ sub process_bug { ...@@ -1053,6 +1054,7 @@ sub process_bug {
$dbh->do( $query, undef, @values ); $dbh->do( $query, undef, @values );
my $id = $dbh->bz_last_key( 'bugs', 'bug_id' ); my $id = $dbh->bz_last_key( 'bugs', 'bug_id' );
my $bug_obj = Bugzilla::Bug->new($id);
# We are almost certain to get some uninitialized warnings # We are almost certain to get some uninitialized warnings
# Since this is just for debugging the query, let's shut them up # Since this is just for debugging the query, let's shut them up
...@@ -1135,31 +1137,41 @@ sub process_bug { ...@@ -1135,31 +1137,41 @@ sub process_bug {
$err .= "No attachment ID specified, dropping attachment\n"; $err .= "No attachment ID specified, dropping attachment\n";
next; next;
} }
if (!$exporter->is_insider && $att->{'isprivate'}) {
$err .= "Exporter not in insidergroup and attachment marked private.\n"; my $attacher;
if ($att->{'attacher'}) {
$attacher = Bugzilla::User->new({name => $att->{'attacher'}, cache => 1});
}
my $new_attacher = $attacher || $exporter;
if ($att->{'isprivate'} && !$new_attacher->is_insider) {
my $who = $new_attacher->login;
$err .= "$who not in insidergroup and attachment marked private.\n";
$err .= " Marking attachment public\n"; $err .= " Marking attachment public\n";
$att->{'isprivate'} = 0; $att->{'isprivate'} = 0;
} }
my $attacher_id = $att->{'attacher'} ? login_to_id($att->{'attacher'}) : undef; # We log in the user so that the attachment creator is set correctly.
Bugzilla->set_user($new_attacher);
$dbh->do("INSERT INTO attachments
(bug_id, creation_ts, modification_time, filename, description, my $attachment = Bugzilla::Attachment->create(
mimetype, ispatch, isprivate, isobsolete, submitter_id) { bug => $bug_obj,
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", creation_ts => $att->{date},
undef, $id, $att->{'date'}, $att->{'date'}, $att->{'filename'}, data => $att->{data},
$att->{'desc'}, $att->{'ctype'}, $att->{'ispatch'}, description => $att->{desc},
$att->{'isprivate'}, $att->{'isobsolete'}, $attacher_id || $exporterid); filename => $att->{filename},
my $att_id = $dbh->bz_last_key( 'attachments', 'attach_id' ); ispatch => $att->{ispatch},
my $att_data = $att->{'data'}; isprivate => $att->{isprivate},
my $sth = $dbh->prepare("INSERT INTO attach_data (id, thedata) isobsolete => $att->{isobsolete},
VALUES ($att_id, ?)" ); mimetype => $att->{ctype},
trick_taint($att_data); });
$sth->bind_param( 1, $att_data, $dbh->BLOB_TYPE ); my $att_id = $attachment->id;
$sth->execute();
# We log out the attacher as the remaining steps are not on his behalf.
Bugzilla->logout_request;
$comments .= "Imported an attachment (id=$att_id)\n"; $comments .= "Imported an attachment (id=$att_id)\n";
if (!$attacher_id) { if (!$attacher) {
if ($att->{'attacher'}) { if ($att->{'attacher'}) {
$err .= "The original submitter of attachment $att_id was\n "; $err .= "The original submitter of attachment $att_id was\n ";
$err .= $att->{'attacher'} . ", but he doesn't have an account here.\n"; $err .= $att->{'attacher'} . ", but he doesn't have an account here.\n";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment