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

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

Return to bug 21466