Bug 18736: (follow-up) Remove duplicate code and adjust tests
[koha.git] / C4 / Message.pm
index eb27a20..e4dafdb 100644 (file)
@@ -5,18 +5,18 @@ 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 <http://www.gnu.org/licenses>.
 
 
 use strict;
@@ -37,7 +37,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',
@@ -311,10 +311,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;
@@ -325,6 +327,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);