Bug 24591: Add developer script to preview a letter
authorJulian Maurice <julian.maurice@biblibre.com>
Wed, 5 Feb 2020 11:20:37 +0000 (12:20 +0100)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 7 Aug 2020 14:54:40 +0000 (16:54 +0200)
The script is very simple, it just calls GetPreparedLetter with
arguments given on command line and print the resulting letter content

Usage example:

misc/devel/get-prepared-letter.pl --module circulation \
    --letter_code ODUE --tables '{"borrowers":1,"branches":"CPL"}' \
    --repeat '{"item":[{"biblio":1,"items":1}]}' \
    --loops '{"overdues":[1]}'

Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Works for the example and other cases.
Correct option is 'letter-code', with dash, not underscore.
An usage message would be nice.
No errors

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

JD amended patch: tidy the new file and rename it matching the other
scripts' names in this directory

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

misc/devel/get_prepared_letter.pl [new file with mode: 0755]

diff --git a/misc/devel/get_prepared_letter.pl b/misc/devel/get_prepared_letter.pl
new file mode 100755 (executable)
index 0000000..c6f3101
--- /dev/null
@@ -0,0 +1,56 @@
+#!/usr/bin/perl
+
+# Copyright 2020 BibLibre
+#
+# 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 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.
+#
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, see <http://www.gnu.org/licenses>.
+
+use Modern::Perl;
+
+use Getopt::Long;
+use JSON;
+
+use C4::Letters;
+
+my ( $module, $letter_code, $branchcode, $message_transport_type, $lang,
+    $repeat, $tables, $loops );
+
+GetOptions(
+    'module=s'                 => \$module,
+    'letter-code=s'            => \$letter_code,
+    'branchcode=s'             => \$branchcode,
+    'message-transport-type=s' => \$message_transport_type,
+    'lang=s'                   => \$lang,
+    'repeat=s'                 => \$repeat,
+    'tables=s'                 => \$tables,
+    'loops=s'                  => \$loops,
+) or die "Error in command line arguments\n";
+
+$repeat = $repeat ? decode_json($repeat) : {};
+$tables = $tables ? decode_json($tables) : {};
+$loops  = $loops  ? decode_json($loops)  : {};
+
+my $letter = C4::Letters::GetPreparedLetter(
+    module                 => $module,
+    letter_code            => $letter_code,
+    branchcode             => $branchcode,
+    message_transport_type => $message_transport_type,
+    lang                   => $lang,
+    repeat                 => $repeat,
+    tables                 => $tables,
+    loops                  => $loops,
+);
+
+print "Subject: " . $letter->{title} . "\n\n";
+print $letter->{content} . "\n";