X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=installer%2Fonboarding.pl;h=68a1345df1ea24bdb39e1f3508a0a30c5a30045d;hb=1bbc53f65fba7cb28d7e56edede0e48349f5fff3;hp=8b032c999b2d1a30ec55b6fa288448f5b7b1a9e9;hpb=f5fc081265c4398f046484b495356ef11405b71d;p=koha-ffzg.git diff --git a/installer/onboarding.pl b/installer/onboarding.pl index 8b032c999b..68a1345df1 100755 --- a/installer/onboarding.pl +++ b/installer/onboarding.pl @@ -19,22 +19,20 @@ 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; +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::Patron::Category; use Koha::ItemTypes; -use Koha::IssuingRule; -use Koha::IssuingRules; +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"); @@ -101,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( { @@ -145,6 +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 ); + if ( my $error_code = checkcardnumber($cardnumber) ) { if ( $error_code == 1 ) { @@ -158,35 +153,40 @@ if ( $step == 3 ) { push @messages, { code => 'ERROR_password_mismatch' }; } - else { + elsif ( $passworderror) { + push @messages, { code => 'ERROR_password_too_short'} if $passworderror eq 'too_short'; + push @messages, { code => 'ERROR_password_too_weak'} if $passworderror eq 'too_weak'; + push @messages, { code => 'ERROR_password_has_whitespaces'} if $passworderror eq 'has_whitespaces'; + } + else { my $patron_data = { surname => scalar $input->param('surname'), 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'), - password => scalar $input->param('password'), - password2 => scalar $input->param('password2'), privacy => "default", address => "", city => "", - flags => 1, # Will be superlibrarian + 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} ); - my $borrowernumber = C4::Members::AddMember(%$patron_data); + eval { + my $patron = Koha::Patron->new($patron_data)->store; + $patron->set_password({ password => $firstpassword }); + }; #Error handling checking if the patron was created successfully - if ($borrowernumber) { + unless ($@) { push @messages, { code => 'success_on_insert_patron' }; } else { + warn $@; push @messages, { code => 'error_on_insert_patron' }; } } @@ -230,59 +230,78 @@ 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'); + my $reservesallowed = $input->param('reservesallowed'); + my $holds_per_day = $input->param('holds_per_day'); + my $holds_per_record = $input->param('holds_per_record'); 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, categorycode => $categorycode, itemtype => $itemtype, - maxissueqty => $maxissueqty, - renewalsallowed => $renewalsallowed, - renewalperiod => $renewalperiod, - issuelength => $issuelength, - lengthunit => $lengthunit, - onshelfholds => $onshelfholds, + rules => { + renewalsallowed => $renewalsallowed, + renewalperiod => $renewalperiod, + issuelength => $issuelength, + lengthunit => $lengthunit, + onshelfholds => $onshelfholds, + article_requests => "no", + auto_renew => 0, + cap_fine_to_replacement_price => 0, + chargeperiod => 0, + chargeperiod_charge_at => 0, + fine => 0, + finedays => 0, + firstremind => 0, + hardduedate => "", + hardduedatecompare => -1, + holds_per_day => $holds_per_day, + holds_per_record => $holds_per_record, + maxissueqty => $maxissueqty, + maxonsiteissueqty => "", + maxsuspensiondays => "", + no_auto_renewal_after => "", + no_auto_renewal_after_hard_limit => "", + norenewalbefore => "", + opacitemholds => "N", + overduefinescap => "", + rentaldiscount => 0, + reservesallowed => $reservesallowed, + 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, + } }; - my $issuingrule = Koha::IssuingRule->new($params); - eval { $issuingrule->store; }; + eval { + Koha::CirculationRules->set_rules($params); + }; - unless ($@) { - push @messages, { code => 'success_on_insert_circ_rule' }; - } - else { + if ($@) { + warn $@; push @messages, { code => 'error_on_insert_circ_rule' }; + } else { + push @messages, { code => 'success_on_insert_circ_rule' }; } } - $step++ if Koha::IssuingRules->count; + $step++ if Koha::CirculationRules->count; } my $libraries = Koha::Libraries->search( {}, { order_by => ['branchcode'] }, ); $template_params->{libraries} = $libraries; -$template_params->{group_types} = [ - { - categorytype => 'searchdomain', - categories => [ - Koha::LibraryCategories->search( - { categorytype => 'searchdomain' } - ) - ], - }, - { - categorytype => 'properties', - categories => [ - Koha::LibraryCategories->search( { categorytype => 'properties' } ) - ], - }, -]; if ( $step > 5 ) { $template_params->{all_done} = 1; # If step 5 is complete, we are done! @@ -296,8 +315,6 @@ my ( $template, $loggedinuser ); template_name => "onboarding/onboardingstep${step}.tt", query => $input, type => "intranet", - authnotrequired => 0, - debug => 1, } );