From 0a4a15a33f3508259115595e4edcebe8f5d9ed47 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 16 Apr 2018 12:31:22 -0300 Subject: [PATCH] Bug 20580: Make create_superlibrarian.pl accept parameters So far this script does not accept parameters and create a koha/koha superlibrarian This patch makes it accept parameters to create a customized superlibrarian patrons. Test plan: Use the script with valid and invalid paramters and confirm that it works as expected. Note: A cryptic "Invalid parameter passed" error is raised when the categorycode is not valid. Better error handling must be provided but Koha::Exceptions seems to be enhancement (see related bug reports). --- misc/devel/create_superlibrarian.pl | 75 +++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/misc/devel/create_superlibrarian.pl b/misc/devel/create_superlibrarian.pl index 623a01ade5..9a8d0ff984 100755 --- a/misc/devel/create_superlibrarian.pl +++ b/misc/devel/create_superlibrarian.pl @@ -21,45 +21,31 @@ use Modern::Perl; use Getopt::Long; use Pod::Usage; -use C4::Installer; -use C4::Context; use C4::Members; -use Koha::DateUtils; -use Koha::Libraries; -use Koha::Patrons; -use Koha::Patron::Categories; - -my $library = Koha::Libraries->search->next; -my $patron_category = Koha::Patron::Categories->search->next; - -die -"Not enough data in the database, library and/or patron category does not exist" - unless $library and $patron_category; - -die "A patron with userid 'koha' already exists" - if Koha::Patrons->find( { userid => 'koha' } ); -die "A patron with cardnumber '42' already exists" - if Koha::Patrons->find( { cardnumber => 'koha' } ); - -my $userid = 'koha'; -my $password = 'koha'; -my $help; - +my ( $help, $surname, $userid, $password, $branchcode, $categorycode, $cardnumber ); GetOptions( - 'help|?' => \$help, - 'userid=s' => \$userid, - 'password=s' => \$password + 'help|?' => \$help, + 'userid=s' => \$userid, + 'password=s' => \$password, + 'branchcode=s' => \$branchcode, + 'categorycode=s' => \$categorycode, + 'cardnumber=s' => \$cardnumber, ); pod2usage(1) if $help; - -AddMember( - surname => 'koha', +pod2usage("userid is mandatory") unless $userid; +pod2usage("password is mandatory") unless $password; +pod2usage("branchcode is mandatory") unless $branchcode; +pod2usage("categorycode is mandatory") unless $categorycode; +pod2usage("cardnumber is mandatory") unless $cardnumber; + +C4::Members::AddMember( + surname => $surname, userid => $userid, - cardnumber => 42, - branchcode => $library->branchcode, - categorycode => $patron_category->categorycode, + cardnumber => $cardnumber, + branchcode => $branchcode, + categorycode => $categorycode, password => $password, flags => 1, ); @@ -71,12 +57,15 @@ create_superlibrarian.pl - create a user in Koha with superlibrarian permissions =head1 SYNOPSIS create_superlibrarian.pl - [ --userid ] [ --password ] + --userid --password --branchcode --categorycode --cardnumber Options: -?|--help brief help message - --userid specify the userid to be set (defaults to koha) - --password specify the password to be set (defaults to koha) + --userid specify the userid to be set + --password specify the password to be set + --branchcode specify the library code + --categorycode specify the patron category code + --cardnumber specify the cardnumber to be set =head1 OPTIONS @@ -88,11 +77,23 @@ Print a brief help message and exits =item B<--userid> -Allows you to specify the userid to be set in the database +To specify the userid to be set in the database =item B<--password> -Allows you to specify the password to be set in the database +To specify the password to be set in the database + +=item B<--branchcode> + +Library code + +=item B<--categorycode> + +Patron category's code + +=item B<--cardnumber> + +Patron's cardnumber =back -- 2.11.0