Bugzilla – Attachment 163329 Details for
Bug 29392
Add plugin hooks before merging biblios or authorities
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29392: Add plugin hooks before merging biblios or authorities
Bug-29392-Add-plugin-hooks-before-merging-biblios-.patch (text/plain), 5.10 KB, created by
Martin Renvoize (ashimema)
on 2024-03-18 13:47:40 UTC
(
hide
)
Description:
Bug 29392: Add plugin hooks before merging biblios or authorities
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2024-03-18 13:47:40 UTC
Size:
5.10 KB
patch
obsolete
>From 159c215ca52979d9202d0b3c2e3199a5d32b57c0 Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Tue, 2 Nov 2021 14:36:49 +0100 >Subject: [PATCH] Bug 29392: Add plugin hooks before merging biblios or > authorities > >Hooks are called 'before_biblio_action' and 'before_authority_action' >and they both take an 'action' parameter whose value is 'merge'. >Other parameters include the record id (biblionumber or authid), the >object itself (Koha::Biblio or Koha::Authority), the MARC::Record about >to be saved (so plugins can modify it), and the list of record ids that >will be deleted after the merge. > >Test plan: >1. Create a plugin with these two methods. For instance: > > sub before_biblio_action { > my ($self, $args) = @_; > > my $action = $args->{action}; > return unless $action eq 'merge'; > > my $record = $args->{record}; > my $merged_biblio_ids = $args->{merged_biblio_ids}; > if ($record && $merged_biblio_ids) { > my @fields = map { > MARC::Field->new('035', ' ', ' ', 'z' => $_) > } @$merged_biblio_ids; > $record->insert_fields_ordered(@fields); > } > } > > sub before_authority_action { > my ($self, $args) = @_; > > my $action = $args->{action}; > return unless $action eq 'merge'; > > my $record = $args->{record}; > my $merged_authority_ids = $args->{merged_authority_ids}; > if ($record && $merged_authority_ids) { > my @fields = map { > MARC::Field->new('035', ' ', ' ', 'z' => $_) > } @$merged_authority_ids; > $record->insert_fields_ordered(@fields); > } > } > > This will copy the identifier of deleted records inside 035$z of the > final record. > (035$z is for "Canceled/invalid system control number") > >2. Add the plugin path to your $KOHA_CONF >3. Run misc/devel/install_plugins.pl. It should say: > Installed <YOUR_PLUGIN_NAME> version <YOUR_PLUGIN_VERSION> >4. Apply patch and restart starman >5. Create two or more biblios with the same title. Make sure they are > indexed in your search engine. >6. Search for them. In the results check their corresponding boxes and > click on "Edit -> Merge records" >7. Merge them and verify that your plugin code was called. If you used > the example above, verify that it added a 035$z for each deleted > record. >8. Do the same for authorities > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > authorities/merge.pl | 14 ++++++++++++++ > cataloguing/merge.pl | 15 ++++++++++++++- > 2 files changed, 28 insertions(+), 1 deletion(-) > >diff --git a/authorities/merge.pl b/authorities/merge.pl >index 2c82340468e..aeaed31649f 100755 >--- a/authorities/merge.pl >+++ b/authorities/merge.pl >@@ -24,9 +24,11 @@ use C4::Auth qw( get_template_and_user ); > use C4::AuthoritiesMarc qw( GetAuthority ModAuthority DelAuthority GetTagsLabels merge ); > use C4::Biblio qw( TransformHtmlToMarc ); > >+use Koha::Authorities; > use Koha::Authority::MergeRequests; > use Koha::Authority::Types; > use Koha::MetadataRecord::Authority; >+use Koha::Plugins; > > my $input = CGI->new; > my @authid = $input->multi_param('authid'); >@@ -73,6 +75,18 @@ if ($op eq 'cud-merge') { > $record->leader( $authrec->leader() ); > } > >+ my $authority = Koha::Authorities->find($recordid1); >+ Koha::Plugins->call( >+ 'before_authority_action', >+ { >+ action => 'merge', >+ authority => $authority, >+ authority_id => $recordid1, >+ record => $record, >+ merged_authority_ids => [$recordid2], >+ } >+ ); >+ > # Modifying the reference record > # This triggers a merge for the biblios attached to $recordid1 > ModAuthority( $recordid1, $record, $typecode ); >diff --git a/cataloguing/merge.pl b/cataloguing/merge.pl >index 9fe7bc4f8b0..a872368e79a 100755 >--- a/cataloguing/merge.pl >+++ b/cataloguing/merge.pl >@@ -40,6 +40,7 @@ use Koha::BiblioFrameworks; > use Koha::Biblios; > use Koha::Items; > use Koha::MetadataRecord; >+use Koha::Plugins; > > my $input = CGI->new; > my ( $template, $loggedinuser, $cookie ) = get_template_and_user( >@@ -67,6 +68,18 @@ if ($op eq 'cud-merge') { > my $ref_biblionumber = $input->param('ref_biblionumber'); > @biblionumbers = grep { $_ != $ref_biblionumber } @biblionumbers; > >+ my $biblio = Koha::Biblios->find($ref_biblionumber); >+ Koha::Plugins->call( >+ 'before_biblio_action', >+ { >+ action => 'merge', >+ biblio => $biblio, >+ biblio_id => $ref_biblionumber, >+ record => $record, >+ merged_biblio_ids => \@biblionumbers >+ } >+ ); >+ > # prepare report > my @report_records; > my $report_fields_str = $input->param('report_fields'); >@@ -83,7 +96,7 @@ if ($op eq 'cud-merge') { > } > > # Rewriting the leader >- my $biblio = Koha::Biblios->find($ref_biblionumber); >+ $biblio = Koha::Biblios->find($ref_biblionumber); > $record->leader($biblio->metadata->record->leader()); > #Take new framework code > my $frameworkcode = $input->param('frameworkcode'); >-- >2.44.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 29392
:
127217
| 163329 |
163330