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

(-)a/Koha/Database/DataInconsistency.pm (+42 lines)
Line 0 Link Here
1
package Koha::Database::DataInconsistency;
2
3
use Modern::Perl;
4
use Koha::I18N qw( __x );
5
6
sub item_library {
7
    my ( $self, $items ) = @_;
8
9
    $items = $items->search( { -or => { homebranch => undef, holdingbranch => undef } } );
10
    my @errors;
11
    while ( my $item = $items->next ) {
12
        if ( not $item->homebranch and not $item->holdingbranch ) {
13
            push @errors,
14
                __x(
15
                "Item with itemnumber={itemnumber} does not have homebranch and holdingbranch defined",
16
                itemnumber => $item->itemnumber
17
                );
18
        } elsif ( not $item->homebranch ) {
19
            push @errors,
20
                __x(
21
                "Item with itemnumber={itemnumber} does not have homebranch defined",
22
                itemnumber => $item->itemnumber
23
                );
24
        } else {
25
            push @errors,
26
                __x(
27
                "Item with itemnumber={itemnumber} does not have holdingbranch defined",
28
                itemnumber => $item->itemnumber
29
                );
30
        }
31
    }
32
    return @errors;
33
}
34
35
sub for_biblio {
36
    my ( $self, $biblio ) = @_;
37
    my @errors;
38
    push @errors, $self->item_library( $biblio->items );
39
    return @errors;
40
}
41
42
1;
(-)a/misc/maintenance/search_for_data_inconsistencies.pl (-14 / +8 lines)
Lines 27-49 use Koha::Items; Link Here
27
use Koha::ItemTypes;
27
use Koha::ItemTypes;
28
use Koha::Patrons;
28
use Koha::Patrons;
29
use C4::Biblio qw( GetMarcFromKohaField );
29
use C4::Biblio qw( GetMarcFromKohaField );
30
use Koha::Database::DataInconsistency;
30
31
31
{
32
{
32
    my $items = Koha::Items->search( { -or => { homebranch => undef, holdingbranch => undef } } );
33
    my $items  = Koha::Items->search;
33
    if ( $items->count ) { new_section("Not defined items.homebranch and/or items.holdingbranch") }
34
    my @errors = Koha::Database::DataInconsistency->item_library($items);
34
    while ( my $item = $items->next ) {
35
    if (@errors) {
35
        if ( not $item->homebranch and not $item->holdingbranch ) {
36
        new_section("Not defined items.homebranch and/or items.holdingbranch");
36
            new_item(
37
        for my $error (@errors) {
37
                sprintf "Item with itemnumber=%s does not have homebranch and holdingbranch defined",
38
            new_item($error);
38
                $item->itemnumber
39
            );
40
        } elsif ( not $item->homebranch ) {
41
            new_item( sprintf "Item with itemnumber=%s does not have homebranch defined", $item->itemnumber );
42
        } else {
43
            new_item( sprintf "Item with itemnumber=%s does not have holdingbranch defined", $item->itemnumber );
44
        }
39
        }
45
    }
40
    }
46
    if ( $items->count ) { new_hint("Edit these items and set valid homebranch and/or holdingbranch") }
41
    if (@errors) { new_hint("Edit these items and set valid homebranch and/or holdingbranch") }
47
}
42
}
48
43
49
{
44
{
50
- 

Return to bug 40777