@@ -, +, @@ biblioitems table. --- C4/Items.pm | 48 ++++++++++++++++++-- .../prog/en/modules/tools/toggle_new_status.tt | 20 ++++---- tools/toggle_new_status.pl | 4 +- 3 files changed, 58 insertions(+), 14 deletions(-) --- a/C4/Items.pm +++ a/C4/Items.pm @@ -2906,6 +2906,39 @@ sub columns { return @data; } +=head2 biblioitems_columns + + my @columns = C4::Items::biblioitems_columns(); + +Returns an array of biblioitems' table columns on success, +and an empty array on failure. + +=cut + +sub biblioitems_columns { + # Pure ANSI SQL goodness. + my $sql = 'SELECT * FROM biblioitems WHERE 1=0;'; + + # Get the database handle. + my $dbh = C4::Context->dbh; + + # Run the SQL statement to load STH's readonly properties. + my $sth = $dbh->prepare($sql); + my $rv = $sth->execute(); + + # This only fails if the table doesn't exist. + # This will always be called AFTER an install or upgrade, + # so borrowers will exist! + my @data; + if ($sth->{NUM_OF_FIELDS}>0) { + @data = @{$sth->{NAME}}; + } + else { + @data = (); + } + return @data; +} + sub ToggleNewStatus { my ( $params ) = @_; my @rules = @{ $params->{rules} }; @@ -2913,7 +2946,8 @@ sub ToggleNewStatus { my $dbh = C4::Context->dbh; my @errors; - my @items_columns = C4::Items::columns; + my @item_columns = map { "items.$_" } C4::Items::columns; + my @biblioitem_columns = map { "biblioitems.$_" } C4::Items::biblioitems_columns; my $report; for my $rule ( @rules ) { my $duration = $rule->{duration}; @@ -2921,9 +2955,17 @@ sub ToggleNewStatus { my $substitutions = $rule->{substitutions}; my @params; - my $query = q|SELECT biblionumber, itemnumber FROM items WHERE 1 |; + my $query = q| + SELECT items.biblionumber, items.itemnumber + FROM items + LEFT JOIN biblioitems ON items.biblioitemnumber = items.itemnumber + WHERE 1 + |; for my $condition ( @$conditions ) { - if ( grep {/^$condition->{field}$/} @items_columns ) { + if ( + grep {/^$condition->{field}$/} @item_columns + or grep {/^$condition->{field}$/} @biblioitem_columns + ) { if ( $condition->{value} =~ /\|/ ) { my @values = split /\|/, $condition->{value}; $query .= qq| AND $condition->{field} IN (| --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/toggle_new_status.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/toggle_new_status.tt @@ -155,11 +155,11 @@
@@ -176,11 +176,11 @@
@@ -217,8 +217,8 @@
= @@ -232,8 +232,8 @@
= --- a/tools/toggle_new_status.pl +++ a/tools/toggle_new_status.pl @@ -106,10 +106,12 @@ if ( $@ ) { exit; } +my @item_fields = map { "items.$_" } C4::Items::columns; +my @biblioitem_fields = map { "biblioitems.$_" } C4::Items::biblioitems_columns; $template->param( op => $op, messages => \@messages, - item_fields => [ C4::Items::columns ], + fields => [ @item_fields, @biblioitem_fields ], rules => $rules, ); --