Bug 24469: Move the new queries to a dedicated ImportBatch subroutine
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Amended: POD line for $import_record_id.
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
(cherry picked from commit 03a9bdc851)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
parent
3f636fdbb9
commit
aba575daed
|
|
@ -78,6 +78,7 @@ BEGIN {
|
|||
SetImportRecordOverlayStatus
|
||||
GetImportRecordStatus
|
||||
SetImportRecordStatus
|
||||
SetMatchedBiblionumber
|
||||
GetImportRecordMatches
|
||||
SetImportRecordMatches
|
||||
);
|
||||
|
|
@ -631,7 +632,7 @@ sub BatchCommitRecords {
|
|||
if ($record_type eq 'biblio') {
|
||||
my $biblioitemnumber;
|
||||
($recordid, $biblioitemnumber) = AddBiblio($marc_record, $framework);
|
||||
$query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?";
|
||||
$query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"; # FIXME call SetMatchedBiblionumber instead
|
||||
if ($item_result eq 'create_new' || $item_result eq 'replace') {
|
||||
my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result);
|
||||
$num_items_added += $bib_items_added;
|
||||
|
|
@ -664,7 +665,7 @@ sub BatchCommitRecords {
|
|||
$oldxml = $old_marc->as_xml($marc_type);
|
||||
|
||||
ModBiblio($marc_record, $recordid, $oldbiblio->frameworkcode);
|
||||
$query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?";
|
||||
$query = "UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"; # FIXME call SetMatchedBiblionumber instead
|
||||
|
||||
if ($item_result eq 'create_new' || $item_result eq 'replace') {
|
||||
my ($bib_items_added, $bib_items_replaced, $bib_items_errored) = BatchCommitItems($rowref->{'import_record_id'}, $recordid, $item_result);
|
||||
|
|
@ -697,7 +698,7 @@ sub BatchCommitRecords {
|
|||
$num_items_errored += $bib_items_errored;
|
||||
# still need to record the matched biblionumber so that the
|
||||
# items can be reverted
|
||||
my $sth2 = $dbh->prepare_cached("UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?");
|
||||
my $sth2 = $dbh->prepare_cached("UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?"); # FIXME call SetMatchedBiblionumber instead
|
||||
$sth2->execute($recordid, $rowref->{'import_record_id'});
|
||||
SetImportRecordOverlayStatus($rowref->{'import_record_id'}, 'match_applied');
|
||||
}
|
||||
|
|
@ -881,7 +882,7 @@ sub BatchRevertRecords {
|
|||
my $query;
|
||||
if ($record_type eq 'biblio') {
|
||||
# remove matched_biblionumber only if there is no 'imported' item left
|
||||
$query = "UPDATE import_biblios SET matched_biblionumber = NULL WHERE import_record_id = ?";
|
||||
$query = "UPDATE import_biblios SET matched_biblionumber = NULL WHERE import_record_id = ?"; # FIXME Remove me
|
||||
$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')";
|
||||
} else {
|
||||
$query = "UPDATE import_auths SET matched_authid = NULL WHERE import_record_id = ?";
|
||||
|
|
@ -1219,6 +1220,22 @@ sub SetImportBatchStatus {
|
|||
|
||||
}
|
||||
|
||||
=head2 SetMatchedBiblionumber
|
||||
|
||||
SetMatchedBiblionumber($import_record_id, $biblionumber);
|
||||
|
||||
=cut
|
||||
|
||||
sub SetMatchedBiblionumber {
|
||||
my ($import_record_id, $biblionumber) = @_;
|
||||
|
||||
my $dbh = C4::Context->dbh;
|
||||
$dbh->do(
|
||||
q|UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?|,
|
||||
undef, $biblionumber, $import_record_id
|
||||
);
|
||||
}
|
||||
|
||||
=head2 GetImportBatchOverlayAction
|
||||
|
||||
my $overlay_action = GetImportBatchOverlayAction($batch_id);
|
||||
|
|
|
|||
|
|
@ -198,11 +198,7 @@ if ($op eq ""){
|
|||
SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' );
|
||||
}
|
||||
|
||||
my $dbh = C4::Context->dbh;
|
||||
$dbh->do(
|
||||
q|UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?|,
|
||||
undef, $biblionumber, $biblio->{import_record_id}
|
||||
);
|
||||
SetMatchedBiblionumber( $biblio->{import_record_id}, $biblionumber );
|
||||
|
||||
# Add items from MarcItemFieldsToOrder
|
||||
my @homebranches = $input->multi_param('homebranch_' . $biblio_count);
|
||||
|
|
|
|||
|
|
@ -180,11 +180,7 @@ if ( $ordernumber eq '' and defined $params->{'breedingid'}){
|
|||
$listprice = GetMarcPrice($marcrecord, $marcflavour);
|
||||
SetImportRecordStatus($params->{'breedingid'}, 'imported');
|
||||
|
||||
my $dbh = C4::Context->dbh;
|
||||
$dbh->do(
|
||||
q|UPDATE import_biblios SET matched_biblionumber = ? WHERE import_record_id = ?|,
|
||||
undef, $biblionumber, $params->{breedingid}
|
||||
);
|
||||
SetMatchedBiblionumber( $params->{breedingid}, $biblionumber );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use Modern::Perl;
|
||||
use Test::More tests => 15;
|
||||
use Test::More tests => 16;
|
||||
use utf8;
|
||||
use File::Basename;
|
||||
use File::Temp qw/tempfile/;
|
||||
|
|
@ -134,6 +134,11 @@ my $record_from_import_biblio_without_items = C4::ImportBatch::GetRecordFromImpo
|
|||
$original_record->leader($record_from_import_biblio_without_items->leader());
|
||||
is_deeply( $record_from_import_biblio_without_items, $original_record, 'GetRecordFromImportBiblio should return the record without items by default' );
|
||||
|
||||
my $another_biblio = $builder->build_sample_biblio;
|
||||
C4::ImportBatch::SetMatchedBiblionumber( $import_record_id, $another_biblio->biblionumber );
|
||||
my $import_biblios = GetImportBiblios( $import_record_id );
|
||||
is( $import_biblios->[0]->{matched_biblionumber}, $another_biblio->biblionumber, 'SetMatchedBiblionumber should set the correct biblionumber' );
|
||||
|
||||
# Add a few tests for GetItemNumbersFromImportBatch
|
||||
my @a = GetItemNumbersFromImportBatch( $id_import_batch1 );
|
||||
is( @a, 0, 'No item numbers expected since we did not commit' );
|
||||
|
|
|
|||
Loading…
Reference in New Issue