Bug 64562 - Do redirect after adding an attachment; Debug BMPConvert extension

git-svn-id: svn://svn.office.custis.ru/3rdparty/bugzilla.org/trunk@831 6955db30-a419-402b-8a0d-67ecbb4d7f56
master
vfilippov 2010-06-30 16:52:43 +00:00
parent c34e1cd4db
commit 3dd4731318
8 changed files with 152 additions and 72 deletions

View File

@ -888,6 +888,8 @@ sub create {
$sth->execute();
}
Bugzilla::Hook::process('attachment_post_create', { attachment => $attachment });
# Return the new attachment object.
return $attachment;
}

View File

@ -79,7 +79,7 @@ sub process
eval { require $pk };
if ($@)
{
warn "Error autoloading hook package $pk: $@";
warn __PACKAGE__."::process(): Error autoloading hook package $pk: $@";
next;
}
}
@ -102,7 +102,7 @@ sub process
$sub = eval "package $pk; sub { my (\$args) = \@_; $sub; return 1; };";
if ($@)
{
warn __PACKAGE__."::load(): error during loading $f->{filename} into a subroutine (note that Bugzilla->hook_args was replaced by \$args): $@";
warn __PACKAGE__."::process(): error during loading $f->{filename} into a subroutine (note that Bugzilla->hook_args was replaced by \$args): $@";
next;
}
$f = $sub;

View File

