4 #use warnings; FIXME - Bug 2505
8 use C4::Biblio qw( ModBiblio );
11 use Getopt::Long qw( GetOptions );
15 # command-line parameters
20 my $result = GetOptions(
21 'run-update' => \$do_update,
22 'where=s@' => \$wherestrings,
23 'h|help' => \$want_help,
26 if (not $result or $want_help or not $do_update) {
31 my $num_bibs_processed = 0;
32 my $num_bibs_modified = 0;
33 my $num_noitem_forbarcode = 0;
34 my $num_nobarcode_inhostfield =0;
35 my $num_hostfields_unabletomodify =0;
37 my $dbh = C4::Context->dbh;
38 $dbh->{AutoCommit} = 0;
46 my $sql = "SELECT biblionumber FROM biblio JOIN biblioitems USING (biblionumber)";
47 $sql.="WHERE ". join(" AND ",@$wherestrings) if ($wherestrings);
48 $sql.="ORDER BY biblionumber ASC";
49 my $sth = $dbh->prepare($sql);
50 eval{$sth->execute();};
51 if ($@){ die "error $@";};
52 while (my ($biblionumber) = $sth->fetchrow_array()) {
53 $num_bibs_processed++;
54 process_bib($biblionumber);
56 if (($num_bibs_processed % 100) == 0) {
57 print_progress_and_commit($num_bibs_processed);
65 Create Analytical records relationships report
66 -----------------------------------------------
67 Number of bibs checked: $num_bibs_processed
68 Number of bibs modified: $num_bibs_modified
69 Number of hostfields with no barcodes: $num_nobarcode_inhostfield
70 Number of barcodes not found: $num_noitem_forbarcode
71 Number of hostfields unable to modify: $num_hostfields_unabletomodify
72 Number of bibs with errors: $num_bad_bibs
77 my $biblionumber = shift;
79 my $biblio = Koha::Biblios->find($biblionumber);
80 my $record = $biblio->metadata->record;
81 unless (defined $record) {
82 print "\nCould not retrieve bib $biblionumber from the database - record is corrupt.\n";
86 #loop through each host field and populate subfield 0 and 9
87 my $analyticfield = '773';
88 foreach my $hostfield ( $record->field($analyticfield) ) {
89 if(my $barcode = $hostfield->subfield('o')){
90 my $item = Koha::Items->find({ barcode => $barcode });
93 if ( $hostfield->subfield('0') ne $biblionumber ) {
94 $hostfield->update( '0', $biblionumber );
97 if ( $hostfield->subfield('9') ne $item->itemnumber ) {
98 $hostfield->update( '9', $item->itemnumber );
102 $num_bibs_modified++;
103 my $modresult = ModBiblio( $record, $biblionumber, '' );
104 warn "Modifying biblio $biblionumber";
106 warn "Unable to modify biblio $biblionumber with update host field";
107 $num_hostfields_unabletomodify++;
112 warn "No item record found for barcode $barcode";
113 $num_noitem_forbarcode++;
116 warn "No barcode in host field for biblionumber $biblionumber";
117 $num_nobarcode_inhostfield++;
122 sub print_progress_and_commit {
125 print "... processed $recs records\n";
130 $0: establish relationship to host items
132 Based on barcode in host field populates subfield 0 with host biblionumber and subfield 9 with host itemnumber.
134 Subfield 0 and 9 are used in Koha screns to display relationships between analytical records and host bibs and items.
136 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.
139 --run-update run the synchronization
140 --where condition selects the biblios on a criterium (Repeatable)
141 --help or -h show this message.