4 use Time::HiRes qw/time/;
11 #-------------------------------------------------------------------------------
12 # The keys of this hash should be the string values stored in your legacy
13 # system that map to the copy statuses in Open-ILS. If you don't see a
14 # legacy status here that you need to carry over to your new Open-ILS install
15 # you can use the "Copy Statuses" bootstrapping CGI to create an entry for it.
16 # Then simply a key for the legacy status that points to the SysID of the new
17 # Open-ILS Copy Status.
18 #-------------------------------------------------------------------------------
39 my ($userid,$cn_id,$cp_id,$cp_file,$cn_file,$lib_map_field,$id_tag, $marc_file) =
40 (1, 1, 1, 'asset_copy.sql','asset_volume.sql','shortname','./datafield[@tag="035"]');
42 my ($holding_tag,$bc,$lbl,$own,$pr,$cpn,$avail) =
43 ('./datafield[@tag="999"]','i','a','m','p','c','k');
45 my ($db_driver,$db_host,$db_name,$db_user,$db_pw) =
46 ('Pg','localhost','evergreen','postgres','postgres');
49 "copy_file=s" => \$cp_file,
50 "volume_file=s" => \$cn_file,
51 "userid=i" => \$userid,
52 "first_volume=i" => \$cn_id,
53 "first_copy=i" => \$cp_id,
54 "db_driver=s" => \$db_driver,
55 "db_host=s" => \$db_host,
56 "db_name=s" => \$db_name,
57 "db_user=s" => \$db_user,
59 "lib_map_field=s" => \$lib_map_field,
60 "id_tag_xpath=s" => \$id_tag,
61 "holding_tag_xpath=s" => \$holding_tag,
62 "item_barcode=s" => \$bc,
63 "item_call_number=s" => \$lbl,
64 "item_owning_lib=s" => \$own,
65 "item_price=s" => \$pr,
66 "item_copy_number=s" => \$cpn,
67 "item_copy_status=s" => \$avail,
68 "marc_file=s" => \$marc_file,
72 my $dsn = "dbi:$db_driver:host=$db_host;dbname=$db_name";
73 my $dbh = DBI->connect($dsn,$db_user,$db_pw);
75 my $t = 'actor_org_unit';
76 if ($db_driver eq 'Pg') {
77 $t = 'actor.org_unit';
79 my $sth = $dbh->prepare("SELECT $lib_map_field,id FROM $t");
83 while (my $lib = $sth->fetchrow_arrayref) {
84 $$lib_map{$$lib[0]} = $$lib[1];
87 my $tcn_sth = $dbh->prepare("SELECT id FROM biblio.record_entry WHERE tcn_value = ?");
90 open CP, ">$cp_file" or die "Can't open $cp_file! $!\n";
91 open CN, ">$cn_file" or die "Can't open $cn_file! $!\n";
95 SET CLIENT_ENCODING TO 'UNICODE';
96 COPY asset.copy (id,circ_lib,editor,creator,barcode,call_number,copy_number,status,loan_duration,fine_level,circulate,deposit,deposit_amount,price,ref,opac_visible) FROM STDIN;
100 SET CLIENT_ENCODING TO 'UNICODE';
101 COPY asset.call_number (id,editor,creator,record,label,owning_lib) FROM STDIN;
106 my $parser = XML::LibXML->new();
111 $doc = $parser->parse_file( $marc_file );
112 my $xc = XML::LibXML::XPathContext->new($doc);
113 my @records = $xc->findnodes('//record');
114 foreach my $record (@records) {
119 $tcn = $xc->findvalue( $id_tag, $record );
125 next unless $success;
127 $tcn =~ s/^\s*(\.+)\s*/$1/o;
131 warn "\nNo TCN found in rec!!\n";
135 $tcn_sth->execute($tcn);
136 $tcn_sth->bind_col(1, \$rec_id);
140 warn "\n !! TCN $tcn not in the map!\n";
144 for my $node ($xc->findnodes($holding_tag, $record)) {
145 my $barcode = $xc->findvalue( "./*[\@code=\"$bc\"]", $node );
146 my $label = $xc->findvalue( "./*[\@code=\"$lbl\"]", $node );
147 my $owning_lib = $$lib_map{ $xc->findvalue( "./*[\@code=\"$own\"]", $node ) };
148 my $price = $xc->findvalue( "./*[\@code=\"$pr\"]", $node );
149 my $copy_number = $xc->findvalue( "./*[\@code=\"$cpn\"]", $node ) || 0;
150 my $available = $xc->findvalue( "./*[\@code=\"$avail\"]", $node ) || '';
152 my $status = $status_map{$available} || 0;
154 next unless $barcode;
155 next unless $owning_lib;
158 $barcode =~ s/\\/\\\\/og;
159 $label =~ s/\\/\\\\/og;
161 if ($price !~ /^\s*\d{1,6}\.\d{2}\s*$/o) {
165 unless (exists($$cn_map{"$rec_id/$owning_lib/$label"})) {
166 $$cn_map{"$rec_id/$owning_lib/$label"} = $cn_id;
167 print CN join("\t",($cn_id,$userid,$userid,$rec_id,$label,$owning_lib))."\n";
172 # id,editor,creator,barcode,call_number,copy_number,available,loan_duration,fine_level,circulate,deposit,deposit_amount,price,ref,opac_visible
174 print CP join("\t", ( $cp_id,$owning_lib,$userid,$userid,$barcode,
175 $$cn_map{"$rec_id/$owning_lib/$label"},
176 $copy_number,$status,2,2,1,0,'0.00',
185 print CN "SELECT setval('asset.call_number_id_seq'::TEXT, $cn_id);\n";
187 print CP "SELECT setval('asset.copy_id_seq'::TEXT, $cp_id);\n";