Bug 12495 - Include streetnumber in hold alert address
[koha_fer] / C4 / ImportBatch.pm
index 02f2424..a487cc6 100644 (file)
@@ -26,7 +26,7 @@ use C4::Biblio;
 use C4::Items;
 use C4::Charset;
 use C4::AuthoritiesMarc;
-use Koha::MarcModificationTemplates;
+use C4::MarcModificationTemplates;
 
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
 
@@ -324,7 +324,7 @@ sub ModAuthInBatch {
 
 =cut
 
-sub  BatchStageMarcRecords {
+sub BatchStageMarcRecords {
     my $record_type = shift;
     my $encoding = shift;
     my $marc_records = shift;
@@ -1028,9 +1028,18 @@ starting at the given offset.
 =cut
 
 sub GetImportRecordsRange {
-    my ($batch_id, $offset, $results_per_group, $status) = @_;
+    my ( $batch_id, $offset, $results_per_group, $status, $parameters ) = @_;
 
     my $dbh = C4::Context->dbh;
+
+    my $order_by = $parameters->{order_by} || 'import_record_id';
+    ( $order_by ) = grep( /^$order_by$/, qw( import_record_id title status overlay_status ) ) ? $order_by : 'import_record_id';
+
+    my $order_by_direction =
+      uc( $parameters->{order_by_direction} ) eq 'DESC' ? 'DESC' : 'ASC';
+
+    $order_by .= " $order_by_direction, authorized_heading" if $order_by eq 'title';
+
     my $query = "SELECT title, author, isbn, issn, authorized_heading, import_records.import_record_id,
                                            record_sequence, status, overlay_status,
                                            matched_biblionumber, matched_authid, record_type
@@ -1044,7 +1053,8 @@ sub GetImportRecordsRange {
         $query .= " AND status=?";
         push(@params,$status);
     }
-    $query.=" ORDER BY import_record_id";
+
+    $query.=" ORDER BY $order_by $order_by_direction";
 
     if($results_per_group){
         $query .= " LIMIT ?";
@@ -1437,7 +1447,7 @@ sub _add_biblio_fields {
     my ($title, $author, $isbn, $issn) = _parse_biblio_fields($marc_record);
     my $dbh = C4::Context->dbh;
     # FIXME no controlnumber, originalsource
-    $isbn = C4::Koha::_isbn_cleanup($isbn); # FIXME C4::Koha::_isbn_cleanup should be made public
+    $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->finish();