X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=C4%2FMessage.pm;h=3a3216657bd0112e499d4ec286e31e7b494cb464;hb=9d6d641d1f8b77271800f43bc027b651f9aea52b;hp=a63b3caa9656a21e950fafddeda7e0d227521cf7;hpb=ea1aa7a0d906d583375618e37be60e9f0d62d939;p=srvgit diff --git a/C4/Message.pm b/C4/Message.pm index a63b3caa96..3a3216657b 100644 --- a/C4/Message.pm +++ b/C4/Message.pm @@ -5,26 +5,27 @@ package C4::Message; # # This file is part of Koha. # -# Koha is free software; you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation; either version 2 of the License, or (at your option) any later -# version. +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. # -# Koha is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License along -# with Koha; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . use strict; use warnings; use C4::Context; -use C4::Letters; -use YAML::Syck; -use Carp; +use C4::Letters qw( GetPreparedLetter EnqueueLetter ); +use YAML::XS qw( Dump ); +use Encode; +use Carp qw( carp ); =head1 NAME @@ -37,7 +38,7 @@ How to add a new message to the queue: use C4::Message; use C4::Items; my $borrower = { borrowernumber => 1 }; - my $item = C4::Items::GetItem(1); + my $item = Koha::Items->find($itemnumber)->unblessed; my $letter = C4::Letters::GetPreparedLetter ( module => 'circulation', letter_code => 'CHECKOUT', @@ -159,8 +160,13 @@ sub enqueue { my ($class, $letter, $borrower, $transport) = @_; my $metadata = _metadata($letter); my $to_address = _to_address($borrower, $transport); - $letter->{metadata} = Dump($metadata); - #carp "enqueuing... to $to_address"; + + # Same as render_metadata + my $format ||= sub { $_[0] || "" }; + my $body = join('', map { $format->($_) } @{$metadata->{body}}); + $letter->{content} = $metadata->{header} . $body . $metadata->{footer}; + + $letter->{metadata} = Encode::decode_utf8(Dump($metadata)); C4::Letters::EnqueueLetter({ letter => $letter, borrowernumber => $borrower->{borrowernumber}, @@ -273,11 +279,11 @@ sub metadata { $data->{header} ||= ''; $data->{body} ||= []; $data->{footer} ||= ''; - $self->{metadata} = Dump($data); + $self->{metadata} = Encode::decode_utf8(Dump($data)); $self->content($self->render_metadata); return $data; } else { - return Load($self->{metadata}); + return YAML::XS::Load(Encode::encode_utf8($self->{metadata})); } } @@ -306,10 +312,12 @@ If passed a string, it'll append the string to the message. # $object->append($letter_or_item) -- add a new item to a message's content sub append { my ($self, $letter_or_item, $format) = @_; - my $item; + my ( $item, $header, $footer ); if (ref($letter_or_item)) { my $letter = $letter_or_item; my $metadata = _metadata($letter); + $header = $metadata->{header}; + $footer = $metadata->{footer}; $item = $metadata->{body}->[0]; } else { $item = $letter_or_item; @@ -320,6 +328,8 @@ sub append { } my $metadata = $self->metadata; push @{$metadata->{body}}, $item; + $metadata->{header} = $header; + $metadata->{footer} = $footer; $self->metadata($metadata); my $new_content = $self->render_metadata($format); return $self->content($new_content);