Bug 29803: Prevent local cover image to be hidden if Coce is enabled
[srvgit] / C4 / Calendar.pm
index 321aad7..257119c 100644 (file)
@@ -19,8 +19,8 @@ use strict;
 use warnings;
 use vars qw(@EXPORT);
 
-use Carp;
-use Date::Calc qw( Date_to_Days Today);
+use Carp qw( croak );
+use Date::Calc qw( Today );
 
 use C4::Context;
 use Koha::Caches;
@@ -277,8 +277,8 @@ sub insert_single_holiday {
 
     # changed the 'single_holidays' table, lets force/reset its cache
     my $cache = Koha::Caches->get_instance();
-    $cache->clear_from_cache( 'single_holidays') ;
-    $cache->clear_from_cache( 'exception_holidays') ;
+    my $key   = $self->{branchcode} . "_holidays";
+    $cache->clear_from_cache($key);
 
     return $self;
 
@@ -322,8 +322,8 @@ sub insert_exception_holiday {
 
     # changed the 'single_holidays' table, lets force/reset its cache
     my $cache = Koha::Caches->get_instance();
-    $cache->clear_from_cache( 'single_holidays') ;
-    $cache->clear_from_cache( 'exception_holidays') ;
+    my $key   = $self->{branchcode} . "_holidays";
+    $cache->clear_from_cache($key);
 
     return $self;
 }
@@ -423,8 +423,8 @@ UPDATE special_holidays SET title = ?, description = ?
 
     # changed the 'single_holidays' table, lets force/reset its cache
     my $cache = Koha::Caches->get_instance();
-    $cache->clear_from_cache( 'single_holidays') ;
-    $cache->clear_from_cache( 'exception_holidays') ;
+    my $key   = $self->{branchcode} . "_holidays";
+    $cache->clear_from_cache($key);
 
     return $self;
 }
@@ -466,8 +466,8 @@ UPDATE special_holidays SET title = ?, description = ?
 
     # changed the 'single_holidays' table, lets force/reset its cache
     my $cache = Koha::Caches->get_instance();
-    $cache->clear_from_cache( 'single_holidays') ;
-    $cache->clear_from_cache( 'exception_holidays') ;
+    my $key   = $self->{branchcode} . "_holidays";
+    $cache->clear_from_cache($key);
 
     return $self;
 }
@@ -547,8 +547,8 @@ sub delete_holiday {
 
     # changed the 'single_holidays' table, lets force/reset its cache
     my $cache = Koha::Caches->get_instance();
-    $cache->clear_from_cache( 'single_holidays') ;
-    $cache->clear_from_cache( 'exception_holidays') ;
+    my $key   = $self->{branchcode} . "_holidays";
+    $cache->clear_from_cache($key);
 
     return $self;
 }
@@ -578,8 +578,8 @@ sub delete_holiday_range {
 
     # changed the 'single_holidays' table, lets force/reset its cache
     my $cache = Koha::Caches->get_instance();
-    $cache->clear_from_cache( 'single_holidays') ;
-    $cache->clear_from_cache( 'exception_holidays') ;
+    my $key   = $self->{branchcode} . "_holidays";
+    $cache->clear_from_cache($key);
 
 }
 
@@ -632,8 +632,8 @@ sub delete_exception_holiday_range {
 
     # changed the 'single_holidays' table, lets force/reset its cache
     my $cache = Koha::Caches->get_instance();
-    $cache->clear_from_cache( 'single_holidays') ;
-    $cache->clear_from_cache( 'exception_holidays') ;
+    my $key   = $self->{branchcode} . "_holidays";
+    $cache->clear_from_cache($key);
 }
 
 =head2 isHoliday
@@ -690,14 +690,36 @@ sub copy_to_branch {
     my $today = sprintf ISO_DATE_FORMAT, $y,$m,$d;
 
     my $wdh = $self->get_week_days_holidays;
-    $target_calendar->insert_week_day_holiday( weekday => $_, %{ $wdh->{$_} } )
-      foreach keys %$wdh;
-    $target_calendar->insert_day_month_holiday(%$_)
-      foreach values %{ $self->get_day_month_holidays };
-    $target_calendar->insert_exception_holiday(%$_)
-      foreach grep { $_->{date} gt $today } values %{ $self->get_exception_holidays };
-    $target_calendar->insert_single_holiday(%$_)
-      foreach grep { $_->{date} gt $today } values %{ $self->get_single_holidays };
+    my $target_wdh = $target_calendar->get_week_days_holidays;
+    foreach my $key (keys %$wdh) {
+        unless (grep { $_ eq $key } keys %$target_wdh) {
+            $target_calendar->insert_week_day_holiday( weekday => $key, %{ $wdh->{$key} } )
+        }
+    }
+
+    my $dmh = $self->get_day_month_holidays;
+    my $target_dmh = $target_calendar->get_day_month_holidays;
+    foreach my $values (values %$dmh) {
+        unless (grep { $_->{day} eq $values->{day} && $_->{month} eq $values->{month} } values %$target_dmh) {
+            $target_calendar->insert_day_month_holiday(%{ $values });
+        }
+    }
+
+    my $exception_holidays = $self->get_exception_holidays;
+    my $target_exceptions = $target_calendar->get_exception_holidays;
+    foreach my $values ( grep {$_->{date} gt $today} values %{ $exception_holidays }) {
+        unless ( grep { $_->{date} eq $values->{date} } values %$target_exceptions) {
+            $target_calendar->insert_exception_holiday(%{ $values });
+        }
+    }
+
+    my $single_holidays = $self->get_single_holidays;
+    my $target_singles = $target_calendar->get_single_holidays;
+    foreach my $values ( grep {$_->{date} gt $today} values %{ $single_holidays }) {
+        unless ( grep { $_->{date} eq $values->{date} } values %$target_singles){
+            $target_calendar->insert_single_holiday(%{ $values });
+        }
+    }
 
     return 1;
 }
@@ -711,3 +733,4 @@ __END__
 Koha Physics Library UNLP <matias_veleda@hotmail.com>
 
 =cut
+