View | Details | Raw Unified | Return to bug 21150
Collapse All | Expand All

(-)a/misc/maintenance/search_for_data_inconsistencies.pl (-1 / +65 lines)
Lines 18-23 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Koha::Items;
20
use Koha::Items;
21
use Koha::Biblioitems;
22
use Koha::ItemTypes;
21
use Koha::Authorities;
23
use Koha::Authorities;
22
24
23
{
25
{
Lines 46-51 use Koha::Authorities; Link Here
46
    if ( $authorities->count ) {new_hint("Go to 'Home › Administration › Authority types' to define them")}
48
    if ( $authorities->count ) {new_hint("Go to 'Home › Administration › Authority types' to define them")}
47
}
49
}
48
50
51
{
52
    if ( C4::Context->preference('item-level_itypes') ) {
53
        my $items_without_itype = Koha::Items->search( { itype => undef } );
54
        if ( $items_without_itype->count ) {
55
            new_section("Items do not have itype defined");
56
            while ( my $item = $items_without_itype->next ) {
57
                new_item(
58
                    sprintf "Item with itemnumber=%s does not have a itype value, biblio's item type will be used (%s)",
59
                    $item->itemnumber, $item->biblioitem->itemtype
60
                );
61
            }
62
            new_hint("The system preference item-level_itypes expects item types to be defined at item level");
63
        }
64
    }
65
    else {
66
        my $biblioitems_without_itemtype = Koha::Biblioitems->search( { itemtype => undef } );
67
        if ( $biblioitems_without_itemtype->count ) {
68
            new_section("Biblioitems do not have itemtype defined");
69
            while ( my $biblioitem = $biblioitems_without_itemtype->next ) {
70
                new_item(
71
                    sprintf "Biblioitem with biblioitemnumber=%s does not have a itemtype value",
72
                    $biblioitem->biblioitemnumber
73
                );
74
            }
75
            new_hint("The system preference item-level_itypes expects item types to be defined at biblio level");
76
        }
77
    }
78
79
    my @itemtypes = Koha::ItemTypes->search->get_column('itemtype');
80
    if ( C4::Context->preference('item-level_itypes') ) {
81
        my $items_with_invalid_itype = Koha::Items->search( { itype => { not_in => \@itemtypes } } );
82
        if ( $items_with_invalid_itype->count ) {
83
            new_section("Items have invalid itype defined");
84
            while ( my $item = $items_with_invalid_itype->next ) {
85
                new_item(
86
                    sprintf "Item with itemnumber=%s does not have a valid itype value (%s)",
87
                    $item->itemnumber, $item->itype
88
                );
89
            }
90
            new_hint("The items must have a itype value that is defined in the item types of Koha (Home › Administration › Item types administration)");
91
        }
92
    }
93
    else {
94
        my $biblioitems_with_invalid_itemtype = Koha::Biblioitems->search(
95
            { itemtype => { not_in => \@itemtypes } }
96
        );
97
        if ( $biblioitems_with_invalid_itemtype->count ) {
98
            new_section("Biblioitems do not have itemtype defined");
99
            while ( my $biblioitem = $biblioitems_with_invalid_itemtype->next ) {
100
                new_item(
101
                    sprintf "Biblioitem with biblioitemnumber=%s does not have a valid itemtype value",
102
                    $biblioitem->biblioitemnumber
103
                );
104
            }
105
            new_hint("The biblioitems must have a itemtype value that is defined in the item types of Koha (Home › Administration › Item types administration)");
106
        }
107
    }
108
}
109
49
sub new_section {
110
sub new_section {
50
    my ( $name ) = @_;
111
    my ( $name ) = @_;
51
    say "\n== $name ==";
112
    say "\n== $name ==";
Lines 74-78 Catch data inconsistencies in Koha database Link Here
74
135
75
* Items with undefined homebranch and/or holdingbranch
136
* Items with undefined homebranch and/or holdingbranch
76
* Authorities with undefined authtypecodes/authority types
137
* Authorities with undefined authtypecodes/authority types
138
* Item types:
139
  * if item types are defined at item level (item-level_itypes=specific item),
140
    then items.itype must be set else biblioitems.itemtype must be set
141
  * Item types defined in items or biblioitems must be defined in the itemtypes table
77
142
78
=cut
143
=cut
79
- 

Return to bug 21150