[Koha] Item batch modifications using custom SQL or Perl?
Joy Nelson
joy at bywatersolutions.com
Tue Jul 10 06:58:08 NZST 2018
Paul,
Using perl is a better way to get at the data. Using ModBiblio will also
update the cn_sort values (for browse feature) in the database as well as
place the biblio into the zebraqueue for updating. Shouldn't be a need to
reindex the site to incorporate your changes.
-Joy
On Mon, Jul 9, 2018 at 12:38 PM, Alvaro Cornejo <cornejo.alvaro at gmail.com>
wrote:
> Hi Paul
>
> I'm not expert in koha, but as I can see, in both cases you are accessing
> directly the DB; therefore the result will be the same. Doing it with perl,
> has the advantage that it will let you extract -if needed- some extra
> error/debug info if something went wrong.
>
> In any case, you I recommend you to manually re-index your database; either
> with zebra or with elasticsearch.
>
> Regards,
>
> Alvaro
>
>
>
> |-----------------------------------------------------------
> ------------------------------------------------------|
> Envíe y Reciba Datos y mensajes de Texto (SMS) hacia y desde cualquier
> celular y Nextel
> en el Perú, México y en mas de 180 paises. Use aplicaciones 2 vias via SMS
> y GPRS online
> Visitenos en www.perusms.com
>
> 2018-07-09 13:09 GMT-05:00 Paul Hoffman <paul at flo.org>:
>
> > 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)
> > _______________________________________________
> > Koha mailing list http://koha-community.org
> > Koha at lists.katipo.co.nz
> > https://lists.katipo.co.nz/mailman/listinfo/koha
> >
> _______________________________________________
> Koha mailing list http://koha-community.org
> Koha at lists.katipo.co.nz
> https://lists.katipo.co.nz/mailman/listinfo/koha
>
--
Joy Nelson
Vice President of Implementations
ByWater Solutions <http://bywatersolutions.com>
Support and Consulting for Open Source Software
Phone/Fax (888)900-8944
What is Koha? <http://bywatersolutions.com/what-is-koha/>
More information about the Koha
mailing list