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

(-)a/Koha/Biblio.pm (-2 / +8 lines)
Lines 772-783 sub custom_cover_image_url { Link Here
772
        $url =~ s|{issn}|$issn|g;
772
        $url =~ s|{issn}|$issn|g;
773
    }
773
    }
774
774
775
    my $re = qr|{(?<field>\d{3})\$(?<subfield>.)}|;
775
    my $re = qr|{(?<field>\d{3})(\$(?<subfield>.))?}|;
776
    if ( $url =~ $re ) {
776
    if ( $url =~ $re ) {
777
        my $field = $+{field};
777
        my $field = $+{field};
778
        my $subfield = $+{subfield};
778
        my $subfield = $+{subfield};
779
        my $marc_record = $self->metadata->record;
779
        my $marc_record = $self->metadata->record;
780
        my $value = $marc_record->subfield($field, $subfield);
780
        my $value;
781
        if ( $subfield ) {
782
            $value = $marc_record->subfield( $field, $subfield );
783
        } else {
784
            my $controlfield = $marc_record->field($field);
785
            $value = $controlfield->data() if $controlfield;
786
        }
781
        return unless $value;
787
        return unless $value;
782
        $url =~ s|$re|$value|;
788
        $url =~ s|$re|$value|;
783
    }
789
    }
(-)a/t/db_dependent/Koha/Biblios.t (-2 / +8 lines)
Lines 193-204 subtest 'can_be_transferred' => sub { Link Here
193
};
193
};
194
194
195
subtest 'custom_cover_image_url' => sub {
195
subtest 'custom_cover_image_url' => sub {
196
    plan tests => 4;
196
    plan tests => 6;
197
197
198
    t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/{isbn}_{issn}.png' );
198
    t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/{isbn}_{issn}.png' );
199
199
200
    my $isbn       = '0553573403 | 9780553573404 (pbk.).png';
200
    my $isbn       = '0553573403 | 9780553573404 (pbk.).png';
201
    my $issn       = 'my_issn';
201
    my $issn       = 'my_issn';
202
    my $cf_value   = 'from_control_field';
202
    my $marc_record = MARC::Record->new;
203
    my $marc_record = MARC::Record->new;
203
    my ( $biblionumber, undef ) = C4::Biblio::AddBiblio($marc_record, '');
204
    my ( $biblionumber, undef ) = C4::Biblio::AddBiblio($marc_record, '');
204
205
Lines 221-226 subtest 'custom_cover_image_url' => sub { Link Here
221
    $biblio->biblioitem->isbn('')->store;
222
    $biblio->biblioitem->isbn('')->store;
222
    is( $biblio->custom_cover_image_url, undef, "Don't generate the url if the biblio does not have the value needed to generate it" );
223
    is( $biblio->custom_cover_image_url, undef, "Don't generate the url if the biblio does not have the value needed to generate it" );
223
224
225
    t::lib::Mocks::mock_preference( 'CustomCoverImagesURL', 'https://my_url/{001}.png' );
226
    is( $biblio->custom_cover_image_url, undef, 'Record does not have 001' );
227
    $marc_record->append_fields(MARC::Field->new('001', $cf_value));
228
    C4::Biblio::ModBiblio( $marc_record, $biblio->biblionumber );
229
    $biblio = Koha::Biblios->find( $biblionumber );
230
    is( $biblio->get_from_storage->custom_cover_image_url, "https://my_url/$cf_value.png", 'URL generated using 001' );
224
};
231
};
225
232
226
$schema->storage->txn_rollback;
233
$schema->storage->txn_rollback;
227
- 

Return to bug 29172