4 #use warnings; FIXME - Bug 2505
8 use C4::Biblio qw( GetMarcBiblio ModBiblio );
10 use Getopt::Long qw( GetOptions );
14 # command-line parameters
19 my $result = GetOptions(
20 'run-update' => \$do_update,
21 'where=s@' => \$wherestrings,
22 'h|help' => \$want_help,
25 if (not $result or $want_help or not $do_update) {
30 my $num_bibs_processed = 0;
31 my $num_bibs_modified = 0;
32 my $num_noitem_forbarcode = 0;
33 my $num_nobarcode_inhostfield =0;
34 my $num_hostfields_unabletomodify =0;
36 my $dbh = C4::Context->dbh;
37 $dbh->{AutoCommit} = 0;
45 my $sql = "SELECT biblionumber FROM biblio JOIN biblioitems USING (biblionumber)";
46 $sql.="WHERE ". join(" AND ",@$wherestrings) if ($wherestrings);
47 $sql.="ORDER BY biblionumber ASC";
48 my $sth = $dbh->prepare($sql);
49 eval{$sth->execute();};
50 if ($@){ die "error $@";};
51 while (my ($biblionumber) = $sth->fetchrow_array()) {
52 $num_bibs_processed++;
53 process_bib($biblionumber);
55 if (($num_bibs_processed % 100) == 0) {
56 print_progress_and_commit($num_bibs_processed);
64 Create Analytical records relationships report
65 -----------------------------------------------
66 Number of bibs checked: $num_bibs_processed
67 Number of bibs modified: $num_bibs_modified
68 Number of hostfields with no barcodes: $num_nobarcode_inhostfield
69 Number of barcodes not found: $num_noitem_forbarcode
70 Number of hostfields unable to modify: $num_hostfields_unabletomodify
71 Number of bibs with errors: $num_bad_bibs
76 my $biblionumber = shift;
78 my $bib = GetMarcBiblio({ biblionumber => $biblionumber });
79 unless (defined $bib) {
80 print "\nCould not retrieve bib $biblionumber from the database - record is corrupt.\n";
84 #loop through each host field and populate subfield 0 and 9
85 my $analyticfield = '773';
86 foreach my $hostfield ( $bib->field($analyticfield) ) {
87 if(my $barcode = $hostfield->subfield('o')){
88 my $item = Koha::Items->find({ barcode => $barcode });
91 if ( $hostfield->subfield('0') ne $biblionumber ) {
92 $hostfield->update( '0', $biblionumber );
95 if ( $hostfield->subfield('9') ne $item->itemnumber ) {
96 $hostfield->update( '9', $item->itemnumber );
100 $num_bibs_modified++;
101 my $modresult = ModBiblio( $bib, $biblionumber, '' );
102 warn "Modifying biblio $biblionumber";
104 warn "Unable to modify biblio $biblionumber with update host field";
105 $num_hostfields_unabletomodify++;
110 warn "No item record found for barcode $barcode";
111 $num_noitem_forbarcode++;
114 warn "No barcode in host field for biblionumber $biblionumber";
115 $num_nobarcode_inhostfield++;
120 sub print_progress_and_commit {
123 print "... processed $recs records\n";
128 $0: establish relationship to host items
130 Based on barcode in host field populates subfield 0 with host biblionumber and subfield 9 with host itemnumber.
132 Subfield 0 and 9 are used in Koha screns to display relationships between analytical records and host bibs and items.
134 NOT usable with UNIMARC data. You can use it only if you have tag 461 with also an items id (like barcode or item numbers). In UNIMARC this situation is very rare. If you have data coded in this way, send a mail to koha-dev mailing list and ask for the feature.
137 --run-update run the synchronization
138 --where condition selects the biblios on a criterium (Repeatable)
139 --help or -h show this message.