Bug 13157: UNIMARC holdingbranch facet is 995$c not 995$b
[koha.git] / C4 / Creators / Batch.pm
index fabfdd7..28beeb7 100644 (file)
@@ -9,7 +9,7 @@ use C4::Context;
 use C4::Debug;
 
 BEGIN {
-    use version; our $VERSION = qv('1.0.0_1');
+    use version; our $VERSION = qv('3.07.00.049');
 }
 
 sub _check_params {
@@ -149,15 +149,14 @@ sub retrieve {
     };
     while (my $record = $sth->fetchrow_hashref) {
         $self->{'branch_code'} = $record->{'branch_code'};
+        $self->{'creator'} = $record->{'creator'};
         push (@{$self->{'items'}}, {$number_type => $record->{$number_type}, label_id => $record->{'label_id'}});
         $record_flag = 1;       # true if one or more rows were retrieved
     }
-    if ($record_flag == 0) {
-        return; # no such record exists return undef
-    }
+    return -2 if $record_flag == 0;     # a hackish sort of way of indicating no such record exists
     if ($sth->err) {
         warn sprintf('Database returned the following error on attempted SELECT: %s', $sth->errstr);
-        return;
+        return -1;
     }
     $self->{'batch_stat'} = 1;
     bless ($self, $type);
@@ -200,7 +199,11 @@ sub remove_duplicates {
     my %seen=();
     my $query = "DELETE FROM creator_batches WHERE label_id = ?;"; # ORDER BY timestamp ASC LIMIT ?;";
     my $sth = C4::Context->dbh->prepare($query);
-    my @duplicate_items = grep{$seen{$_->{'item_number'}}++} @{$self->{'items'}};
+    my @duplicate_items = grep{
+        $_->{'item_number'}
+            ? $seen{$_->{'item_number'}}++
+            : $seen{$_->{'borrower_number'}}++
+    } @{$self->{'items'}};
     foreach my $item (@duplicate_items) {
         $sth->execute($item->{'label_id'});
         if ($sth->err) {
@@ -265,12 +268,12 @@ This module provides methods for creating, and otherwise manipulating batch obje
 
 =head2 C4::Labels::Batch->retrieve(batch_id => $batch_id)
 
-    Invoking the I<retrieve> method constructs a new batch object containing the current values for batch_id. The method returns a new object upon success and undefined upon failure.
+    Invoking the I<retrieve> method constructs a new batch object containing the current values for batch_id. The method returns a new object upon success and 1 upon failure.
     Errors are logged to the Apache log.
 
     examples:
 
-        my $batch = C4::Labels::Batch->(batch_id => 1); # Retrieves batch 1 and returns an object containing the record
+        my $batch = C4::Labels::Batch->retrieve(batch_id => 1); # Retrieves batch 1 and returns an object containing the record
 
 =head2 delete()