Bugzilla – Attachment 155335 Details for
Bug 33960
Add ability to retrieve deleted bibliographic records
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33960: Add api mapping and biblioitems to Old::Biblios to match Biblio
Bug-33960-Add-api-mapping-and-biblioitems-to-OldBi.patch (text/plain), 4.94 KB, created by
Nick Clemens (kidclamp)
on 2023-09-07 16:28:07 UTC
(
hide
)
Description:
Bug 33960: Add api mapping and biblioitems to Old::Biblios to match Biblio
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2023-09-07 16:28:07 UTC
Size:
4.94 KB
patch
obsolete
>From b55591eb4a01c2a93b2902c90e8486f9765c220e Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Thu, 7 Sep 2023 16:27:07 +0000 >Subject: [PATCH] Bug 33960: Add api mapping and biblioitems to Old::Biblios to > match Biblio > >--- > Koha/Old/Biblio.pm | 56 +++++++++++++++++++++++++++++++++ > Koha/REST/V1/Biblios.pm | 10 ++++-- > t/db_dependent/api/v1/biblios.t | 20 ++++++------ > 3 files changed, 74 insertions(+), 12 deletions(-) > >diff --git a/Koha/Old/Biblio.pm b/Koha/Old/Biblio.pm >index 5c0e416619..ded3faabbc 100644 >--- a/Koha/Old/Biblio.pm >+++ b/Koha/Old/Biblio.pm >@@ -20,6 +20,7 @@ use Modern::Perl; > use base qw(Koha::Object); > > use Koha::Old::Biblio::Metadatas; >+use Koha::Old::Biblioitems; > > =head1 NAME > >@@ -74,6 +75,61 @@ sub record_schema { > return $self->metadata->schema // C4::Context->preference("marcflavour"); > } > >+=head3 biblioitem >+ >+my $field = $self->biblioitem >+ >+Returns the related Koha::Old::Biblioitem object for this Biblio object >+ >+=cut >+ >+sub biblioitem { >+ my ($self) = @_; >+ return Koha::Old::Biblioitems->find( { biblionumber => $self->biblionumber } ); >+} >+ >+=head3 to_api >+ >+ my $json = $deleted_biblio->to_api; >+ >+Overloaded method that returns a JSON representation of the Koha::Old::Biblio object, >+suitable for API output. The related Koha::Old::Biblioitem object is merged as expected >+on the API. >+ >+=cut >+ >+sub to_api { >+ my ($self, $args) = @_; >+ >+ my $response = $self->SUPER::to_api( $args ); >+ >+ $args = defined $args ? {%$args} : {}; >+ delete $args->{embed}; >+ >+ my $biblioitem = $self->biblioitem->to_api( $args ); >+ >+ return { %$response, %$biblioitem }; >+} >+ >+=head3 to_api_mapping >+ >+This method returns the mapping for representing a Koha::Old::Biblio object >+on the API. >+ >+=cut >+ >+sub to_api_mapping { >+ return { >+ biblionumber => 'biblio_id', >+ frameworkcode => 'framework_id', >+ unititle => 'uniform_title', >+ seriestitle => 'series_title', >+ copyrightdate => 'copyright_date', >+ datecreated => 'creation_date', >+ deleted_on => 'timestamp', >+ }; >+} >+ > > =head2 Internal methods > >diff --git a/Koha/REST/V1/Biblios.pm b/Koha/REST/V1/Biblios.pm >index 0f628d6ff5..5b7ae63c96 100644 >--- a/Koha/REST/V1/Biblios.pm >+++ b/Koha/REST/V1/Biblios.pm >@@ -806,8 +806,14 @@ sub list { > my $deleted = $c->param('deleted'); > $c->req->params->remove('deleted'); > >- my $rs = $deleted ? Koha::Old::Biblios->search() : Koha::Biblios->search( undef, { prefetch => \@prefetch } ); >- my $biblios = $c->objects->search_rs( $rs, [(sub{ $rs->api_query_fixer( $_[0], '', $_[1] ) })] ); >+ my $biblios; >+ if( $deleted ){ >+ my $rs = Koha::Old::Biblios->search(); >+ $biblios = $c->objects->search_rs( $rs ); >+ } else { >+ my $rs = Koha::Biblios->search( undef, { prefetch => \@prefetch } ); >+ $biblios = $c->objects->search_rs( $rs, [(sub{ $rs->api_query_fixer( $_[0], '', $_[1] ) })] ); >+ } > > return try { > >diff --git a/t/db_dependent/api/v1/biblios.t b/t/db_dependent/api/v1/biblios.t >index c5d7ff29f3..19c9401e68 100755 >--- a/t/db_dependent/api/v1/biblios.t >+++ b/t/db_dependent/api/v1/biblios.t >@@ -1700,27 +1700,27 @@ subtest 'list() tests' => sub { > DelBiblio( $biblio->id ); > DelBiblio( $biblio2->id ); > >- $t->get_ok( "//$userid:$password@/api/v1/biblios/?deleted=1" => >- { Accept => 'application/json', 'x-koha-query' => $search } ) >+ $t->get_ok( "//$userid:$password@/api/v1/biblios/?deleted=1&q=$query" => >+ { Accept => 'application/json' } ) > ->status_is(200); > >- $result = $t->get_ok( "//$userid:$password@/api/v1/biblios/?deleted=1" => >- { Accept => 'application/marcxml+xml', 'x-koha-query' => $search } ) >+ $result = $t->get_ok( "//$userid:$password@/api/v1/biblios/?deleted=1&q=$query" => >+ { Accept => 'application/marcxml+xml' } ) > ->status_is(200)->tx->res->body; > > $encoded_title = Encode::encode( "UTF-8", $title_with_diacritics ); > like( $result, qr/\Q$encoded_title/, "The title is not double encoded" ); > >- $t->get_ok( "//$userid:$password@/api/v1/biblios/?deleted=1" => >- { Accept => 'application/marc-in-json', 'x-koha-query' => $search } ) >+ $t->get_ok( "//$userid:$password@/api/v1/biblios/?deleted=1&q=$query" => >+ { Accept => 'application/marc-in-json' } ) > ->status_is(200); > >- $t->get_ok( "//$userid:$password@/api/v1/biblios/?deleted=1" => >- { Accept => 'application/marc', 'x-koha-query' => $search } ) >+ $t->get_ok( "//$userid:$password@/api/v1/biblios/?deleted=1&q=$query" => >+ { Accept => 'application/marc' } ) > ->status_is(200); > >- $t->get_ok( "//$userid:$password@/api/v1/biblios/?deleted=1" => >- { Accept => 'text/plain', 'x-koha-query' => $search } ) >+ $t->get_ok( "//$userid:$password@/api/v1/biblios/?deleted=1&q=$query" => >+ { Accept => 'text/plain' } ) > ->status_is(200); > > >-- >2.30.2
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 33960
:
152199
|
152200
|
152201
|
152215
|
155331
|
155332
|
155333
|
155334
|
155335
|
155416
|
155417
|
155418
|
155419
|
155420
|
157899
|
157900
|
157901
|
157902
|
157903
|
157904
|
158071
|
159998
|
159999
|
160000
|
160001
|
160002
|
160552
|
163852
|
163853
|
163854
|
163855
|
163948
|
163949
|
163950
|
163951