From c3301fed0554d249a221633d1dedba46cb7b5742 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Mon, 9 Feb 2015 16:26:32 +0100 Subject: [PATCH] Bug 11708: Remove column aqbasketgroups.closed It is redundant with aqbasketgroups.closeddate Signed-off-by: Paola Rossi Patch updated: use atmoic update --- C4/Acquisition.pm | 25 ++++++++++++-------- ...g-11708-remove-column-aqbasketgroups-closed.sql | 3 +++ 2 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/Bug-11708-remove-column-aqbasketgroups-closed.sql diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 4c6ff20..800ddcb 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -435,8 +435,7 @@ sub CloseBasketgroup { my $dbh = C4::Context->dbh; my $sth = $dbh->prepare(" UPDATE aqbasketgroups - SET closed=1, - closeddate=CAST(NOW() AS DATE) + SET closeddate=CAST(NOW() AS DATE) WHERE id=? "); $sth->execute($basketgroupno); @@ -457,7 +456,7 @@ sub ReOpenBasketgroup { my $dbh = C4::Context->dbh; my $sth = $dbh->prepare(" UPDATE aqbasketgroups - SET closed=0, closeddate=NULL + SET closeddate=NULL WHERE id=? "); $sth->execute($basketgroupno); @@ -874,7 +873,7 @@ $hashref->{'freedeliveryplace'} is the 'freedeliveryplace' field of the basketgr $hashref->{'deliverycomment'} is the 'deliverycomment' field of the basketgroup in the aqbasketgroups table, -$hashref->{'closed'} is the 'closed' field of the aqbasketgroups table, it is false if 0, true otherwise. +$hashref->{'closed'} set 'closeddate' if true, or reset 'closeddate' if defined but false. =cut @@ -883,7 +882,7 @@ sub NewBasketgroup { die "booksellerid is required to create a basketgroup" unless $basketgroupinfo->{'booksellerid'}; my $query = "INSERT INTO aqbasketgroups ("; my @params; - foreach my $field (qw(name billingplace deliveryplace freedeliveryplace deliverycomment closed)) { + foreach my $field (qw(name billingplace deliveryplace freedeliveryplace deliverycomment)) { if ( defined $basketgroupinfo->{$field} ) { $query .= "$field, "; push(@params, $basketgroupinfo->{$field}); @@ -938,7 +937,7 @@ $hashref->{'freedeliveryplace'} is the 'freedeliveryplace' field of the basketgr $hashref->{'deliverycomment'} is the 'deliverycomment' field of the basketgroup in the aqbasketgroups table, -$hashref->{'closed'} is the 'closed' field of the aqbasketgroups table, it is false if 0, true otherwise. +$hashref->{'closed'} set 'closeddate' if true, or reset 'closeddate' if defined but false. =cut @@ -950,12 +949,12 @@ sub ModBasketgroup { my @params; if ($basketgroupinfo->{closed}) { - $query .= "closeddate = IF(closed = 0, CAST(NOW() AS DATE), closeddate), "; + $query .= "closeddate = IF(closeddate IS NULL, CAST(NOW() AS DATE), closeddate), "; } elsif (defined $basketgroupinfo->{closed}) { $query .= "closeddate = NULL, "; } - foreach my $field (qw(name billingplace deliveryplace freedeliveryplace deliverycomment closed)) { + foreach my $field (qw(name billingplace deliveryplace freedeliveryplace deliverycomment)) { if ( defined $basketgroupinfo->{$field} ) { $query .= "$field=?, "; push(@params, $basketgroupinfo->{$field}); @@ -1028,7 +1027,9 @@ sub GetBasketgroup { { Slice => {} }, $basketgroupid ); - return $result_set->[0]; # id is unique + my $basketgroup = $result_set->[0]; # id is unique + $basketgroup->{closed} = defined($basketgroup->{closeddate}) ? 1 : 0; + return $basketgroup; } #------------------------------------------------------------# @@ -1048,7 +1049,11 @@ sub GetBasketgroups { my $dbh = C4::Context->dbh; my $sth = $dbh->prepare($query); $sth->execute($booksellerid); - return $sth->fetchall_arrayref({}); + my $basketgroups = $sth->fetchall_arrayref({}); + foreach my $bg (@$basketgroups) { + $bg->{closed} = defined($bg->{closeddate}) ? 1 : 0; + } + return $basketgroups; } #------------------------------------------------------------# diff --git a/installer/data/mysql/atomicupdate/Bug-11708-remove-column-aqbasketgroups-closed.sql b/installer/data/mysql/atomicupdate/Bug-11708-remove-column-aqbasketgroups-closed.sql new file mode 100644 index 0000000..5e95153 --- /dev/null +++ b/installer/data/mysql/atomicupdate/Bug-11708-remove-column-aqbasketgroups-closed.sql @@ -0,0 +1,3 @@ +UPDATE aqbasketgroups SET closeddate = CAST(NOW() AS DATE) WHERE closed = 1; + +ALTER TABLE aqbasketgroups DROP COLUMN closed; \ No newline at end of file -- 1.7.10.4