From 89f8feb46bbbd4ea923f45e20c395dbce33abe71 Mon Sep 17 00:00:00 2001 From: Emmi Takkinen Date: Tue, 23 May 2023 15:29:12 +0300 Subject: [PATCH] Bug 33667: Allow copying holidays to all libraries when editing When editing an existing holiday and checking the "copy to all libraires" checkbox, the other calendars won't get updates. Allow this by first checking if holiday exists in target calendar and if not, add it. To test: 1. Add unique holiday to branch A. 2. Don't check checkbox "Copy to all libraries". 3. Save. 4. Verify the holidays shows on all calendars as a green box. 5. Edit the holiday, now check "Copy to all libraries" and save. => Verify nothing has changed in other calendars: only the green box, no holiday in list on the right 6. Edit again, make a change to description, check checkbox, save. => Verify it's still not showing in the other calendars. 9. Apply this patch. 10. Edit holiday again, check "Copy to all libraries" and save. => Verify holiday is now added to other calendars. 11. Edit again, this time do not copy and save. => Verify holiday was edited just in branch A. 12. Again edit, check and save. => Verify holiday was edited in all libraries. Sponsored-by: Koha-Suomi Oy --- .../prog/en/modules/tools/holidays.tt | 2 +- tools/exceptionHolidays.pl | 98 +++++++++++++++---- 2 files changed, 78 insertions(+), 22 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt index 0cade7a1c6..f03db0c0ff 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt @@ -123,7 +123,7 @@ . [?] -
If checked, changes for this holiday will be copied to all libraries. If the holiday doesn't exists for a library, no change is made.
+
If checked, changes for this holiday will be copied to all libraries. If the holiday doesn't exists for a library, holiday is added to calendar. NOTE! This might overwrite existing holidays in other calendars.
diff --git a/tools/exceptionHolidays.pl b/tools/exceptionHolidays.pl index a96b1d0ebb..bdfd6d2313 100755 --- a/tools/exceptionHolidays.pl +++ b/tools/exceptionHolidays.pl @@ -86,27 +86,83 @@ sub edit_holiday { } } } elsif ($showoperation eq 'edit') { - if($holidaytype eq 'weekday') { - $calendar->ModWeekdayholiday(weekday => $weekday, - title => $title, - description => $description); - } elsif ($holidaytype eq 'daymonth') { - $calendar->ModDaymonthholiday(day => $day, - month => $month, - title => $title, - description => $description); - } elsif ($holidaytype eq 'ymd') { - $calendar->ModSingleholiday(day => $day, - month => $month, - year => $year, - title => $title, - description => $description); - } elsif ($holidaytype eq 'exception') { - $calendar->ModExceptionholiday(day => $day, - month => $month, - year => $year, - title => $title, - description => $description); + if ( $holidaytype eq 'weekday' ) { + my $isHoliday = $calendar->isHoliday( $day, $month, $year ); + if ($isHoliday) { + $calendar->ModWeekdayholiday( + weekday => $weekday, + title => $title, + description => $description + ); + } + else { + $calendar->insert_week_day_holiday( + weekday => $weekday, + title => $title, + description => $description + ); + } + } + elsif ( $holidaytype eq 'daymonth' ) { + my $isHoliday = $calendar->isHoliday( $day, $month, $year ); + if ($isHoliday) { + $calendar->ModDaymonthholiday( + day => $day, + month => $month, + title => $title, + description => $description + ); + } + else { + $calendar->insert_day_month_holiday( + day => $day, + month => $month, + title => $title, + description => $description + ); + } + } + elsif ( $holidaytype eq 'ymd' ) { + my $isHoliday = $calendar->isHoliday( $day, $month, $year ); + if ($isHoliday) { + $calendar->ModSingleholiday( + day => $day, + month => $month, + year => $year, + title => $title, + description => $description + ); + } + else { + $calendar->insert_single_holiday( + day => $day, + month => $month, + year => $year, + title => $title, + description => $description + ); + } + } + elsif ( $holidaytype eq 'exception' ) { + my $isHoliday = $calendar->isHoliday( $day, $month, $year ); + if ($isHoliday) { + $calendar->ModExceptionholiday( + day => $day, + month => $month, + year => $year, + title => $title, + description => $description + ); + } + else { + $calendar->insert_exception_holiday( + day => $day, + month => $month, + year => $year, + title => $title, + description => $description + ); + } } } elsif ($showoperation eq 'delete') { $calendar->delete_holiday(weekday => $weekday, -- 2.34.1