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

(-)a/C4/Items.pm (-22 / +22 lines)
Lines 1560-1583 sub PrepareItemrecordDisplay { Link Here
1560
}
1560
}
1561
1561
1562
sub ToggleNewStatus {
1562
sub ToggleNewStatus {
1563
    my ( $params ) = @_;
1563
    my ($params)    = @_;
1564
    my @rules = @{ $params->{rules} };
1564
    my @rules       = @{ $params->{rules} };
1565
    my $report_only = $params->{report_only};
1565
    my $report_only = $params->{report_only};
1566
1566
1567
    my $dbh = C4::Context->dbh;
1567
    my $dbh = C4::Context->dbh;
1568
    my @errors;
1568
    my @errors;
1569
    my @item_columns = map { "items.$_" } Koha::Items->columns;
1569
    my @item_columns       = map { "items.$_" } Koha::Items->columns;
1570
    my @biblioitem_columns = map { "biblioitems.$_" } Koha::Biblioitems->columns;
1570
    my @biblioitem_columns = map { "biblioitems.$_" } Koha::Biblioitems->columns;
1571
    my @biblio_columns = map { "biblio.$_" } Koha::Biblios->columns;
1571
    my @biblio_columns     = map { "biblio.$_" } Koha::Biblios->columns;
1572
    my $report;
1572
    my $report;
1573
    for my $rule ( @rules ) {
1573
    for my $rule (@rules) {
1574
        my $age = $rule->{age};
1574
        my $age = $rule->{age};
1575
1575
        # Default to using items.dateaccessioned if there's an old item modification rule
1576
        # Default to using items.dateaccessioned if there's an old item modification rule
1576
        # missing an agefield value
1577
        # missing an agefield value
1577
        my $agefield = $rule->{agefield} ? $rule->{agefield} : 'items.dateaccessioned';
1578
        my $agefield      = $rule->{agefield} ? $rule->{agefield} : 'items.dateaccessioned';
1578
        my $conditions = $rule->{conditions};
1579
        my $conditions    = $rule->{conditions};
1579
        my $substitutions = $rule->{substitutions};
1580
        my $substitutions = $rule->{substitutions};
1580
        foreach ( @$substitutions ) {
1581
        foreach (@$substitutions) {
1581
            ( $_->{item_field} ) = ( $_->{field} =~ /items\.(.*)/ );
1582
            ( $_->{item_field} ) = ( $_->{field} =~ /items\.(.*)/ );
1582
        }
1583
        }
1583
        my @params;
1584
        my @params;
Lines 1589-1606 sub ToggleNewStatus { Link Here
1589
            LEFT JOIN biblio ON biblio.biblionumber = biblioitems.biblionumber
1590
            LEFT JOIN biblio ON biblio.biblionumber = biblioitems.biblionumber
1590
            WHERE 1
1591
            WHERE 1
1591
        |;
1592
        |;
1592
        for my $condition ( @$conditions ) {
1593
        for my $condition (@$conditions) {
1593
            next unless $condition->{field};
1594
            next unless $condition->{field};
1594
            if (
1595
            if (   grep { $_ eq $condition->{field} } @item_columns
1595
                 grep { $_ eq $condition->{field} } @item_columns
1596
                or grep { $_ eq $condition->{field} } @biblioitem_columns
1596
              or grep { $_ eq $condition->{field} } @biblioitem_columns
1597
                or grep { $_ eq $condition->{field} } @biblio_columns )
1597
              or grep { $_ eq $condition->{field} } @biblio_columns
1598
            {
1598
            ) {
1599
                if ( $condition->{value} =~ /\|/ ) {
1599
                if ( $condition->{value} =~ /\|/ ) {
1600
                    my @values = split /\|/, $condition->{value};
1600
                    my @values = split /\|/, $condition->{value};
1601
                    $query .= qq| AND $condition->{field} IN (|
1601
                    $query .= qq| AND $condition->{field} IN (| . join( ',', ('?') x scalar @values ) . q|)|;
1602
                        . join( ',', ('?') x scalar @values )
1603
                        . q|)|;
1604
                    push @params, @values;
1602
                    push @params, @values;
1605
                } else {
1603
                } else {
1606
                    $query .= qq| AND $condition->{field} = ?|;
1604
                    $query .= qq| AND $condition->{field} = ?|;
Lines 1613-1628 sub ToggleNewStatus { Link Here
1613
            push @params, $age;
1611
            push @params, $age;
1614
        }
1612
        }
1615
        my $sth = $dbh->prepare($query);
1613
        my $sth = $dbh->prepare($query);
1616
        $sth->execute( @params );
1614
        $sth->execute(@params);
1617
        while ( my $values = $sth->fetchrow_hashref ) {
1615
        while ( my $values = $sth->fetchrow_hashref ) {
1618
            my $biblionumber = $values->{biblionumber};
1616
            my $biblionumber = $values->{biblionumber};
1619
            my $itemnumber = $values->{itemnumber};
1617
            my $itemnumber   = $values->{itemnumber};
1620
            my $item = Koha::Items->find($itemnumber);
1618
            my $item         = Koha::Items->find($itemnumber);
1621
            for my $substitution ( @$substitutions ) {
1619
            for my $substitution (@$substitutions) {
1622
                my $field = $substitution->{item_field};
1620
                my $field = $substitution->{item_field};
1623
                my $value = $substitution->{value};
1621
                my $value = $substitution->{value};
1624
                next unless $substitution->{field};
1622
                next unless $substitution->{field};
1625
                next if ( defined $values->{ $substitution->{item_field} } and $values->{ $substitution->{item_field} } eq $substitution->{value} );
1623
                next
1624
                    if ( defined $values->{ $substitution->{item_field} }
1625
                    and $values->{ $substitution->{item_field} } eq $substitution->{value} );
1626
                $item->$field($value);
1626
                $item->$field($value);
1627
                push @{ $report->{$itemnumber} }, $substitution;
1627
                push @{ $report->{$itemnumber} }, $substitution;
1628
            }
1628
            }
(-)a/t/db_dependent/Items/AutomaticItemModificationByAge.t (-4 / +4 lines)
Lines 46-54 $cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode"); Link Here
46
46
47
my $record = MARC::Record->new();
47
my $record = MARC::Record->new();
48
$record->append_fields(
48
$record->append_fields(
49
    MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'),
49
    MARC::Field->new( '100', ' ', ' ', a => 'Moffat, Steven' ),
50
    MARC::Field->new('245', ' ', ' ', a => 'Silence in the library', h => 'Book'),
50
    MARC::Field->new( '245', ' ', ' ', a => 'Silence in the library', h => 'Book' ),
51
    MARC::Field->new('942', ' ', ' ', c => 'ITEMTYPE_T'),
51
    MARC::Field->new( '942', ' ', ' ', c => 'ITEMTYPE_T' ),
52
);
52
);
53
my ($biblionumber, undef) = C4::Biblio::AddBiblio($record, $frameworkcode);
53
my ($biblionumber, undef) = C4::Biblio::AddBiblio($record, $frameworkcode);
54
54
Lines 344-350 is( $modified_item->new_status, 'agefield_new_value', q|ToggleNewStatus: Age = 2 Link Here
344
            {
344
            {
345
                field => 'items.new_status',
345
                field => 'items.new_status',
346
                value => 'new_updated_value_biblio',
346
                value => 'new_updated_value_biblio',
347
             },
347
            },
348
        ],
348
        ],
349
        age => '0',
349
        age => '0',
350
    },
350
    },
(-)a/tools/automatic_item_modification_by_age.pl (-9 / +11 lines)
Lines 114-130 if ( $@ ) { Link Here
114
    exit;
114
    exit;
115
}
115
}
116
116
117
my @item_fields = map { "items.$_" } Koha::Items->columns;
117
my @item_fields       = map { "items.$_" } Koha::Items->columns;
118
my @biblioitem_fields = map { "biblioitems.$_" } Koha::Biblioitems->columns;
118
my @biblioitem_fields = map { "biblioitems.$_" } Koha::Biblioitems->columns;
119
my @biblio_fields = map { "biblio.$_" } Koha::Biblios->columns;
119
my @biblio_fields     = map { "biblio.$_" } Koha::Biblios->columns;
120
my @age_fields = ('items.dateaccessioned', 'items.replacementpricedate', 'items.datelastborrowed', 'items.datelastseen', 'items.damaged_on', 'items.itemlost_on', 'items.withdrawn_on');
120
my @age_fields        = (
121
    'items.dateaccessioned', 'items.replacementpricedate', 'items.datelastborrowed', 'items.datelastseen',
122
    'items.damaged_on',      'items.itemlost_on',          'items.withdrawn_on'
123
);
121
$template->param(
124
$template->param(
122
    op => $op,
125
    op                  => $op,
123
    messages => \@messages,
126
    messages            => \@messages,
124
    agefields => [ @age_fields ],
127
    agefields           => [@age_fields],
125
    condition_fields => [ @item_fields, @biblioitem_fields, @biblio_fields ],
128
    condition_fields    => [ @item_fields, @biblioitem_fields, @biblio_fields ],
126
    substitution_fields => \@item_fields,
129
    substitution_fields => \@item_fields,
127
    rules => $rules,
130
    rules               => $rules,
128
);
131
);
129
132
130
output_html_with_http_headers $cgi, $cookie, $template->output;
133
output_html_with_http_headers $cgi, $cookie, $template->output;
131
- 

Return to bug 32029