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,$map_file,$lib_map_field,$id_tag) =
40 (1, 1, 1, 'asset_copy.sql','asset_volume.sql','record_id_map.pl','shortname','/*/*/*[@tag="035"][1]');
42 my ($holding_tag,$bc,$lbl,$own,$pr,$cpn,$avail) =
43 ('/*/*/*[@tag="999"]','i','a','m','p','c','k');
45 my ($db_driver,$db_host,$db_name,$db_user,$db_pw) =
46 ('Pg','localhost','demo-dev','postgres','postgres');
49 "copy_file=s" => \$cp_file,
50 "volume_file=s" => \$cn_file,
51 "tcn_map_file=s" => \$map_file,
52 "userid=i" => \$userid,
53 "first_volume=i" => \$cn_id,
54 "first_copy=i" => \$cp_id,
55 "db_driver=s" => \$db_driver,
56 "db_host=s" => \$db_host,
57 "db_name=s" => \$db_name,
58 "db_user=s" => \$db_user,
60 "lib_map_field=s" => \$lib_map_field,
61 "id_tag_xpath=s" => \$id_tag,
62 "holding_tag_xpath=s" => \$holding_tag,
63 "item_barcode=s" => \$bc,
64 "item_call_number=s" => \$lbl,
65 "item_owning_lib=s" => \$own,
66 "item_price=s" => \$pr,
67 "item_copy_number=s" => \$cpn,
68 "item_copy_status=s" => \$avail,
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];
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 while ( $xml .= <STDIN> ) {
119 $doc = $parser->parse_string($xml);;
120 $tcn = $doc->documentElement->findvalue( '//*[@tag="035"][1]' );
127 next unless $success;
129 $tcn =~ s/^.*?(\w+)\s*$/$1/go;
132 warn "\nNo TCN found in rec!!\n";
138 unless (exists($$tcn_map{$tcn})) {
139 warn "\n !! TCN $tcn not in the map!\n";
144 my $rec_id = $$tcn_map{$tcn};
146 for my $node ($doc->documentElement->findnodes($holding_tag)) {
147 my $barcode = $node->findvalue( "*[\@code=\"$bc\"]" );
148 my $label = $node->findvalue( "*[\@code=\"$lbl\"]" );
149 my $owning_lib = $$lib_map{ $node->findvalue( "*[\@code=\"$own\"]" ) };
150 my $price = $node->findvalue( "*[\@code=\"$pr\"]" );
151 my $copy_number = $node->findvalue( "*[\@code=\"$cpn\"]" ) || 0;
152 my $available = $node->findvalue( "*[\@code=\"$avail\"]" ) || '';
154 my $status = $status_map{$available} || 0;
156 next unless $barcode;
157 next unless $owning_lib;
160 $barcode =~ s/\\/\\\\/og;
161 $label =~ s/\\/\\\\/og;
163 if ($price !~ /^\s*\d{1,6}\.\d{2}\s*$/o) {
167 unless (exists($$cn_map{"$rec_id/$owning_lib/$label"})) {
168 $$cn_map{"$rec_id/$owning_lib/$label"} = $cn_id;
169 print CN join("\t",($cn_id,$userid,$userid,$rec_id,$label,$owning_lib))."\n";
174 # id,editor,creator,barcode,call_number,copy_number,available,loan_duration,fine_level,circulate,deposit,deposit_amount,price,ref,opac_visible
176 print CP join("\t", ( $cp_id,$owning_lib,$userid,$userid,$barcode,
177 $$cn_map{"$rec_id/$owning_lib/$label"},
178 $copy_number,$status,2,2,1,0,'0.00',
188 print CN "SELECT setval('asset.call_number_id_seq'::TEXT, $cn_id);\n";
190 print CP "SELECT setval('asset.copy_id_seq'::TEXT, $cp_id);\n";