Bug 16088: Introduce Koha::Cache::Memory::Lite to cache the language
[koha.git] / Koha / Calendar.pm
index 6be7c16..1321621 100644 (file)
@@ -52,23 +52,15 @@ sub _init {
     return;
 }
 
-
-# FIXME: use of package-level variables for caching the holiday
-# lists breaks persistance engines.  As of 2013-12-10, the RM
-# is allowing this with the expectation that prior to release of
-# 3.16, bug 8089 will be fixed and we can switch the caching over
-# to Koha::Cache.
-
-our ( $exception_holidays, $single_holidays ); ## no need for $single_holidays now, surely?
-
 sub exception_holidays {
     my ( $self ) = @_;
+
+    my $cache  = Koha::Cache->get_instance();
+    my $cached = $cache->get_from_cache('exception_holidays');
+    return $cached if $cached;
+
     my $dbh = C4::Context->dbh;
     my $branch = $self->{branchcode};
-    if ( $exception_holidays ) {
-        $self->{exception_holidays} = $exception_holidays;
-        return $exception_holidays;
-    }
     my $exception_holidays_sth = $dbh->prepare(
 'SELECT day, month, year FROM special_holidays WHERE branchcode = ? AND isexception = 1'
     );
@@ -85,8 +77,8 @@ sub exception_holidays {
     }
     $self->{exception_holidays} =
       DateTime::Set->from_datetimes( dates => $dates );
-    $exception_holidays = $self->{exception_holidays};
-    return $exception_holidays;
+    $cache->set_in_cache( 'exception_holidays', $self->{exception_holidays} );
+    return $self->{exception_holidays};
 }
 
 sub single_holidays {
@@ -95,23 +87,14 @@ sub single_holidays {
     my $cache           = Koha::Cache->get_instance();
     my $single_holidays = $cache->get_from_cache('single_holidays');
 
-=c
-$single_holidays looks like this..
-
-\ {
-   CPL   [
-        [0] 20131122,
-        [1] 20131123,
-        [2] 20131124
-    ],
-   MPL   [
-        [0] 20131122,
-        [1] 20131123,
-        [2] 20131124
-    ]
-}
-
-=cut
+    # $single_holidays looks like:
+    # {
+    #   CPL =>  [
+    #        [0] 20131122,
+    #         ...
+    #    ],
+    #   ...
+    # }
 
     unless ($single_holidays) {
         my $dbh = C4::Context->dbh;
@@ -125,7 +108,7 @@ $single_holidays looks like this..
             my $single_holidays_sth = $dbh->prepare(
 'SELECT day, month, year FROM special_holidays WHERE branchcode = ? AND isexception = 0'
             );
-            $single_holidays_sth->execute($branchcode);
+            $single_holidays_sth->execute($br);
 
             my @ymd_arr;
             while ( my ( $day, $month, $year ) =
@@ -383,28 +366,6 @@ sub clear_weekly_closed_days {
     return;
 }
 
-
-sub add_dummy_holiday {
-    my ( $self, $new_dt ) = @_;
-
-    my $cache           = Koha::Cache->get_instance();
-    my $single_holidays = $cache->get_from_cache('single_holidays');
-
-    # add a dummy holiday to the holiday cache...
-    my $ymd = $new_dt->ymd('');
-    $single_holidays->{'MPL'} = [$ymd];
-    $cache->set_in_cache( 'single_holidays', $single_holidays, 76800 );
-
-    # ...but *dont* reset the cache, as this holiday was not really written to the db
-    # its only used to mock a holiday insert for 1 test in t/db_dependent/Holidays.t
-
-    #   is( $koha_calendar->is_holiday($custom_holiday), 0, '2013-11-10 does not start off as a holiday' );
-    #   $koha_calendar->add_dummy_holiday($custom_holiday );
-    #   is( $koha_calendar->is_holiday($custom_holiday), 1, 'able to add holiday for testing' );
-
-}
-
-
 1;
 __END__
 
@@ -412,10 +373,6 @@ __END__
 
 Koha::Calendar - Object containing a branches calendar
 
-=head1 VERSION
-
-This documentation refers to Koha::Calendar version 0.0.1
-
 =head1 SYNOPSIS
 
   use Koha::Calendar