Bug 32336: (QA follow-up) Use $metadata->schema
[srvgit] / installer / onboarding.pl
index 7a76342..68a1345 100755 (executable)
 
 use Modern::Perl;
 use C4::Context;
-use C4::InstallAuth;
+use C4::InstallAuth qw( checkauth get_template_and_user );
 use CGI qw ( -utf8 );
-use C4::Output;
-use C4::Members qw(checkcardnumber);
+use C4::Output qw( output_html_with_http_headers );
+use C4::Members qw( checkcardnumber );
 use Koha::Patrons;
 use Koha::Libraries;
 use Koha::Database;
-use Koha::DateUtils;
 use Koha::Patrons;
 use Koha::Patron::Categories;
 use Koha::ItemTypes;
 use Koha::CirculationRules;
 
 #Setting variables
-my $input = new CGI;
+my $input = CGI->new;
 
 unless ( C4::Context->preference('Version') ) {
     print $input->redirect("/cgi-bin/koha/installer/install.pl");
@@ -100,17 +99,6 @@ if ( $step == 2 ) {
         my $enrolmentperiod       = $input->param('enrolmentperiod');
         my $enrolmentperioddate = $input->param('enrolmentperioddate') || undef;
 
-        #Converts the string into a date format
-        if ($enrolmentperioddate) {
-            $enrolmentperioddate = output_pref(
-                {
-                    dt         => dt_from_string($enrolmentperioddate),
-                    dateformat => 'DateTime',
-                    dateonly   => 1,
-                }
-            );
-        }
-
         #Adds a new patron category to the database
         $category = Koha::Patron::Category->new(
             {
@@ -144,8 +132,14 @@ if ( $step == 3 ) {
         my $secondpassword = $input->param('password2') || '';
         my $cardnumber     = $input->param('cardnumber');
         my $userid         = $input->param('userid');
+        my $categorycode = $input->param('categorycode_entry');
+        my $patron_category =
+          Koha::Patron::Categories->find( $categorycode );
+
+        my ( $is_valid, $passworderror ) =
+          Koha::AuthUtils::is_password_valid( $firstpassword,
+            $patron_category );
 
-        my ( $is_valid, $passworderror) = Koha::AuthUtils::is_password_valid( $firstpassword );
 
         if ( my $error_code = checkcardnumber($cardnumber) ) {
             if ( $error_code == 1 ) {
@@ -171,7 +165,7 @@ if ( $step == 3 ) {
                 firstname    => scalar $input->param('firstname'),
                 cardnumber   => scalar $input->param('cardnumber'),
                 branchcode   => scalar $input->param('libraries'),
-                categorycode => scalar $input->param('categorycode_entry'),
+                categorycode => $categorycode,
                 userid       => scalar $input->param('userid'),
                 privacy      => "default",
                 address      => "",
@@ -179,8 +173,6 @@ if ( $step == 3 ) {
                 flags        => 1,    # Will be superlibrarian
             };
 
-            my $patron_category =
-              Koha::Patron::Categories->find( $patron_data->{categorycode} );
             $patron_data->{dateexpiry} =
               $patron_category->get_expiry_date( $patron_data->{dateenrolled} );
 
@@ -238,7 +230,7 @@ if ( $step == 5 ) {
         my $categorycode    = $input->param('categorycode');
         my $itemtype        = $input->param('itemtype');
         my $maxissueqty     = $input->param('maxissueqty');
-        my $issuelength     = $input->param('issuelength');
+        my $issuelength     = $input->param('issuelength') || 0;
         my $lengthunit      = $input->param('lengthunit');
         my $renewalsallowed = $input->param('renewalsallowed');
         my $renewalperiod   = $input->param('renewalperiod');
@@ -248,7 +240,6 @@ if ( $step == 5 ) {
         my $onshelfholds    = $input->param('onshelfholds') || 0;
         $maxissueqty =~ s/\s//g;
         $maxissueqty = undef if $maxissueqty !~ /^\d+/;
-        $issuelength = $issuelength eq q{} ? undef : $issuelength;
 
         my $params = {
             branchcode      => $branchcode,
@@ -282,7 +273,15 @@ if ( $step == 5 ) {
                 overduefinescap                  => "",
                 rentaldiscount                   => 0,
                 reservesallowed                  => $reservesallowed,
-                suspension_chargeperiod          => undef,
+                suspension_chargeperiod          => 1,
+                decreaseloanholds                => "",
+                unseen_renewals_allowed          => "",
+                recalls_allowed                  => undef,
+                recalls_per_record               => undef,
+                on_shelf_recalls                 => undef,
+                recall_due_date_interval         => undef,
+                recall_overdue_fine              => undef,
+                recall_shelf_time                => undef,
               }
         };
 
@@ -316,8 +315,6 @@ my ( $template, $loggedinuser );
         template_name   => "onboarding/onboardingstep${step}.tt",
         query           => $input,
         type            => "intranet",
-        authnotrequired => 0,
-        debug           => 1,
     }
 );