Bugzilla – Attachment 188692 Details for
Bug 17387
Add an undelete feature for items/biblios
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17387: item cannot be restored if associated biblio does not exist
Bug-17387-item-cannot-be-restored-if-associated-bi.patch (text/plain), 3.23 KB, created by
Jacob O'Mara
on 2025-10-30 17:38:43 UTC
(
hide
)
Description:
Bug 17387: item cannot be restored if associated biblio does not exist
Filename:
MIME Type:
Creator:
Jacob O'Mara
Created:
2025-10-30 17:38:43 UTC
Size:
3.23 KB
patch
obsolete
>From dad5c416f34aa6a62d5993f57ea1a2f83aeed4e5 Mon Sep 17 00:00:00 2001 >From: Jacob O'Mara <Jacob.omara@openfifth.co.uk> >Date: Thu, 30 Oct 2025 10:26:38 +0000 >Subject: [PATCH] Bug 17387: item cannot be restored if associated biblio does > not exist > >--- > Koha/REST/V1/DeletedItems.pm | 13 ++++++++++++- > api/v1/swagger/paths/deleted_items.yaml | 4 ++++ > t/db_dependent/api/v1/deleted_items.t | 13 ++++++++++++- > 3 files changed, 28 insertions(+), 2 deletions(-) > >diff --git a/Koha/REST/V1/DeletedItems.pm b/Koha/REST/V1/DeletedItems.pm >index d3fa1a21df1..fa3522477c1 100644 >--- a/Koha/REST/V1/DeletedItems.pm >+++ b/Koha/REST/V1/DeletedItems.pm >@@ -19,9 +19,11 @@ use Modern::Perl; > > use Mojo::Base 'Mojolicious::Controller'; > >+use Koha::Exceptions; > use Koha::Old::Items; > >-use Try::Tiny qw( catch try ); >+use Scalar::Util qw( blessed ); >+use Try::Tiny qw( catch try ); > > =head1 API > >@@ -90,6 +92,15 @@ sub restore { > openapi => $c->objects->to_api($item), > ); > } catch { >+ if ( blessed $_ && $_->isa('Koha::Exceptions::ObjectNotFound') ) { >+ return $c->render( >+ status => 409, >+ openapi => { >+ error => >+ "Bibliographic record not found for this item. Cannot restore item without its bibliographic record." >+ } >+ ); >+ } > $c->unhandled_exception($_); > }; > } >diff --git a/api/v1/swagger/paths/deleted_items.yaml b/api/v1/swagger/paths/deleted_items.yaml >index 923ce641ccc..31a4d3f9e01 100644 >--- a/api/v1/swagger/paths/deleted_items.yaml >+++ b/api/v1/swagger/paths/deleted_items.yaml >@@ -129,6 +129,10 @@ > description: Deleted item not found > schema: > $ref: "../swagger.yaml#/definitions/error" >+ "409": >+ description: Cannot restore item - bibliographic record not found >+ schema: >+ $ref: "../swagger.yaml#/definitions/error" > "500": > description: | > Internal server error. Possible `error_code` attribute values: >diff --git a/t/db_dependent/api/v1/deleted_items.t b/t/db_dependent/api/v1/deleted_items.t >index 464e1a18b78..4b2ca64bcb3 100755 >--- a/t/db_dependent/api/v1/deleted_items.t >+++ b/t/db_dependent/api/v1/deleted_items.t >@@ -127,7 +127,7 @@ subtest 'get() tests' => sub { > > subtest 'restore() tests' => sub { > >- plan tests => 11; >+ plan tests => 15; > > $schema->storage->txn_begin; > >@@ -183,5 +183,16 @@ subtest 'restore() tests' => sub { > > $t->put_ok("//$userid:$password@/api/v1/deleted/items/$item_id")->status_is(404); > >+ my $item_without_biblio = $builder->build_sample_item( { barcode => 'TEST_NO_BIBLIO' } ); >+ my $orphan_item_id = $item_without_biblio->itemnumber; >+ my $orphan_biblio_id = $item_without_biblio->biblionumber; >+ my $orphan_item_data = $item_without_biblio->unblessed; >+ my $deleted_orphan_item = Koha::Old::Item->new($orphan_item_data)->store; >+ $item_without_biblio->delete; >+ Koha::Biblios->find($orphan_biblio_id)->delete; >+ >+ $t->put_ok("//$userid:$password@/api/v1/deleted/items/$orphan_item_id")->status_is(409)->json_has('/error') >+ ->json_like( '/error', qr/Bibliographic record not found/ ); >+ > $schema->storage->txn_rollback; > }; >-- >2.39.5
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 17387
:
188670
|
188671
|
188672
|
188673
|
188674
|
188675
|
188676
|
188677
|
188678
|
188679
|
188680
|
188681
|
188682
|
188683
|
188684
|
188685
|
188686
|
188687
|
188688
|
188689
|
188690
|
188691
|
188692
|
188693
|
188694
|
188695
|
188696
|
188697
|
188698
|
188699
|
188700
|
188701
|
188780
|
188781
|
188782
|
188783
|
188784
|
188785
|
188786
|
188787
|
188788
|
188789
|
188790
|
188791
|
188792
|
188793
|
188794
|
188795
|
189046
|
189047
|
189048
|
189049
|
189050
|
189051
|
189052
|
189053
|
189054
|
189055
|
189056
|
189057
|
189058
|
189059
|
189060
|
189061
|
189062
|
189082
|
189083
|
189084
|
189085
|
189086
|
189087
|
189088
|
189089
|
189090
|
189091
|
189092
|
189093
|
189094
|
189095
|
189096
|
189097
|
189098
|
189099
|
189100
|
189101
|
189102
|
189103
|
189104
|
189105
|
189106
|
189107
|
189108
|
189109
|
189110
|
189111
|
189112
|
189113
|
189114
|
189115
|
189116
|
189117
|
189118
|
189119