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

(-)a/Koha/AuthorisedValues.pm (-2 / +3 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 154-161 sub get_descriptions_by_koha_field { Link Here
154
    my @descriptions = map {
155
    my @descriptions = map {
155
        {
156
        {
156
            authorised_value => $_->authorised_value,
157
            authorised_value => $_->authorised_value,
157
            lib              => $_->lib,
158
            lib              => db_t('authorised_value:' . $_->category, $_->lib),
158
            opac_description => $_->opac_description
159
            opac_description => db_t('authorised_value:' . $_->category, $_->opac_description),
159
        }
160
        }
160
    } @avs;
161
    } @avs;
161
    $memory_cache->set_in_cache( $cache_key, \@descriptions );
162
    $memory_cache->set_in_cache( $cache_key, \@descriptions );
(-)a/Koha/DBIx/Component/L10nSource.pm (+2 lines)
Lines 54-59 sub update_l10n_source { Link Here
54
54
55
    my $l10n_source_rs = $self->result_source->schema->resultset('L10nSource')->search({ context => $context });
55
    my $l10n_source_rs = $self->result_source->schema->resultset('L10nSource')->search({ context => $context });
56
56
57
    @sources = grep { defined $_ && $_ ne '' } @sources;
58
57
    # Insert missing l10n_source rows
59
    # Insert missing l10n_source rows
58
    foreach my $source (@sources) {
60
    foreach my $source (@sources) {
59
        my $count = $l10n_source_rs->search({ source => $source })->count;
61
        my $count = $l10n_source_rs->search({ source => $source })->count;
(-)a/Koha/Schema/Result/AuthorisedValue.pm (-2 / +59 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
151
__PACKAGE__->load_components('+Koha::DBIx::Component::L10nSource');
152
# You can replace this text with custom code or comments, and it will be preserved on regeneration
152
153
sub insert {
154
    my $self = shift;
155
156
    my $result = $self->next::method(@_);
157
158
    my @authorised_values = $self->result_source->resultset->search(undef, {
159
        result_class => 'DBIx::Class::ResultClass::HashRefInflator',
160
        columns => ['lib', 'lib_opac'],
161
    });
162
    my @sources = map { $_->{lib}, $_->{lib_opac} } @authorised_values;
163
    my $category = $self->get_column('category');
164
    my $context = "authorised_value:$category";
165
    $self->update_l10n_source($context, @sources);
166
167
    return $result;
168
}
169
170
sub update {
171
    my $self = shift;
172
173
    my $is_lib_changed = $self->is_column_changed('lib') || $self->is_column_changed('lib_opac');
174
175
    my $result = $self->next::method(@_);
176
177
    if ($is_lib_changed) {
178
        my $category = $self->get_column('category');
179
        my @authorised_values = $self->result_source->resultset->search(
180
            { category => $category },
181
            {
182
                result_class => 'DBIx::Class::ResultClass::HashRefInflator',
183
                columns => ['lib', 'lib_opac'],
184
            }
185
        );
186
        my @sources = map { $_->{lib}, $_->{lib_opac} } @authorised_values;
187
        my $context = "authorised_value:$category";
188
        $self->update_l10n_source($context, @sources);
189
    }
190
191
    return $result;
192
}
193
194
sub delete {
195
    my $self = shift;
196
197
    my $result = $self->next::method(@_);
198
199
    my @authorised_values = $self->result_source->resultset->search(undef, {
200
        result_class => 'DBIx::Class::ResultClass::HashRefInflator',
201
        columns => ['lib', 'lib_opac'],
202
    });
203
    my @sources = map { $_->{lib}, $_->{lib_opac} } @authorised_values;
204
    my $category = $self->get_column('category');
205
    my $context = "authorised_value:$category";
206
    $self->update_l10n_source($context, @sources);
207
208
    return $result;
209
}
153
1;
210
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 INTO l10n_source (context, source)
5
        SELECT DISTINCT CONCAT('authorised_value:', category), lib FROM authorised_values WHERE lib IS NOT NULL AND lib != ''
6
        UNION
7
        SELECT DISTINCT CONCAT('authorised_value:', category), 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