Bugzilla – Attachment 175844 Details for
Bug 38745
Add a proof of concept JSON-RPC driven endpoint for RPC style calls that don't fit REST ideals
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 38745: Start adding a populate_empty_callnumbers RPC method
Bug-38745-Start-adding-a-populateemptycallnumbers-.patch (text/plain), 3.36 KB, created by
Martin Renvoize (ashimema)
on 2024-12-20 13:44:43 UTC
(
hide
)
Description:
Bug 38745: Start adding a populate_empty_callnumbers RPC method
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2024-12-20 13:44:43 UTC
Size:
3.36 KB
patch
obsolete
>From be887b367a767eb3f60ad997a37bc1526ec33cfd Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Fri, 20 Dec 2024 13:20:01 +0000 >Subject: [PATCH] Bug 38745: Start adding a populate_empty_callnumbers RPC > method > >This patch takes the populate_empty_callnumbers method as proposed on >bug 38226 and modifies it for json-rpc expectations. >--- > Koha/REST/V1/Biblios.pm | 90 ++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 89 insertions(+), 1 deletion(-) > >diff --git a/Koha/REST/V1/Biblios.pm b/Koha/REST/V1/Biblios.pm >index 035d215c52f..30cd8c7caea 100644 >--- a/Koha/REST/V1/Biblios.pm >+++ b/Koha/REST/V1/Biblios.pm >@@ -39,7 +39,7 @@ use JSON qw( decode_json ); > > =head1 API > >-=head2 Methods >+=head2 REST Methods > > =head3 get > >@@ -918,4 +918,92 @@ sub merge { > }; > } > >+=head2 RPC Methods >+ >+=head3 populate_empty_callnumbers >+ >+Controller function that handles populating empty callnumbers in bulk >+ >+=cut >+ >+sub populate_empty_callnumbers { >+ my ( $c, $params ) = @_; >+ >+ my $biblio = Koha::Biblios->find( $params->{'biblio_id'} ); >+ >+ return $c->render_resource_not_found("Bibliographic record") >+ unless $biblio; >+ >+ my $items = $biblio->items->search( >+ { >+ -or => [ >+ itemcallnumber => undef, >+ itemcallnumber => q{}, >+ ] >+ } >+ ); >+ >+ $items = $items->search( { itemnumber => $c->param('item_id') } ) >+ if $c->param('item_id'); >+ >+ return try { >+ >+ my $cn_fields = C4::Context->preference('itemcallnumber'); >+ return $c->render( >+ status => 409, >+ openapi => { >+ error => "Callnumber fields not found", >+ error_code => 'missing_configuration', >+ } >+ ) unless $cn_fields; >+ >+ my $record = $biblio->record; >+ my $callnumber; >+ >+ foreach my $callnumber_marc_field ( split( /,/, $cn_fields ) ) { >+ my $callnumber_tag = substr( $callnumber_marc_field, 0, 3 ); >+ my $callnumber_subfields = substr( $callnumber_marc_field, 3 ); >+ >+ next unless $callnumber_tag && $callnumber_subfields; >+ >+ my $field = $record->field($callnumber_tag); >+ >+ next unless $field; >+ >+ $callnumber = $field->as_string( $callnumber_subfields, '' ); >+ last if $callnumber; >+ } >+ >+ return $c->render( >+ status => 409, >+ openapi => { >+ error => "Callnumber empty in bibliographic record", >+ error_code => 'callnumber_empty', >+ } >+ ) unless $callnumber; >+ >+ return $c->render( >+ status => 200, >+ openapi => { >+ updated_items_count => 0, >+ callnumber => $callnumber >+ }, >+ ) unless $items->count; >+ >+ my ($res) = $items->batch_update( { new_values => { itemcallnumber => $callnumber } } ); >+ my @modified_itemnumbers = @{ $res->{modified_itemnumbers} }; >+ >+ return $c->render( >+ status => 200, >+ openapi => { >+ updated_items_count => scalar @modified_itemnumbers, >+ callnumber => $callnumber, >+ modified_item_ids => \@modified_itemnumbers, >+ }, >+ ); >+ } catch { >+ $c->unhandled_exception($_); >+ }; >+} >+ > 1; >-- >2.47.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 38745
:
175843
| 175844