[Koha-patches] [PATCH] _set_defaults_for_add easier to read

Marc Chantreux marc.chantreux at biblibre.com
Fri Jan 16 10:23:27 CET 2009


---
 C4/Items.pm |   16 ++--------------
 1 files changed, 2 insertions(+), 14 deletions(-)

diff --git a/C4/Items.pm b/C4/Items.pm
index fba4a21..af58439 100644
--- a/C4/Items.pm
+++ b/C4/Items.pm
@@ -1788,20 +1788,8 @@ C<items.wthdrawn>
 
 sub _set_defaults_for_add {
     my $item = shift;
-
-    # if dateaccessioned is provided, use it. Otherwise, set to NOW()
-    if (!(exists $item->{'dateaccessioned'}) || 
-         ($item->{'dateaccessioned'} eq '')) {
-        # FIXME add check for invalid date
-        my $today = C4::Dates->new();    
-        $item->{'dateaccessioned'} =  $today->output("iso"); #TODO: check time issues
-    }
-
-    # various item status fields cannot be null
-    $item->{'notforloan'} = 0 unless exists $item->{'notforloan'} and defined $item->{'notforloan'} and $item->{'notforloan'} ne '';
-    $item->{'damaged'}    = 0 unless exists $item->{'damaged'}    and defined $item->{'damaged'}    and $item->{'damaged'} ne '';
-    $item->{'itemlost'}   = 0 unless exists $item->{'itemlost'}   and defined $item->{'itemlost'}   and $item->{'itemlost'} ne '';
-    $item->{'wthdrawn'}   = 0 unless exists $item->{'wthdrawn'}   and defined $item->{'wthdrawn'}   and $item->{'wthdrawn'} ne '';
+    $item->{dateaccessioned} ||= C4::Dates->new->output('iso');
+    $item->{$_} ||= 0 for (qw( notforloan damaged itemlost wthdrawn));
 }
 
 =head2 _koha_new_item
-- 
1.5.6.5




More information about the Koha-patches mailing list