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

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

Return to bug 21466