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

(-)a/Koha/Import/Record.pm (+22 lines)
Lines 23-28 use MARC::Record; Link Here
23
use C4::Context;
23
use C4::Context;
24
use Koha::Database;
24
use Koha::Database;
25
use Koha::Import::Record::Biblios;
25
use Koha::Import::Record::Biblios;
26
use Koha::Import::Record::Matches;
26
27
27
use base qw(Koha::Object);
28
use base qw(Koha::Object);
28
29
Lines 71-76 sub import_biblio { Link Here
71
    return Koha::Import::Record::Biblio->_new_from_dbic( $import_biblio_rs );
72
    return Koha::Import::Record::Biblio->_new_from_dbic( $import_biblio_rs );
72
}
73
}
73
74
75
=head3 get_import_record_matches
76
77
Returns the Import::Record::Matches for the record
78
optionally specify a 'chosen' param to get only the chosen match
79
80
    my $matches = $import_record->get_import_record_matches([{ chosen => 1 }])
81
82
=cut
83
84
sub get_import_record_matches {
85
    my ($self, $params) = @_;
86
    my $chosen = $params->{chosen};
87
88
    my $matches = $self->_result->import_record_matches;
89
    $matches = Koha::Import::Record::Matches->_new_from_dbic( $matches );
90
91
    return $matches->filter_by_chosen() if $chosen;
92
93
    return $matches->search({},{ order_by => { -desc => ['score','candidate_match_id'] } });
94
}
95
74
=head2 Internal methods
96
=head2 Internal methods
75
97
76
=head3 _type
98
=head3 _type
(-)a/Koha/Import/Record/Matches.pm (+18 lines)
Lines 35-40 Koha::Import::Record::Matches - Koha Import Record Matches Object set class Link Here
35
35
36
=cut
36
=cut
37
37
38
=head3 filter_by_chosen
39
40
    Koha::Import::Record::Matches->filter_by_chosen();
41
42
    Returns chosen import record matches
