X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=admin%2Fcheckmarc.pl;h=432078d4ab6d6c565c01b5177c29dc1dad356ee1;hb=4dc05803d5ff64494ca4924078f10dac23814455;hp=2469f91d784aabaa1fd0887b7b29a31f2bc13add;hpb=5e44e797eb9e685339971f17f1b76291b3b32c38;p=koha.git diff --git a/admin/checkmarc.pl b/admin/checkmarc.pl index 2469f91d78..432078d4ab 100755 --- a/admin/checkmarc.pl +++ b/admin/checkmarc.pl @@ -20,18 +20,16 @@ use strict; use C4::Output; -use C4::Interface::CGI::Output; use C4::Auth; use CGI; -use C4::Search; use C4::Context; use C4::Biblio; -use HTML::Template; + my $input = new CGI; my ($template, $borrowernumber, $cookie) - = get_template_and_user({template_name => "parameters/checkmarc.tmpl", + = get_template_and_user({template_name => "admin/checkmarc.tmpl", query => $input, type => "intranet", authnotrequired => 0, @@ -40,46 +38,67 @@ my ($template, $borrowernumber, $cookie) }); my $dbh = C4::Context->dbh; -my $total; +my $total = 0; # checks itemnum field my $sth = $dbh->prepare("select tab from marc_subfield_structure where kohafield=\"items.itemnumber\""); $sth->execute; -my ($res) = $sth->fetchrow; -if ($res==-1) { - $template->param(itemnum => 0); -} else { - $template->param(itemnum => 1); - $total++; +while (my ($res) = $sth->fetchrow) { + if ($res==-1) { + $template->param(itemnum => 0); + } else { + $template->param(itemnum => 1); + $total++; + last; + } } # checks biblio.biblionumber and biblioitem.biblioitemnumber (same tag and tab=-1) -$sth = $dbh->prepare("select tagfield,tab from marc_subfield_structure where kohafield=\"biblio.biblionumber\""); -$sth->execute; -my $tab; -($res,$tab) = $sth->fetchrow; -$sth = $dbh->prepare("select tagfield,tab from marc_subfield_structure where kohafield=\"biblioitems.biblioitemnumber\""); +$sth = $dbh->prepare("select tagfield,tab,frameworkcode from marc_subfield_structure where kohafield=\"biblio.biblionumber\""); $sth->execute; -my ($res2,$tab2) = $sth->fetchrow; -if ($res && $res2 && ($res eq $res2) && $tab==-1 && $tab2==-1) { - $template->param(biblionumber => 0); -} else { - $template->param(biblionumber => 1); - $total++; +my $first = 1; +my $bibliotag = ''; +while (my ($res,$tab,$frameworkcode) = $sth->fetchrow) { + if ($first) { + $bibliotag = $res; + $first = 0; + } else { + if ($bibliotag != $res) { + $template->param(biblionumber => 1); + $total++; + last; + } + } + my $sth2 = $dbh->prepare("SELECT tagfield,tab + FROM marc_subfield_structure + WHERE kohafield=\"biblioitems.biblioitemnumber\" + AND frameworkcode = ? "); + $sth2->execute($frameworkcode); + my ($res2,$tab2) = $sth2->fetchrow; + if ($res && $res2 && $tab==-1 && $tab2==-1) { + $template->param(biblionumber => 0); + } else { + $template->param(biblionumber => 1); + $total++; + last; + } } # checks all item fields are in the same tag and in tab 10 -$sth = $dbh->prepare("select tagfield,tab,kohafield from marc_subfield_structure where kohafield like \"items.%\""); +$sth = $dbh->prepare("select tagfield,tab,kohafield from marc_subfield_structure where kohafield like \"items.%\" and tab >=0"); $sth->execute; my $field; +my $res; +my $res2; +my $tab; ($res,$res2,$field) = $sth->fetchrow; my $tagfield = $res; -my $tab = $res2; +$tab = $res2; my $subtotal=0; -warn "TAGF : $tagfield"; +#warn "TAGF : $tagfield"; while (($res,$res2,$field) = $sth->fetchrow) { # (ignore itemnumber, that must be in -1 tab) - if (($res ne $tagfield or $res2 ne $tab ) && $res2 ne -1) { + if (($res ne $tagfield) or ($res2 ne $tab)) { $subtotal++; } } @@ -91,7 +110,7 @@ while (($res2) = $sth->fetchrow) { $subtotal++; } } -if ($subtotal eq 0) { +if ($subtotal == 0) { $template->param(itemfields => 0); } else { $template->param(itemfields => 1); @@ -117,59 +136,63 @@ if ($totaltags > 1) { # checks biblioitems.itemtype must be mapped and use authorised_value=itemtype $sth = $dbh->prepare("select tagfield,tab,authorised_value from marc_subfield_structure where kohafield = \"biblioitems.itemtype\""); $sth->execute; -($res,$res2,$field) = $sth->fetchrow; -if ($res && $res2>=0 && $field eq "itemtypes") { - $template->param(itemtype => 0); -} else { - $template->param(itemtype => 1); - $total++; +while (($res,$res2,$field) = $sth->fetchrow) { + if ($res && $res2>=0 && $field eq "itemtypes") { + $template->param(itemtype => 0); + } else { + $template->param(itemtype => 1); + $total++; + last; + } } # checks items.homebranch must be mapped and use authorised_value=branches $sth = $dbh->prepare("select tagfield,tab,authorised_value from marc_subfield_structure where kohafield = \"items.homebranch\""); $sth->execute; -($res,$res2,$field) = $sth->fetchrow; -if ($res && $res2 eq 10 && $field eq "branches") { - $template->param(branch => 0); -} else { - $template->param(branch => 1); - $total++; +while (($res,$res2,$field) = $sth->fetchrow) { + if ($res && $res2 eq 10 && $field eq "branches") { + $template->param(branch => 0); + } else { + $template->param(branch => 1); + $total++; + last; + } } + # checks items.homebranch must be mapped and use authorised_value=branches $sth = $dbh->prepare("select tagfield,tab,authorised_value from marc_subfield_structure where kohafield = \"items.holdingbranch\""); $sth->execute; -($res,$res2,$field) = $sth->fetchrow; -if ($res && $res2 eq 10 && $field eq "branches") { - $template->param(holdingbranch => 0); -} else { - $template->param(holdingbranch => 1); - $total++; +while (($res,$res2,$field) = $sth->fetchrow) { + if ($res && $res2 eq 10 && $field eq "branches") { + $template->param(holdingbranch => 0); + } else { + $template->param(holdingbranch => 1); + $total++; + } } # checks that itemtypes & branches tables are not empty $sth = $dbh->prepare("select count(*) from itemtypes"); $sth->execute; ($res) = $sth->fetchrow; -unless ($res) { +if ($res) { + $template->param(itemtypes_empty =>0); +} else { $template->param(itemtypes_empty =>1); $total++; } + $sth = $dbh->prepare("select count(*) from branches"); $sth->execute; ($res) = $sth->fetchrow; -unless ($res) { +if ($res) { + $template->param(branches_empty =>0); +} else { $template->param(branches_empty =>1); $total++; } -$sth = $dbh->prepare("select count(*) from marc_biblio where frameworkcode is NULL"); -$sth->execute; -($res) = $sth->fetchrow; -if ($res) { - $template->param(frameworknull =>1); - $total++; -} $sth = $dbh->prepare("select count(*) from marc_subfield_structure where frameworkcode is NULL"); $sth->execute; ($res) = $sth->fetchrow; @@ -185,5 +208,41 @@ if ($res) { $total++; } -$template->param(total => $total); +# verify that all of a field's subfields (except the ones explicitly ignored) +# are in the same tab +$sth = $dbh->prepare("SELECT tagfield, frameworkcode, frameworktext, GROUP_CONCAT(DISTINCT tab) AS tabs + FROM marc_subfield_structure + LEFT JOIN biblio_framework USING (frameworkcode) + WHERE tab != -1 + GROUP BY tagfield, frameworkcode, frameworktext + HAVING COUNT(DISTINCT tab) > 1"); +$sth->execute; +my $inconsistent_tabs = $sth->fetchall_arrayref({}); +if (scalar(@$inconsistent_tabs) > 0) { + $total++; + $template->param(inconsistent_tabs => 1); + $template->param(tab_info => $inconsistent_tabs); +} + +# verify that authtypecodes used in the framework +# are defined in auth_types +$sth = $dbh->prepare("SELECT frameworkcode, frameworktext, tagfield, tagsubfield, authtypecode + FROM marc_subfield_structure + LEFT JOIN biblio_framework USING (frameworkcode) + WHERE authtypecode IS NOT NULL + AND authtypecode <> '' + AND tab > '-1' + AND authtypecode NOT IN (SELECT authtypecode FROM auth_types) + ORDER BY frameworkcode, tagfield, tagsubfield"); +$sth->execute; +my $invalid_authtypecodes = $sth->fetchall_arrayref({}); +if (scalar(@$invalid_authtypecodes) > 0) { + $total++; + $template->param(invalid_authtypecodes => 1); + $template->param(authtypecode_info => $invalid_authtypecodes); +} + +$template->param(total => $total, + ); + output_html_with_http_headers $input, $cookie, $template->output;