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

(-)a/Koha/AuthorisedValues.pm (-3 / +8 lines)
Lines 24-29 use Carp; Link Here
24
use Koha::Database;
24
use Koha::Database;
25
25
26
use Koha::AuthorisedValue;
26
use Koha::AuthorisedValue;
27
use Koha::I18N;
27
use Koha::MarcSubfieldStructures;
28
use Koha::MarcSubfieldStructures;
28
use Koha::Cache::Memory::Lite;
29
use Koha::Cache::Memory::Lite;
29
30
Lines 135-141 sub get_description_by_koha_field { Link Here
135
136
136
    my $av = $self->find_by_koha_field($params);
137
    my $av = $self->find_by_koha_field($params);
137
    return {} unless defined $av;
138
    return {} unless defined $av;
138
    my $descriptions = { lib => $av->lib, opac_description => $av->opac_description };
139
    my $l10n_group = 'authorised_value:' . $av->category;
140
    my $descriptions = {
141
        lib => db_t($l10n_group, $av->lib),
142
        opac_description => db_t($l10n_group, $av->opac_description),
143
    };
139
    $memory_cache->set_in_cache( $cache_key, $descriptions );
144
    $memory_cache->set_in_cache( $cache_key, $descriptions );
140
    return $descriptions;
145
    return $descriptions;
141
}
146
}
Lines 154-161 sub get_descriptions_by_koha_field { Link Here
154
    my @descriptions = map {
159
    my @descriptions = map {
155
        {
160
        {
156
            authorised_value => $_->authorised_value,
161
            authorised_value => $_->authorised_value,
157
            lib              => $_->lib,
162
            lib              => db_t('authorised_value:' . $_->category, $_->lib),
158
            opac_description => $_->opac_description
163
            opac_description => db_t('authorised_value:' . $_->category, $_->opac_description),
159
        }
164
        }
160
    } @avs;
165
    } @avs;
161
    $memory_cache->set_in_cache( $cache_key, \@descriptions );
166
    $memory_cache->set_in_cache( $cache_key, \@descriptions );
(-)a/Koha/DBIx/Component/L10nSource.pm (-10 / +14 lines)
Lines 52-67 sub update_l10n_source { Link Here
52
    my ($self, $group, $key, $text) = @_;
52
    my ($self, $group, $key, $text) = @_;
53
53
54
    my $l10n_source_rs = $self->result_source->schema->resultset('L10nSource');
54
    my $l10n_source_rs = $self->result_source->schema->resultset('L10nSource');
55
    $l10n_source_rs->update_or_create(
55
    if (defined $text and $text ne '') {
56
        {
56
        $l10n_source_rs->update_or_create(
57
            group => $group,
57
            {
58
            key   => $key,
58
                group => $group,
59
            text  => $text,
59
                key   => $key,
60
        },
60
                text  => $text,
61
        {
61
            },
62
            key => 'group_key',
62
            {
63
        }
63
                key => 'group_key',
64
    );
64
            }
65
        );
66
    } else {
67
        $self->delete_l10n_source($group, $key);
68
    }
65
}
69
}
66
70
67
=head2 delete_l10n_source
71
=head2 delete_l10n_source
(-)a/Koha/Schema/Result/AuthorisedValue.pm (-1 / +52 lines)
Lines 148-153 __PACKAGE__->has_many( Link Here
148
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-02-22 14:32:48
148
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-02-22 14:32:48
149
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:hDlebhEn+f+thqwBo/LOqQ
149
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:hDlebhEn+f+thqwBo/LOqQ
150
150
151
__PACKAGE__->load_components('+Koha::DBIx::Component::L10nSource');
152
153
sub insert {
154
    my $self = shift;
155
156
    my $result = $self->next::method(@_);
157
158
    my $group = sprintf('authorised_value:%s', $self->get_column('category'));
159
    $self->update_l10n_source( $group,
160
        $self->authorised_value . ':intranet',
161
        $self->lib );
162
    $self->update_l10n_source( $group,
163
        $self->authorised_value . ':opac',
164
        $self->lib_opac );
165
166
    return $result;
167
}
168
169
sub update {
170
    my $self = shift;
171
172
    my $is_lib_changed = $self->is_column_changed('lib');
173
    my $is_lib_opac_changed = $self->is_column_changed('lib_opac');
174
175
    my $result = $self->next::method(@_);
176
177
    my $group = sprintf('authorised_value:%s', $self->get_column('category'));
178
    if ($is_lib_changed) {
179
        $self->update_l10n_source( $group,
180
            $self->authorised_value . ':intranet',
181
            $self->lib );
182
    }
183
    if ($is_lib_opac_changed) {
184
        $self->update_l10n_source( $group,
185
            $self->authorised_value . ':opac',
186
            $self->lib_opac );
187
    }
188
189
    return $result;
190
}
191
192
sub delete {
193
    my $self = shift;
194
195
    my $result = $self->next::method(@_);
196
197
    my $group = sprintf('authorised_value:%s', $self->get_column('category'));
198
    $self->delete_l10n_source($group, sprintf('%s:intranet', $self->authorised_value));
199
    $self->delete_l10n_source($group, sprintf('%s:opac', $self->authorised_value));
200
201
    return $result;
202
}
151
203
152
# You can replace this text with custom code or comments, and it will be preserved on regeneration
153
1;
204
1;
(-)a/installer/data/mysql/atomicupdate/bug-24977.perl (-1 / +12 lines)
Line 0 Link Here
0
- 
1
$DBversion = 'XXX';
2
if( CheckVersion( $DBversion ) ) {
3
    $dbh->do(q{
4
        INSERT IGNORE INTO l10n_source (`group`, `key`, `text`)
5
        SELECT DISTINCT CONCAT('authorised_value:', category), CONCAT(authorised_value, ':intranet'), lib FROM authorised_values WHERE lib IS NOT NULL AND lib != ''
6
        UNION
7
        SELECT DISTINCT CONCAT('authorised_value:', category), CONCAT(authorised_value, ':opac'), lib_opac FROM authorised_values WHERE lib_opac IS NOT NULL AND lib_opac != ''
8
    });
9
10
    SetVersion( $DBversion );
11
    print "Upgrade to $DBversion done (Bug 24977 - populate l10n_source with authorised_values)\n";
12
}

Return to bug 24977