Bug 18989: Add atomic update
[koha-ffzg.git] / installer / onboarding.pl
index 547df29..6680cd9 100755 (executable)
@@ -33,7 +33,7 @@ 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");
@@ -144,8 +144,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 +177,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 +185,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} );
 
@@ -272,7 +276,7 @@ if ( $step == 5 ) {
                 hardduedatecompare               => -1,
                 holds_per_day                    => $holds_per_day,
                 holds_per_record                 => $holds_per_record,
-                maxissueqty                      => "",
+                maxissueqty                      => $maxissueqty,
                 maxonsiteissueqty                => "",
                 maxsuspensiondays                => "",
                 no_auto_renewal_after            => "",
@@ -283,59 +287,19 @@ if ( $step == 5 ) {
                 rentaldiscount                   => 0,
                 reservesallowed                  => $reservesallowed,
                 suspension_chargeperiod          => undef,
+                decreaseloanholds                => undef,
               }
         };
 
-        my $params_2 = {
-            branchcode   => $branchcode,
-            categorycode => $categorycode,
-            rules        => {
-                patron_maxissueqty       => "",
-                patron_maxonsiteissueqty => "",
-                max_holds                => "",
-            }
-        };
-
-        my $params_3 = {
-            branchcode => $branchcode,
-            itemtype   => $itemtype,
-            rules      => {
-                holdallowed             => "",
-                hold_fulfillment_policy => "",
-                returnbranch            => "",
-            }
-        };
-
         eval {
             Koha::CirculationRules->set_rules($params);
-            Koha::CirculationRules->set_rules($params_2);
-            Koha::CirculationRules->set_rules($params_3);
         };
 
         if ($@) {
             warn $@;
             push @messages, { code => 'error_on_insert_circ_rule' };
         } else {
-
-            eval {
-                Koha::CirculationRules->set_rules(
-                    {
-                        categorycode => $categorycode,
-                        itemtype     => $itemtype,
-                        branchcode   => $branchcode,
-                        rules        => {
-                            maxissueqty => $maxissueqty,
-                        }
-                    }
-                );
-            };
-
-            unless ($@) {
-                push @messages, { code => 'success_on_insert_circ_rule' };
-            }
-            else {
-                push @messages, { code => 'error_on_insert_circ_rule' };
-            }
+            push @messages, { code => 'success_on_insert_circ_rule' };
         }
     }
 
@@ -357,7 +321,6 @@ my ( $template, $loggedinuser );
         template_name   => "onboarding/onboardingstep${step}.tt",
         query           => $input,
         type            => "intranet",
-        authnotrequired => 0,
         debug           => 1,
     }
 );