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

(-)a/Koha/Biblio.pm (-2 / +8 lines)
Lines 753-764 sub custom_cover_image_url { Link Here
753
        $url =~ s|{issn}|$issn|g;
753
        $url =~ s|{issn}|$issn|g;
754
    }
754
    }
755
755
756
    my $re = qr|{(?<field>\d{3})\$(?<subfield>.)}|;
756
    my $re = qr|{(?<field>\d{3})(\$(?<subfield>.))?}|;
757
    if ( $url =~ $re ) {
757
    if ( $url =~ $re ) {
758
        my $field = $+{field};
758
        my $field = $+{field};
759
        my $subfield = $+{subfield};
759
        my $subfield = $+{subfield};
760
        my $marc_record = $self->metadata->record;
760
        my $marc_record = $self->metadata->record;
761
        my $value = $marc_record->subfield($field, $subfield);
761
        my $value;
762
        if ( $subfield ) {
763
            $value = $marc_record->subfield( $field, $subfield );
764
        } else {
765
            my $controlfield = $marc_record->field($field);
766
            $value = $controlfield->data() if $controlfield;
767
        }
762
        return unless $value;
768
        return unless $value;
763
        $url =~ s|$re|$value|;
769
        $url =~ s|$re|$value|;
764
    }
770
    }
(-)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