[Koha] How do I bulk delete bibliographic records (of one given item type)?

Ricardo Dias Marques lists at ricmarques.net
Sat Jan 9 09:17:04 NZDT 2010


Hi Paul (and list)


On Thu, Jan 7, 2010 , Paul Poulain <paul.poulain at biblibre.com> wrote:

> Ricardo Dias Marques a écrit :

>> mysql> select barcode from biblioitems, items where itemtype=2 and
>> biblioitems.biblionumber = items.biblionumber and
>> biblioitems.biblioitemnumber = items.biblioitemnumber;
>>
> that's exactly the best option !

Great. Many thanks for the feedback!  :)


>> By doing some research, I see that I would need (at least) to change
>> the "Items.pm" file, in the "C4" Koha 3.0.5 directory, with code that
>> was added in the "master" branch (and that contains that new
>> "Item2Marc" function / subroutine). I wish to avoid that, if possible
>> (because that seems to be touching a more "essential" part of my Koha
>> installation, and I'm afraid that could cause other problems).
>>
> wise decision. I can guarantee that the "at least" on 1st line would in
> fact be "first", and have many others after !

Right, I though so. Thanks for confirming my impression.


>> So, let me rephrase my initial question: how do people *currently* do
>> batch deletions / bulk deletions of bibliographic records (and
>> associated items), for a given / specific item type, in Koha 3.0.x
>> (e.g. 3.0.5)?
>>
> I think they don't, that's why we added this feature.
> A small Perl script could do the job you want though. Something like :
> [ snipped example script. Thank you very much for the script Paul! ]

Cool. Thank you for the Perl script! I ended up writing a similar
script and it seemed to do the trick:

----------------------------------------
#!/usr/bin/perl
use warnings;
use strict;

use C4::Context;
use C4::Items;
use C4::Koha;
use C4::Biblio;

my $dbh = C4::Context->dbh;

my $query2 = "select biblio.biblionumber,
biblioitems.biblioitemnumber, items.itemnumber from biblio,
biblioitems, items where itemtype=2 and biblio.biblionumber =
biblioitems.biblionumber and
biblioitems.biblionumber=biblio.biblionumber and
biblioitems.biblioitemnumber = items.biblioitemnumber;";

my $sth2 = $dbh->prepare("$query2");

$sth2->execute
    or die("ERROR: Could not run the query: $query2  The following
error occurred: $! \n");


while (my ($biblionumber, $biblioitemnumber, $itemnumber) = $sth2->fetchrow) {
    print "Deleting item record with biblionumber = $biblionumber and
itemnumber = $itemnumber \n";
    DelItem($dbh,$biblionumber,$itemnumber);

    print "Deleting biblio record with biblionumber = $biblionumber \n";
    DelBiblio($biblionumber);
   }

----------------------------------------


I needed to do a small change in "Biblio.pm" for my script to work
(without errors). The change I did was around the line 2800 of that
file, by "surrounding" the "unless" block that starts with:

unless ($result{'__RAW__'}->{$_} =~ /$biblionumber,$title\-(\d);/) {

... with the following "if" block:

if (defined($result{'__RAW__'}->{$_}) && $result{'__RAW__'}->{$_} ne "")


Like I said, this seemed to do the trick, at least for me. I'm posting
this script in the hope this helps others, as well. As always: I'm NOT
giving any guarantees, YMMV, do a database backup before trying this,
etc...


Thanks again Paul!  :)

Cheers,
Ricardo


More information about the Koha mailing list