Koha support in Austria and beyond

Allgemein

HOWTO undelete biblio&items in Koha

One of our customers requested the deletion of biblioitems and biblios with certain signatures.

DELETE

C4::Biblio::DelBiblio requires all biblioitems of a biblio to be deleted before the biblio can be deleted.

my $sql = "SELECT biblionumber FROM items WHERE itemcallnumber = '$signature';";
# ...
my $biblio = Koha::Biblios->find( $biblionumber );
my $items_rs = $biblio->items;
while( my $item = $items_rs->next) {
   $item->move_to_deleted;
   $item->delete;
}
my $error = DelBiblio($biblionumber);

After we ran this code on our production instance we noticed that not all items should have been deleted.

The correct solution for biblios with multiple biblioitems would have been to only delete the biblioitem with a matching signature and leave the biblio in place.

But we have to fix the production system, using the backup that we had would require us to repeat all the work that was done in the meantime.

RESTORE

Luckily our deletion script logged the signatures, biblionumbers and itemnumbers.

Processing signature: F6247 E
biblionumber: 2663003
  delete itemnumber: 2841035
  delete itemnumber: 2841036
    DELETE OK

We just have to restore the deleted entries and once everything is back to the previous state we can run the fixed deletion script again and only delete what we want deleted.

https://schema.koha-community.org/22_11/tables/items.html

table biblio and deletedbiblio have the same table structure.
table biblio_metadata and deletedbiblio_metadata have the same table structure.
table biblioitems and deletedbiblioitems have the same table structure.
table items and deleteditems have the same table structure.

We just have to:

INSERT INTO biblio SELECT * FROM deletedbiblio WHERE biblionumber = '...';
INSERT INTO biblio_metadata SELECT * FROM deletedbiblio_metadata WHERE biblionumber = '...';
INSERT INTO biblioitems SELECT * FROM deletedbiblioitems WHERE biblionumber = '...' AND biblioitemnumber = '...';
INSERT INTO items SELECT * FROM deleteditems WHERE itemnumber = '...';

afterwards we clean up the entries in the deleted* tables:

DELETE FROM deletedbiblio_metadata WHERE biblionumber=?;
DELETE FROM deleteditems WHERE itemnumber=?;
DELETE FROM deletedbiblioitems WHERE biblionumber=? AND biblioitemnumber=?;

DELETE FROM deletedbiblio WHERE biblionumber=?;

And now we have restored the deleted biblios.

You probably have to refresh your zebra/elasticsearch index.

rebuild_elasticsearch.pl -b -v -bn $biblionumber

See Also

There is also a plugin that might be helpful.
https://inlibro.com/en/koha-plugins/undeleterecords-instructions/

Schreibe eine Antwort