Bugzilla – Attachment 137221 Details for
Bug 17015
New Koha Calendar
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17015: Install scripts for DiscreteCalendar
Bug-17015-Install-scripts-for-DiscreteCalendar.patch (text/plain), 9.56 KB, created by
Shi Yao Wang
on 2022-07-06 15:23:29 UTC
(
hide
)
Description:
Bug 17015: Install scripts for DiscreteCalendar
Filename:
MIME Type:
Creator:
Shi Yao Wang
Created:
2022-07-06 15:23:29 UTC
Size:
9.56 KB
patch
obsolete
>From f390dee6c9ab395ed6491f4631ff99efb6c68643 Mon Sep 17 00:00:00 2001 >From: Charles Farmer <charles.farmer@inLibro.com> >Date: Wed, 4 Sep 2019 14:57:19 -0400 >Subject: [PATCH] Bug 17015: Install scripts for DiscreteCalendar > >Signed-off-by: Michal Denar <black23@gmail.com> >--- > ..._17015_part1_create_discrete_calendar.perl | 19 +++ > ...ug_17015_part2_fill_discrete_calendar.perl | 150 ++++++++++++++++++ > .../bug_17015_part3_drop_calendar.perl | 11 ++ > installer/data/mysql/updatedatabase.pl | 4 +- > 4 files changed, 182 insertions(+), 2 deletions(-) > create mode 100644 installer/data/mysql/atomicupdate/bug_17015_part1_create_discrete_calendar.perl > create mode 100755 installer/data/mysql/atomicupdate/bug_17015_part2_fill_discrete_calendar.perl > create mode 100644 installer/data/mysql/atomicupdate/bug_17015_part3_drop_calendar.perl > >diff --git a/installer/data/mysql/atomicupdate/bug_17015_part1_create_discrete_calendar.perl b/installer/data/mysql/atomicupdate/bug_17015_part1_create_discrete_calendar.perl >new file mode 100644 >index 0000000000..0e5d16ed65 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_17015_part1_create_discrete_calendar.perl >@@ -0,0 +1,19 @@ >+$DBversion = 'XXX'; >+if( CheckVersion( $DBversion ) ) { >+ if ( !TableExists( 'discrete_calendar' ) ) { >+ $dbh->do( qq{ >+ CREATE TABLE `discrete_calendar` ( >+ `date` datetime NOT NULL, >+ `branchcode` varchar(10) NOT NULL, >+ `is_opened` tinyint(1) DEFAULT 1, >+ `holiday_type` varchar(1) DEFAULT '', >+ `note` varchar(30) DEFAULT '', >+ `open_hour` time NOT NULL, >+ `close_hour` time NOT NULL, >+ PRIMARY KEY (`branchcode`,`date`) >+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; >+ } ); >+ } >+ >+ NewVersion( $DBversion, 17015, "New koha calendar Part 1 - Create discrete_calendar table to keep track of library day's information"); >+} >diff --git a/installer/data/mysql/atomicupdate/bug_17015_part2_fill_discrete_calendar.perl b/installer/data/mysql/atomicupdate/bug_17015_part2_fill_discrete_calendar.perl >new file mode 100755 >index 0000000000..05c83a05e3 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_17015_part2_fill_discrete_calendar.perl >@@ -0,0 +1,150 @@ >+#!/usr/bin/perl >+ >+# >+# Script that fills the discrete_calendar table with dates, using the other date-related tables >+# >+use Modern::Perl; >+use DateTime; >+use DateTime::Format::Strptime; >+use Data::Dumper; >+use Getopt::Long; >+use C4::Context; >+ >+# Options >+my $daysInFuture = 365; >+ >+my $dbh = C4::Context->dbh; >+$dbh->{AutoCommit} = 0; >+$dbh->{RaiseError} = 1; >+ >+my $currentDate = DateTime->today; >+ >+# two years ago >+my $startDate = DateTime->new( >+day => $currentDate->day(), >+month => $currentDate->month(), >+year => $currentDate->year()-2, >+time_zone => C4::Context->tz() >+)->truncate( to => 'day' ); >+ >+# a year into the future >+my $endDate = DateTime->new( >+day => $currentDate->day(), >+month => $currentDate->month(), >+year => $currentDate->year(), >+time_zone => C4::Context->tz() >+)->truncate( to => 'day' ); >+$endDate->add(days => $daysInFuture); >+ >+# finds branches; >+my $selectBranchesSt = 'SELECT branchname, branchcode FROM branches'; >+my $selectBranchesSth = $dbh->prepare($selectBranchesSt); >+$selectBranchesSth->execute(); >+my @branches = (); >+while (my @row = $selectBranchesSth->fetchrow_array ) { >+ print "[$row[1]] $row[0]\n"; >+ push @branches, $row[1]; >+} >+ >+# finds what days are closed for each branch >+my %repeatableHolidaysPerBranch = (); >+my %specialHolidaysPerBranch = (); >+my $selectWeeklySt; >+my $selectWeeklySth; >+ >+foreach my $branch (@branches){ >+ if ( TableExists( 'repeatable_holidays' ) ) { >+ $selectWeeklySt = 'SELECT weekday, title, day, month FROM repeatable_holidays WHERE branchcode = ?'; >+ $selectWeeklySth = $dbh->prepare($selectWeeklySt); >+ $selectWeeklySth->execute($branch); >+ >+ my @weeklyHolidays = (); >+ >+ while ( my ($weekDay, $title, $day, $month) = $selectWeeklySth->fetchrow_array ) { >+ push @weeklyHolidays,{weekday => $weekDay, title => $title, day => $day, month => $month}; >+ >+ } >+ >+ $repeatableHolidaysPerBranch{$branch} = \@weeklyHolidays; >+ } >+ >+ if ( TableExists( 'repeatable_holidays' ) ) { >+ my $selectSpecialHolidayDateSt = 'SELECT day,month,year,title FROM special_holidays WHERE branchcode = ? AND isexception = 0'; >+ my $specialHolidayDatesSth = $dbh->prepare($selectSpecialHolidayDateSt); >+ $specialHolidayDatesSth -> execute($branch); >+ # Tranforms dates from specialHolidays table in DateTime for our new table >+ my @specialHolidayDates = (); >+ while ( my ($day, $month, $year, $title) = $specialHolidayDatesSth->fetchrow_array ) { >+ >+ my $specialHolidayDate = DateTime->new( >+ day => $day, >+ month => $month, >+ year => $year, >+ time_zone => C4::Context->tz() >+ )->truncate( to => 'day' ); >+ push @specialHolidayDates,{date=>$specialHolidayDate, title=> $title}; >+ } >+ >+ $specialHolidaysPerBranch{$branch} = \@specialHolidayDates; >+ } >+} >+ >+# Fills table with dates and sets 'is_opened' according to the branch's weekly restrictions (repeatable_holidays) >+my $insertDateSt; >+my $insertDateSth; >+ >+# Loop that does everything in the world >+for (my $tempDate = $startDate->clone(); $tempDate <= $endDate;$tempDate->add(days => 1)){ >+ foreach my $branch (@branches){ >+ my $dayOfWeek = $tempDate->day_of_week; >+ # Representation fix >+ # DateTime object dow (1-7) where Monday is 1 >+ # Arrays are 0-based where 0 = Sunday, not 7. >+ my $open_hour = "09:00:00"; >+ my $close_hour = "17:00:00"; >+ >+ # Finds closed days >+ my $is_opened =1; >+ my $specialDescription = ""; >+ my $holiday_type =''; >+ $dayOfWeek = $tempDate->day_of_week % 7; >+ foreach my $holidayWeekDay ( @{$repeatableHolidaysPerBranch{$branch}} ) { >+ if (defined($holidayWeekDay) && $dayOfWeek == $holidayWeekDay->{weekday}) { >+ $is_opened = 0; >+ $specialDescription = $holidayWeekDay->{title}; >+ $holiday_type = 'W'; >+ } elsif ($holidayWeekDay->{day} && $holidayWeekDay->{month}) { >+ my $date = DateTime->new( >+ day => $holidayWeekDay->{day}, >+ month => $holidayWeekDay->{month}, >+ year => $tempDate->year(), >+ time_zone => C4::Context->tz() >+ )->truncate( to => 'day' ); >+ >+ if ($tempDate == $date) { >+ $is_opened = 0; >+ $specialDescription = $holidayWeekDay->{title}; >+ $holiday_type = 'R'; >+ } >+ } >+ } >+ >+ foreach my $specialDate (@{$specialHolidaysPerBranch{$branch}}){ >+ if ($tempDate->datetime() eq $specialDate->{date}->datetime()) { >+ $is_opened = 0; >+ $specialDescription = $specialDate->{title}; >+ $holiday_type = 'E'; >+ } >+ } >+ #final insert statement >+ >+ $insertDateSt = 'INSERT IGNORE INTO discrete_calendar (date,branchcode,is_opened,holiday_type,note,open_hour,close_hour) VALUES (?,?,?,?,?,?,?)'; >+ $insertDateSth = $dbh->prepare($insertDateSt); >+ $insertDateSth->execute($tempDate,$branch,$is_opened,$holiday_type,$specialDescription,$open_hour,$close_hour); >+ } >+} >+ >+# If everything went well we commit to the database >+$dbh->commit(); >+$dbh->{AutoCommit} = 1; >+$dbh->{RaiseError} = 0; >diff --git a/installer/data/mysql/atomicupdate/bug_17015_part3_drop_calendar.perl b/installer/data/mysql/atomicupdate/bug_17015_part3_drop_calendar.perl >new file mode 100644 >index 0000000000..a7e96b0ae5 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_17015_part3_drop_calendar.perl >@@ -0,0 +1,11 @@ >+$DBversion = 'XXX'; >+if( CheckVersion( $DBversion ) ) { >+ if ( TableExists( 'repeatable_holidays' ) ) { >+ $dbh->do( "DROP TABLE IF EXISTS `repeatable_holidays`;" ); >+ } >+ if ( TableExists( 'special_holidays' ) ) { >+ $dbh->do( "DROP TABLE IF EXISTS `special_holidays`;" ); >+ } >+ >+ NewVersion( $DBversion, 17015, "New koha calendar Part 3 - Drop deprecated calendar-related tables after creating and filling discrete_calendar"); >+} >diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl >index 811b7ee632..737d5f8316 100755 >--- a/installer/data/mysql/updatedatabase.pl >+++ b/installer/data/mysql/updatedatabase.pl >@@ -14344,7 +14344,7 @@ if( CheckVersion( $DBversion ) ) { > > $DBversion = '16.12.00.032'; > if( CheckVersion( $DBversion ) ) { >- require Koha::Calendar; >+ require Koha::DiscreteCalendar; > > $dbh->do(q{ > INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) >@@ -14371,7 +14371,7 @@ if( CheckVersion( $DBversion ) ) { > > my $expirationdate = dt_from_string($hold->{waitingdate}); > if ( C4::Context->preference("ExcludeHolidaysFromMaxPickUpDelay") ) { >- my $calendar = Koha::Calendar->new( branchcode => $hold->{branchcode}, days_mode => C4::Context->preference('useDaysMode') ); >+ my $calendar = Koha::DiscreteCalendar->new( branchcode => $hold->{branchcode}, days_mode => C4::Context->preference('useDaysMode') ); > $expirationdate = $calendar->days_forward( $expirationdate, $max_pickup_delay ); > } else { > $expirationdate->add( days => $max_pickup_delay ); >-- >2.25.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 17015
:
53859
|
54318
|
54419
|
59166
|
59167
|
59168
|
59169
|
59170
|
59171
|
59267
|
59268
|
59269
|
59270
|
59271
|
59463
|
59516
|
59517
|
59518
|
59519
|
59520
|
59561
|
59562
|
59586
|
59587
|
59888
|
59889
|
60902
|
60903
|
60904
|
60905
|
60906
|
60986
|
61737
|
62375
|
62376
|
62380
|
63257
|
63282
|
63362
|
63363
|
63364
|
63365
|
63366
|
63367
|
64235
|
65073
|
65074
|
65075
|
65076
|
65077
|
67721
|
67722
|
67723
|
67724
|
67725
|
67879
|
67929
|
67930
|
67931
|
67932
|
67933
|
67934
|
68392
|
68393
|
68394
|
68395
|
68396
|
68397
|
71634
|
71635
|
71636
|
71637
|
71638
|
72890
|
73145
|
74859
|
74860
|
74861
|
74862
|
74863
|
74864
|
74865
|
74866
|
75444
|
75479
|
76594
|
77249
|
77250
|
77607
|
77608
|
77609
|
77610
|
77611
|
77612
|
77613
|
77770
|
77771
|
77772
|
77773
|
77774
|
79035
|
80523
|
80524
|
80525
|
80526
|
80527
|
80528
|
80529
|
80530
|
80531
|
80532
|
80533
|
80534
|
80535
|
83547
|
85394
|
85677
|
85678
|
85679
|
85680
|
85681
|
85682
|
85683
|
85684
|
85685
|
85686
|
85687
|
85688
|
85689
|
85690
|
85691
|
92595
|
92596
|
92597
|
92598
|
100079
|
110383
|
110384
|
110386
|
110387
|
110388
|
110389
|
113541
|
113905
|
115501
|
115502
|
115503
|
115504
|
115505
|
115506
|
115507
|
115508
|
115509
|
115510
|
115511
|
118554
|
118555
|
118556
|
118557
|
118558
|
118559
|
119095
|
119097
|
119099
|
119100
|
119101
|
119102
|
131619
|
131620
|
131621
|
131622
|
131623
|
131624
|
131625
|
131626
|
131634
|
131635
|
131636
|
131637
|
131638
|
131639
|
131640
|
131641
|
131667
|
132199
|
133596
|
133597
|
133598
|
133599
|
133600
|
133601
|
133602
|
133603
|
133604
|
133605
|
133678
|
137219
|
137220
|
137221
|
137222
|
137223
|
137224
|
137225
|
137226
|
137227
|
137228
|
137229
|
139378
|
139379
|
139380
|
139381
|
139382
|
139599
|
139600
|
139601
|
139602
|
139603
|
139851
|
140150
|
141176
|
144257
|
144258
|
144259
|
144260
|
144261
|
144262
|
144264
|
144268
|
144269
|
144270
|
144271
|
144272
|
144273
|
151438
|
151439
|
151440
|
151441
|
151442
|
151443
|
151444
|
151445
|
151446
|
151447
|
151448
|
151449
|
151450
|
156340
|
156341
|
156342
|
156343
|
156344
|
156345
|
156346
|
156347
|
156348
|
156349
|
156350
|
156351
|
156352
|
156353
|
156354
|
156355
|
157656
|
157657
|
157658
|
157659
|
157660
|
157661
|
157662
|
157663
|
157664
|
157665
|
157666
|
157667
|
157668
|
157669
|
157670
|
157671
|
157672
|
167805
|
167806
|
167807
|
167808
|
167809