From 4184620ccf1ff6d6f37f2846b18fd9b259358397 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 21 Mar 2013 07:18:34 -0700 Subject: [PATCH] Bug 9673 - Track when items are marked as lost or withdrawn - QA Followup --- C4/Items.pm | 29 +++++++++++++++---- installer/data/mysql/kohastructure.sql | 4 +- installer/data/mysql/updatedatabase.pl | 4 +- .../prog/en/modules/catalogue/moredetail.tt | 2 +- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/C4/Items.pm b/C4/Items.pm index 050f1c4..4216a78 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -31,8 +31,10 @@ use C4::ClassSource; use C4::Log; use List::MoreUtils qw/any/; use YAML qw/Load/; +use DateTime::Format::MySQL; use Data::Dumper; # used as part of logging item record changes, not just for # debugging; so please don't remove this +use Koha::DateUtils qw/dt_from_string/; use vars qw($VERSION @ISA @EXPORT); @@ -536,16 +538,31 @@ sub ModItem { $item->{onloan} = undef if $item->{itemlost}; - for my $field ( qw( itemlost withdrawn ) ) { - if ( defined( $item->{$field} ) ) { - if ( $item->{$field} ) { - $item->{$field . '_on'} = DateTime::Format::MySQL->format_datetime( DateTime->now() ); - } else { - $item->{$field . '_on'} = undef; + my @fields = qw( itemlost withdrawn ); + + # Only call GetItem if we need to set an "on" date field + if ( $item->{itemlost} || $item->{withdrawn} ) { + my $pre_mod_item = GetItem( $item->{'itemnumber'} ); + for my $field (@fields) { + if ( defined( $item->{$field} ) + and not $pre_mod_item->{$field} + and $item->{$field} ) + { + $item->{ $field . '_on' } = + DateTime::Format::MySQL->format_datetime( dt_from_string() ); } } } + # If the field is defined but empty, we are removing and, + # and thus need to clear out the 'on' field as well + for my $field (@fields) { + if ( defined( $item->{$field} ) && !$item->{$field} ) { + $item->{ $field . '_on' } = undef; + } + } + + _set_derived_columns_for_mod($item); _do_column_fixes_for_mod($item); # FIXME add checks diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 23f851e..eff8042 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -868,7 +868,7 @@ CREATE TABLE `deleteditems` ( `itemlost` tinyint(1) NOT NULL default 0, -- authorized value defining this item as lost (MARC21 952$1) `itemlost_on` datetime DEFAULT NULL, -- the date and time an item was last marked as lost, NULL if not lost `withdrawn` tinyint(1) NOT NULL default 0, -- authorized value defining this item as withdrawn (MARC21 952$0) - `wthdrawn_on` datetime DEFAULT NULL, -- the date and time an item was last marked as withdrawn, NULL if not withdrawn + `withdrawn_on` datetime DEFAULT NULL, -- the date and time an item was last marked as withdrawn, NULL if not withdrawn `itemcallnumber` varchar(255) default NULL, -- call number for this item (MARC21 952$o) `coded_location_qualifier` varchar(10) default NULL, -- coded location qualifier(MARC21 952$f) `issues` smallint(6) default NULL, -- number of times this item has been checked out @@ -1162,7 +1162,7 @@ CREATE TABLE `items` ( -- holdings/item information `itemlost` tinyint(1) NOT NULL default 0, -- authorized value defining this item as lost (MARC21 952$1) `itemlost_on` datetime DEFAULT NULL, -- the date and time an item was last marked as lost, NULL if not lost `withdrawn` tinyint(1) NOT NULL default 0, -- authorized value defining this item as withdrawn (MARC21 952$0) - `wthdrawn_on` datetime DEFAULT NULL, -- the date and time an item was last marked as withdrawn, NULL if not withdrawn + `withdrawn_on` datetime DEFAULT NULL, -- the date and time an item was last marked as withdrawn, NULL if not withdrawn `itemcallnumber` varchar(255) default NULL, -- call number for this item (MARC21 952$o) `coded_location_qualifier` varchar(10) default NULL, -- coded location qualifier(MARC21 952$f) `issues` smallint(6) default NULL, -- number of times this item has been checked out/issued diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index bdc684c..ea94ab4 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -7158,9 +7158,9 @@ if ( CheckVersion($DBversion) ) { $DBversion = "3.13.00.XXX"; if ( CheckVersion($DBversion) ) { $dbh->do("ALTER TABLE items ADD itemlost_on DATETIME NULL AFTER itemlost"); - $dbh->do("ALTER TABLE items ADD wthdrawn_on DATETIME NULL AFTER wthdrawn"); + $dbh->do("ALTER TABLE items ADD withdrawn_on DATETIME NULL AFTER wthdrawn"); $dbh->do("ALTER TABLE deleteditems ADD itemlost_on DATETIME NULL AFTER itemlost"); - $dbh->do("ALTER TABLE deleteditems ADD wthdrawn_on DATETIME NULL AFTER wthdrawn"); + $dbh->do("ALTER TABLE deleteditems ADD withdrawn_on DATETIME NULL AFTER wthdrawn"); print "Upgrade to $DBversion done (Bug 9673 - Track when items are marked as lost or withdrawn)\n"; SetVersion ($DBversion); } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt index 5008bdb..d54513d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt @@ -177,7 +177,7 @@ [% END %] - [% IF ITEM_DAT.wthdrawn_on %]
  • Withdrawn on:[% ITEM_DAT.wthdrawn_on | $KohaDates %]  
  • [% END %] + [% IF ITEM_DAT.withdrawn_on %]
  • Withdrawn on:[% ITEM_DAT.withdrawn_on | $KohaDates %]  
  • [% END %]

    History

      -- 1.7.2.5