[Koha] Item batch modifications using custom SQL or Perl?

Paul Hoffman paul at flo.org
Tue Jul 10 06:09:30 NZST 2018


I've been asked to modify a batch of item call numbers, substituting 
"PYA" for "PZ100" whenever the latter occurs at the beginning of the 
call number.  This doesn't seem possible using the existing Batch Item 
Modification tool (batchMod.pl).

I would love to do this using SQL only, like so:

    UPDATE items
    SET    itemcallnumber = concat("PYA", substr(itemcallnumber, 6))
    WHERE  itemcallnumber LIKE 'PZ100%';

However, I suspect that this will mess up indexing or call number browse 
or *something*.  Reading the relevant parts of C4::Items, I believe I 
can more safely accomplish this in Perl, something along these lines...

    use C4::Items;
    use C4::Context;

    use strict;
    use warnings;

    my $dbh = C4::Context->dbh;
    $dbh->{RaiseError} = 1;
    my $sql = q{
        SELECT  biblionumber, itemnumber, itemcallnumber
        FROM    items
        WHERE   itemcallnumber LIKE 'PZ100%'
    };
    my $sth = $dbh->prepare($sql);
    $sth->execute;
    while (my ($bibnum, $itemnum, $callnum) = $sth->fetchrow_array) {
        $callnum =~ s/^PZ100/PYA/;
        ModItem(
            {'itemcallnumber' => $callnum},
            $bibnum,
            $itemnum
        ) or print STDERR "Could not update item $itemnum\n";
    }

Is this pretty much the simplest way to safely make unusual batch 
modifications like this?

Thanks in advance,

Paul.

-- 
Paul Hoffman <paul at flo.org>
Systems Librarian
Fenway Libraries Online
c/o Wentworth Institute of Technology
550 Huntington Ave.
Boston, MA 02115
(617) 442-2384 (FLO main number)


More information about the Koha mailing list