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

(-)a/misc/maintenance/search_for_data_inconsistencies.pl (-21 / +30 lines)
Lines 127-167 use Koha::ItemTypes; Link Here
127
    my $frameworks = Koha::BiblioFrameworks->search;
127
    my $frameworks = Koha::BiblioFrameworks->search;
128
    my $invalid_locations_per_framework;
128
    my $invalid_locations_per_framework;
129
    while ( my $framework = $frameworks->next ) {
129
    while ( my $framework = $frameworks->next ) {
130
        my $avs = Koha::AuthorisedValues->search_by_koha_field(
130
        my $msss = Koha::MarcSubfieldStructures->search({ frameworkcode => $framework->frameworkcode, authorised_value => { '!=' => [ -and => ( undef, '' ) ]} });
131
            {
131
        while ( my $mss = $msss->next ) {
132
                frameworkcode => $framework->frameworkcode,
132
            my $kohafield = $mss->kohafield;
133
                kohafield     => 'items.location'
133
            next if grep {/$kohafield/} qw( branches itemtypes cn_source ); # internal categories
134
            my $avs = Koha::AuthorisedValues->search_by_koha_field(
135
                {
136
                    frameworkcode => $framework->frameworkcode,
137
                    kohafield     => $kohafield,
138
                }
139
            );
140
            (my $tmp_kohafield = $kohafield) =~ s|items|me|; # replace items.attr with me.attr
141
            my $items = Koha::Items->search(
142
                {
143
                    $tmp_kohafield =>
144
                      { -not_in => [ $avs->get_column('authorised_value') ] },
145
                    'biblio.frameworkcode' => $framework->frameworkcode
146
                },
147
                { join => [ 'biblioitem', 'biblio' ] }
148
            );
149
            if ( $items->count ) {
150
                $invalid_locations_per_framework->{ $framework->frameworkcode } =
151
                  { items => $items, av_category => $mss->authorised_value, kohafield => $kohafield };
134
            }
152
            }
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
        }
153
        }
148
    }
154
    }
149
    if (%$invalid_locations_per_framework) {
155
    if (%$invalid_locations_per_framework) {
150
        new_section('Wrong value dor items.location');
156
        new_section('Wrong values linked to authorised values');
151
        for my $frameworkcode ( keys %$invalid_locations_per_framework ) {
157
        for my $frameworkcode ( keys %$invalid_locations_per_framework ) {
152
            my $output;
158
            my $output;
153
            my $items =
159
            my $items =
154
              $invalid_locations_per_framework->{$frameworkcode}->{items};
160
              $invalid_locations_per_framework->{$frameworkcode}->{items};
155
            my $av_category =
161
            my $av_category =
156
              $invalid_locations_per_framework->{$frameworkcode}->{av_category};
162
              $invalid_locations_per_framework->{$frameworkcode}->{av_category};
163
            my $kohafield =
164
              $invalid_locations_per_framework->{$frameworkcode}->{kohafield};
165
            my ( $table, $column ) = split '\.', $kohafield;
157
            while ( my $i = $items->next ) {
166
            while ( my $i = $items->next ) {
158
                $output .= " {" . $i->itemnumber . " => " . $i->location . "}";
167
                my $value = $table eq 'items' ? $i->$column : $i->biblioitem->$column;
168
                $output .= " {" . $i->itemnumber . " => " . $value . "}";
159
            }
169
            }
160
            new_item(
170
            new_item(
161
                sprintf(
171
                sprintf(
162
                    "The Framework *%s* is using the authorised value's category *%s*, "
172
                    "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",
173
                    . "but the following %s do not have a value defined ({itemnumber => value }):\n%s",
164
                    $frameworkcode, $av_category, $output
174
                    $frameworkcode, $av_category, $kohafield, $output
165
                )
175
                )
166
            );
176
            );
167
        }
177
        }
168
- 

Return to bug 21466