Bugzilla – Attachment 93460 Details for
Bug 11708
Display all basketgroups on one page, and new column aqbasketgroups.closeddate
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 11708: Change aqbasketgroups.closed to closeddate
Bug-11708-Change-aqbasketgroupsclosed-to-closeddat.patch (text/plain), 9.16 KB, created by
Julian Maurice
on 2019-10-02 13:19:18 UTC
(
hide
)
Description:
Bug 11708: Change aqbasketgroups.closed to closeddate
Filename:
MIME Type:
Creator:
Julian Maurice
Created:
2019-10-02 13:19:18 UTC
Size:
9.16 KB
patch
obsolete
>From 412dcbc3d966ec2b8b6a8d9904a30b46abe8b2b5 Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Fri, 7 Feb 2014 11:01:30 +0100 >Subject: [PATCH] Bug 11708: Change aqbasketgroups.closed to closeddate >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >Signed-off-by: juliette levast <juliette.levast@iepg.fr> >Signed-off-by: Paola Rossi <paola.rossi@cineca.it> >Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr> >--- > C4/Acquisition.pm | 36 +++++++--- > .../data/mysql/atomicupdate/bug_11708.perl | 32 +++++++++ > installer/data/mysql/kohastructure.sql | 2 +- > t/db_dependent/Acquisition/Basketgroups.t | 67 +++++++++++++++++++ > 4 files changed, 128 insertions(+), 9 deletions(-) > create mode 100644 installer/data/mysql/atomicupdate/bug_11708.perl > create mode 100755 t/db_dependent/Acquisition/Basketgroups.t > >diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm >index 4122c5da27..50e4fcc4b4 100644 >--- a/C4/Acquisition.pm >+++ b/C4/Acquisition.pm >@@ -457,7 +457,7 @@ sub CloseBasketgroup { > my $dbh = C4::Context->dbh; > my $sth = $dbh->prepare(" > UPDATE aqbasketgroups >- SET closed=1 >+ SET closeddate=CAST(NOW() AS DATE) > WHERE id=? > "); > $sth->execute($basketgroupno); >@@ -478,7 +478,7 @@ sub ReOpenBasketgroup { > my $dbh = C4::Context->dbh; > my $sth = $dbh->prepare(" > UPDATE aqbasketgroups >- SET closed=0 >+ SET closeddate=NULL > WHERE id=? > "); > $sth->execute($basketgroupno); >@@ -914,7 +914,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 > >@@ -923,16 +923,23 @@ 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}); > } > } >+ >+ if ($basketgroupinfo->{closed}) { >+ $query .= "closeddate, "; >+ } > $query .= "booksellerid) VALUES ("; > foreach (@params) { > $query .= "?, "; > } >+ if ($basketgroupinfo->{closed}) { >+ $query .= "CAST(NOW() AS DATE), "; >+ } > $query .= "?)"; > push(@params, $basketgroupinfo->{'booksellerid'}); > my $dbh = C4::Context->dbh; >@@ -971,7 +978,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 > >@@ -981,7 +988,14 @@ sub ModBasketgroup { > my $dbh = C4::Context->dbh; > my $query = "UPDATE aqbasketgroups SET "; > my @params; >- foreach my $field (qw(name billingplace deliveryplace freedeliveryplace deliverycomment closed)) { >+ >+ if ($basketgroupinfo->{closed}) { >+ $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)) { > if ( defined $basketgroupinfo->{$field} ) { > $query .= "$field=?, "; > push(@params, $basketgroupinfo->{$field}); >@@ -1054,7 +1068,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; > } > > #------------------------------------------------------------# >@@ -1074,7 +1090,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.perl b/installer/data/mysql/atomicupdate/bug_11708.perl >new file mode 100644 >index 0000000000..54d7e72f8b >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_11708.perl >@@ -0,0 +1,32 @@ >+$DBversion = 'XXX'; >+if( CheckVersion( $DBversion ) ) { >+ unless (column_exists('aqbasketgroups', 'closeddate')) { >+ $dbh->do(q{ >+ ALTER TABLE aqbasketgroups >+ ADD COLUMN closeddate DATE DEFAULT NULL AFTER name >+ }); >+ } >+ >+ if (column_exists('aqbasketgroups', 'closed')) { >+ # Set basketgroup's close date to the latest close date of its baskets, >+ # or NOW() if it has no baskets >+ $dbh->do(q{ >+ UPDATE aqbasketgroups >+ LEFT JOIN ( >+ SELECT basketgroupid, MAX(closedate) AS closedate >+ FROM aqbasket >+ GROUP BY basketgroupid >+ ) AS aqbasket ON (aqbasketgroups.id = aqbasket.basketgroupid) >+ SET aqbasketgroups.closeddate = COALESCE(aqbasket.closedate, CAST(NOW() AS DATE)) >+ WHERE closed = 1 >+ AND closeddate IS NULL >+ }); >+ $dbh->do(q{ >+ ALTER TABLE aqbasketgroups >+ DROP COLUMN closed >+ }); >+ } >+ >+ SetVersion( $DBversion ); >+ print "Upgrade to $DBversion done (Bug 11708 - Change aqbasketgroups.closed to closeddate)\n"; >+} >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index 7073c9a2d1..a691b8737a 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -2772,7 +2772,7 @@ DROP TABLE IF EXISTS `aqbasketgroups`; > CREATE TABLE `aqbasketgroups` ( > `id` int(11) NOT NULL auto_increment, > `name` varchar(50) default NULL, >- `closed` tinyint(1) default NULL, >+ `closeddate` date default NULL, > `booksellerid` int(11) NOT NULL, > `deliveryplace` varchar(10) default NULL, > `freedeliveryplace` MEDIUMTEXT default NULL, >diff --git a/t/db_dependent/Acquisition/Basketgroups.t b/t/db_dependent/Acquisition/Basketgroups.t >new file mode 100755 >index 0000000000..856c864794 >--- /dev/null >+++ b/t/db_dependent/Acquisition/Basketgroups.t >@@ -0,0 +1,67 @@ >+#!/usr/bin/perl >+ >+use Modern::Perl; >+ >+use DateTime; >+ >+use Koha::Database; >+ >+use C4::Context; >+use C4::Acquisition; >+ >+use Test::More tests => 13; >+ >+use t::lib::TestBuilder; >+ >+my $schema = Koha::Database->new->schema; >+$schema->storage->txn_begin; >+ >+my $builder = t::lib::TestBuilder->new; >+ >+my $bookseller = $builder->build_object({ >+ class => 'Koha::Acquisition::Booksellers', >+ value => { >+ name => 'Bookseller test 1', >+ } >+}); >+ >+my $booksellerid = $bookseller->id; >+my $basketgroupid = NewBasketgroup({ >+ booksellerid => $booksellerid, >+ name => "Basketgroup test 1", >+}); >+ >+my $basketgroup = GetBasketgroup($basketgroupid); >+ok(!$basketgroup->{closed}, "basket group is open"); >+ok(!defined($basketgroup->{closeddate}), "basket group closed date is empty"); >+ >+CloseBasketgroup($basketgroupid); >+$basketgroup = GetBasketgroup($basketgroupid); >+ok($basketgroup->{closed}, "basket group is closed"); >+ok(defined($basketgroup->{closeddate}), "basket group closed date is not empty"); >+my $today = DateTime->now(time_zone => C4::Context->tz); >+is($basketgroup->{closeddate}, $today->ymd, "basket group closed date is correct"); >+ >+ReOpenBasketgroup($basketgroupid); >+$basketgroup = GetBasketgroup($basketgroupid); >+ok(!$basketgroup->{closed}, "basket group is open"); >+ok(!defined($basketgroup->{closeddate}), "basket group closed date is empty"); >+ >+$basketgroup->{closed} = 1; >+ModBasketgroup($basketgroup); >+$basketgroup = GetBasketgroup($basketgroupid); >+ok($basketgroup->{closed}, "basket group is closed"); >+ok(defined($basketgroup->{closeddate}), "basket group closed date is not empty"); >+is($basketgroup->{closeddate}, $today->ymd, "basket group closed date is correct"); >+ >+$basketgroupid = NewBasketgroup({ >+ booksellerid => $booksellerid, >+ name => "Basketgroup test 1", >+ closed => 1, >+}); >+$basketgroup = GetBasketgroup($basketgroupid); >+ok($basketgroup->{closed}, "basket group is closed"); >+ok(defined($basketgroup->{closeddate}), "basket group closed date is not empty"); >+is($basketgroup->{closeddate}, $today->ymd, "basket group closed date is correct"); >+ >+$schema->storage->txn_rollback(); >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 11708
:
25115
|
25116
|
25117
|
26003
|
26004
|
26006
|
28868
|
28869
|
28870
|
28871
|
28872
|
31305
|
31306
|
31307
|
31308
|
31309
|
31530
|
31531
|
31532
|
31533
|
31534
|
31535
|
31536
|
31537
|
31538
|
31539
|
31540
|
31541
|
31542
|
31543
|
31544
|
31702
|
31703
|
31704
|
31705
|
31748
|
31749
|
31750
|
31751
|
31752
|
31753
|
32909
|
32910
|
32911
|
32912
|
32913
|
32914
|
33308
|
33309
|
33310
|
33311
|
33312
|
33313
|
34936
|
34937
|
34938
|
34939
|
34940
|
34941
|
34977
|
35748
|
35749
|
35750
|
35751
|
35752
|
35753
|
35754
|
35755
|
35756
|
35971
|
35972
|
35973
|
35974
|
35975
|
35976
|
35977
|
35978
|
35979
|
40260
|
40261
|
40262
|
40263
|
40264
|
40265
|
40266
|
40267
|
40268
|
40272
|
48992
|
48993
|
48994
|
48995
|
48996
|
52417
|
52418
|
52419
|
52420
|
52421
|
55277
|
55278
|
55279
|
58770
|
58771
|
58772
|
58773
|
58774
|
58775
|
58776
|
58777
|
58778
|
59301
|
59302
|
59303
|
59304
|
59305
|
59306
|
59307
|
59308
|
59309
|
61018
|
61019
|
61020
|
61021
|
61022
|
61023
|
61024
|
61025
|
61026
|
71260
|
71261
|
71262
|
71263
|
71264
|
71265
|
71266
|
71267
|
71268
|
72069
|
72070
|
72071
|
72072
|
72073
|
72074
|
72075
|
72076
|
72077
|
72691
|
72692
|
72693
|
72694
|
72695
|
72696
|
72697
|
72698
|
72699
|
74213
|
74214
|
74215
|
74216
|
74217
|
74218
|
74219
|
74220
|
74221
|
74222
|
74302
|
74303
|
74304
|
74305
|
74306
|
74307
|
74308
|
74309
|
74310
|
74311
|
74349
|
74350
|
74351
|
74352
|
74353
|
74354
|
74355
|
74356
|
74357
|
74358
|
75003
|
75004
|
75908
|
75909
|
78662
|
78663
|
78664
|
80697
|
80698
|
80699
|
80700
|
80979
|
80980
|
80981
|
80982
|
85786
|
85787
|
91285
|
91286
|
92378
|
92379
|
92380
|
92381
|
92382
|
93460
|
93461
|
93462
|
93463
|
93464
|
93482
|
93483
|
93484
|
93485
|
93487
|
104928
|
104929
|
104930
|
104931
|
104932
|
104933
|
104934
|
104935