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

(-)a/Koha/AuthorisedValues.pm (-3 / +8 lines)
Lines 23-28 use Modern::Perl; Link Here
23
use Koha::Database;
23
use Koha::Database;
24
24
25
use Koha::AuthorisedValue;
25
use Koha::AuthorisedValue;
26
use Koha::I18N;
26
use Koha::MarcSubfieldStructures;
27
use Koha::MarcSubfieldStructures;
27
use Koha::Cache::Memory::Lite;
28
use Koha::Cache::Memory::Lite;
28
29
Lines 111-117 sub get_description_by_koha_field { Link Here
111
112
112
    my $av = $self->find_by_koha_field($params);
113
    my $av = $self->find_by_koha_field($params);
113
    return {} unless defined $av;
114
    return {} unless defined $av;
114
    my $descriptions = { lib => $av->lib, opac_description => $av->opac_description };
115
    my $l10n_group = 'authorised_value:' . $av->category;
116
    my $descriptions = {
117
        lib => db_t($l10n_group, $av->lib),
118
        opac_description => db_t($l10n_group, $av->opac_description),
119
    };
115
    $memory_cache->set_in_cache( $cache_key, $descriptions );
120
    $memory_cache->set_in_cache( $cache_key, $descriptions );
116
    return $descriptions;
121
    return $descriptions;
117
}
122
}
Lines 130-137 sub get_descriptions_by_koha_field { Link Here
130
    my @descriptions = map {
135
    my @descriptions = map {
131
        {
136
        {
132
            authorised_value => $_->authorised_value,
137
            authorised_value => $_->authorised_value,
133
            lib              => $_->lib,
138
            lib              => db_t('authorised_value:' . $_->category, $_->lib),
134
            opac_description => $_->opac_description
139
            opac_description => db_t('authorised_value:' . $_->category, $_->opac_description),
135
        }
140
        }
136
    } @avs;
141
    } @avs;
137
    $memory_cache->set_in_cache( $cache_key, \@descriptions );
142
    $memory_cache->set_in_cache( $cache_key, \@descriptions );
(-)a/Koha/DBIx/Component/L10nSource.pm (-9 / +13 lines)
Lines 55-69 sub update_l10n_source { Link Here
55
      $self->result_source->schema->resultset('L10nSource')
55
      $self->result_source->schema->resultset('L10nSource')
56
      ->find( { group => $group, key => $key }, { key => 'group_key' } );
56
      ->find( { group => $group, key => $key }, { key => 'group_key' } );
57
57
58
    if ($l10n_source_rs) {
58
    if ($source_text) {
59
        $l10n_source_rs->update( { text => $source_text } );
59
        if ($l10n_source_rs) {
60
        my $l10n_target_rs = $l10n_source_rs->l10n_targets_rs;
60
            $l10n_source_rs->update( { text => $source_text } );
61
        $l10n_target_rs->update( { fuzzy => 1 } );
61
            my $l10n_target_rs = $l10n_source_rs->l10n_targets_rs;
62
    }
62
            $l10n_target_rs->update( { fuzzy => 1 } );
63
    else {
63
        }
64
        $l10n_source_rs =
64
        else {
65
          $self->result_source->schema->resultset('L10nSource')
65
            $l10n_source_rs =
66
          ->create( { group => $group, key => $key, text => $source_text } );
66
              $self->result_source->schema->resultset('L10nSource')
67
              ->create( { group => $group, key => $key, text => $source_text } );
68
        }
69
    } else {
70
        $self->delete_l10n_source($group, $key);
67
    }
71
    }
68
}
72
}
69
73
(-)a/Koha/Schema/Result/AuthorisedValue.pm (-1 / +52 lines)
Lines 176-181 __PACKAGE__->has_many( Link Here
176
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-21 13:39:29
176
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-21 13:39:29
177
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:LH9dpEEzlVVsjNVv/jnONg
177
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:LH9dpEEzlVVsjNVv/jnONg
178
178
179
__PACKAGE__->load_components('+Koha::DBIx::Component::L10nSource');
180
181
sub insert {
182
    my $self = shift;
183
184
    my $result = $self->next::method(@_);
185
186
    my $group = sprintf('authorised_value:%s', $self->get_column('category'));
187
    $self->update_l10n_source( $group,
188
        $self->authorised_value . ':intranet',
189
        $self->lib );
190
    $self->update_l10n_source( $group,
191
        $self->authorised_value . ':opac',
192
        $self->lib_opac );
193
194
    return $result;
195
}
196
197
sub update {
198
    my $self = shift;
199
200
    my $is_lib_changed = $self->is_column_changed('lib');
201
    my $is_lib_opac_changed = $self->is_column_changed('lib_opac');
202
203
    my $result = $self->next::method(@_);
204
205
    my $group = sprintf('authorised_value:%s', $self->get_column('category'));
206
    if ($is_lib_changed) {
207
        $self->update_l10n_source( $group,
208
            $self->authorised_value . ':intranet',
209
            $self->lib );
210
    }
211
    if ($is_lib_opac_changed) {
212
        $self->update_l10n_source( $group,
213
            $self->authorised_value . ':opac',
214
            $self->lib_opac );
215
    }
216
217
    return $result;
218
}
219
220
sub delete {
221
    my $self = shift;
222
223
    my $result = $self->next::method(@_);
224
225
    my $group = sprintf('authorised_value:%s', $self->get_column('category'));
226
    $self->delete_l10n_source($group, sprintf('%s:intranet', $self->authorised_value));
227
    $self->delete_l10n_source($group, sprintf('%s:opac', $self->authorised_value));
228
229
    return $result;
230
}
179
231
180
# You can replace this text with custom code or comments, and it will be preserved on regeneration
181
1;
232
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