Bugzilla – Attachment 188780 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: add restore functionality to Old::Biblio/Item
Bug-17387-add-restore-functionality-to-OldBiblioIt.patch (text/plain), 4.77 KB, created by
Biblibre Sandboxes
on 2025-10-31 09:50:36 UTC
(
hide
)
Description:
Bug 17387: add restore functionality to Old::Biblio/Item
Filename:
MIME Type:
Creator:
Biblibre Sandboxes
Created:
2025-10-31 09:50:36 UTC
Size:
4.77 KB
patch
obsolete
>From 724475c2da42f9d5aef81c3f98b9e4f8f9bfc579 Mon Sep 17 00:00:00 2001 >From: Jacob O'Mara <Jacob.omara@openfifth.co.uk> >Date: Thu, 30 Oct 2025 09:53:52 +0000 >Subject: [PATCH] Bug 17387: add restore functionality to Old::Biblio/Item > >TEST PLAN: Item/Biblio Undelete Feature > > SETUP: > - Apply patches and update database > - Give test user "Restore deleted records" permission under Cataloging >permissions > - Delete at least one bibliographic record with items attached > - Delete at least one standalone item > > TESTING: > > Navigate to Cataloging: > - Go to Cataloging home page > - Click "Restore deleted records" link (should be visible with >permission) > > Test Restore Records Page: > - Verify two tables appear: "Deleted bibliographic records" and >"Deleted items" > - Verify deleted records appear in tables with biblio ID, title, >barcode, deleted date > > Test Date Filtering: > - In left sidebar, enter date range in "Deleted from" and "Deleted to" >fields > - Click "Apply" button - tables should filter by date range > - Click "Clear" button - filter should reset > > Test Item Restore: > - Find a deleted item in the items table (with existing biblio) > - Click "Restore" button in Actions column > - Verify success message appears and item disappears from table > - Search catalog for the restored item - confirm it's back > > Test Biblio Warning Modal: > - Find a deleted item whose biblio is also deleted > - Click "Restore" button on the item > - Modal appears warning "bibliographic record is deleted" > - Click "Restore biblio" - biblio restores, modal closes > - Click "Restore" on the item again - item now restores successfully > - Verify both records are back in catalog > > Test Biblio with Items Restore: > - Find deleted biblio with multiple deleted items > - Click "Restore" button for the biblio > - Modal shows checkboxes for each deleted item > - Select some items (not all), click "Restore with selected items" > - Verify biblio and selected items restore > - Unselected items remain in deleted items table > > Permission Testing: > - Remove "Restore deleted records" permission from user > - Verify "Restore deleted records" link no longer appears in >Cataloging home > >Signed-off-by: Michaela <michaela.sieber@kit.edu> >--- > Koha/Old/Biblio.pm | 42 ++++++++++++++++++++++++++++++++++++++++++ > Koha/Old/Item.pm | 26 ++++++++++++++++++++++++++ > 2 files changed, 68 insertions(+) > >diff --git a/Koha/Old/Biblio.pm b/Koha/Old/Biblio.pm >index 1b3f46b59e..7d4200cb74 100644 >--- a/Koha/Old/Biblio.pm >+++ b/Koha/Old/Biblio.pm >@@ -19,6 +19,10 @@ use Modern::Perl; > > use base qw(Koha::Object); > >+use Koha::Database; >+use Koha::Biblio; >+use Koha::Biblioitem; >+use Koha::Biblio::Metadata; > use Koha::Old::Biblio::Metadatas; > use Koha::Old::Biblioitems; > >@@ -130,6 +134,44 @@ sub to_api_mapping { > }; > } > >+=head3 restore >+ >+ my $biblio = $deleted_biblio->restore; >+ >+Restores the deleted biblio record back to the biblio table along with >+its biblioitems and metadata. This removes the record from the deleted tables >+and re-inserts it into the active tables. >+ >+Returns the newly restored Koha::Biblio object. >+ >+=cut >+ >+sub restore { >+ my ($self) = @_; >+ >+ my $biblio_data = $self->unblessed; >+ my $biblioitem = $self->biblioitem; >+ my $biblioitem_data = $biblioitem->unblessed; >+ my $metadata = $self->metadata; >+ my $metadata_data = $metadata->unblessed; >+ >+ my $new_biblio = Koha::Biblio->new($biblio_data)->store; >+ >+ $biblioitem_data->{biblionumber} = $new_biblio->biblionumber; >+ $biblioitem_data->{biblioitemnumber} = $new_biblio->biblionumber; >+ Koha::Biblioitem->new($biblioitem_data)->store; >+ >+ delete $metadata_data->{id}; >+ $metadata_data->{biblionumber} = $new_biblio->biblionumber; >+ Koha::Biblio::Metadata->new($metadata_data)->store; >+ >+ $metadata->delete; >+ $biblioitem->delete; >+ $self->delete; >+ >+ return $new_biblio; >+} >+ > =head2 Internal methods > > =head3 _type >diff --git a/Koha/Old/Item.pm b/Koha/Old/Item.pm >index d95201024e..edaec7a368 100644 >--- a/Koha/Old/Item.pm >+++ b/Koha/Old/Item.pm >@@ -19,6 +19,8 @@ use Modern::Perl; > > use base qw(Koha::Object); > >+use Koha::Item; >+ > =head1 NAME > > Koha::Old::Item - Koha Old::Item Object class >@@ -29,6 +31,30 @@ Koha::Old::Item - Koha Old::Item Object class > > =cut > >+=head3 restore >+ >+ my $item = $deleted_item->restore; >+ >+Restores the deleted item record back to the items table. This removes >+the record from the deleteditems table and re-inserts it into the items table. >+ >+Returns the newly restored Koha::Item object. >+ >+=cut >+ >+sub restore { >+ my ($self) = @_; >+ >+ my $item_data = $self->unblessed; >+ delete $item_data->{deleted_on}; >+ >+ my $new_item = Koha::Item->new($item_data)->store; >+ >+ $self->delete; >+ >+ return $new_item; >+} >+ > =head2 Internal methods > > =head3 _type >-- >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