43
44
=cut
45
46
sub filter_by_chosen {
47
48
    my ( $self ) = @_;
49
50
    my $chosen = $self->search({ chosen => 1 });
51
52
    return $chosen;
53
54
}
55
38
=head3 _type
56
=head3 _type
39
57
40
=cut
58
=cut
(-)a/acqui/addorderiso2709.pl (-7 / +10 lines)
Lines 30-36 use Encode; Link Here
30
use C4::Context;
30
use C4::Context;
31
use C4::Auth qw( get_template_and_user );
31
use C4::Auth qw( get_template_and_user );
32
use C4::Output qw( output_html_with_http_headers );
32
use C4::Output qw( output_html_with_http_headers );
33
use C4::ImportBatch qw( GetImportRecordMatches SetImportBatchStatus GetImportBatch GetImportBatchRangeDesc GetNumberOfNonZ3950ImportBatches GetImportBatchOverlayAction GetImportBatchNoMatchAction GetImportBatchItemAction );
33
use C4::ImportBatch qw( SetImportBatchStatus GetImportBatch GetImportBatchRangeDesc GetNumberOfNonZ3950ImportBatches GetImportBatchOverlayAction GetImportBatchNoMatchAction GetImportBatchItemAction );
34
use C4::Matcher;
34
use C4::Matcher;
35
use C4::Search qw( FindDuplicate );
35
use C4::Search qw( FindDuplicate );
36
use C4::Biblio qw(
36
use C4::Biblio qw(
Lines 157-164 if ($op eq ""){ Link Here
157
        # Check if this import_record_id was selected
157
        # Check if this import_record_id was selected
158
        next if not grep { $_ eq $import_record->import_record_id } @import_record_id_selected;
158
        next if not grep { $_ eq $import_record->import_record_id } @import_record_id_selected;
159
        my $marcrecord = $import_record->get_marc_record || die "couldn't translate marc information";
159
        my $marcrecord = $import_record->get_marc_record || die "couldn't translate marc information";
160
        my $match = GetImportRecordMatches( $import_record->import_record_id, 1 );
160
        my $matches = $import_record->get_import_record_matches({ chosen => 1 });
161
        my $biblionumber=$#$match > -1?$match->[0]->{'biblionumber'}:0;
161
        my $match = $matches->count ? $matches->next : undef;
162
        my $biblionumber = $match ? $match->candidate_match_id : 0;
162
        my $c_quantity = shift( @quantities ) || GetMarcQuantity($marcrecord, C4::Context->preference('marcflavour') ) || 1;
163
        my $c_quantity = shift( @quantities ) || GetMarcQuantity($marcrecord, C4::Context->preference('marcflavour') ) || 1;
163
        my $c_budget_id = shift( @budgets_id ) || $input->param('all_budget_id') || $budget_id;
164
        my $c_budget_id = shift( @budgets_id ) || $input->param('all_budget_id') || $budget_id;
164
        my $c_discount = shift ( @discount);
165
        my $c_discount = shift ( @discount);
Lines 472-478 sub import_biblios_list { Link Here
472
    while ( my $import_record = $import_records->next ) {
473
    while ( my $import_record = $import_records->next ) {
473
        my $item_id = 1;
474
        my $item_id = 1;
474
        $biblio_count++;
475
        $biblio_count++;
475
        my $match = GetImportRecordMatches($import_record->import_record_id, 1);
476
        my $matches = $import_record->get_import_record_matches({ chosen => 1 });
477
        my $match = $matches->count ? $matches->next : undef;
478
        my $match_biblio = $match ? Koha::Biblios->find({ biblionumber => $match->candidate_match_id }) : undef;
476
        my %cellrecord = (
479
        my %cellrecord = (
477
            import_record_id => $import_record->import_record_id,
480
            import_record_id => $import_record->import_record_id,
478
            import_biblio => $import_record->import_biblio,
481
            import_biblio => $import_record->import_biblio,
Lines 480-488 sub import_biblios_list { Link Here
480
            status => $import_record->status,
483
            status => $import_record->status,
481
            record_sequence => $import_record->record_sequence,
484
            record_sequence => $import_record->record_sequence,
482
            overlay_status => $import_record->overlay_status,
485
            overlay_status => $import_record->overlay_status,
483
            match_biblionumber => $#$match > -1 ? $match->[0]->{'biblionumber'} : 0,
486
            match_biblionumber => $match ? $match->candidate_match_id : 0,
484
            match_citation     => $#$match > -1 ? $match->[0]->{'title'} || '' . ' ' . $match->[0]->{'author'} || '': '',
487
            match_citation     => $match_biblio ? ($match_biblio->title || '') . ' ' .( $match_biblio->author || ''): '',
485
            match_score => $#$match > -1 ? $match->[0]->{'score'} : 0,
488
            match_score => $match ? $match->score : 0,
486
        );
489
        );
487
        my $marcrecord = $import_record->get_marc_record || die "couldn't translate marc information";
490
        my $marcrecord = $import_record->get_marc_record || die "couldn't translate marc information";
488
491
(-)a/t/db_dependent/Koha/Import/Records.t (-2 / +44 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 3;
22
use Test::More tests => 10;
23
23
24
use Koha::Import::Records;
24
use Koha::Import::Records;
25
use Koha::Database;
25
use Koha::Database;
Lines 40-45 is( Koha::Import::Records->search->count, $nb_of_records + 2, 'The 2 records sho Link Here
40
my $retrieved_record_1 = Koha::Import::Records->search({ import_record_id => $record_1->{import_record_id}})->next;
40
my $retrieved_record_1 = Koha::Import::Records->search({ import_record_id => $record_1->{import_record_id}})->next;
41
is_deeply( $retrieved_record_1->unblessed, $record_1, 'Find a record by import record id should return the correct record' );
41
is_deeply( $retrieved_record_1->unblessed, $record_1, 'Find a record by import record id should return the correct record' );
42
42
43
my $matches = $retrieved_record_1->get_import_record_matches();
44
is( $matches->count, 0, "No matches returned if none set");
45
46
my $biblio = $builder->build_sample_biblio;
47
my $biblio_1 = $builder->build_sample_biblio;
48
my $biblio_2 = $builder->build_sample_biblio;
49
my $match_1 = $builder->build_object({ class => 'Koha::Import::Record::Matches',
50
                  value => {
51
                      score => 100,
52
                      chosen => 0,
53
                      candidate_match_id => $biblio->biblionumber,
54
                      import_record_id => $retrieved_record_1->import_record_id
55
                  }
56
              });
57
my $match_2 = $builder->build_object({ class => 'Koha::Import::Record::Matches',
58
                  value => {
59
                      score => 50,
60
                      chosen => 1,
61
                      candidate_match_id => $biblio_1->biblionumber,
62
                      import_record_id => $retrieved_record_1->import_record_id
63
                  }
64
              });
65
my $match_3 = $builder->build_object({ class => 'Koha::Import::Record::Matches',
66
                  value => {
67
                      score => 100,
68
                      chosen => 0,
69
                      candidate_match_id => $biblio_2->biblionumber,
70
                      import_record_id => $retrieved_record_1->import_record_id
71
                  }
72
              });
73
74
$matches = $retrieved_record_1->get_import_record_matches();
75
is( $matches->count, 3, 'We get three matches');
76
77
is_deeply( $matches->next->unblessed, $match_3->unblessed, "Match order is score desc, biblionumber desc, so 3 is first");
78
79
is_deeply( $matches->next->unblessed, $match_1->unblessed, "Match order is score desc, biblionumber desc, so 1 is second");
80
is_deeply( $matches->next->unblessed, $match_2->unblessed, "Match order is score desc, biblionumber desc, so 2 is third");
81
82
$matches = $retrieved_record_1->get_import_record_matches({ chosen => 1 });
83
is( $matches->count, 1, 'We get only the chosen match when requesting chosen');
84
is_deeply( $matches->next->unblessed, $match_2->unblessed, "Match 2 is the chosen match");
85
43
$retrieved_record_1->delete;
86
$retrieved_record_1->delete;
44
is( Koha::Import::Records->search->count, $nb_of_records + 1, 'Delete should have deleted the record' );
87
is( Koha::Import::Records->search->count, $nb_of_records + 1, 'Delete should have deleted the record' );
45
88
46
- 

Return to bug 32054