Bug 24591: Add --help option to misc/devel/get-prepared-letter.pl
[koha.git] / misc / devel / get_prepared_letter.pl
blob45f5544d8244548db7a7afc7cedf4b419aa2f28f
1 #!/usr/bin/perl
3 # Copyright 2020 BibLibre
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
10 # version.
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, see <http://www.gnu.org/licenses>.
19 =head1 NAME
21 get-prepared-letter.pl - preview letter content
23 =head1 SYNOPSIS
25 get-prepared-letter.pl --module MODULE --letter-code CODE [options]
27 =head1 OPTIONS
29 =over
31 =item B<--module MODULE>
33 The letter module (acquisition, catalogue, circulation, ...)
35 =item B<--letter-code CODE>
37 The letter code (DUE, PREDUE, ...)
39 =item B<--branchcode BRANCHCODE>
41 The letter branchcode
43 =item B<--message-transport-type TYPE>
45 The message transport type (email, print, ...)
47 =item B<--lang LANG>
49 The letter language (es-ES, fr-FR, ...)
51 =item B<--repeat REPEAT>
53 A JSON formatted string that will be used as repeat parameter. See
54 documentation of GetPreparedLetter for more informations.
56 =item B<--tables TABLES>
58 A JSON formatted string that will be used as tables parameter. See
59 documentation of GetPreparedLetter for more informations.
61 =item B<--loops LOOPS>
63 A JSON formatted string that will be used as loops parameter. See
64 documentation of GetPreparedLetter for more informations.
66 =back
68 =cut
70 use Modern::Perl;
72 use Getopt::Long;
73 use JSON;
74 use Pod::Usage;
76 use C4::Letters;
78 my $help;
79 my ( $module, $letter_code, $branchcode, $message_transport_type, $lang,
80 $repeat, $tables, $loops );
82 GetOptions(
83 'help' => \$help,
84 'module=s' => \$module,
85 'letter-code=s' => \$letter_code,
86 'branchcode=s' => \$branchcode,
87 'message-transport-type=s' => \$message_transport_type,
88 'lang=s' => \$lang,
89 'repeat=s' => \$repeat,
90 'tables=s' => \$tables,
91 'loops=s' => \$loops,
92 ) or pod2usage( -exitval => 2, -verbose => 1 );
94 if ($help) {
95 pod2usage( -exitval => 0, -verbose => 1 );
98 $repeat = $repeat ? decode_json($repeat) : {};
99 $tables = $tables ? decode_json($tables) : {};
100 $loops = $loops ? decode_json($loops) : {};
102 my $letter = C4::Letters::GetPreparedLetter(
103 module => $module,
104 letter_code => $letter_code,
105 branchcode => $branchcode,
106 message_transport_type => $message_transport_type,
107 lang => $lang,
108 repeat => $repeat,
109 tables => $tables,
110 loops => $loops,
113 print "Subject: " . $letter->{title} . "\n\n";
114 print $letter->{content} . "\n";