From 6a508dd9da148921387dcdf1f4def3e011524cb9 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 8 Mar 2016 09:53:35 +0000 Subject: [PATCH] Bug 16004: Replace items.new with items.new_status Content-Type: text/plain; charset=utf-8 The items.new column is badly named, the Koha::Item->new accessor will never returns this value, but the constructor will be called instead. This patch renames it with new_status to avoid the ambiguity. Test plan: 0/ Do not apply this patch 1/ Define some rules in the "Automatic item modifications by age" tool with at least one items.new field used 2/ Apply this patch 3/ Execute the update DB entry 4/ Reload the tool page and confirm that the changes have been taken into account Signed-off-by: Kyle M Hall Signed-off-by: Marcel de Rooy --- C4/Items.pm | 6 +-- .../bug_xxxx-change_new_to_new_status.sql | 3 ++ installer/data/mysql/kohastructure.sql | 4 +- .../Items/AutomaticItemModificationByAge.t | 56 ++++++++++---------- 4 files changed, 36 insertions(+), 33 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_xxxx-change_new_to_new_status.sql diff --git a/C4/Items.pm b/C4/Items.pm index 7b41d2b..a0dfb29 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -473,7 +473,7 @@ sub _build_default_values_for_mod_marc { location => undef, permanent_location => undef, materials => undef, - new => undef, + new_status => undef, notforloan => 0, # paidfor => undef, # commented, see bug 12817 price => undef, @@ -2200,7 +2200,7 @@ sub _koha_new_item { more_subfields_xml = ?, copynumber = ?, stocknumber = ?, - new = ? + new_status = ? "; my $sth = $dbh->prepare($query); my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }); @@ -2244,7 +2244,7 @@ sub _koha_new_item { $item->{'more_subfields_xml'}, $item->{'copynumber'}, $item->{'stocknumber'}, - $item->{'new'}, + $item->{'new_status'}, ); my $itemnumber; diff --git a/installer/data/mysql/atomicupdate/bug_xxxx-change_new_to_new_status.sql b/installer/data/mysql/atomicupdate/bug_xxxx-change_new_to_new_status.sql new file mode 100644 index 0000000..1f1711d --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_xxxx-change_new_to_new_status.sql @@ -0,0 +1,3 @@ +ALTER TABLE items CHANGE new new_status VARCHAR(32) NULL; +ALTER TABLE deleteditems CHANGE new new_status VARCHAR(32) NULL; +UPDATE systempreferences SET value=REPLACE(value, '"items.new"', '"items.new_status"') WHERE variable="automatic_item_modification_by_age_configuration"; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 63fefe7..9c3ccdd 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -972,7 +972,7 @@ CREATE TABLE `deleteditems` ( `enumchron` text default NULL, -- serial enumeration/chronology for the item (MARC21 952$h) `copynumber` varchar(32) default NULL, -- copy number (MARC21 952$t) `stocknumber` varchar(32) default NULL, -- inventory number (MARC21 952$i) - `new` VARCHAR(32) DEFAULT NULL, -- 'new' value, you can put whatever free-text information. This field is intented to be managed by the automatic_item_modification_by_age cronjob. + `new_status` VARCHAR(32) DEFAULT NULL, -- 'new' value, you can put whatever free-text information. This field is intented to be managed by the automatic_item_modification_by_age cronjob. PRIMARY KEY (`itemnumber`), KEY `delitembarcodeidx` (`barcode`), KEY `delitemstocknumberidx` (`stocknumber`), @@ -1268,7 +1268,7 @@ CREATE TABLE `items` ( -- holdings/item information `enumchron` text default NULL, -- serial enumeration/chronology for the item (MARC21 952$h) `copynumber` varchar(32) default NULL, -- copy number (MARC21 952$t) `stocknumber` varchar(32) default NULL, -- inventory number (MARC21 952$i) - `new` VARCHAR(32) DEFAULT NULL, -- 'new' value, you can put whatever free-text information. This field is intented to be managed by the automatic_item_modification_by_age cronjob. + `new_status` VARCHAR(32) DEFAULT NULL, -- 'new' value, you can put whatever free-text information. This field is intented to be managed by the automatic_item_modification_by_age cronjob. PRIMARY KEY (`itemnumber`), UNIQUE KEY `itembarcodeidx` (`barcode`), KEY `itemstocknumberidx` (`stocknumber`), diff --git a/t/db_dependent/Items/AutomaticItemModificationByAge.t b/t/db_dependent/Items/AutomaticItemModificationByAge.t index 3f2943c..0bad51a 100644 --- a/t/db_dependent/Items/AutomaticItemModificationByAge.t +++ b/t/db_dependent/Items/AutomaticItemModificationByAge.t @@ -18,13 +18,13 @@ $dbh->{RaiseError} = 1; $dbh->do(q| DELETE FROM marc_subfield_structure - WHERE kohafield = 'items.new' OR kohafield = 'items.stocknumber' + WHERE kohafield = 'items.new_status' OR kohafield = 'items.stocknumber' |); my $new_tagfield = 'i'; $dbh->do(qq| INSERT INTO marc_subfield_structure(tagfield, tagsubfield, kohafield, frameworkcode) - VALUES ( 952, '$new_tagfield', 'items.new', '' ) + VALUES ( 952, '$new_tagfield', 'items.new_status', '' ) |); my $record = MARC::Record->new(); @@ -39,20 +39,20 @@ my ($item_bibnum, $item_bibitemnum, $itemnumber) = C4::Items::AddItem( { homebranch => 'CPL', holdingbranch => 'CPL', - new => 'new_value', + new_status => 'new_value', ccode => 'FIC', }, $biblionumber ); my $item = C4::Items::GetItem( $itemnumber ); -is ( $item->{new}, 'new_value', q|AddItem insert the 'new' field| ); +is ( $item->{new_status}, 'new_value', q|AddItem insert the 'new_status' field| ); my ( $tagfield, undef ) = GetMarcFromKohaField('items.itemnumber', ''); my $marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber ); is( $marc_item->subfield($tagfield, $new_tagfield), 'new_value', q|Koha mapping is correct|); -# Update the items.new field if items.ccode eq 'FIC' => should be updated +# Update the items.new_status field if items.ccode eq 'FIC' => should be updated my @rules = ( { conditions => [ @@ -63,7 +63,7 @@ my @rules = ( ], substitutions => [ { - field => 'items.new', + field => 'items.new_status', value => 'updated_value', }, ], @@ -74,11 +74,11 @@ my @rules = ( C4::Items::ToggleNewStatus( { rules => \@rules } ); my $modified_item = C4::Items::GetItem( $itemnumber ); -is( $modified_item->{new}, 'updated_value', q|ToggleNewStatus: The new value is updated|); +is( $modified_item->{new_status}, 'updated_value', q|ToggleNewStatus: The new_status value is updated|); $marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber ); -is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNewStatus: The new value is updated| ); +is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNewStatus: The new_status value is updated| ); -# Update the items.new field if items.ccode eq 'DONT_EXIST' => should not be updated +# Update the items.new_status field if items.ccode eq 'DONT_EXIST' => should not be updated @rules = ( { conditions => [ @@ -89,7 +89,7 @@ is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNew ], substitutions => [ { - field => 'items.new', + field => 'items.new_status', value => 'new_updated_value', }, ], @@ -100,9 +100,9 @@ is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNew C4::Items::ToggleNewStatus( { rules => \@rules } ); $modified_item = C4::Items::GetItem( $itemnumber ); -is( $modified_item->{new}, 'updated_value', q|ToggleNewStatus: The new value is not updated|); +is( $modified_item->{new_status}, 'updated_value', q|ToggleNewStatus: The new_status value is not updated|); $marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber ); -is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNewStatus: The new value is not updated| ); +is( $marc_item->subfield($tagfield, $new_tagfield), 'updated_value', q|ToggleNewStatus: The new_status value is not updated| ); # Play with age $item = C4::Items::GetItem( $itemnumber ); @@ -122,7 +122,7 @@ $item = C4::Items::GetItem( $itemnumber ); ], substitutions => [ { - field => 'items.new', + field => 'items.new_status', value => 'new_updated_value', }, ], @@ -131,25 +131,25 @@ $item = C4::Items::GetItem( $itemnumber ); ); C4::Items::ToggleNewStatus( { rules => \@rules } ); $modified_item = C4::Items::GetItem( $itemnumber ); -is( $modified_item->{new}, 'updated_value', q|ToggleNewStatus: Age = 10 : The new value is not updated|); +is( $modified_item->{new_status}, 'updated_value', q|ToggleNewStatus: Age = 10 : The new_status value is not updated|); $rules[0]->{age} = 5; $rules[0]->{substitutions}[0]{value} = 'new_updated_value5'; C4::Items::ToggleNewStatus( { rules => \@rules } ); $modified_item = C4::Items::GetItem( $itemnumber ); -is( $modified_item->{new}, 'new_updated_value5', q|ToggleNewStatus: Age = 5 : The new value is updated|); +is( $modified_item->{new_status}, 'new_updated_value5', q|ToggleNewStatus: Age = 5 : The new_status value is updated|); $rules[0]->{age} = ''; $rules[0]->{substitutions}[0]{value} = 'new_updated_value_empty_string'; C4::Items::ToggleNewStatus( { rules => \@rules } ); $modified_item = C4::Items::GetItem( $itemnumber ); -is( $modified_item->{new}, 'new_updated_value_empty_string', q|ToggleNewStatus: Age = '' : The new value is updated|); +is( $modified_item->{new_status}, 'new_updated_value_empty_string', q|ToggleNewStatus: Age = '' : The new_status value is updated|); $rules[0]->{age} = undef; $rules[0]->{substitutions}[0]{value} = 'new_updated_value_undef'; C4::Items::ToggleNewStatus( { rules => \@rules } ); $modified_item = C4::Items::GetItem( $itemnumber ); -is( $modified_item->{new}, 'new_updated_value_undef', q|ToggleNewStatus: Age = undef : The new value is updated|); +is( $modified_item->{new_status}, 'new_updated_value_undef', q|ToggleNewStatus: Age = undef : The new_status value is updated|); # Field deletion @rules = ( @@ -162,7 +162,7 @@ is( $modified_item->{new}, 'new_updated_value_undef', q|ToggleNewStatus: Age = u ], substitutions => [ { - field => 'items.new', + field => 'items.new_status', value => '', }, ], @@ -173,9 +173,9 @@ is( $modified_item->{new}, 'new_updated_value_undef', q|ToggleNewStatus: Age = u C4::Items::ToggleNewStatus( { rules => \@rules } ); $modified_item = C4::Items::GetItem( $itemnumber ); -is( $modified_item->{new}, '', q|ToggleNewStatus: The new value is empty|); +is( $modified_item->{new_status}, '', q|ToggleNewStatus: The new_status value is empty|); $marc_item = C4::Items::GetMarcItem( $biblionumber, $itemnumber ); -is( $marc_item->subfield($tagfield, $new_tagfield), undef, q|ToggleNewStatus: The new field is removed from the item marc| ); +is( $marc_item->subfield($tagfield, $new_tagfield), undef, q|ToggleNewStatus: The new_status field is removed from the item marc| ); # conditions multiple @rules = ( @@ -192,7 +192,7 @@ is( $marc_item->subfield($tagfield, $new_tagfield), undef, q|ToggleNewStatus: Th ], substitutions => [ { - field => 'items.new', + field => 'items.new_status', value => 'new_value', }, ], @@ -203,7 +203,7 @@ is( $marc_item->subfield($tagfield, $new_tagfield), undef, q|ToggleNewStatus: Th C4::Items::ToggleNewStatus( { rules => \@rules } ); $modified_item = C4::Items::GetItem( $itemnumber ); -is( $modified_item->{new}, 'new_value', q|ToggleNewStatus: conditions multiple: all match, the new value is updated|); +is( $modified_item->{new_status}, 'new_value', q|ToggleNewStatus: conditions multiple: all match, the new_status value is updated|); @rules = ( { @@ -219,7 +219,7 @@ is( $modified_item->{new}, 'new_value', q|ToggleNewStatus: conditions multiple: ], substitutions => [ { - field => 'items.new', + field => 'items.new_status', value => 'new_updated_value', }, ], @@ -230,7 +230,7 @@ is( $modified_item->{new}, 'new_value', q|ToggleNewStatus: conditions multiple: C4::Items::ToggleNewStatus( { rules => \@rules } ); $modified_item = C4::Items::GetItem( $itemnumber ); -is( $modified_item->{new}, 'new_value', q|ToggleNewStatus: conditions multiple: at least 1 condition does not match, the new value is not updated|); +is( $modified_item->{new_status}, 'new_value', q|ToggleNewStatus: conditions multiple: at least 1 condition does not match, the new_status value is not updated|); @rules = ( { @@ -246,7 +246,7 @@ is( $modified_item->{new}, 'new_value', q|ToggleNewStatus: conditions multiple: ], substitutions => [ { - field => 'items.new', + field => 'items.new_status', value => 'new_updated_value', }, ], @@ -257,7 +257,7 @@ is( $modified_item->{new}, 'new_value', q|ToggleNewStatus: conditions multiple: C4::Items::ToggleNewStatus( { rules => \@rules } ); $modified_item = C4::Items::GetItem( $itemnumber ); -is( $modified_item->{new}, 'new_updated_value', q|ToggleNewStatus: conditions multiple: the 2 conditions match, the new value is updated|); +is( $modified_item->{new_status}, 'new_updated_value', q|ToggleNewStatus: conditions multiple: the 2 conditions match, the new_status value is updated|); @rules = ( { @@ -269,7 +269,7 @@ is( $modified_item->{new}, 'new_updated_value', q|ToggleNewStatus: conditions mu ], substitutions => [ { - field => 'items.new', + field => 'items.new_status', value => 'another_new_updated_value', }, ], @@ -280,4 +280,4 @@ is( $modified_item->{new}, 'new_updated_value', q|ToggleNewStatus: conditions mu C4::Items::ToggleNewStatus( { rules => \@rules } ); $modified_item = C4::Items::GetItem( $itemnumber ); -is( $modified_item->{new}, 'another_new_updated_value', q|ToggleNewStatus: conditions on biblioitems|); +is( $modified_item->{new_status}, 'another_new_updated_value', q|ToggleNewStatus: conditions on biblioitems|); -- 1.7.10.4