From 7fa312965b5bae0d327d7c7cad626908e0fa5538 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 --- Koha/BiblioFramework.pm | 35 ++++++++++++++++++++++ Koha/BiblioFrameworks.pm | 15 ++++++++++ admin/biblio_framework.pl | 3 ++ cataloguing/addbiblio.pl | 6 ++++ cataloguing/addbooks.pl | 5 ++++ ...11_add-is_default-column-to-biblio_framework.pl | 16 ++++++++++ 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 | 6 +++- t/db_dependent/Koha/BiblioFrameworks.t | 18 ++++++++++- 11 files changed, 116 insertions(+), 3 deletions(-) create mode 100644 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..8d8e4512064 100644 --- a/Koha/BiblioFramework.pm +++ b/Koha/BiblioFramework.pm @@ -32,6 +32,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 7202d2fec5f..e448850370e 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 4712f0ea728..16d49fb9f10 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 92abe81082c..7a6eb592826 100755 --- a/cataloguing/addbiblio.pl +++ b/cataloguing/addbiblio.pl @@ -1008,6 +1008,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 2206c5e143b..af13a64bf8d 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 100644 index 00000000000..ec7d24145b3 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug-23111_add-is_default-column-to-biblio_framework.pl @@ -0,0 +1,16 @@ +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` + }); + } + }, +}; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 3f524aec6a9..dfe2a14b06a 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1032,6 +1032,7 @@ DROP TABLE IF EXISTS `biblio_framework`; CREATE TABLE `biblio_framework` ( `frameworkcode` varchar(4) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'the unique code assigned to the framework', `frameworktext` varchar(255) COLLATE utf8mb4_unicode_ci 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 6162ebbd070..bb928f9bd53 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 @@ -126,6 +126,14 @@ MARC frameworks › Administration › Koha 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 126e49e5249..f7625070e89 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbooks.tt @@ -283,7 +283,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 7cac2154136..8407f7fda4b 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 @@ -247,7 +247,11 @@ [% END %] 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.11.0