Bugzilla – Attachment 152439 Details for
Bug 33036
Add route to merge bibliographic records
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33036: REST API: Merge biblio records implements merging of records + attached items, subscriptions etc via the API as an alternative to the web interface: cgi-bin/koha/cataloguing/merge.pl
Bug-33036-REST-API-Merge-biblio-records-implements.patch (text/plain), 9.09 KB, created by
Mark Hofstetter
on 2023-06-16 16:52:15 UTC
(
hide
)
Description:
Bug 33036: REST API: Merge biblio records implements merging of records + attached items, subscriptions etc via the API as an alternative to the web interface: cgi-bin/koha/cataloguing/merge.pl
Filename:
MIME Type:
Creator:
Mark Hofstetter
Created:
2023-06-16 16:52:15 UTC
Size:
9.09 KB
patch
obsolete
>From 0675754ae4300604394d71ddd5b21ced69bfa567 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Fri, 9 Jun 2023 15:42:23 -0300 >Subject: [PATCH] Bug 33036: REST API: Merge biblio records implements merging > of records + attached items, subscriptions etc via the API as an alternative > to the web interface: cgi-bin/koha/cataloguing/merge.pl > >To Test: >1) you need an API user with the permissions "editcatalogue" >2) two records: one to be merged into (with biblio_id, eg 262) and another one from > which to merge (with biblio_id_to_merge, eg 9) which will be deleted! > both records may/should have items, subscription, subscriptionhistory, serial, suggestions > orders and holds >3) check both records via the web >4) Apply patch >5) execute API calls eg like > PUT /biblios/{biblio_id}/merge/{biblio_id_to_merge} > eg: > curl -s -u koha:koha -X PUT "http://127.0.0.1:8081/api/v1/biblios/262/merge/9" >6) the record with the id <biblio_id_to_merge> is deleted now, the record with <biblio_id> > has all items, etc attached, return code is 200, with the message {"message":"Successfuly merged 9 into 262"} >7) optionally a full MARCXML record may be sent as body of the API call > curl -s -u koha:koha -X PUT "http://127.0.0.1:8081/api/v1/biblios/262/merge/2" -d @marcfile.xml >8) now also the content of the record with <biblio_id> is replaced with the content of the MARCXML file >9) Sign off. >10) Thx > >Sponsored-by: Technische Hochschule Wildau >Co-authored-by: domm@plix.at >--- > Koha/REST/V1/Biblios.pm | 108 ++++++++++++++++++++++++ > Makefile.PL | 1 + > api/v1/swagger/paths/biblios_merge.yaml | 51 +++++++++++ > api/v1/swagger/swagger.yaml | 2 + > 4 files changed, 162 insertions(+) > create mode 100644 api/v1/swagger/paths/biblios_merge.yaml > >diff --git a/Koha/REST/V1/Biblios.pm b/Koha/REST/V1/Biblios.pm >index 6457d49d7a..d8a01a7be7 100644 >--- a/Koha/REST/V1/Biblios.pm >+++ b/Koha/REST/V1/Biblios.pm >@@ -25,6 +25,9 @@ use Koha::Ratings; > use Koha::RecordProcessor; > use C4::Biblio qw( DelBiblio AddBiblio ModBiblio ); > use C4::Search qw( FindDuplicate ); >+use C4::Serials qw( CountSubscriptionFromBiblionumber ); >+use C4::Reserves qw( MergeHolds ); >+use C4::Acquisition qw( ModOrder GetOrdersByBiblionumber ); > > use C4::Barcodes::ValueBuilder; > use C4::Context; >@@ -859,4 +862,109 @@ sub list { > }; > } > >+<<<<<<< HEAD >+<<<<<<< HEAD >+======= >+>>>>>>> 2f05489f09... cleanup to make qa script happy >+=head3 merge >+ >+Controller function that handles merging two biblios. If an optional >+MARCXML is provided as the request body, this MARCXML replaces the >+bibliodata of the merge target biblio. >+ >+=cut >+ >+sub merge { >+ my $c = shift->openapi->valid_input or return; >+ my $ref_biblionumber = $c->validation->param('biblio_id'); >+ my $bn_merge = $c->validation->param('biblio_id_to_merge'); >+ my $dbh = C4::Context->dbh; >+ >+ my $body = $c->req->body; >+ my $biblio = Koha::Biblios->find( $ref_biblionumber ); >+ if ( not defined $biblio ) { >+ return $c->render( >+ status => 404, >+ json => { error => sprintf("[%s] biblio to merge into not found", $ref_biblionumber) } >+ ); >+ } >+ >+ my $from_biblio = Koha::Biblios->find( $bn_merge ); >+ if ( not defined $from_biblio ) { >+ return $c->render( >+ status => 404, >+ # openapi => { error => sprintf("[%s] biblio to merge from not found", $bn_merge) } >+ json => { error => sprintf("[%s] biblio to merge from not found", $bn_merge) } >+ ); >+ } >+ >+ return try { >+ if ($body) { >+ my $record = MARC::Record->new_from_xml($body, 'UTF-8', 'MARC21'); >+ $record->leader($biblio->metadata->record->leader()); >+<<<<<<< HEAD >+<<<<<<< HEAD >+ ModBiblio($record, $ref_biblionumber, $biblio->frameworkcode); >+======= >+ ModBiblio($record, $ref_biblionumber, $biblio->frameworkcode); >+>>>>>>> 5e0fa69e16... implement API for biblio merge >+======= >+ ModBiblio($record, $ref_biblionumber, $biblio->frameworkcode); >+>>>>>>> 2f05489f09... cleanup to make qa script happy >+ } >+ >+ $from_biblio->items->move_to_biblio($biblio); >+ $from_biblio->article_requests->update({ biblionumber => $ref_biblionumber }, { no_triggers => 1 }); >+ >+ my $sth_subscription = $dbh->prepare(" >+ UPDATE subscription SET biblionumber = ? WHERE biblionumber = ? >+ "); >+ >+ my $sth_subscriptionhistory = $dbh->prepare(" >+ UPDATE subscriptionhistory SET biblionumber = ? WHERE biblionumber = ? >+ "); >+ my $sth_serial = $dbh->prepare(" >+ UPDATE serial SET biblionumber = ? WHERE biblionumber = ? >+ "); >+ my $sth_suggestions = $dbh->prepare(" >+ UPDATE suggestions SET biblionumber = ? WHERE biblionumber = ? >+ "); >+ >+ # Moving subscriptions from the other record to the reference record >+ my $subcount = CountSubscriptionFromBiblionumber($bn_merge); >+ if ($subcount > 0) { >+ $sth_subscription->execute($ref_biblionumber, $bn_merge); >+ $sth_subscriptionhistory->execute($ref_biblionumber, $bn_merge); >+ } >+ >+ # Moving serials >+ $sth_serial->execute($ref_biblionumber, $bn_merge); >+ >+ # Moving suggestions >+ $sth_suggestions->execute($ref_biblionumber, $bn_merge); >+ >+ # Moving orders (orders linked to items of frombiblio have already been moved by move_to_biblio) >+ my @allorders = GetOrdersByBiblionumber($bn_merge); >+ foreach my $myorder (@allorders) { >+ $myorder->{'biblionumber'} = $ref_biblionumber; >+ ModOrder ($myorder); >+ # TODO : add error control (in ModOrder?) >+ } >+ >+ # Deleting the other records >+ # Move holds >+ MergeHolds($dbh, $ref_biblionumber, $bn_merge); >+ my $error = DelBiblio($bn_merge); >+ if ($error) { >+ $c->render( status => 400, json => {error => $error}); >+ } >+ >+ return $c->render( status => 200, openapi => { message => sprintf("Successfully merged %s into %s", >+ $bn_merge, $ref_biblionumber) >+ }); >+ } catch { >+ $c->render( status => 400, json => {error => $_}); >+ }; >+} >+ > 1; >diff --git a/Makefile.PL b/Makefile.PL >index 2acf916bd3..93e9f0c385 100644 >--- a/Makefile.PL >+++ b/Makefile.PL >@@ -351,6 +351,7 @@ my $target_map = { > './README.txt' => 'NONE', > './patroncards' => 'INTRANET_CGI_DIR', > './patron_lists' => 'INTRANET_CGI_DIR', >+ './perltidyrc' => 'NONE', > './plugins' => 'INTRANET_CGI_DIR', > './pos' => 'INTRANET_CGI_DIR', > './recalls' => 'INTRANET_CGI_DIR', >diff --git a/api/v1/swagger/paths/biblios_merge.yaml b/api/v1/swagger/paths/biblios_merge.yaml >new file mode 100644 >index 0000000000..4714be1532 >--- /dev/null >+++ b/api/v1/swagger/paths/biblios_merge.yaml >@@ -0,0 +1,51 @@ >+--- >+"/biblios/{biblio_id}/merge/{biblio_id_to_merge}": >+ put: >+ x-mojo-to: Biblios#merge >+ operationId: mergeBiblios >+ tags: >+ - merge_biblios >+ summary: Merge Biblios >+ parameters: >+ - name: biblio_id >+ in: path >+ description: Bilblionumber to be merged into >+ required: true >+ type: string >+ - name: biblio_id_to_merge >+ in: path >+ required: true >+ description: Biblionumber from which to merge >+ type: string >+ - name: body >+ in: body >+ description: MARCXML for final record >+ required: false >+ schema: >+ type: object >+ responses: >+ '200': >+ description: Result message >+ '404': >+ description: Biblio not found >+ schema: >+ "$ref": "../swagger.yaml#/definitions/error" >+ '401': >+ description: Authentication required >+ schema: >+ "$ref": "../swagger.yaml#/definitions/error" >+ '403': >+ description: Access forbidden >+ schema: >+ "$ref": "../swagger.yaml#/definitions/error" >+ '500': >+ description: Internal server error >+ schema: >+ "$ref": "../swagger.yaml#/definitions/error" >+ '503': >+ description: Under maintenance >+ schema: >+ "$ref": "../swagger.yaml#/definitions/error" >+ x-koha-authorization: >+ permissions: >+ catalogue: "editcatalogue" >diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml >index 9e60aa77a2..d32fc45551 100644 >--- a/api/v1/swagger/swagger.yaml >+++ b/api/v1/swagger/swagger.yaml >@@ -183,6 +183,8 @@ paths: > $ref: "./paths/biblios_item_groups.yaml#/~1biblios~1{biblio_id}~1item_groups~1{item_group_id}~1items" > "/biblios/{biblio_id}/item_groups/{item_group_id}/items/{item_id}": > $ref: "./paths/biblios_item_groups.yaml#/~1biblios~1{biblio_id}~1item_groups~1{item_group_id}~1items~1{item_id}" >+ "/biblios/{biblio_id}/merge/{biblio_id_to_merge}": >+ $ref: "./paths/biblios_merge.yaml#/~1biblios~1{biblio_id}~1merge~1{biblio_id_to_merge}" > "/cash_registers/{cash_register_id}/cashups": > $ref: "./paths/cash_registers.yaml#/~1cash_registers~1{cash_register_id}~1cashups" > "/cashups/{cashup_id}": >-- >2.20.1
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 33036
:
152436
|
152437
|
152438
|
152439
|
152440
|
152447
|
152472
|
152659
|
152678
|
157481
|
157482
|
157731
|
159011
|
159012
|
159103
|
159120
|
159191
|
159239
|
159826
|
159827
|
159828
|
159829
|
160302
|
160468
|
160469
|
160470
|
160471
|
160472