Fix messages/messages hook, move convertedbmp to a separate result_message
parent
c746664a83
commit
715d373356
|
@ -35,8 +35,8 @@ my $REQUIRED_MODULES = [
|
|||
|
||||
extension_version('BmpConvert', $VERSION);
|
||||
required_modules('BmpConvert', $REQUIRED_MODULES);
|
||||
clear_hooks('BmpConvert');
|
||||
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');
|
||||
|
||||
1;
|
||||
|
|
|
@ -3,14 +3,12 @@
|
|||
package BmpConvert;
|
||||
|
||||
use strict;
|
||||
use Bugzilla;
|
||||
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}};
|
||||
|
@ -38,22 +36,23 @@ sub attachment_process_data
|
|||
${$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;
|
||||
Bugzilla->add_result_message({ message => 'attachment_convertedbmp' });
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub attachment_post_create_result
|
||||
{
|
||||
my ($args) = @_;
|
||||
my $r = Bugzilla->result_messages;
|
||||
$r->[$#$r]->{convertedbmp} = $args->{vars}->{convertedbmp} = $args->{vars}->{attachment}->{convertedbmp};
|
||||
# Move last attachment_convertedbmp to the end of result_messages
|
||||
my $rm = Bugzilla->result_messages;
|
||||
my $l = @$rm;
|
||||
for (my $i = $l-1; $i >= 0; $i--)
|
||||
{
|
||||
if ($rm->[$i]->{message} eq 'attachment_convertedbmp' && $i != $l-1)
|
||||
{
|
||||
push @$rm, splice @$rm, $i, 1;
|
||||
last;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
[% IF message_tag == 'attachment_convertedbmp' %]
|
||||
<dl><dd><p>
|
||||
<b>Note:</b> [% terms.Bugzilla %] automatically converted your BMP image file to a
|
||||
compressed PNG format.
|
||||
</p></dd></dl>
|
||||
[% END %]
|
|
@ -44,12 +44,6 @@
|
|||
[% END %]
|
||||
</dd>
|
||||
</dl>
|
||||
[% IF att.convertedbmp %]
|
||||
<p>
|
||||
<b>Note:</b> [% terms.Bugzilla %] automatically converted your BMP image file to a
|
||||
compressed PNG format.
|
||||
</p>
|
||||
[% END %]
|
||||
[% END %]
|
||||
|
||||
[% BLOCK msg_changed_attachment %]
|
||||
|
@ -1049,8 +1043,12 @@
|
|||
|
||||
[% IF message %]
|
||||
[% message_tag = message %]
|
||||
[% message = BLOCK %][% 'msg_' _ message_tag FILTER process %][% END %]
|
||||
[% IF !message %][% message = Hook.process('messages') %][% END %]
|
||||
[% message_exists = 'msg_' _ message_tag FILTER block_exists %]
|
||||
[% IF message_exists;
|
||||
message = 'msg_' _ message_tag | process;
|
||||
ELSE;
|
||||
message = Hook.process('messages');
|
||||
END %]
|
||||
[% message %]
|
||||
[%# Give sensible error if a message is unknown. %]
|
||||
[% IF !message %]
|
||||
|
|
Loading…
Reference in New Issue