SetImportRecordOverlayStatus
GetImportRecordStatus
SetImportRecordStatus
+ SetMatchedBiblionumber
GetImportRecordMatches
SetImportRecordMatches
);
}
-our $logger = Koha::Logger->get( { category => 'C4.ImportBatch' } );
-
=head1 NAME
C4::ImportBatch - manage batches of imported MARC records
my ($batch_id) = @_;
my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare_cached("SELECT * FROM import_batches WHERE import_batch_id = ?");
+ my $sth = $dbh->prepare_cached("SELECT b.*, p.name as profile FROM import_batches b LEFT JOIN import_batch_profiles p ON p.id = b.profile_id WHERE import_batch_id = ?");
$sth->bind_param(1, $batch_id);
$sth->execute();
my $result = $sth->fetchrow_hashref;
my $num_items_errored = 0;
my $num_ignored = 0;
# commit (i.e., save, all records in the batch)
- SetImportBatchStatus('importing');
+ SetImportBatchStatus($batch_id, 'importing');
my $overlay_action = GetImportBatchOverlayAction($batch_id);
my $nomatch_action = GetImportBatchNoMatchAction($batch_id);
my $item_action = GetImportBatchItemAction($batch_id);
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;
$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);
$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');
}
$updsth->execute();
$num_items_errored++;
} else {
+ # Remove the itemnumber if it exists, we want to create a new item
+ my ( $itemtag, $itemsubfield ) = GetMarcFromKohaField( "items.itemnumber" );
+ $item_marc->field($itemtag)->delete_subfield( code => $itemsubfield );
+
my ( $item_biblionumber, $biblioitemnumber, $itemnumber ) = AddItemFromMarc( $item_marc, $biblionumber );
if( $itemnumber ) {
$updsth->bind_param( 1, 'imported' );
sub BatchRevertRecords {
my $batch_id = shift;
+ my $logger = Koha::Logger->get( { category => 'C4.ImportBatch' } );
+
$logger->trace("C4::ImportBatch::BatchRevertRecords( $batch_id )");
my $record_type;
my $num_ignored = 0;
my $num_items_deleted = 0;
# commit (i.e., save, all records in the batch)
- SetImportBatchStatus('reverting');
+ SetImportBatchStatus($batch_id, 'reverting');
my $overlay_action = GetImportBatchOverlayAction($batch_id);
my $nomatch_action = GetImportBatchNoMatchAction($batch_id);
my $dbh = C4::Context->dbh;
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 = ?";
my ($offset, $results_per_group) = @_;
my $dbh = C4::Context->dbh;
- my $query = "SELECT * FROM import_batches
- WHERE batch_type IN ('batch', 'webservice')
- ORDER BY import_batch_id DESC";
+ my $query = "SELECT b.*, p.name as profile FROM import_batches b
+ LEFT JOIN import_batch_profiles p
+ ON b.profile_id = p.id
+ WHERE b.batch_type IN ('batch', 'webservice')
+ ORDER BY b.import_batch_id DESC";
my @params;
if ($results_per_group){
$query .= " LIMIT ?";
}
+=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);
my $marc_type = C4::Context->preference('marcflavour');
$marc_type .= 'AUTH' if ($marc_type eq 'UNIMARC' && $record_type eq 'auth');
- open IN, "<$input_file" or die "$0: cannot open input file $input_file: $!\n";
+ open my $fh, '<', $input_file or die "$0: cannot open input file $input_file: $!\n";
my @marc_records;
$/ = "\035";
- while (<IN>) {
+ while (<$fh>) {
s/^\s+//;
s/\s+$//;
next unless $_; # skip if record has only whitespace, as might occur
"Unexpected charset $charset_guessed, expecting $encoding";
}
}
- close IN;
+ close $fh;
return ( \@errors, \@marc_records );
}
return \@return if !$input_file || !$plugin_class;
# Read input file
- open IN, "<$input_file" or die "$0: cannot open input file $input_file: $!\n";
+ open my $fh, '<', $input_file or die "$0: cannot open input file $input_file: $!\n";
$/ = "\035";
- while (<IN>) {
+ while (<$fh>) {
s/^\s+//;
s/\s+$//;
next unless $_;
$text .= $_;
}
- close IN;
+ close $fh;
# Convert to large MARC blob with plugin
$text = Koha::Plugins::Handler->run({
# FIXME no controlnumber, originalsource
$isbn = C4::Koha::GetNormalizedISBN($isbn);
my $sth = $dbh->prepare("INSERT INTO import_biblios (import_record_id, title, author, isbn, issn) VALUES (?, ?, ?, ?, ?)");
- $sth->execute($import_record_id, $title, $author, $isbn, $issn);
+ $sth->execute($import_record_id, $title, $author, $isbn, $issn) or die $sth->errstr;
$sth->finish();
}