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

(-)a/misc/maintenance/search_for_data_inconsistencies.pl (-3 / +49 lines)
Lines 17-26 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Koha::Items;
20
use Koha::AuthorisedValues;
21
use Koha::Authorities;
22
use Koha::BiblioFrameworks;
21
use Koha::Biblioitems;
23
use Koha::Biblioitems;
24
use Koha::Items;
22
use Koha::ItemTypes;
25
use Koha::ItemTypes;
23
use Koha::Authorities;
24
26
25
{
27
{
26
    my $items = Koha::Items->search({ -or => { homebranch => undef, holdingbranch => undef }});
28
    my $items = Koha::Items->search({ -or => { homebranch => undef, holdingbranch => undef }});
Lines 107-112 use Koha::Authorities; Link Here
107
    }
109
    }
108
}
110
}
109
111
112
{
113
    my $frameworks = Koha::BiblioFrameworks->search;
114
    my $invalid_locations_per_framework;
115
    while ( my $framework = $frameworks->next ) {
116
        my $avs = Koha::AuthorisedValues->search_by_koha_field(
117
            {
118
                frameworkcode => $framework->frameworkcode,
119
                kohafield     => 'items.location'
120
            }
121
        );
122
        my $items = Koha::Items->search(
123
            {
124
                location =>
125
                  { -not_in => [ $avs->get_column('authorised_value') ] },
126
                'biblio.frameworkcode' => $framework->frameworkcode
127
            },
128
            { join => [ 'biblioitem', 'biblio' ] }
129
        );
130
        if ( $items->count ) {
131
            $invalid_locations_per_framework->{ $framework->frameworkcode } =
132
              { items => $items, av_category => $avs->next->category, };
133
        }
134
    }
135
    if (%$invalid_locations_per_framework) {
136
        new_section('Wrong value dor items.location');
137
        for my $frameworkcode ( keys %$invalid_locations_per_framework ) {
138
            my $output;
139
            my $items =
140
              $invalid_locations_per_framework->{$frameworkcode}->{items};
141
            my $av_category =
142
              $invalid_locations_per_framework->{$frameworkcode}->{av_category};
143
            while ( my $i = $items->next ) {
144
                $output .= " {" . $i->itemnumber . " => " . $i->location . "}";
145
            }
146
            new_item(
147
                sprintf(
148
                    "The Framework *%s* is using the authorised value's category *%s*, "
149
                    . "but the following items.location do not have a value defined ({itemnumber => value }):\n%s",
150
                    $frameworkcode, $av_category, $output
151
                )
152
            );
153
        }
154
    }
155
}
156
110
sub new_section {
157
sub new_section {
111
    my ( $name ) = @_;
158
    my ( $name ) = @_;
112
    say "\n== $name ==";
159
    say "\n== $name ==";
113
- 

Return to bug 21466