View | Details | Raw Unified | Return to bug 25723
Collapse All | Expand All

(-)a/Koha/Calendar.pm (-50 / +21 lines)
Lines 54-88 sub _init { Link Here
54
sub exception_holidays {
54
sub exception_holidays {
55
    my ($self) = @_;
55
    my ($self) = @_;
56
56
57
    my $cache              = Koha::Caches->get_instance();
57
    return $self->_holidays('exception');
58
    my $exception_holidays = $cache->get_from_cache('exception_holidays');
58
}
59
60
sub _holidays {
61
    my ( $self, $type ) = @_;
62
63
    die "Unknown type, only 'exception' or 'single' is supported"
64
        unless $type eq 'exception' or $type eq 'single';
65
66
    my $cache    = Koha::Caches->get_instance();
67
    my $holidays = $cache->get_from_cache("${type}_holidays");
59
68
60
    # Populate the cache is necessary
69
    # Populate the cache is necessary
61
    unless ($exception_holidays) {
70
    unless ($holidays) {
62
        my $dbh = C4::Context->dbh;
71
        my $dbh = C4::Context->dbh;
63
        $exception_holidays = {};
72
        $holidays = {};
64
73
65
        # Push holidays for each branch
74
        # Push holidays for each branch
66
        my $exception_holidays_sth = $dbh->prepare(
75
        my $holidays_sth = $dbh->prepare(
67
'SELECT day, month, year, branchcode FROM special_holidays WHERE isexception = 1'
76
            'SELECT day, month, year, branchcode FROM special_holidays WHERE isexception = ?'
68
        );
77
        );
69
        $exception_holidays_sth->execute();
78
        $holidays_sth->execute($type eq 'exception' ? 1 : 0);
70
        my $dates = [];
79
        my $dates = [];
71
        while ( my ( $day, $month, $year, $branch ) =
80
        while ( my ( $day, $month, $year, $branch ) =
72
            $exception_holidays_sth->fetchrow )
81
            $holidays_sth->fetchrow )
73
        {
82
        {
74
            my $datestring =
83
            my $datestring =
75
                sprintf( "%04d", $year )
84
                sprintf( "%04d", $year )
76
              . sprintf( "%02d", $month )
85
              . sprintf( "%02d", $month )
77
              . sprintf( "%02d", $day );
86
              . sprintf( "%02d", $day );
78
87
79
            $exception_holidays->{$branch}->{$datestring} = 1;
88
            $holidays->{$branch}->{$datestring} = 1;
80
        }
89
        }
81
        $cache->set_in_cache( 'exception_holidays', $exception_holidays,
90
        $cache->set_in_cache( "${type}_holidays", $holidays,
82
            { expiry => 76800 } );
91
            { expiry => 76800 } );
83
    }
92
    }
84
93
85
    return $exception_holidays->{ $self->{branchcode} } // {};
94
    return $holidays->{ $self->{branchcode} } // {};
86
}
95
}
87
96
88
sub is_exception_holiday {
97
sub is_exception_holiday {
Lines 95-138 sub is_exception_holiday { Link Here
95
sub single_holidays {
104
sub single_holidays {
96
    my ($self) = @_;
105
    my ($self) = @_;
97
106
98
    my $cache           = Koha::Caches->get_instance();
107
    return $self->_holidays('single');
99
    my $single_holidays = $cache->get_from_cache('single_holidays');
100
101
    # $single_holidays looks like:
102
    # {
103
    #   CPL =>  [
104
    #        [0] 20131122,
105
    #         ...
106
    #    ],
107
    #   ...
108
    # }
109
110
    # Populate the cache if necessary
111
    unless ($single_holidays) {
112
        my $dbh = C4::Context->dbh;
113
        $single_holidays = {};
114
115
        # Push holidays for each branch
116
        my $single_holidays_sth = $dbh->prepare(
117
'SELECT day, month, year, branchcode FROM special_holidays WHERE isexception = 0'
118
        );
119
        $single_holidays_sth->execute();
120
121
        while ( my ( $day, $month, $year, $branch ) =
122
            $single_holidays_sth->fetchrow )
123
        {
124
            my $datestring =
125
                sprintf( "%04d", $year )
126
              . sprintf( "%02d", $month )
127
              . sprintf( "%02d", $day );
128
129
            $single_holidays->{$branch}->{$datestring} = 1;
130
        }
131
        $cache->set_in_cache( 'single_holidays', $single_holidays,
132
            { expiry => 76800 } );
133
    }
134
135
    return $single_holidays->{ $self->{branchcode} } // {};
136
}
108
}
137
109
138
sub is_single_holiday {
110
sub is_single_holiday {
139
- 

Return to bug 25723