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

(-)a/C4/ImportBatch.pm (-4 / +20 lines)
Lines 631-637 sub BatchCommitRecords { Link Here
631
            if ($record_type eq 'biblio') {
631
            if ($record_type eq 'biblio') {
632
                my $biblioitemnumber;
632
                my $biblioitemnumber;
633
                ($recordid, $biblioitemnumber) = AddBiblio($marc_record, $framework);
633
                ($recordid, $biblioitemnumber) = AddBiblio($marc_record, $framework);
634
                $query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?";
634
                $query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"; # FIXME call SetMatchedBiblionumber instead
635
                if ($item_result eq 'create_new' || $item_result eq 'replace') {
635
                if ($item_result eq 'create_new' || $item_result eq 'replace') {
636
                    my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result);
636
                    my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result);
637
                    $num_items_added += $bib_items_added;
637
                    $num_items_added += $bib_items_added;
Lines 664-670 sub BatchCommitRecords { Link Here
664
                $oldxml = $old_marc->as_xml($marc_type);
664
                $oldxml = $old_marc->as_xml($marc_type);
665
665
666
                ModBiblio($marc_record, $recordid, $oldbiblio->frameworkcode);
666
                ModBiblio($marc_record, $recordid, $oldbiblio->frameworkcode);
667
                $query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?";
667
                $query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"; # FIXME call SetMatchedBiblionumber instead
668
668
669
                if ($item_result eq 'create_new' || $item_result eq 'replace') {
669
                if ($item_result eq 'create_new' || $item_result eq 'replace') {
670
                    my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result);
670
                    my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result);
Lines 697-703 sub BatchCommitRecords { Link Here
697
                $num_items_errored += $bib_items_errored;
697
                $num_items_errored += $bib_items_errored;
698
                # still need to record the matched biblionumber so that the
698
                # still need to record the matched biblionumber so that the
699
                # items can be reverted
699
                # items can be reverted
700
                my $sth2 = $dbh->prepare_cached("UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?");
700
                my $sth2 = $dbh->prepare_cached("UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"); # FIXME call SetMatchedBiblionumber instead
701
                $sth2->execute($recordid, $rowref->{'import_record_id'});
701
                $sth2->execute($recordid, $rowref->{'import_record_id'});
702
                SetImportRecordOverlayStatus($rowref->{'import_record_id'}, 'match_applied');
702
                SetImportRecordOverlayStatus($rowref->{'import_record_id'}, 'match_applied');
703
            }
703
            }
Lines 881-887 sub BatchRevertRecords { Link Here
881
        my $query;
881
        my $query;
882
        if ($record_type eq 'biblio') {
882
        if ($record_type eq 'biblio') {
883
            # remove matched_biblionumber only if there is no 'imported' item left
883
            # remove matched_biblionumber only if there is no 'imported' item left
884
            $query = "UPDATE import_biblios SET matched_biblionumber = NULL WHERE import_record_id = ?";
884
            $query = "UPDATE import_biblios SET matched_biblionumber = NULL WHERE import_record_id = ?"; # FIXME Remove me
885
            $query = "UPDATE import_biblios SET matched_biblionumber = NULL WHERE import_record_id = ?  AND NOT EXISTS (SELECT * FROM import_items WHERE import_items.import_record_id=import_biblios.import_record_id and status='imported')";
885
            $query = "UPDATE import_biblios SET matched_biblionumber = NULL WHERE import_record_id = ?  AND NOT EXISTS (SELECT * FROM import_items WHERE import_items.import_record_id=import_biblios.import_record_id and status='imported')";
886
        } else {
886
        } else {
887
            $query = "UPDATE import_auths SET matched_authid = NULL WHERE import_record_id = ?";
887
            $query = "UPDATE import_auths SET matched_authid = NULL WHERE import_record_id = ?";
Lines 1219-1224 sub SetImportBatchStatus { Link Here
1219
1219
1220
}
1220
}
1221
1221
1222
=head2 SetMatchedBiblionumber
1223
1224
  SetMatchedBiblionumber($batch_id, $biblionumber);
1225
1226
=cut
1227
1228
sub SetMatchedBiblionumber {
1229
    my ($import_record_id, $biblionumber) = @_;
1230
1231
    my $dbh = C4::Context->dbh;
1232
    $dbh->do(
1233
        q|UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?|,
1234
        undef, $biblionumber, $import_record_id
1235
    );
1236
}
1237
1222
=head2 GetImportBatchOverlayAction
1238
=head2 GetImportBatchOverlayAction
1223
1239
1224
  my $overlay_action = GetImportBatchOverlayAction($batch_id);
1240
  my $overlay_action = GetImportBatchOverlayAction($batch_id);
(-)a/acqui/addorderiso2709.pl (-5 / +1 lines)
Lines 198-208 if ($op eq ""){ Link Here
198
            SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' );
198
            SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' );
199
        }
199
        }
200
200
201
        my $dbh = C4::Context->dbh;
201
        SetMatchedBiblionumber( $biblio->{import_record_id}, $biblionumber );
202
        $dbh->do(
203
            q|UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?|,
204
            undef, $biblionumber, $biblio->{import_record_id}
205
        );
206
202
207
        # Add items from MarcItemFieldsToOrder
203
        # Add items from MarcItemFieldsToOrder
208
        my @homebranches = $input->multi_param('homebranch_' . $biblio_count);
204
        my @homebranches = $input->multi_param('homebranch_' . $biblio_count);
(-)a/acqui/neworderempty.pl (-5 / +1 lines)
Lines 180-190 if ( $ordernumber eq '' and defined $params->{'breedingid'}){ Link Here
180
    $listprice = GetMarcPrice($marcrecord, $marcflavour);
180
    $listprice = GetMarcPrice($marcrecord, $marcflavour);
181
    SetImportRecordStatus($params->{'breedingid'}, 'imported');
181
    SetImportRecordStatus($params->{'breedingid'}, 'imported');
182
182
183
    my $dbh = C4::Context->dbh;
183
    SetMatchedBiblionumber( $params->{breedingid}, $biblionumber );
184
    $dbh->do(
185
        q|UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?|,
186
        undef, $biblionumber, $params->{breedingid}
187
    );
188
}
184
}
189
185
190
186
(-)a/t/db_dependent/ImportBatch.t (-2 / +6 lines)
Lines 1-7 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use Test::More tests => 15;
4
use Test::More tests => 16;
5
use utf8;
5
use utf8;
6
use File::Basename;
6
use File::Basename;
7
use File::Temp qw/tempfile/;
7
use File::Temp qw/tempfile/;
Lines 134-139 my $record_from_import_biblio_without_items = C4::ImportBatch::GetRecordFromImpo Link Here
134
$original_record->leader($record_from_import_biblio_without_items->leader());
134
$original_record->leader($record_from_import_biblio_without_items->leader());
135
is_deeply( $record_from_import_biblio_without_items, $original_record, 'GetRecordFromImportBiblio should return the record without items by default' );
135
is_deeply( $record_from_import_biblio_without_items, $original_record, 'GetRecordFromImportBiblio should return the record without items by default' );
136
136
137
my $another_biblio = $builder->build_sample_biblio;
138
C4::ImportBatch::SetMatchedBiblionumber( $import_record_id, $another_biblio->biblionumber );
139
my $import_biblios = GetImportBiblios( $import_record_id );
140
is( $import_biblios->[0]->{matched_biblionumber}, $another_biblio->biblionumber, 'SetMatchedBiblionumber  should set the correct biblionumber' );
141
137
# Add a few tests for GetItemNumbersFromImportBatch
142
# Add a few tests for GetItemNumbersFromImportBatch
138
my @a = GetItemNumbersFromImportBatch( $id_import_batch1 );
143
my @a = GetItemNumbersFromImportBatch( $id_import_batch1 );
139
is( @a, 0, 'No item numbers expected since we did not commit' );
144
is( @a, 0, 'No item numbers expected since we did not commit' );
140
- 

Return to bug 24469