Bug 24883: Add POD entry and remove unused variable
[koha.git] / misc / load_yaml.pl
1 #!/usr/bin/perl
2 #
3 #  Copyright 2020 Koha Development Team
4 #
5 #  This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 use Modern::Perl;
21
22 use Getopt::Long qw(:config no_ignore_case);
23 use C4::Context;
24 use C4::Installer;
25
26 sub print_usage {
27      ( my $basename = $0 ) =~ s|.*/||;
28      print <<USAGE;
29
30 $basename
31  Load file in YAML format into database.
32
33 Usage:
34 $0 [--file=FILE]
35 $0 -h
36  -h, --help              Show this help
37  -f, --file=FILE         File to load.
38  --load                  Load the file into the database
39
40 USAGE
41 }
42
43 # Getting parameters
44 my ( @files, $load, $help );
45
46 GetOptions(
47  'help|h'        => \$help,
48  'load'          => \$load,
49  'file|f=s@'     => \@files,
50 ) or print_usage, exit 1;
51
52 if ($help or not @files or not $load) {
53     print_usage;
54     exit;
55 }
56
57 my $installer = C4::Installer->new;
58 if ( $load ) {
59     for my $f ( @files ) {
60         my $error = $installer->load_sql($f);
61         say $error if $error;
62     }
63 }