From e7a062c3aadd05edef79b13e6904c93dcdf775d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9rick?= Date: Wed, 27 Nov 2013 12:30:55 -0500 Subject: [PATCH] Bug 11315 : Add the overwriteSubfieldsOnMerge preference. If it is activated, all of the biblio's subfields will be overwritten when doing an authority merge. This means that subfields that exist in the biblio, but not in the authority will be deleted in the biblio when doing the merge. Sponsored-by: CCSR ( http://www.ccsr.qc.ca ) Test plan : Preparation : * Set dontmerge system preference to "Do automatically update attached biblios..." * Create a test authority. For example, lets create a PERSON authority with this value : 100$a : "Bruce Wayne" * Rebuild the Zebra authority index. (rebuild_zebra.pl -a) * Create a new biblio record and link it to the newly created authority by clicking the icon right of the 600$a field and searching for the "Bruce Wayne" authority. * Add the "2014" value in the 600$d field of the biblio record before saving the biblio record. This is the value we will use to check the behavior of the new system preference. * Rebuild the Zebra biblio index. (rebuild_zebra.pl -b) Test 1 : * Set the "overwriteSubfieldsOnMerge" system preference to "Don't overwrite". * Edit the "Bruce Wayne" authority, change 100$a value to "Batman". * Save the authority and go check the test biblio record. The 600$a field should now be "Batman", and the 600$d should still be "2014". Test 2 : * Set the "overwriteSubfieldsOnMerge" system preference to "Overwrite". * Edit the "Batman" authority, change the 100$a value back to "Bruce Wayne". * Save the authority and go check the test biblio record. The 600$a field should now be "Bruce Wayne", and the 600$d should now be empty. The additional subfield was overwritten this time. Signed-off-by: Chris Cormack --- C4/AuthoritiesMarc.pm | 24 +++++++++++++--------- ...FIELD_DELETION_WHEN_DOING_AUTHORITY_MERGES.perl | 6 ++++++ installer/data/mysql/sysprefs.sql | 1 + .../en/modules/admin/preferences/authorities.pref | 7 +++++++ 4 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/BZ11315_ADD_SUPPORT_FOR_SUBFIELD_DELETION_WHEN_DOING_AUTHORITY_MERGES.perl diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index e14c85f..9a4907b 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -1399,7 +1399,7 @@ sub AddAuthorityTrees{ =head2 merge - $ref= &merge(mergefrom,$MARCfrom,$mergeto,$MARCto) + $ref= &merge(mergefrom,$MARCfrom,$mergeto,$MARCto,$overwrite) Could add some feature : Migrating from a typecode to an other for instance. Then we should add some new parameter : bibliotargettag, authtargettag @@ -1407,7 +1407,8 @@ Then we should add some new parameter : bibliotargettag, authtargettag =cut sub merge { - my ($mergefrom,$MARCfrom,$mergeto,$MARCto) = @_; + my ($mergefrom,$MARCfrom,$mergeto,$MARCto,$overwrite) = @_; + $overwrite = C4::Context->preference('overwriteSubfieldsOnMerge') unless defined $overwrite; my ($counteditedbiblio,$countunmodifiedbiblio,$counterrors)=(0,0,0); my $dbh=C4::Context->dbh; my $authfrom = Koha::Authorities->find($mergefrom); @@ -1483,17 +1484,20 @@ sub merge { my $tag=$field->tag(); if ($auth_number==$mergefrom) { my $field_to=MARC::Field->new(($tag_to?$tag_to:$tag),$field->indicator(1),$field->indicator(2),"9"=>$mergeto); - my $exclude='9'; + my $exclude='9'; foreach my $subfield (grep {$_->[0] ne '9'} @record_to) { $field_to->add_subfields($subfield->[0] =>$subfield->[1]); - $exclude.= $subfield->[0]; + $exclude.= $subfield->[0]; } - $exclude='['.$exclude.']'; -# add subfields in $field not included in @record_to - my @restore= grep {$_->[0]!~/$exclude/} $field->subfields(); - foreach my $subfield (@restore) { - $field_to->add_subfields($subfield->[0] =>$subfield->[1]); - } + $exclude='['.$exclude.']'; + unless($overwrite) { + # add subfields in $field not included in @record_to + my @restore= grep {$_->[0]!~/$exclude/} $field->subfields(); + foreach my $subfield (@restore) { + $field_to->add_subfields($subfield->[0] =>$subfield->[1]); + } + } + $marcrecord->delete_field($field); $marcrecord->insert_grouped_field($field_to); $update=1; diff --git a/installer/data/mysql/atomicupdate/BZ11315_ADD_SUPPORT_FOR_SUBFIELD_DELETION_WHEN_DOING_AUTHORITY_MERGES.perl b/installer/data/mysql/atomicupdate/BZ11315_ADD_SUPPORT_FOR_SUBFIELD_DELETION_WHEN_DOING_AUTHORITY_MERGES.perl new file mode 100644 index 0000000..c87750d --- /dev/null +++ b/installer/data/mysql/atomicupdate/BZ11315_ADD_SUPPORT_FOR_SUBFIELD_DELETION_WHEN_DOING_AUTHORITY_MERGES.perl @@ -0,0 +1,6 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES('overwriteSubfieldsOnMerge','0',NULL,'Overwrite the biblio\\'s subfields when merging an authority record with a biblio record.','YesNo')"); + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 11315 - Add the overwriteSubfieldsOnMerge preference)\n"; +} diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index ef83c3d..423eb7e 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -389,6 +389,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('OverdueNoticeCalendar',0,NULL,'Take the calendar into consideration when generating overdue notices','YesNo'), ('OverduesBlockCirc','noblock','noblock|confirmation|block','When checking out an item should overdues block checkout, generate a confirmation dialogue, or allow checkout','Choice'), ('OverduesBlockRenewing','allow','allow|blockitem|block','If any of patron checked out documents is late, should renewal be allowed, blocked only on overdue items or blocked on whatever checked out document','Choice'), +('overwriteSubfieldsOnMerge','0',NULL,'Overwrite the biblio\'s subfields when merging an authority record with a biblio record.','YesNo'), ('patronimages','0',NULL,'Enable patron images for the Staff Client','YesNo'), ('PatronSelfModificationBorrowerUnwantedField','',NULL,'Name the fields you don\'t want to display when a patron is editing their information via the OPAC.','free'), ('PatronSelfRegistration','0',NULL,'If enabled, patrons will be able to register themselves via the OPAC.','YesNo'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/authorities.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/authorities.pref index 2762411..7913240 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/authorities.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/authorities.pref @@ -44,6 +44,13 @@ Authorities: no: "Don't use" - authority record numbers instead of text strings for searches from subject tracings. - + - pref: overwriteSubfieldsOnMerge + default: no + choices: + yes: Overwrite + no: "Don't overwrite" + - "the biblio's subfields when merging an authority record with a biblio record." + - - Use the following text for the contents of UNIMARC authority field 100 position 08-35 (fixed length data elements). Do NOT include the date (position 00-07). - pref: UNIMARCAuthorityField100 defautl: "afrey50 ba0" -- 1.9.1