|
Lines 31-42
use Koha::Database::DataInconsistency;
Link Here
|
| 31 |
|
31 |
|
| 32 |
{ |
32 |
{ |
| 33 |
my $items = Koha::Items->search; |
33 |
my $items = Koha::Items->search; |
| 34 |
my @errors = Koha::Database::DataInconsistency->item_library($items); |
34 |
my @errors = Koha::Database::DataInconsistency->invalid_item_library($items); |
| 35 |
if (@errors) { |
35 |
if (@errors) { |
| 36 |
new_section("Not defined items.homebranch and/or items.holdingbranch"); |
36 |
new_section("Not defined items.homebranch and/or items.holdingbranch"); |
| 37 |
for my $error (@errors) { |
37 |
new_item($_) for @errors; |
| 38 |
new_item($error); |
|
|
| 39 |
} |
| 40 |
} |
38 |
} |
| 41 |
if (@errors) { new_hint("Edit these items and set valid homebranch and/or holdingbranch") } |
39 |
if (@errors) { new_hint("Edit these items and set valid homebranch and/or holdingbranch") } |
| 42 |
} |
40 |
} |
|
Lines 56-325
use Koha::Database::DataInconsistency;
Link Here
|
| 56 |
} |
54 |
} |
| 57 |
|
55 |
|
| 58 |
{ |
56 |
{ |
| 59 |
if ( C4::Context->preference('item-level_itypes') ) { |
57 |
my $biblios = Koha::Biblios->search; |
| 60 |
my $items_without_itype = Koha::Items->search( { -or => [ itype => undef, itype => '' ] } ); |
58 |
my @errors = Koha::Database::DataInconsistency->no_item_type($biblios); |
| 61 |
if ( $items_without_itype->count ) { |
59 |
if (@errors) { |
|
|
60 |
if ( C4::Context->preference('item-level_itypes') ) { |
| 62 |
new_section("Items do not have itype defined"); |
61 |
new_section("Items do not have itype defined"); |
| 63 |
while ( my $item = $items_without_itype->next ) { |
62 |
new_item($_) for @errors; |
| 64 |
if ( defined $item->biblioitem->itemtype && $item->biblioitem->itemtype ne '' ) { |
|
|
| 65 |
new_item( |
| 66 |
sprintf |
| 67 |
"Item with itemnumber=%s does not have a itype value, biblio's item type will be used (%s)", |
| 68 |
$item->itemnumber, $item->biblioitem->itemtype |
| 69 |
); |
| 70 |
} else { |
| 71 |
new_item( |
| 72 |
sprintf |
| 73 |
"Item with itemnumber=%s does not have a itype value, additionally no item type defined for biblionumber=%s", |
| 74 |
$item->itemnumber, $item->biblioitem->biblionumber |
| 75 |
); |
| 76 |
} |
| 77 |
} |
| 78 |
new_hint("The system preference item-level_itypes expects item types to be defined at item level"); |
63 |
new_hint("The system preference item-level_itypes expects item types to be defined at item level"); |
| 79 |
} |
64 |
} else { |
| 80 |
} else { |
|
|
| 81 |
my $biblioitems_without_itemtype = Koha::Biblioitems->search( { itemtype => undef } ); |
| 82 |
if ( $biblioitems_without_itemtype->count ) { |
| 83 |
new_section("Biblioitems do not have itemtype defined"); |
65 |
new_section("Biblioitems do not have itemtype defined"); |
| 84 |
while ( my $biblioitem = $biblioitems_without_itemtype->next ) { |
66 |
new_item($_) for @errors; |
| 85 |
new_item( |
|
|
| 86 |
sprintf "Biblioitem with biblioitemnumber=%s does not have a itemtype value", |
| 87 |
$biblioitem->biblioitemnumber |
| 88 |
); |
| 89 |
} |
| 90 |
new_hint("The system preference item-level_itypes expects item types to be defined at biblio level"); |
67 |
new_hint("The system preference item-level_itypes expects item types to be defined at biblio level"); |
| 91 |
} |
68 |
} |
| 92 |
} |
69 |
} |
| 93 |
|
70 |
|
| 94 |
my @itemtypes = Koha::ItemTypes->search->get_column('itemtype'); |
71 |
$biblios = Koha::Biblios->search; |
| 95 |
if ( C4::Context->preference('item-level_itypes') ) { |
72 |
@errors = Koha::Database::DataInconsistency->invalid_item_type($biblios); |
| 96 |
my $items_with_invalid_itype = |
73 |
if (@errors) { |
| 97 |
Koha::Items->search( { -and => [ itype => { not_in => \@itemtypes }, itype => { '!=' => '' } ] } ); |
74 |
if ( C4::Context->preference('item-level_itypes') ) { |
| 98 |
if ( $items_with_invalid_itype->count ) { |
|
|
| 99 |
new_section("Items have invalid itype defined"); |
75 |
new_section("Items have invalid itype defined"); |
| 100 |
while ( my $item = $items_with_invalid_itype->next ) { |
76 |
new_item($_) for @errors; |
| 101 |
new_item( |
|
|
| 102 |
sprintf "Item with itemnumber=%s, biblionumber=%s does not have a valid itype value (%s)", |
| 103 |
$item->itemnumber, $item->biblionumber, $item->itype |
| 104 |
); |
| 105 |
} |
| 106 |
new_hint( |
77 |
new_hint( |
| 107 |
"The items must have a itype value that is defined in the item types of Koha (Home › Administration › Item types administration)" |
78 |
"The items must have a itype value that is defined in the item types of Koha (Home › Administration › Item types administration)" |
| 108 |
); |
79 |
); |
| 109 |
} |
80 |
} else { |
| 110 |
} else { |
|
|
| 111 |
my $biblioitems_with_invalid_itemtype = Koha::Biblioitems->search( { itemtype => { not_in => \@itemtypes } } ); |
| 112 |
if ( $biblioitems_with_invalid_itemtype->count ) { |
| 113 |
new_section("Biblioitems do not have itemtype defined"); |
81 |
new_section("Biblioitems do not have itemtype defined"); |
| 114 |
while ( my $biblioitem = $biblioitems_with_invalid_itemtype->next ) { |
82 |
new_item($_) for @errors; |
| 115 |
new_item( |
|
|
| 116 |
sprintf "Biblioitem with biblioitemnumber=%s does not have a valid itemtype value", |
| 117 |
$biblioitem->biblioitemnumber |
| 118 |
); |
| 119 |
} |
| 120 |
new_hint( |
83 |
new_hint( |
| 121 |
"The biblioitems must have a itemtype value that is defined in the item types of Koha (Home › Administration › Item types administration)" |
84 |
"The biblioitems must have a itemtype value that is defined in the item types of Koha (Home › Administration › Item types administration)" |
| 122 |
); |
85 |
); |
| 123 |
} |
86 |
} |
| 124 |
} |
87 |
} |
| 125 |
|
88 |
|
| 126 |
my @item_fields_in_marc; |
89 |
$biblios = Koha::Biblios->search; |
| 127 |
my ( $item_tag, $item_subfield ) = C4::Biblio::GetMarcFromKohaField("items.itemnumber"); |
90 |
my $errors = Koha::Database::DataInconsistency->errors_in_marc($biblios); |
| 128 |
my $search_string = q{ExtractValue(metadata,'count(//datafield[@tag="} . $item_tag . q{"])')>0}; |
91 |
if ( $errors && %$errors ) { |
| 129 |
my $biblio_metadatas_with_item_fields = Koha::Biblio::Metadatas->search( \$search_string ); |
92 |
if ( exists $errors->{decoding_errors} ) { |
| 130 |
if ( $biblio_metadatas_with_item_fields->count ) { |
93 |
new_section("Bibliographic records have invalid MARCXML"); |
| 131 |
while ( my $biblio_metadata_with_item_fields = $biblio_metadatas_with_item_fields->next ) { |
94 |
new_item($_) for @{ $errors->{decoding_errors} }; |
| 132 |
push @item_fields_in_marc, |
95 |
new_hint( |
| 133 |
{ |
96 |
"The bibliographic records must have a valid MARCXML or you will face encoding issues or wrong displays" |
| 134 |
biblionumber => $biblio_metadata_with_item_fields->biblionumber, |
97 |
); |
| 135 |
}; |
|
|
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
my ( @decoding_errors, @ids_not_in_marc ); |
| 140 |
my $biblios = Koha::Biblios->search; |
| 141 |
my ( $biblio_tag, $biblio_subfield ) = C4::Biblio::GetMarcFromKohaField("biblio.biblionumber"); |
| 142 |
my ( $biblioitem_tag, $biblioitem_subfield ) = C4::Biblio::GetMarcFromKohaField("biblioitems.biblioitemnumber"); |
| 143 |
while ( my $biblio = $biblios->next ) { |
| 144 |
my $record = eval { $biblio->metadata->record; }; |
| 145 |
if ($@) { |
| 146 |
push @decoding_errors, $@; |
| 147 |
next; |
| 148 |
} |
| 149 |
my ( $biblionumber, $biblioitemnumber ); |
| 150 |
if ( $biblio_tag < 10 ) { |
| 151 |
my $biblio_control_field = $record->field($biblio_tag); |
| 152 |
$biblionumber = $biblio_control_field->data if $biblio_control_field; |
| 153 |
} else { |
| 154 |
$biblionumber = $record->subfield( $biblio_tag, $biblio_subfield ); |
| 155 |
} |
| 156 |
if ( $biblioitem_tag < 10 ) { |
| 157 |
my $biblioitem_control_field = $record->field($biblioitem_tag); |
| 158 |
$biblioitemnumber = $biblioitem_control_field->data if $biblioitem_control_field; |
| 159 |
} else { |
| 160 |
$biblioitemnumber = $record->subfield( $biblioitem_tag, $biblioitem_subfield ); |
| 161 |
} |
| 162 |
if ( $biblionumber != $biblio->biblionumber ) { |
| 163 |
push @ids_not_in_marc, |
| 164 |
{ |
| 165 |
biblionumber => $biblio->biblionumber, |
| 166 |
biblionumber_in_marc => $biblionumber, |
| 167 |
}; |
| 168 |
} |
| 169 |
if ( $biblioitemnumber != $biblio->biblioitem->biblioitemnumber ) { |
| 170 |
push @ids_not_in_marc, |
| 171 |
{ |
| 172 |
biblionumber => $biblio->biblionumber, |
| 173 |
biblioitemnumber => $biblio->biblioitem->biblioitemnumber, |
| 174 |
biblioitemnumber_in_marc => $biblionumber, |
| 175 |
}; |
| 176 |
} |
98 |
} |
| 177 |
} |
99 |
if ( exists $errors->{ids_not_in_marc} ) { |
| 178 |
if (@decoding_errors) { |
100 |
new_section("Bibliographic records have MARCXML without biblionumber or biblioitemnumber"); |
| 179 |
new_section("Bibliographic records have invalid MARCXML"); |
101 |
new_item($_) for @{ $errors->{ids_not_in_marc} }; |
| 180 |
new_item($_) for @decoding_errors; |
102 |
new_hint("The bibliographic records must have the biblionumber and biblioitemnumber in MARCXML"); |
| 181 |
new_hint( |
|
|
| 182 |
"The bibliographic records must have a valid MARCXML or you will face encoding issues or wrong displays"); |
| 183 |
} |
| 184 |
if (@ids_not_in_marc) { |
| 185 |
new_section("Bibliographic records have MARCXML without biblionumber or biblioitemnumber"); |
| 186 |
for my $id (@ids_not_in_marc) { |
| 187 |
if ( exists $id->{biblioitemnumber} ) { |
| 188 |
new_item( |
| 189 |
sprintf( |
| 190 |
q{Biblionumber %s has biblioitemnumber '%s' but should be '%s' in %s$%s}, |
| 191 |
$id->{biblionumber}, |
| 192 |
$id->{biblioitemnumber}, |
| 193 |
$id->{biblioitemnumber_in_marc}, |
| 194 |
$biblioitem_tag, |
| 195 |
$biblioitem_subfield, |
| 196 |
) |
| 197 |
); |
| 198 |
} else { |
| 199 |
new_item( |
| 200 |
sprintf( |
| 201 |
q{Biblionumber %s has '%s' in %s$%s}, |
| 202 |
$id->{biblionumber}, |
| 203 |
$id->{biblionumber_in_marc}, |
| 204 |
$biblio_tag, |
| 205 |
$biblio_subfield, |
| 206 |
) |
| 207 |
); |
| 208 |
} |
| 209 |
} |
103 |
} |
| 210 |
new_hint("The bibliographic records must have the biblionumber and biblioitemnumber in MARCXML"); |
104 |
if ( exists $errors->{item_fields_in_marc} ) { |
| 211 |
} |
105 |
new_section("Bibliographic records have item fields in the MARC"); |
| 212 |
if (@item_fields_in_marc) { |
106 |
new_item($_) for @{ $errors->{item_fields_in_marc} }; |
| 213 |
new_section("Bibliographic records have item fields in the MARC"); |
107 |
new_hint("You can fix these by running misc/maintenance/touch_all_biblios.pl"); |
| 214 |
for my $biblionumber (@item_fields_in_marc) { |
|
|
| 215 |
new_item( |
| 216 |
sprintf( |
| 217 |
q{Biblionumber %s has item fields (%s) in the marc record}, |
| 218 |
$biblionumber->{biblionumber}, |
| 219 |
$item_tag, |
| 220 |
) |
| 221 |
); |
| 222 |
} |
108 |
} |
| 223 |
new_hint("You can fix these by running misc/maintenance/touch_all_biblios.pl"); |
|
|
| 224 |
} |
109 |
} |
| 225 |
} |
110 |
} |
| 226 |
|
111 |
|
| 227 |
{ |
112 |
{ |
| 228 |
my @framework_codes = Koha::BiblioFrameworks->search()->get_column('frameworkcode'); |
113 |
my $biblios = Koha::Biblios->search; |
| 229 |
push @framework_codes, ""; # The default is not stored in frameworks, we need to force it |
114 |
my @errors = Koha::Database::DataInconsistency->nonexistent_AV($biblios); |
| 230 |
|
115 |
if (@errors) { |
| 231 |
my $invalid_av_per_framework = {}; |
|
|
| 232 |
foreach my $frameworkcode (@framework_codes) { |
| 233 |
|
| 234 |
# We are only checking fields that are mapped to DB fields |
| 235 |
my $msss = Koha::MarcSubfieldStructures->search( |
| 236 |
{ |
| 237 |
frameworkcode => $frameworkcode, |
| 238 |
authorised_value => { '!=' => [ -and => ( undef, '' ) ] }, |
| 239 |
kohafield => { '!=' => [ -and => ( undef, '' ) ] } |
| 240 |
} |
| 241 |
); |
| 242 |
while ( my $mss = $msss->next ) { |
| 243 |
my $kohafield = $mss->kohafield; |
| 244 |
my $av = $mss->authorised_value; |
| 245 |
next if grep { $_ eq $av } qw( branches itemtypes cn_source ); # internal categories |
| 246 |
|
| 247 |
my $avs = Koha::AuthorisedValues->search_by_koha_field( |
| 248 |
{ |
| 249 |
frameworkcode => $frameworkcode, |
| 250 |
kohafield => $kohafield, |
| 251 |
} |
| 252 |
); |
| 253 |
my $tmp_kohafield = $kohafield; |
| 254 |
if ( $tmp_kohafield =~ /^biblioitems/ ) { |
| 255 |
$tmp_kohafield =~ s|biblioitems|biblioitem|; |
| 256 |
} else { |
| 257 |
$tmp_kohafield =~ s|items|me|; |
| 258 |
} |
| 259 |
|
| 260 |
# replace items.attr with me.attr |
| 261 |
|
| 262 |
# We are only checking biblios with items |
| 263 |
my $items = Koha::Items->search( |
| 264 |
{ |
| 265 |
$tmp_kohafield => { |
| 266 |
-not_in => [ $avs->get_column('authorised_value'), '' ], |
| 267 |
'!=' => undef, |
| 268 |
}, |
| 269 |
'biblio.frameworkcode' => $frameworkcode |
| 270 |
}, |
| 271 |
{ join => [ 'biblioitem', 'biblio' ] } |
| 272 |
); |
| 273 |
if ( $items->count ) { |
| 274 |
$invalid_av_per_framework->{$frameworkcode}->{$av} = |
| 275 |
{ items => $items, kohafield => $kohafield }; |
| 276 |
} |
| 277 |
} |
| 278 |
} |
| 279 |
if (%$invalid_av_per_framework) { |
| 280 |
new_section('Wrong values linked to authorised values'); |
116 |
new_section('Wrong values linked to authorised values'); |
| 281 |
for my $frameworkcode ( keys %$invalid_av_per_framework ) { |
117 |
new_item($_) for @errors; |
| 282 |
while ( my ( $av_category, $v ) = each %{ $invalid_av_per_framework->{$frameworkcode} } ) { |
|
|
| 283 |
my $items = $v->{items}; |
| 284 |
my $kohafield = $v->{kohafield}; |
| 285 |
my ( $table, $column ) = split '\.', $kohafield; |
| 286 |
my $output; |
| 287 |
while ( my $i = $items->next ) { |
| 288 |
my $value = |
| 289 |
$table eq 'items' ? $i->$column |
| 290 |
: $table eq 'biblio' ? $i->biblio->$column |
| 291 |
: $i->biblioitem->$column; |
| 292 |
$output .= " {" . $i->itemnumber . " => " . $value . "}\n"; |
| 293 |
} |
| 294 |
new_item( |
| 295 |
sprintf( |
| 296 |
"The Framework *%s* is using the authorised value's category *%s*, " |
| 297 |
. "but the following %s do not have a value defined ({itemnumber => value }):\n%s", |
| 298 |
$frameworkcode, $av_category, $kohafield, $output |
| 299 |
) |
| 300 |
); |
| 301 |
} |
| 302 |
} |
| 303 |
} |
118 |
} |
| 304 |
} |
119 |
} |
| 305 |
|
120 |
|
| 306 |
{ |
121 |
{ |
| 307 |
my $biblios = Koha::Biblios->search( |
122 |
my $biblios = Koha::Biblios->search; |
| 308 |
{ |
123 |
my @errors = Koha::Database::DataInconsistency->empty_title($biblios); |
| 309 |
-or => [ |
124 |
if (@errors) { |
| 310 |
title => '', |
|
|
| 311 |
title => undef, |
| 312 |
] |
| 313 |
} |
| 314 |
); |
| 315 |
if ( $biblios->count ) { |
| 316 |
my ( $title_tag, $title_subtag ) = C4::Biblio::GetMarcFromKohaField('biblio.title'); |
125 |
my ( $title_tag, $title_subtag ) = C4::Biblio::GetMarcFromKohaField('biblio.title'); |
| 317 |
my $title_field = $title_tag // ''; |
126 |
my $title_field = $title_tag // ''; |
| 318 |
$title_field .= '$' . $title_subtag if $title_subtag; |
127 |
$title_field .= '$' . $title_subtag if $title_subtag; |
| 319 |
new_section("Biblio without title $title_field"); |
128 |
new_section("Biblio without title $title_field"); |
| 320 |
while ( my $biblio = $biblios->next ) { |
129 |
new_item($_) for @errors; |
| 321 |
new_item( sprintf "Biblio with biblionumber=%s does not have title defined", $biblio->biblionumber ); |
|
|
| 322 |
} |
| 323 |
new_hint("Edit these bibliographic records to define a title"); |
130 |
new_hint("Edit these bibliographic records to define a title"); |
| 324 |
} |
131 |
} |
| 325 |
} |
132 |
} |
| 326 |
- |
|
|