# Suite 330, Boston, MA 02111-1307 USA
use strict;
+use warnings;
+
use C4::Context;
use C4::Koha;
use C4::Biblio;
BatchFindBibDuplicates
BatchCommitBibRecords
BatchRevertBibRecords
+ CleanBatch
GetAllImportBatches
GetImportBatchRangeDesc
$sth->execute($import_record_id);
my ($marc, $encoding) = $sth->fetchrow();
$sth->finish();
- return $marc;
+ return $marc, $encoding;
}
$num_items_deleted += BatchRevertItems($rowref->{'import_record_id'}, $rowref->{'matched_biblionumber'});
SetImportRecordStatus($rowref->{'import_record_id'}, 'reverted');
}
+ my $sth2 = $dbh->prepare_cached("UPDATE import_biblios SET matched_biblionumber = NULL WHERE import_record_id = ?");
+ $sth2->execute($rowref->{'import_record_id'});
}
$sth->finish();
return $num_items_deleted;
}
+=head2 CleanBatch
+
+=over 4
+
+CleanBatch($batch_id)
+
+=back
+
+Deletes all staged records from the import batch
+and sets the status of the batch to 'cleaned'. Note
+that deleting a stage record does *not* affect
+any record that has been committed to the database.
+
+=cut
+
+sub CleanBatch {
+ my $batch_id = shift;
+ return unless defined $batch_id;
+
+ C4::Context->dbh->do('DELETE FROM import_records WHERE import_batch_id = ?', {}, $batch_id);
+ SetImportBatchStatus($batch_id, 'cleaned');
+}
+
=head2 GetAllImportBatches
=over 4
my ($offset, $results_per_group) = @_;
my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare_cached("SELECT * FROM import_batches
+ my $query = "SELECT * FROM import_batches
WHERE batch_type = 'batch'
- ORDER BY import_batch_id DESC
- LIMIT ? OFFSET ?");
- $sth->bind_param(1, $results_per_group);
- $sth->bind_param(2, $offset);
-
- my $results = [];
- $sth->execute();
- while (my $row = $sth->fetchrow_hashref) {
- push @$results, $row;
+ ORDER BY import_batch_id DESC";
+ my @params;
+ if ($offset){
+ if ($results_per_group){
+ $query .= " LIMIT ?";
+ push(@params, $results_per_group);
+ }
+ $query .= " OFFSET ?";
+ push(@params, $offset);
}
+ my $sth = $dbh->prepare_cached($query);
+ $sth->execute(@params);
+ my $results = $sth->fetchall_arrayref({});
$sth->finish();
return $results;
}
sub GetItemNumbersFromImportBatch {
my ($batch_id) = @_;
my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare("select itemnumber from import_batches,import_records,import_items where import_batches.import_batch_id=import_records.import_batch_id and import_records.import_record_id=import_items.import_record_id and import_batches.import_batch_id=?");
+ my $sth = $dbh->prepare("SELECT itemnumber FROM import_batches,import_records,import_items WHERE import_batches.import_batch_id=import_records.import_batch_id AND import_records.import_record_id=import_items.import_record_id AND import_batches.import_batch_id=?");
$sth->execute($batch_id);
my @items ;
while ( my ($itm) = $sth->fetchrow_array ) {
=cut
sub GetImportBibliosRange {
- my ($batch_id, $offset, $results_per_group) = @_;
+ my ($batch_id, $offset, $results_per_group, $status) = @_;
my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare_cached("SELECT title, author, isbn, issn, import_record_id, record_sequence,
- matched_biblionumber, status, overlay_status
+ my $query = "SELECT title, author, isbn, issn, import_record_id, record_sequence,
+ status, overlay_status
FROM import_records
JOIN import_biblios USING (import_record_id)
- WHERE import_batch_id = ?
- ORDER BY import_record_id LIMIT ? OFFSET ?");
- $sth->bind_param(1, $batch_id);
- $sth->bind_param(2, $results_per_group);
- $sth->bind_param(3, $offset);
- my $results = [];
- $sth->execute();
- while (my $row = $sth->fetchrow_hashref) {
- push @$results, $row;
+ WHERE import_batch_id = ?";
+ my @params;
+ push(@params, $batch_id);
+ if ($status) {
+ $query .= " AND status=?";
+ push(@params,$status);
+ }
+ $query.=" ORDER BY import_record_id";
+
+ if($offset){
+ if($results_per_group){
+ $query .= " LIMIT ?";
+ push(@params, $results_per_group);
+ }
+ $query .= " OFFSET ?";
+ push(@params, $offset);
}
+ my $sth = $dbh->prepare_cached($query);
+ $sth->execute(@params);
+ my $results = $sth->fetchall_arrayref({});
$sth->finish();
return $results;
my ($title, $author, $isbn, $issn) = _parse_biblio_fields($marc_record);
my $dbh = C4::Context->dbh;
# FIXME no controlnumber, originalsource
- # FIXME 2 - should regularize normalization of ISBN wherever it is done
- $isbn =~ s/\(.*$//;
- $isbn =~ tr/ -_//;
- $isbn = uc $isbn;
+ $isbn = C4::Koha::_isbn_cleanup($isbn); # FIXME C4::Koha::_isbn_cleanup should be made public
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->finish();