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

(-)a/Koha/Biblio.pm (-4 / +4 lines)
Lines 891-901 sub to_api_mapping { Link Here
891
    };
891
    };
892
}
892
}
893
893
894
=head3 host_record
894
=head3 get_marc_host
895
895
896
    $host = $biblio->host_record;
896
    $host = $biblio->get_marc_host;
897
    # OR:
897
    # OR:
898
    ( $host, $relatedparts ) = $biblio->host_record;
898
    ( $host, $relatedparts ) = $biblio->get_marc_host;
899
899
900
    Returns host biblio record from MARC21 773 (undef if no 773 present).
900
    Returns host biblio record from MARC21 773 (undef if no 773 present).
901
    It looks at the first 773 field with MARCorgCode or only a control
901
    It looks at the first 773 field with MARCorgCode or only a control
Lines 906-912 sub to_api_mapping { Link Here
906
906
907
=cut
907
=cut
908
908
909
sub host_record {
909
sub get_marc_host {
910
    my ($self, $params) = @_;
910
    my ($self, $params) = @_;
911
    my $no_items = $params->{no_items};
911
    my $no_items = $params->{no_items};
912
    return if C4::Context->preference('marcflavour') eq 'UNIMARC'; # TODO
912
    return if C4::Context->preference('marcflavour') eq 'UNIMARC'; # TODO
(-)a/opac/opac-request-article.pl (-1 / +1 lines)
Lines 81-87 if ( $action eq 'create' ) { Link Here
81
}
81
}
82
elsif ( !$action && C4::Context->preference('ArticleRequestsHostRedirection') ) {
82
elsif ( !$action && C4::Context->preference('ArticleRequestsHostRedirection') ) {
83
  # Conditions: no items, host item entry (MARC21 773)
83
  # Conditions: no items, host item entry (MARC21 773)
84
  my ( $host, $pageinfo ) = $biblio->host_record( { no_items => 1 } );
84
  my ( $host, $pageinfo ) = $biblio->get_marc_host( { no_items => 1 } );
85
  if ($host) {
85
  if ($host) {
86
      $template->param(
86
      $template->param(
87
          pageinfo => $pageinfo,
87
          pageinfo => $pageinfo,
(-)a/t/db_dependent/Koha/Biblio/host_record.t (-13 / +12 lines)
Lines 35-41 my $schema = Koha::Database->new->schema; Link Here
35
$schema->storage->txn_begin;
35
$schema->storage->txn_begin;
36
our $builder = t::lib::TestBuilder->new;
36
our $builder = t::lib::TestBuilder->new;
37
37
38
subtest 'host_record' => sub {
38
subtest 'get_marc_host' => sub {
39
    plan tests => 11;
39
    plan tests => 11;
40
40
41
    t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' );
41
    t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' );
Lines 58-97 subtest 'host_record' => sub { Link Here
58
    $search_mod->mock( 'new', sub { return $engine; } );
58
    $search_mod->mock( 'new', sub { return $engine; } );
59
59
60
    # Case 1: Search engine does not return any results on controlnumber
60
    # Case 1: Search engine does not return any results on controlnumber
61
    is( $bib1->host_record, undef, 'Empty MARC record' );
61
    is( $bib1->get_marc_host, undef, 'Empty MARC record' );
62
    $marc->append_fields(
62
    $marc->append_fields(
63
        MARC::Field->new( '773', '', '', g => 'relpart', w => '(xyz)123' ),
63
        MARC::Field->new( '773', '', '', g => 'relpart', w => '(xyz)123' ),
64
    );
64
    );
65
    is( $bib1->host_record, undef, '773 looks fine, but no search results' );
65
    is( $bib1->get_marc_host, undef, '773 looks fine, but no search results' );
66
66
67
    # Case 2: Search engine returns (at maximum) one result
67
    # Case 2: Search engine returns (at maximum) one result
68
    $results = [ $bib1->biblionumber ]; # will be found because 773w is in shape
68
    $results = [ $bib1->biblionumber ]; # will be found because 773w is in shape
69
    my $host = $bib1->host_record;
69
    my $host = $bib1->get_marc_host;
70
    is( ref( $host ), 'Koha::Biblio', 'Correct object returned' );
70
    is( ref( $host ), 'Koha::Biblio', 'Correct object returned' );
71
    is( $host->biblionumber, $bib1->biblionumber, 'Check biblionumber' );
71
    is( $host->biblionumber, $bib1->biblionumber, 'Check biblionumber' );
72
    $marc->field('773')->update( w => '(xyz) bad data' ); # causes no results
72
    $marc->field('773')->update( w => '(xyz) bad data' ); # causes no results
73
    $host = $bib1->host_record;
73
    $host = $bib1->get_marc_host;
74
    is( $bib1->host_record, undef, 'No results for bad 773' );
74
    is( $bib1->get_marc_host, undef, 'No results for bad 773' );
75
    # Add second 773
75
    # Add second 773
76
    $marc->append_fields( MARC::Field->new( '773', '', '', g => 'relpart2', w => '234' ) );
76
    $marc->append_fields( MARC::Field->new( '773', '', '', g => 'relpart2', w => '234' ) );
77
    $host = $bib1->host_record;
77
    $host = $bib1->get_marc_host;
78
    is( $host->biblionumber, $bib1->biblionumber, 'Result triggered by second 773' );
78
    is( $host->biblionumber, $bib1->biblionumber, 'Result triggered by second 773' );
79
    # Replace orgcode
79
    # Replace orgcode
80
    ($marc->field('773'))[1]->update( w => '(abc)345' );
80
    ($marc->field('773'))[1]->update( w => '(abc)345' );
81
    is( $bib1->host_record, undef, 'No results for two 773s' );
81
    is( $bib1->get_marc_host, undef, 'No results for two 773s' );
82
    # Test no_items flag
82
    # Test no_items flag
83
    ($marc->field('773'))[1]->update( w => '234' ); # restore
83
    ($marc->field('773'))[1]->update( w => '234' ); # restore
84
    $host = $bib1->host_record({ no_items => 1 });
84
    $host = $bib1->get_marc_host({ no_items => 1 });
85
    is( $host->biblionumber, $bib1->biblionumber, 'Record found with no_items' );
85
    is( $host->biblionumber, $bib1->biblionumber, 'Record found with no_items' );
86
    $builder->build({ source => 'Item', value => { biblionumber => $bib1->biblionumber } });
86
    $builder->build({ source => 'Item', value => { biblionumber => $bib1->biblionumber } });
87
    is( $bib1->host_record({ no_items => 1 }), undef, 'Record not found with no_items flag after adding one item' );
87
    is( $bib1->get_marc_host({ no_items => 1 }), undef, 'Record not found with no_items flag after adding one item' );
88
    # Test list context
88
    # Test list context
89
    my @temp = $bib1->host_record;
89
    my @temp = $bib1->get_marc_host;
90
    is( $temp[1], 'relpart2', 'Return $g in list context' );
90
    is( $temp[1], 'relpart2', 'Return $g in list context' );
91
91
92
    # Case 3: Search engine returns more results
92
    # Case 3: Search engine returns more results
93
    $results = [ 1, 2 ];
93
    $results = [ 1, 2 ];
94
    is( $bib1->host_record, undef, 'host_record returns undef for non-unique control number' );
94
    is( $bib1->get_marc_host, undef, 'get_marc_host returns undef for non-unique control number' );
95
};
95
};
96
96
97
sub mocked_search {
97
sub mocked_search {
98
- 

Return to bug 20310