[Koha] Fixing Default Item Types - Conversion Question

Chris Cormack chris at bigballofwax.co.nz
Mon Oct 11 12:19:27 NZDT 2010


On 11 October 2010 12:02, Chris Hobbs <chobbs at nhusd.k12.ca.us> wrote:
> On 10/10/10 2:54 PM, Chris Cormack wrote:
>
> 2010/10/9 Chris Hobbs <CHobbs at nhusd.k12.ca.us>:
>
> Is there a way for me to fix the Default item types for our biblios en
> masse? Our biblioitems records have the correct item type from our
> conversion, but every time we add a new item type it defaults to our '0'
> type (Art Print).
>
> There are 2 places where itemtype is set, either at
> biblioitems.itemype or items.itype
> There is a systempreference which controls which one is used.
>
> I would recommend using the item level itemtypes.
>
> That is our setting, but I think I did a poor job of explaining our problem.
> The real issue is that I didn't populate the 942c (or 942n) sub-fields when
> I imported our MARC records, so those are unset. If somebody edits an
> existing MARC record, 942c is defaulting to our itemtype 0, which is Art
> Print, unless the cataloger is paying attention and edits 942c in addition
> to whatever else she went in to edit. Later, when they go to add a new item
> of that biblio, the item-level itype becomes Art Print unless they notice
> and change it.
>
> Since we have no biblios with multiple item types associated with them (we
> create a different biblio for each media type of a title), I'd like to set
> the 942c sub-field based on an example item attached to that biblio. *If*
> there were an itemtype in the biblio table, the pseudo-SQL might look
> something like this:
>
> update biblio set itemtype=(select top 1 itype from items where
> items.biblionumber=biblio.biblionumber)
>
Ah right, I getcha... ok, we the problem there is, you wont get it
into the MARC, just into the biblioitems table (itemtype is in
biblioitems not biblio),
So while

UPDATE biblioitems, items SET biblioitems.itemtype = items.itype WHERE
biblioitems.biblioitemnumber = items.biblioitemnumber

would mostly fix your problem, it sill wouldnt get the value into the marc.

Heres some perl im typing free hand,so the chances of it actually
working are fairly slim but it might put you on the right path

#!/usr/bin/perl

use strict;
use warnings;
use C4::Context;
use C4::Biblio;

my $dbh = C4::Context->dbh();
my $items_sth = $dbh->prepare("SELECT itype FROM items WHERE
biblioitemnumber = ? LIMIT 1");
my $biblioitems_sth = $dbh->prepare("SELECT
biblionumber,biblioitemnumber FROM biblioitems");

$biblioitems_sth->execute();
while (my $biblioitem = $biblioitems_sth->fetchfow_hashref()){
    $items_sth->execute($biblioitem->{biblioitemnumber};
    if (my $item = $items_sth->fetchrow_hashref())){
        my $marc = GetMarcBiblio($biblioitem->{biblionumber});
        my $field = MARC::Field->new('942,'','','c' => $item->{itype});
        my @old_fields = $marc->field('942');
        $marc->delete_field($_) foreach (@old_fields);
        $marc->append_fields($field);
        ModBiblio($marc, $biblioitems->{biblionumber}, '');
    }
}

Back up your db, and it probably has at least 2 syntax errors in
there, but the theory should work :)

Chris


More information about the Koha mailing list