Bug 11529: Simplify and optimize batchRebuildBiblioTables.pl
[koha.git] / misc / devel / create_superlibrarian.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Copyright 2016 Koha Development Team
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 use Getopt::Long;
22 use Pod::Usage;
23
24 use Koha::Script;
25 use Koha::Patrons;
26
27 my ( $help, $surname, $userid, $password, $branchcode, $categorycode, $cardnumber );
28 GetOptions(
29     'help|?'         => \$help,
30     'userid=s'       => \$userid,
31     'password=s'     => \$password,
32     'branchcode=s'   => \$branchcode,
33     'categorycode=s' => \$categorycode,
34     'cardnumber=s'   => \$cardnumber,
35 );
36
37 pod2usage(1) if $help;
38 pod2usage("userid is mandatory")       unless $userid;
39 pod2usage("password is mandatory")     unless $password;
40 pod2usage("branchcode is mandatory")   unless $branchcode;
41 pod2usage("categorycode is mandatory") unless $categorycode;
42 pod2usage("cardnumber is mandatory")   unless $cardnumber;
43
44 my $patron = Koha::Patron->new({
45     surname      => $surname,
46     userid       => $userid,
47     cardnumber   => $cardnumber,
48     branchcode   => $branchcode,
49     categorycode => $categorycode,
50     flags        => 1,
51 })->store;
52
53 $patron->set_password({ password => $password, skip_validation => 1 });
54
55 =head1 NAME
56
57 create_superlibrarian.pl - create a user in Koha with superlibrarian permissions
58
59 =head1 SYNOPSIS
60
61 create_superlibrarian.pl
62   --userid <userid> --password <password> --branchcode <branchcode> --categorycode <categorycode> --cardnumber <cardnumber>
63
64  Options:
65    -?|--help        brief help message
66    --userid         specify the userid to be set
67    --password       specify the password to be set
68    --branchcode     specify the library code
69    --categorycode   specify the patron category code
70    --cardnumber     specify the cardnumber to be set
71
72 =head1 OPTIONS
73
74 =over 8
75
76 =item B<--help|-?>
77
78 Print a brief help message and exits
79
80 =item B<--userid>
81
82 To specify the userid to be set in the database
83
84 =item B<--password>
85
86 To specify the password to be set in the database
87
88 =item B<--branchcode>
89
90 Library code
91
92 =item B<--categorycode>
93
94 Patron category's code
95
96 =item B<--cardnumber>
97
98 Patron's cardnumber
99
100 =back
101
102 =head1 DESCRIPTION
103
104 A simple script to create a user in the Koha database with superlibrarian permissions
105
106 =cut