From e23f252d0b15d8a9de2c26c88927c49faa43be75 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 Signed-off-by: Bernardo Gonzalez Kriegel Signed-off-by: David Nind --- Koha/BiblioFramework.pm | 36 +++++++++++++++++++ Koha/BiblioFrameworks.pm | 15 ++++++++ admin/biblio_framework.pl | 3 ++ cataloguing/addbiblio.pl | 7 ++++ cataloguing/addbooks.pl | 5 +++ ...d-is_default-column-to-biblio_framework.pl | 17 +++++++++ installer/data/mysql/kohastructure.sql | 1 + .../prog/en/modules/admin/biblio_framework.tt | 8 +++++ .../prog/en/modules/cataloguing/addbooks.tt | 6 +++- .../en/modules/tools/manage-marc-import.tt | 6 +++- t/db_dependent/Koha/BiblioFrameworks.t | 18 +++++++++- 11 files changed, 119 insertions(+), 3 deletions(-) create mode 100755 installer/data/mysql/atomicupdate/bug-23111_add-is_default-column-to-biblio_framework.pl diff --git a/Koha/BiblioFramework.pm b/Koha/BiblioFramework.pm index 30367570ba0..a934f3ed5a8 100644 --- a/Koha/BiblioFramework.pm +++ b/Koha/BiblioFramework.pm @@ -32,6 +32,42 @@ 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 7202d2fec5f..9df66280376 100644 --- a/Koha/BiblioFrameworks.pm +++ b/Koha/BiblioFrameworks.pm @@ -34,6 +34,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 d8988e0ecd1..212eb3da5e4 100755 --- a/admin/biblio_framework.pl +++ b/admin/biblio_framework.pl @@ -52,11 +52,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' }; @@ -69,6 +71,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 a11711afd32..2bf820818f6 100755 --- a/cataloguing/addbiblio.pl +++ b/cataloguing/addbiblio.pl @@ -807,6 +807,13 @@ 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 2206c5e143b..26d3f6b350f 100755 --- a/cataloguing/addbooks.pl +++ b/cataloguing/addbooks.pl @@ -135,5 +135,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.pl b/installer/data/mysql/atomicupdate/bug-23111_add-is_default-column-to-biblio_framework.pl new file mode 100755 index 00000000000..1c74acc7b13 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug-23111_add-is_default-column-to-biblio_framework.pl @@ -0,0 +1,17 @@ +use Modern::Perl; + +return { + bug_number => "23111", + description => "Add is_default column to biblio_framework table", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + if ( !column_exists( 'biblio_framework', 'is_default' ) ) { + $dbh->do( + q{ ALTER TABLE biblio_framework ADD is_default TINYINT(1) DEFAULT 0 NOT NULL AFTER `frameworktext` }); + + say $out "Added column 'biblio_framework.is_default'"; + } + }, +}; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index ae30fd34784..794ee7ab1c5 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1117,6 +1117,7 @@ DROP TABLE IF EXISTS `biblio_framework`; CREATE TABLE `biblio_framework` ( `frameworkcode` varchar(4) NOT NULL DEFAULT '' COMMENT 'the unique code assigned to the framework', `frameworktext` varchar(255) NOT NULL DEFAULT '' COMMENT 'the description/name given to the framework', + `is_default` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '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; /*!40101 SET character_set_client = @saved_cs_client */; 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 540988a26d6..b2b13a9e32f 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 @@ -135,6 +135,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 1c68a871ac8..1d70a769703 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt @@ -290,7 +290,11 @@ }); $("#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 e11c2611a1a..496ff398a94 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 @@ -265,7 +265,11 @@
    New bibliographic records will use this framework
    diff --git a/t/db_dependent/Koha/BiblioFrameworks.t b/t/db_dependent/Koha/BiblioFrameworks.t index d2e31d91496..a5bc29b391b 100755 --- 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.30.2