@@ -, +, @@ patron category types => a patron of the first category can't have a guarantor => a patron from the second category can => tests should still pass --- Koha/Patron.pm | 2 +- admin/categories.pl | 6 +++--- installer/data/mysql/atomicupdate/bug_12446.perl | 10 ++++++++++ installer/data/mysql/kohastructure.sql | 4 ++-- .../intranet-tmpl/prog/en/modules/admin/categories.tt | 10 +++++----- members/memberentry.pl | 3 ++- t/db_dependent/Patrons.t | 10 ++++++---- 7 files changed, 29 insertions(+), 16 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_12446.perl --- a/Koha/Patron.pm +++ a/Koha/Patron.pm @@ -309,7 +309,7 @@ sub store { # Clean up guarantors on category change if required $self->guarantor_relationships->delete - unless ( $self->category->can_be_guarantee ); + unless ( $self->category->canbeguarantee ); } --- a/admin/categories.pl +++ a/admin/categories.pl @@ -79,7 +79,7 @@ elsif ( $op eq 'add_validate' ) { my $min_password_length = $input->param('min_password_length'); my $require_strong_password = $input->param('require_strong_password'); my @branches = grep { $_ ne q{} } $input->multi_param('branches'); - my $can_be_guarantee = $input->param('can_be_guarantee'); + my $canbeguarantee = $input->param('canbeguarantee'); $reset_password = undef if $reset_password eq -1; $change_password = undef if $change_password eq -1; @@ -102,7 +102,7 @@ elsif ( $op eq 'add_validate' ) { $category->hidelostitems($hidelostitems); $category->overduenoticerequired($overduenoticerequired); $category->category_type($category_type); - $category->can_be_guarantee($can_be_guarantee); + $category->canbeguarantee($canbeguarantee); $category->BlockExpiredPatronOpacActions($BlockExpiredPatronOpacActions); $category->checkprevcheckout($checkPrevCheckout); $category->default_privacy($default_privacy); @@ -135,7 +135,7 @@ elsif ( $op eq 'add_validate' ) { hidelostitems => $hidelostitems, overduenoticerequired => $overduenoticerequired, category_type => $category_type, - can_be_guarantee => $can_be_guarantee, + canbeguarantee => $canbeguarantee, BlockExpiredPatronOpacActions => $BlockExpiredPatronOpacActions, checkprevcheckout => $checkPrevCheckout, default_privacy => $default_privacy, --- a/installer/data/mysql/atomicupdate/bug_12446.perl +++ a/installer/data/mysql/atomicupdate/bug_12446.perl @@ -0,0 +1,10 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + if ( !column_exists( 'categories', 'canbeguarantee') ){ + $dbh->do("ALTER TABLE categories ADD COLUMN `canbeguarantee` tinyint(1) NOT NULL default '0' AFTER `checkprevcheckout`"); + $dbh->do("UPDATE categories SET canbeguarantee = 1 WHERE category_type = 'P' OR category_type = 'C'"); + } + + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 12446 - Ability to allow guarantor relationship for all patron category types)\n"; +} --- a/installer/data/mysql/kohastructure.sql +++ a/installer/data/mysql/kohastructure.sql @@ -1672,8 +1672,8 @@ CREATE TABLE `categories` ( `BlockExpiredPatronOpacActions` tinyint(1) NOT NULL DEFAULT -1 COMMENT 'wheither or not a patron of this category can renew books or place holds once their card has expired. 0 means they can, 1 means they cannot, -1 means use syspref BlockExpiredPatronOpacActions', `default_privacy` enum('default','never','forever') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'default' COMMENT 'Default privacy setting for this patron category', `checkprevcheckout` varchar(7) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'inherit' COMMENT 'produce a warning for this patron category if this item has previously been checked out to this patron if ''yes'', not if ''no'', defer to syspref setting if ''inherit''.', - `can_be_guarantee` tinyint(1) NOT NULL default 0 COMMENT 'if patrons of this category can be guarantees', - `reset_password` tinyint(1) DEFAULT NULL COMMENT 'if patrons of this category can do the password reset flow,', +`canbeguarantee` tinyint(1) NOT NULL default '0', +`reset_password` tinyint(1) DEFAULT NULL COMMENT 'if patrons of this category can do the password reset flow,', `change_password` tinyint(1) DEFAULT NULL COMMENT 'if patrons of this category can change their passwords in the OAPC', `min_password_length` smallint(6) DEFAULT NULL COMMENT 'set minimum password length for patrons in this category', `require_strong_password` tinyint(1) DEFAULT NULL COMMENT 'set required password strength for patrons in this category', --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt @@ -239,9 +239,9 @@ Required
  • - - + [% IF category.canbeguarantee %] [% ELSE %] @@ -509,7 +509,7 @@ [% END %] - Can be guarantee[% IF category.can_be_guarantee %]Yes[% ELSE %]No[% END %] + Can be guarantee[% IF category.canbeguarantee %]Yes[% ELSE %]No[% END %] Default privacy: @@ -689,7 +689,7 @@ [% END %] [% END %] - [% IF category.can_be_guarantee %] Yes [% ELSE %] no [% END %] + [% IF category.canbeguarantee %] Yes [% ELSE %] no [% END %] [% SWITCH category.default_privacy %] [% CASE 'default' %] --- a/members/memberentry.pl +++ a/members/memberentry.pl @@ -755,7 +755,8 @@ if (C4::Context->preference('EnhancedMessagingPreferences')) { } $template->param( borrower_data => \%data ); -$template->param( "show_guarantor" => $category ? $category->can_be_guarantee : 1); # associate with step to know where you are +$template->param( "show_guarantor" => $categorycode ? Koha::Patron::Categories->find($categorycode)->canbeguarantee : 1); # associate with step to know where you are +$debug and warn "memberentry step: $step"; $template->param( "step_$step" => 1) if $step; # associate with step to know where u are $template->param( step => $step ) if $step; # associate with step to know where u are --- a/t/db_dependent/Patrons.t +++ a/t/db_dependent/Patrons.t @@ -112,16 +112,16 @@ subtest "Update patron categories" => sub { category_type=>'C', upperagelimit=>17, dateofbirthrequired=>5, - can_be_guarantee=>1, + canbeguarantee=>1, } })->{categorycode}; my $c_categorycode_2 = $builder->build({ source => 'Category', value => { category_type=>'C', upperagelimit=>17, dateofbirthrequired=>5, - can_be_guarantee=>1, + canbeguarantee=>1, } })->{categorycode}; - my $a_categorycode = $builder->build({ source => 'Category', value => {category_type=>'A', can_be_guarantee=>0} })->{categorycode}; - my $a_categorycode_2 = $builder->build({ source => 'Category', value => {category_type=>'A', can_be_guarantee=>1} })->{categorycode}; + my $a_categorycode = $builder->build({ source => 'Category', value => {category_type=>'A', canbeguarantee=>0} })->{categorycode}; + my $a_categorycode_2 = $builder->build({ source => 'Category', value => {category_type=>'A', canbeguarantee=>1} })->{categorycode}; my $p_categorycode = $builder->build({ source => 'Category', value => {category_type=>'P'} })->{categorycode}; my $i_categorycode = $builder->build({ source => 'Category', value => {category_type=>'I'} })->{categorycode}; my $branchcode1 = $builder->build({ source => 'Branch' })->{branchcode}; @@ -201,6 +201,8 @@ subtest "Update patron categories" => sub { is( Koha::Patrons->search_patrons_to_update_category({from=>$c_categorycode_2,too_young=>1})->next->borrowernumber, $child1->borrowernumber ); is( Koha::Patrons->search_patrons_to_update_category({from=>$c_categorycode_2,too_young=>1})->update_category_to({category=>$a_categorycode}),1,'One child patron updated to adult category because too young'); is( Koha::Patrons->find($adult1->borrowernumber)->guarantee_relationships->guarantees->count,2,'Guarantee was removed when made adult'); + is( Koha::Patrons->search_patrons_to_update_category({from=>$c_categorycode_2})->update_category_to({category=>$a_categorycode_2}),2,'Two child patrons updated to adult category'); + is( Koha::Patrons->find($adult1->borrowernumber)->guarantee_relationships->guarantees->count,2,'Guarantees were not removed when made adult which can be guarantee'); is( Koha::Patrons->search_patrons_to_update_category({from=>$c_categorycode_2,too_old=>1})->next->borrowernumber, $child3->borrowernumber ); is( Koha::Patrons->search_patrons_to_update_category({from=>$c_categorycode_2,too_old=>1})->update_category_to({category=>$a_categorycode}),1,'One child patron updated to adult category because too old'); --