Bugzilla – Attachment 160552 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: Tidy
Bug-33960-Tidy.patch (text/plain), 16.39 KB, created by
Nick Clemens (kidclamp)
on 2024-01-04 19:00:11 UTC
(
hide
)
Description:
Bug 33960: Tidy
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2024-01-04 19:00:11 UTC
Size:
16.39 KB
patch
obsolete
>From 061e9b3e9e92a2ec0d7180f53482e67ca28f301e Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Tue, 19 Dec 2023 13:46:11 +0000 >Subject: [PATCH] Bug 33960: Tidy > >--- > Koha/Old/Biblios.pm | 2 +- > Koha/REST/V1/DeletedBiblios.pm | 44 ++++----- > Koha/Schema/Result/Deletedbiblio.pm | 17 ++-- > t/db_dependent/api/v1/deleted_biblios.t | 114 +++++++++++------------- > 4 files changed, 76 insertions(+), 101 deletions(-) > >diff --git a/Koha/Old/Biblios.pm b/Koha/Old/Biblios.pm >index 20341677c8f..ce7d12ad68e 100644 >--- a/Koha/Old/Biblios.pm >+++ b/Koha/Old/Biblios.pm >@@ -54,7 +54,7 @@ sub api_query_fixer { > } else { > $query =~ > s/${quotes}(age_restriction|cn_class|cn_item|cn_sort|cn_source|cn_suffix|collection_issn|collection_title|collection_volume|ean|edition_statement|illustrations|isbn|issn|item_type|lc_control_number|notes|number|pages|publication_place|publication_year|publisher|material_size|serial_total_issues|url|volume|volume_date|volume_description)${quotes}/${quotes}deletedbiblioitem\.$1${quotes}/g; >- $query =~ # handle ambiguous 'biblionumber' >+ $query =~ # handle ambiguous 'biblionumber' > s/${quotes}(biblio_id)${quotes}/${quotes}me\.$1${quotes}/g; > } > >diff --git a/Koha/REST/V1/DeletedBiblios.pm b/Koha/REST/V1/DeletedBiblios.pm >index 21e6dd1f3f6..c165b6d84b3 100644 >--- a/Koha/REST/V1/DeletedBiblios.pm >+++ b/Koha/REST/V1/DeletedBiblios.pm >@@ -46,17 +46,15 @@ sub get { > my $c = shift->openapi->valid_input or return; > > my $attributes; >- $attributes = { prefetch => [ 'metadata' ] } # don't prefetch metadata if not needed >+ $attributes = { prefetch => ['metadata'] } # don't prefetch metadata if not needed > unless $c->req->headers->accept =~ m/application\/json/; > > my $biblio = Koha::Old::Biblios->find( { biblionumber => $c->param('biblio_id') }, $attributes ); > >- unless ( $biblio ) { >+ unless ($biblio) { > return $c->render( > status => 404, >- openapi => { >- error => "Object not found." >- } >+ openapi => { error => "Object not found." } > ); > } > >@@ -67,8 +65,7 @@ sub get { > status => 200, > json => $biblio->to_api > ); >- } >- else { >+ } else { > my $metadata = $biblio->metadata; > my $record = $metadata->record; > my $schema = $metadata->schema // C4::Context->preference("marcflavour"); >@@ -106,8 +103,7 @@ sub get { > } > ); > } >- } >- catch { >+ } catch { > $c->unhandled_exception($_); > }; > } >@@ -123,51 +119,42 @@ sub list { > > my @prefetch = qw(biblioitem); > push @prefetch, 'metadata' # don't prefetch metadata if not needed >- unless $c->req->headers->accept =~ m/application\/json/; >+ unless $c->req->headers->accept =~ m/application\/json/; > >- my $rs = Koha::Old::Biblios->search( undef, { prefetch => \@prefetch }); >- my $biblios = $c->objects->search_rs( $rs, [(sub{ $rs->api_query_fixer( $_[0], '', $_[1] ) })] ); >+ my $rs = Koha::Old::Biblios->search( undef, { prefetch => \@prefetch } ); >+ my $biblios = $c->objects->search_rs( $rs, [ ( sub { $rs->api_query_fixer( $_[0], '', $_[1] ) } ) ] ); > > return try { > > if ( $c->req->headers->accept =~ m/application\/json(;.*)?$/ ) { > return $c->render( > status => 200, >- json => $c->objects->to_api( $biblios ), >+ json => $c->objects->to_api($biblios), > ); >- } >- elsif ( >- $c->req->headers->accept =~ m/application\/marcxml\+xml(;.*)?$/ ) >- { >+ } elsif ( $c->req->headers->accept =~ m/application\/marcxml\+xml(;.*)?$/ ) { > $c->res->headers->add( 'Content-Type', 'application/marcxml+xml' ); > return $c->render( > status => 200, > text => $biblios->print_collection('marcxml') > ); >- } >- elsif ( >- $c->req->headers->accept =~ m/application\/marc-in-json(;.*)?$/ ) >- { >+ } elsif ( $c->req->headers->accept =~ m/application\/marc-in-json(;.*)?$/ ) { > $c->res->headers->add( 'Content-Type', 'application/marc-in-json' ); > return $c->render( > status => 200, > data => $biblios->print_collection('mij') > ); >- } >- elsif ( $c->req->headers->accept =~ m/application\/marc(;.*)?$/ ) { >+ } elsif ( $c->req->headers->accept =~ m/application\/marc(;.*)?$/ ) { > $c->res->headers->add( 'Content-Type', 'application/marc' ); > return $c->render( > status => 200, > text => $biblios->print_collection('marc') > ); >- } >- elsif ( $c->req->headers->accept =~ m/text\/plain(;.*)?$/ ) { >+ } elsif ( $c->req->headers->accept =~ m/text\/plain(;.*)?$/ ) { > return $c->render( > status => 200, > text => $biblios->print_collection('txt') > ); >- } >- else { >+ } else { > return $c->render( > status => 406, > openapi => [ >@@ -177,8 +164,7 @@ sub list { > ] > ); > } >- } >- catch { >+ } catch { > $c->unhandled_exception($_); > }; > } >diff --git a/Koha/Schema/Result/Deletedbiblio.pm b/Koha/Schema/Result/Deletedbiblio.pm >index 8ca5772e888..33b8c92ead7 100644 >--- a/Koha/Schema/Result/Deletedbiblio.pm >+++ b/Koha/Schema/Result/Deletedbiblio.pm >@@ -215,22 +215,23 @@ __PACKAGE__->has_many( > # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:KwlqhkWWX6CYWb3l2fCcSg > > __PACKAGE__->has_many( >- "biblioitem", >- "Koha::Schema::Result::Deletedbiblioitem", >- { "foreign.biblionumber" => "self.biblionumber" }, >- { cascade_copy => 0, cascade_delete => 0 }, >+ "biblioitem", >+ "Koha::Schema::Result::Deletedbiblioitem", >+ { "foreign.biblionumber" => "self.biblionumber" }, >+ { cascade_copy => 0, cascade_delete => 0 }, > ); > > __PACKAGE__->has_one( >- "metadata", >- "Koha::Schema::Result::DeletedbiblioMetadata", >- { "foreign.biblionumber" => "self.biblionumber" }, >- { cascade_copy => 0, cascade_delete => 0 }, >+ "metadata", >+ "Koha::Schema::Result::DeletedbiblioMetadata", >+ { "foreign.biblionumber" => "self.biblionumber" }, >+ { cascade_copy => 0, cascade_delete => 0 }, > ); > > sub koha_objects_class { > 'Koha::Old::Biblios'; > } >+ > sub koha_object_class { > 'Koha::Old::Biblio'; > } >diff --git a/t/db_dependent/api/v1/deleted_biblios.t b/t/db_dependent/api/v1/deleted_biblios.t >index dff52824159..c5f04b19b39 100755 >--- a/t/db_dependent/api/v1/deleted_biblios.t >+++ b/t/db_dependent/api/v1/deleted_biblios.t >@@ -31,7 +31,7 @@ use t::lib::TestBuilder; > use Mojo::JSON qw(encode_json); > > use C4::Auth; >-use C4::Biblio qw( DelBiblio ); >+use C4::Biblio qw( DelBiblio ); > use C4::Circulation qw( AddIssue AddReturn ); > > use Koha::Biblios; >@@ -65,51 +65,45 @@ subtest 'get() tests' => sub { > $patron->discard_changes; > my $userid = $patron->userid; > >- my $biblio = $builder->build_sample_biblio({ >- title => 'The unbearable lightness of being', >- author => 'Milan Kundera' >- }); >+ my $biblio = $builder->build_sample_biblio( >+ { >+ title => 'The unbearable lightness of being', >+ author => 'Milan Kundera' >+ } >+ ); > > my $formatted = $biblio->metadata->record->as_formatted; > DelBiblio( $biblio->id ); > >- $t->get_ok("//$userid:$password@/api/v1/deleted/biblios/" . $biblio->biblionumber) >- ->status_is(403); >+ $t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" . $biblio->biblionumber )->status_is(403); > > $patron->flags(4)->store; > >- $t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" . $biblio->biblionumber >- => { Accept => 'application/weird+format' } ) >- ->status_is(400); >+ $t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" >+ . $biblio->biblionumber => { Accept => 'application/weird+format' } )->status_is(400); > >- $t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" . $biblio->biblionumber >- => { Accept => 'application/json' } ) >- ->status_is(200) >- ->json_is( '/title', 'The unbearable lightness of being' ) >- ->json_is( '/author', 'Milan Kundera' ); >+ $t->get_ok( >+ "//$userid:$password@/api/v1/deleted/biblios/" . $biblio->biblionumber => { Accept => 'application/json' } ) >+ ->status_is(200)->json_is( '/title', 'The unbearable lightness of being' ) >+ ->json_is( '/author', 'Milan Kundera' ); > >- $t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" . $biblio->biblionumber >- => { Accept => 'application/marcxml+xml' } ) >- ->status_is(200); >+ $t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" >+ . $biblio->biblionumber => { Accept => 'application/marcxml+xml' } )->status_is(200); > >- $t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" . $biblio->biblionumber >- => { Accept => 'application/marc-in-json' } ) >- ->status_is(200); >+ $t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" >+ . $biblio->biblionumber => { Accept => 'application/marc-in-json' } )->status_is(200); > >- $t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" . $biblio->biblionumber >- => { Accept => 'application/marc' } ) >- ->status_is(200); >+ $t->get_ok( >+ "//$userid:$password@/api/v1/deleted/biblios/" . $biblio->biblionumber => { Accept => 'application/marc' } ) >+ ->status_is(200); > >- $t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" . $biblio->biblionumber >- => { Accept => 'text/plain' } ) >- ->status_is(200) >- ->content_is($formatted); >+ $t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" . $biblio->biblionumber => { Accept => 'text/plain' } ) >+ ->status_is(200)->content_is($formatted); > > my $biblio_exist = $builder->build_sample_biblio(); >- $t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" . $biblio_exist->biblionumber >- => { Accept => 'application/marc' } ) >- ->status_is(404) >- ->json_is( '/error', 'Object not found.' ); >+ $t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" >+ . $biblio_exist->biblionumber => { Accept => 'application/marc' } )->status_is(404) >+ ->json_is( '/error', 'Object not found.' ); > > subtest 'marc-in-json encoding tests' => sub { > >@@ -126,11 +120,10 @@ subtest 'get() tests' => sub { > > DelBiblio( $biblio->id ); > >- my $result = $t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" . $biblio->biblionumber >- => { Accept => 'application/marc-in-json' } ) >- ->status_is(200)->tx->res->body; >+ my $result = $t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" >+ . $biblio->biblionumber => { Accept => 'application/marc-in-json' } )->status_is(200)->tx->res->body; > >- my $encoded_title = Encode::encode( "UTF-8", $title_with_diacritics ); >+ my $encoded_title = Encode::encode( "UTF-8", $title_with_diacritics ); > > like( $result, qr/\Q$encoded_title/, "The title is not double encoded" ); > }; >@@ -139,8 +132,7 @@ subtest 'get() tests' => sub { > plan tests => 3; > > my $marcflavour = C4::Context->preference('marcflavour'); >- t::lib::Mocks::mock_preference('marcflavour', 'UNIMARC'); >- >+ t::lib::Mocks::mock_preference( 'marcflavour', 'UNIMARC' ); > > my $title_with_diacritics = "L'insoutenable légèreté de l'être"; > >@@ -153,19 +145,18 @@ subtest 'get() tests' => sub { > > my $record = $biblio->metadata->record; > $record->leader(' nam 3 4500'); >- $biblio->metadata->metadata($record->as_xml_record('UNIMARC')); >+ $biblio->metadata->metadata( $record->as_xml_record('UNIMARC') ); > $biblio->metadata->store; > > DelBiblio( $biblio->id ); > >- my $result = $t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" . $biblio->biblionumber >- => { Accept => 'application/marcxml+xml' } ) >- ->status_is(200)->tx->res->body; >+ my $result = $t->get_ok( "//$userid:$password@/api/v1/deleted/biblios/" >+ . $biblio->biblionumber => { Accept => 'application/marcxml+xml' } )->status_is(200)->tx->res->body; > >- my $encoded_title = Encode::encode( "UTF-8", $title_with_diacritics ); >+ my $encoded_title = Encode::encode( "UTF-8", $title_with_diacritics ); > > like( $result, qr/\Q$encoded_title/, "The title is not double encoded" ); >- t::lib::Mocks::mock_preference('marcflavour', $marcflavour); >+ t::lib::Mocks::mock_preference( 'marcflavour', $marcflavour ); > }; > > $schema->storage->txn_rollback; >@@ -188,10 +179,10 @@ subtest 'list() tests' => sub { > $patron->discard_changes; > my $userid = $patron->userid; > >- t::lib::Mocks::mock_preference('marcflavour', 'UNIMARC'); >+ t::lib::Mocks::mock_preference( 'marcflavour', 'UNIMARC' ); > > my $title_with_diacritics = "L'insoutenable légèreté de l'être"; >- my $biblio = $builder->build_sample_biblio( >+ my $biblio = $builder->build_sample_biblio( > { > title => $title_with_diacritics, > author => "Milan Kundera", >@@ -200,15 +191,15 @@ subtest 'list() tests' => sub { > > my $record = $biblio->metadata->record; > $record->leader(' nam 3 4500'); >- $biblio->metadata->metadata($record->as_xml_record('UNIMARC'))->store; >+ $biblio->metadata->metadata( $record->as_xml_record('UNIMARC') )->store; > > my $biblio_id_1 = $biblio->id; > >- t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); >+ t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); > my $biblio_id_2 = $builder->build_sample_biblio->id; > >- DelBiblio( $biblio_id_1 ); >- DelBiblio( $biblio_id_2 ); >+ DelBiblio($biblio_id_1); >+ DelBiblio($biblio_id_2); > > my $query = encode_json( [ { biblio_id => $biblio_id_1 }, { biblio_id => $biblio_id_2 } ] ); > >@@ -219,9 +210,11 @@ subtest 'list() tests' => sub { > $t->get_ok( "//$userid:$password@/api/v1/deleted/biblios?q=$query" => { Accept => 'application/weird+format' } ) > ->status_is(400); > >- $t->get_ok( "//$userid:$password@/api/v1/deleted/biblios?q=$query" => { Accept => 'application/json' } )->status_is(200); >+ $t->get_ok( "//$userid:$password@/api/v1/deleted/biblios?q=$query" => { Accept => 'application/json' } ) >+ ->status_is(200); > >- my $result = $t->get_ok( "//$userid:$password@/api/v1/deleted/biblios?q=$query" => { Accept => 'application/marcxml+xml' } ) >+ my $result = >+ $t->get_ok( "//$userid:$password@/api/v1/deleted/biblios?q=$query" => { Accept => 'application/marcxml+xml' } ) > ->status_is(200)->tx->res->body; > > my $encoded_title = Encode::encode( "UTF-8", $title_with_diacritics ); >@@ -230,23 +223,18 @@ subtest 'list() tests' => sub { > $t->get_ok( "//$userid:$password@/api/v1/deleted/biblios?q=$query" => { Accept => 'application/marc-in-json' } ) > ->status_is(200); > >- $t->get_ok( "//$userid:$password@/api/v1/deleted/biblios?q=$query" => { Accept => 'application/marc' } )->status_is(200); >+ $t->get_ok( "//$userid:$password@/api/v1/deleted/biblios?q=$query" => { Accept => 'application/marc' } ) >+ ->status_is(200); > > $t->get_ok( "//$userid:$password@/api/v1/deleted/biblios?q=$query" => { Accept => 'text/plain' } )->status_is(200); > > # DELETE any biblio with ISBN = TOMAS >- Koha::Biblios->search({ 'biblioitem.isbn' => 'TOMAS' }, { join => [ 'biblioitem' ] }) >- ->delete; >- >+ Koha::Biblios->search( { 'biblioitem.isbn' => 'TOMAS' }, { join => ['biblioitem'] } )->delete; > >- my $isbn_query = encode_json({ isbn => 'TOMAS' }); >- my $tomas_biblio = $builder->build_sample_biblio({ >- isbn => 'TOMAS' >- }); >+ my $isbn_query = encode_json( { isbn => 'TOMAS' } ); >+ my $tomas_biblio = $builder->build_sample_biblio( { isbn => 'TOMAS' } ); > DelBiblio( $tomas_biblio->id ); >- $t->get_ok( "//$userid:$password@/api/v1/biblios?q=$isbn_query" => >- { Accept => 'text/plain' } ) >- ->status_is(200); >+ $t->get_ok( "//$userid:$password@/api/v1/biblios?q=$isbn_query" => { Accept => 'text/plain' } )->status_is(200); > > $schema->storage->txn_rollback; > }; >-- >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