From 2d64ea748512eb003ab7482fc6c5ccbe659cda19 Mon Sep 17 00:00:00 2001 From: Thomas Klausner Date: Tue, 23 Jan 2024 17:09:22 +0100 Subject: [PATCH] Bug 35591: Prevent bulkmarcimport from replacing local auth_header MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If you run bulkmarcimport,pl on authorities with --update (or --all) it will overwrite a local auth_header if the auth_id of a local auth_header matches the control-number (field 001) of an imported MARC record. This patch adds a new option --guessauthid (which is still enabled by default to keep the script backwards compatible, but broken), which can turn off this behaviour if called as --noguessauthid. To test with koha-testing-docker: * Inspect cgi-bin/koha/authorities/detail.pl?authid=1402 which should be PERSO_NAME of Aristotles. * get the file twin_040682714.xml from Bugzilla and make it available inside of koha-testing-docker * run: misc/migration_tools/bulkmarcimport.pl -m MARCXML -c utf8 -a --file twin_040682714.xml --all --match isbn,001 * Check cgi-bin/koha/authorities/detail.pl?authid=1402, which now is a TOPIC_TERM "Zwilling" (twin...) Reset koha-testing-docker, apply the patch * run with the new flag misc/migration_tools/bulkmarcimport.pl -m MARCXML -c utf8 -a --file twin_040682714.xml --all --match isbn,001 --noguessauthid * cgi-bin/koha/authorities/detail.pl?authid=1402 still is "Aristotle" * "Zwilling" is cgi-bin/koha/authorities/detail.pl?authid=1708 (at least on my ktd, the actual id might vary) Sponsored-by: Steiermärkische Landesbibliothek Signed-off-by: Victor Grousset/tuxayo --- misc/migration_tools/bulkmarcimport.pl | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/misc/migration_tools/bulkmarcimport.pl b/misc/migration_tools/bulkmarcimport.pl index d2dfe1ad56..be650cfdfa 100755 --- a/misc/migration_tools/bulkmarcimport.pl +++ b/misc/migration_tools/bulkmarcimport.pl @@ -50,6 +50,7 @@ my $framework = ''; my $localcust; my $marc_mod_template = ''; my $marc_mod_template_id = -1; +my $guess_auth_id = 1; $|=1; @@ -87,6 +88,7 @@ GetOptions( 'framework=s' => \$framework, 'custom:s' => \$localcust, 'marcmodtemplate:s' => \$marc_mod_template, + 'guessauthid!' => \$guess_auth_id, ); $biblios ||= !$authorities; $insert ||= !$update; @@ -385,8 +387,11 @@ RECORD: while ( ) { } unless ($test_parameter) { if ($authorities){ - my $authtypecode=GuessAuthTypeCode($record, $heading_fields); - my $authid= ($id?$id:GuessAuthId($record)); + my $authtypecode = GuessAuthTypeCode($record, $heading_fields); + my $authid = $id; + if (!$authid && $guess_auth_id) { + $authid = GuessAuthId($record); + } if ($authid && GetAuthority($authid) && $update ){ ## Authority has an id and is in database : Replace eval { ( $authid ) = ModAuthority($authid,$record, $authtypecode) }; @@ -397,7 +402,7 @@ RECORD: while ( ) { else{ printlog({id=>$originalid||$id||$authid, op=>"edit",status=>"ok"}) if ($logfile); } - } + } else { ## True insert in database eval { ( $authid ) = AddAuthority($record,"", $authtypecode) }; @@ -823,6 +828,14 @@ modification template to apply as the MARC records are imported (these templates are created in the "MARC modification templates" tool in Koha). If not specified, no MARC modification templates are used (default). +=item B<--guessauthid> + +Keep the buggy behaviour to guess the auth-id based on control-number (001). +This might overwrite your local auth_headers if the imported auth_headers 001 +randomly matches the auth_id of one of your local auth_headers. See Bug#35591 + +Use --noguessauthid to prevent this buggy behaviour. + =back =cut -- 2.44.0