Bug 32336: (QA follow-up) Use $metadata->schema
[srvgit] / Koha / ClassSource.pm
1 package Koha::ClassSource;
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19
20 use Koha::Caches;
21 use Koha::Database;
22
23 use base qw(Koha::Object);
24
25 my $cache = Koha::Caches->get_instance();
26
27 =head1 NAME
28
29 Koha::ClassSource - Koha Classfication Source Object class
30
31 =head1 API
32
33 =head2 Class Methods
34
35 =head3 store
36
37 ClassSource specific store to ensure relevant caches are flushed on change
38
39 =cut
40
41 sub store {
42     my ($self) = @_;
43
44     my $flush = 0;
45
46     if ( !$self->in_storage ) {
47         $flush = 1;
48     }
49     else {
50         my $self_from_storage = $self->get_from_storage;
51         $flush = 1 if ( $self_from_storage->description ne $self->description );
52     }
53
54     $self = $self->SUPER::store;
55
56     if ($flush) {
57         $cache->clear_from_cache('cn_sources:description');
58     }
59
60     return $self;
61 }
62
63 =head2 delete
64
65 ClassSource specific C<delete> to clear relevant caches on delete.
66
67 =cut
68
69 sub delete {
70     my $self = shift @_;
71     $cache->clear_from_cache('cn_sources:description');
72     $self->SUPER::delete(@_);
73 }
74
75 =head3 _type
76
77 Returns name of corresponding DBIC resultset
78
79 =cut
80
81 sub _type {
82     return 'ClassSource';
83 }
84
85 1;