From 7118dcbebdc9e9d363f309793a8df9978a2438cb Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Mon, 6 Apr 2020 23:53:08 +0000 Subject: [PATCH] Bug 23111: Set a custom framework as the default when importing records or editing records with no framework mapped. To test: 1) Go to edit a biblio with no framework mapped 2) Click the Settings dropdown, notice that the 'Default' framework is selected 3) Go to the Cataloguing home page. Click the main 'New from Z39.50/SRU' button and notice the selected framework in the URL is 'Default' 4) Go to Tools -> Stage MARC records for import. Stage a bibliographic record. Go to Staged MARC management for your newly imported batch. Notice that the frameworks dropdown (above the 'Import this batch into the catalog' button) has the 'Default' framework selected 5) Apply this patch and update the database. Apply the schema changes patch or update your schema files. Restart memcached and plack. 6) Go to Administration -> MARC bibliographic frameworks. Edit one of your custom frameworks. Set it as default by checking the checkbox and saving. 7) Edit a different custom framework and set this one as the default now. Confirm that the previous framework has been unset (the checkbox is no longer checked) as the default. 8) Repeat steps 1-4 and confirm that the selected framework is your newly set default framework, instead of the provided 'Default' framework. 9) Go back to Administration -> MARC bibliographic frameworks. Edit your default framework and unset it as default (uncheck the checkbox). Save. 10) Repeat steps 1-4 and confirm that the selected framework is the provided 'Default' framework again, so we can have no default custom framework if chosen. 11) Confirm the tests pass: t/db_dependent/Koha/BiblioFrameworks.t Sponsored-by: Catalyst IT --- Koha/BiblioFramework.pm | 35 ++++++++++++++++++++++ Koha/BiblioFrameworks.pm | 15 ++++++++++ admin/biblio_framework.pl | 3 ++ cataloguing/addbiblio.pl | 6 ++++ cataloguing/addbooks.pl | 5 ++++ ..._add-is_default-column-to-biblio_framework.perl | 7 +++++ installer/data/mysql/kohastructure.sql | 1 + .../prog/en/modules/admin/biblio_framework.tt | 8 +++++ .../prog/en/modules/cataloguing/addbooks.tt | 6 +++- .../prog/en/modules/tools/manage-marc-import.tt | 8 +++-- t/db_dependent/Koha/BiblioFrameworks.t | 18 ++++++++++- 11 files changed, 108 insertions(+), 4 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug-23111_add-is_default-column-to-biblio_framework.perl diff --git a/Koha/BiblioFramework.pm b/Koha/BiblioFramework.pm index ca69f37e84..4dd1cad017 100644 --- a/Koha/BiblioFramework.pm +++ b/Koha/BiblioFramework.pm @@ -33,6 +33,41 @@ Koha::BiblioFramework - Koha BiblioFramework Object class =cut +=head3 set_default + + $framework->set_default; + +Set this framework as the new default, and unset whichever framework is currently the default. + +=cut + +sub set_default { + my ( $self ) = @_; + + my $current_default = Koha::BiblioFrameworks->get_default; + if ( defined $current_default ){ + $current_default->unset_default; + } + + $self->update({ is_default => 1 })->store; + return $self; +} + +=head3 unset_default + + $framework->unset_default; + +Unset this framework as the default. + +=cut + +sub unset_default { + my ( $self ) = @_; + + $self->update({ is_default => 0 })->store; + return $self; +} + =head3 type =cut diff --git a/Koha/BiblioFrameworks.pm b/Koha/BiblioFrameworks.pm index 16db02b586..7ccbf8ce8f 100644 --- a/Koha/BiblioFrameworks.pm +++ b/Koha/BiblioFrameworks.pm @@ -35,6 +35,21 @@ Koha::BiblioFrameworks - Koha BiblioFramework Object set class =cut +=head3 get_default + + my $default_framework = Koha::BiblioFrameworks->get_default; + +Get the allocated default framework. +If returned undefined, then the current default framework is the Default framework (framework with no frameworkcode). + +=cut + +sub get_default { + my ( $self ) = @_; + + return $self->find({ is_default => 1 }); +} + =head3 type =cut diff --git a/admin/biblio_framework.pl b/admin/biblio_framework.pl index 0c30e95774..f273f18b03 100755 --- a/admin/biblio_framework.pl +++ b/admin/biblio_framework.pl @@ -54,11 +54,13 @@ if ( $op eq 'add_form' ) { } elsif ( $op eq 'add_validate' ) { my $frameworkcode = $input->param('frameworkcode'); my $frameworktext = $input->param('frameworktext'); + my $is_default = $input->param('is_default'); my $is_a_modif = $input->param('is_a_modif'); if ($is_a_modif) { my $framework = Koha::BiblioFrameworks->find($frameworkcode); $framework->frameworktext($frameworktext); + $is_default ? $framework->set_default : $framework->unset_default; eval { $framework->store; }; if ($@) { push @messages, { type => 'error', code => 'error_on_update' }; @@ -71,6 +73,7 @@ if ( $op eq 'add_form' ) { frameworktext => $frameworktext, } ); + $is_default ? $framework->set_default : $framework->unset_default; eval { $framework->store; }; if ($@) { push @messages, { type => 'error', code => 'error_on_insert' }; diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl index cd53c66e70..c56b3c4207 100755 --- a/cataloguing/addbiblio.pl +++ b/cataloguing/addbiblio.pl @@ -970,6 +970,12 @@ if ( $record ne '-1' ) { my $title = C4::Context->preference('marcflavour') eq "UNIMARC" ? $record->subfield('200', 'a') : $record->title; $template->param( title => $title ); } +my $default_framework = Koha::BiblioFrameworks->get_default; +if ( defined $default_framework + && defined $frameworkcode + && $frameworkcode eq '' ){ + $frameworkcode = $default_framework->frameworkcode; +} $template->param( popup => $mode, frameworkcode => $frameworkcode, diff --git a/cataloguing/addbooks.pl b/cataloguing/addbooks.pl index 9f6fec7f05..396e1b5cf2 100755 --- a/cataloguing/addbooks.pl +++ b/cataloguing/addbooks.pl @@ -155,5 +155,10 @@ $template->param( z3950_search_params => C4::Search::z3950_search_args($query), ); +my $default_framework = Koha::BiblioFrameworks->get_default; +if ( $default_framework ){ + $template->param( default_frameworkcode => $default_framework->frameworkcode ); +} + output_html_with_http_headers $input, $cookie, $template->output; diff --git a/installer/data/mysql/atomicupdate/bug-23111_add-is_default-column-to-biblio_framework.perl b/installer/data/mysql/atomicupdate/bug-23111_add-is_default-column-to-biblio_framework.perl new file mode 100644 index 0000000000..73ccc57085 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug-23111_add-is_default-column-to-biblio_framework.perl @@ -0,0 +1,7 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + if( !column_exists( 'biblio_framework', 'default' ) ) { + $dbh->do(q{ALTER TABLE biblio_framework ADD is_default TINYINT(1) default 0 NOT NULL}); + } + NewVersion( $DBversion, 23111, "Add is_default column to biblio_framework table"); +} diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index af10ac5317..26ec8bb467 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -156,6 +156,7 @@ DROP TABLE IF EXISTS `biblio_framework`; CREATE TABLE `biblio_framework` ( -- information about MARC frameworks `frameworkcode` varchar(4) NOT NULL default '', -- the unique code assigned to the framework `frameworktext` varchar(255) NOT NULL default '', -- the description/name given to the framework + `is_default` TINYINT(1) NOT NULL default 0 -- indicates whether this framework is the default to be used when importing records or editing records with no framework mapped PRIMARY KEY (`frameworkcode`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/biblio_framework.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/biblio_framework.tt index 59ae3a6d07..1ddbdcfe3f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/biblio_framework.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/biblio_framework.tt @@ -87,6 +87,14 @@ Required +
  • + + [% IF framework.is_default %] + + [% ELSE %] + + [% END %] +
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt index 57fa62ba35..c24d046181 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt @@ -228,7 +228,11 @@ $("input[name=q]:eq(0)").focus(); $("#z3950search").click(function(){ - PopupZ3950("Default"); + [% IF default_frameworkcode %] + PopupZ3950('[% default_frameworkcode | html %]'); + [% ELSE %] + PopupZ3950("Default"); + [% END %] return false; }); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt index 0fde39f7a6..77019c2530 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt @@ -219,7 +219,11 @@ [% END %] @@ -591,4 +595,4 @@ [% END %] -[% END %] \ No newline at end of file +[% END %] diff --git a/t/db_dependent/Koha/BiblioFrameworks.t b/t/db_dependent/Koha/BiblioFrameworks.t index d2e31d9149..a5bc29b391 100644 --- a/t/db_dependent/Koha/BiblioFrameworks.t +++ b/t/db_dependent/Koha/BiblioFrameworks.t @@ -18,7 +18,7 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 3; +use Test::More tests => 7; use Koha::BiblioFramework; use Koha::BiblioFrameworks; @@ -40,6 +40,22 @@ is( Koha::BiblioFrameworks->search->count, $nb_of_frameworks + 2, 'The 2 biblio my $retrieved_framework_1 = Koha::BiblioFrameworks->find( $new_framework_1->frameworkcode ); is( $retrieved_framework_1->frameworktext, $new_framework_1->frameworktext, 'Find a biblio framework by frameworkcode should return the correct framework' ); +# testing of default frameworks +$new_framework_1->set_default; +my $default_framework = Koha::BiblioFrameworks->get_default; +is( $default_framework->frameworkcode, $new_framework_1->frameworkcode, 'Successfully identified default framework' ); + +$new_framework_2->set_default; +$default_framework = Koha::BiblioFrameworks->get_default; +is( $default_framework->frameworkcode, $new_framework_2->frameworkcode, 'Successfully changed default framework' ); +$new_framework_1 = Koha::BiblioFrameworks->find( $new_framework_1->frameworkcode ); +is( $new_framework_1->is_default, 0, 'Old default framework has been unset' ); + +$default_framework->unset_default; +my $nb_of_defaults = Koha::BiblioFrameworks->search({ is_default => 1 })->count; +is( $nb_of_defaults, 0, 'No default framework is set' ); +# end of default frameworks testing + $retrieved_framework_1->delete; is( Koha::BiblioFrameworks->search->count, $nb_of_frameworks + 1, 'Delete should have deleted the biblio framework' ); $schema->storage->txn_rollback; -- 2.11.0