@ -537,53 +537,79 @@ sub insert {
work_time => scalar $cgi->param('work_time'),
extra_data => $attachment->id });
# Assign the bug to the user, if they are allowed to take it
my $owner = "";
if ($cgi->param('takebug') && $user->in_group('editbugs', $bug->product_id)) {
# When taking a bug, we have to follow the workflow.
my $bug_status = $cgi->param('bug_status') || '';
($bug_status) = grep {$_->name eq $bug_status} @{$bug->status->can_change_to};
# Assign the bug to the user, if they are allowed to take it
my $owner = "";
if ($cgi->param('takebug') && $user->in_group('editbugs', $bug->product_id)) {
# When taking a bug, we have to follow the workflow.
my $bug_status = $cgi->param('bug_status') || '';
($bug_status) = grep {$_->name eq $bug_status} @{$bug->status->can_change_to};
if ($bug_status && $bug_status->is_open
&& ($bug_status->name ne 'UNCONFIRMED'
|| $bug->product_obj->allows_unconfirmed))
{
$bug->set_status($bug_status->name);
$bug->clear_resolution();
}
# Make sure the person we are taking the bug from gets mail.
$owner = $bug->assigned_to->login;
$bug->set_assigned_to($user);
}
$bug->update($timestamp);
if ($bug_status && $bug_status->is_open
&& ($bug_status->name ne 'UNCONFIRMED'
|| $bug->product_obj->allows_unconfirmed))
{
$bug->set_status($bug_status->name);
$bug->clear_resolution();
}
# Make sure the person we are taking the bug from gets mail.
$owner = $bug->assigned_to->login;
$bug->set_assigned_to($user);
}
$bug->update($timestamp);
if ($token) {
trick_taint($token);
$dbh->do('UPDATE tokens SET eventdata = ? WHERE token = ?', undef,
("create_attachment:" . $attachment->id, $token));
}
if ($token) {
trick_taint($token);
$dbh->do('UPDATE tokens SET eventdata = ? WHERE token = ?', undef,
("create_attachment:" . $attachment->id, $token));
}
$dbh->bz_commit_transaction;
$dbh->bz_commit_transaction;
# Define the variables and functions that will be passed to the UI template.
$vars->{'attachment'} = $attachment;
# We cannot reuse the $bug object as delta_ts has eventually been updated
# since the object was created.
$vars->{'bugs'} = [new Bugzilla::Bug($bugid)];
$vars->{'header_done'} = 1;
$vars->{'contenttypemethod'} = $cgi->param('contenttypemethod');
# Define the variables and functions that will be passed to the UI template.
$vars->{'attachment'} = $attachment;
# We cannot reuse the $bug object as delta_ts has eventually been updated
# since the object was created.
$vars->{'bugs'} = [new Bugzilla::Bug($bugid)];
$vars->{'header_done'} = 1;
$vars->{'contenttypemethod'} = $cgi->param('contenttypemethod');
my $recipients = { 'changer' => $user->login, 'owner' => $owner };
my $silent = $vars->{commentsilent} = $cgi->param('commentsilent') ? 1 : 0;
$vars->{'sent_bugmail'} = Bugzilla::BugMail::Send($bugid, $recipients, $silent);
my $recipients = { 'changer' => $user->login, 'owner' => $owner };
my $silent = $vars->{commentsilent} = $cgi->param('commentsilent') ? 1 : 0;
my $sent_bugmail = Bugzilla::BugMail::Send($bugid, $recipients, $silent);
if (Bugzilla->usage_mode != USAGE_MODE_EMAIL)
{
$cgi->send_header();
# Generate and return the UI (HTML page) from the appropriate template.
$template->process("attachment/created.html.tmpl", $vars)
|| ThrowTemplateError($template->error());
}
# Operation result to save into session (CustIS Bug 64562)
my $session_data = {
title => "Attachment ".$attachment->id." added to ".template_var('terms')->{Bug}." ".$attachment->bug_id,
sent => [ {
commentsilent => $silent,
sent_bugmail => $sent_bugmail,
mailrecipients => $recipients,
id => $bugid,
} ],
sent_attrs => {
contenttypemethod => $vars->{contenttypemethod},
added_attachment => {
id => $attachment->id,
bug_id => $attachment->bug_id,
description => $attachment->description,
contenttype => $attachment->contenttype,
},
},
};
Bugzilla::Hook::process('attachment_post_create_result', { session_data => $session_data, vars => $vars });
if (Bugzilla->usage_mode != USAGE_MODE_EMAIL)
{
if (Bugzilla->save_session_data($session_data))
{
print $cgi->redirect(-location => 'show_bug.cgi?id='.$attachment->bug_id);
exit;
}
# Generate and return the UI (HTML page) from the appropriate template.
$template->process("attachment/created.html.tmpl", $vars)
|| ThrowTemplateError($template->error());
}
}
# Displays a form for editing attachment properties.
@ -591,27 +617,27 @@ sub insert {
# is private and the user does not belong to the insider group.
# Validations are done later when the user submits changes.
sub edit {
my $attachment = validateID();
my $attachment = validateID();
my $bugattachments =
Bugzilla::Attachment->get_attachments_by_bug($attachment->bug_id);
# We only want attachment IDs.
@$bugattachments = map { $_->id } @$bugattachments;
my $bugattachments =
Bugzilla::Attachment->get_attachments_by_bug($attachment->bug_id);
# We only want attachment IDs.
@$bugattachments = map { $_->id } @$bugattachments;
my $any_flags_requesteeble =
grep { $_->is_requestable && $_->is_requesteeble } @{$attachment->flag_types};
# Useful in case a flagtype is no longer requestable but a requestee
# has been set before we turned off that bit.
$any_flags_requesteeble ||= grep { $_->requestee_id } @{$attachment->flags};
$vars->{'any_flags_requesteeble'} = $any_flags_requesteeble;
$vars->{'attachment'} = $attachment;
$vars->{'attachments'} = $bugattachments;
my $any_flags_requesteeble =
grep { $_->is_requestable && $_->is_requesteeble } @{$attachment->flag_types};
# Useful in case a flagtype is no longer requestable but a requestee
# has been set before we turned off that bit.
$any_flags_requesteeble ||= grep { $_->requestee_id } @{$attachment->flags};
$vars->{'any_flags_requesteeble'} = $any_flags_requesteeble;
$vars->{'attachment'} = $attachment;
$vars->{'attachments'} = $bugattachments;
$cgi->send_header();
$cgi->send_header();
# Generate and return the UI (HTML page) from the appropriate template.
$template->process("attachment/edit.html.tmpl", $vars)
|| ThrowTemplateError($template->error());
# Generate and return the UI (HTML page) from the appropriate template.
$template->process("attachment/edit.html.tmpl", $vars)
|| ThrowTemplateError($template->error());
}
# Updates an attachment record. Only users with "editbugs" privileges,
@ -713,7 +739,7 @@ sub update {
# Generate and return the UI (HTML page) from the appropriate template.
$template->process("attachment/updated.html.tmpl", $vars)
|| ThrowTemplateError($template->error());
|| ThrowTemplateError($template->error());
}
# Only administrators can delete attachments.

View File

@ -36,3 +36,5 @@ my $REQUIRED_MODULES = [
extension_version('BmpConvert', $VERSION);
required_modules('BmpConvert', $REQUIRED_MODULES);
set_hook('BmpConvert', 'attachment_process_data', 'BmpConvert::attachment_process_data');
set_hook('BmpConvert', 'attachment_post_create', 'BmpConvert::attachment_post_create');
set_hook('BmpConvert', 'attachment_post_create_result', 'BmpConvert::attachment_post_create_result');

View File

@ -5,9 +5,12 @@ package BmpConvert;
use strict;
use Image::Magick;
my $convertedbmp;
sub attachment_process_data
{
my ($args) = @_;
$convertedbmp = 0;
return 1 unless $args->{attributes}->{mimetype} eq 'image/bmp';
my $data = ${$args->{data}};
@ -17,19 +20,33 @@ sub attachment_process_data
if (ref $data) {
$img->Read(file => \*$data);
$img->set(magick => 'png');
$img->Write(file => \*$data);
}
# $data is a blob.
else {
$img->BlobToImage($data);
$img->set(magick => 'png');
$data = $img->ImageToBlob();
}
$data = $img->ImageToBlob();
undef $img;
${$args->{data}} = $data;
$args->{attributes}->{mimetype} = 'image/png';
$args->{attributes}->{filename} =~ s/^(.+)\.bmp$/$1.png/i;
$convertedbmp = 1;
return 1;
}
sub attachment_post_create
{
my ($args) = @_;
$args->{attachment}->{convertedbmp} = 1 if $convertedbmp;
return 1;
}
sub attachment_post_create_result
{
my ($args) = @_;
$args->{session_data}->{sent_attrs}->{convertedbmp} = $args->{vars}->{convertedbmp} = $args->{vars}->{attachment}->{convertedbmp};
return 1;
}

View File

@ -726,7 +726,7 @@ elsif (($action eq 'next_bug' or $action eq 'same_bug') && ($bug = $vars->{bug})
{
$title = template_var('terms')->{Bugs} . ' processed';
}
if (Bugzilla->save_session_data({ sent => $send_results, title => $title, nextbug => $action eq 'next_bug' ? 1 : 0 }))
if (Bugzilla->save_session_data({ sent => $send_results, title => $title, sent_attrs => { nextbug => $action eq 'next_bug' ? 1 : 0 } }))
{
print $cgi->redirect(-location => 'show_bug.cgi?id='.$bug->id);
exit;

View File

@ -126,11 +126,11 @@ $vars->{'displayfields'} = \%displayfields;
my $sd;
if (Bugzilla->session && ($sd = Bugzilla->session_data) && $sd->{sent})
{
Bugzilla->save_session_data({ sent => undef, title => undef, header => undef, nextbug => undef });
$vars->{nextbug} = $sd->{nextbug};
Bugzilla->save_session_data({ sent => undef, title => undef, header => undef, sent_attrs => undef });
$vars->{last_title} = $sd->{title};
$vars->{last_header} = $sd->{header};
$vars->{sentmail} = $sd->{sent};
$vars->{$_} = $sd->{sent_attrs}->{$_} for keys %{$sd->{sent_attrs} || {}};
}
$cgi->send_header($format->{'ctype'});

View File

@ -35,13 +35,46 @@
[% header_done = 1 %]
[% IF added_attachment %]
<dl>
<dt>
<a title="[% added_attachment.description FILTER html %]"
href="attachment.cgi?id=[% added_attachment.id %]&amp;action=edit">Attachment #[% added_attachment.id %]</a>
to [% "$terms.bug $added_attachment.bug_id" FILTER bug_link(added_attachment.bug_id) FILTER none %] created
</dt>
</dl>
[% END %]
[% FOREACH item = sentmail %]
[% PROCESS bug/process/results.html.tmpl
type = item.type
id = item.id
sent_bugmail = item.sent_bugmail
commentsilent = item.commentsilent
%]
[% FOR k = item.keys; $k = item.$k; END %]
[% PROCESS bug/process/results.html.tmpl %]
[% END %]
[% IF added_attachment %]
<dl>
<dd>
[% IF convertedbmp %]
<p>
<b>Note:</b> [% terms.Bugzilla %] automatically converted your BMP image file to a
compressed PNG format.
</p>
[% END %]
[% IF contenttypemethod == 'autodetect' %]
<p>
<b>Note:</b> [% terms.Bugzilla %] automatically detected the content type
<em>[% added_attachment.contenttype FILTER html %]</em> for this attachment. If this is
incorrect, correct the value by editing the attachment's
<a href="attachment.cgi?id=[% added_attachment.id %]&amp;action=edit">details</a>.
</p>
[% END %]
[% Hook.process("added_attachment_links") %]
</dd>
</dl>
<p>
<a href="attachment.cgi?bugid=[% added_attachment.bug_id %]&amp;action=enter">
Create Another Attachment to [% terms.Bug %] [%+ added_attachment.bug_id %]</a>
</p>
[% END %]
[% IF nextbug %]