From: Ryan Higgins Date: Tue, 18 Mar 2008 02:27:41 +0000 (-0500) Subject: Mod C4::Labels::add_batch to accept an array of items. X-Git-Tag: v3.00.00-beta~76 X-Git-Url: http://git.rot13.org/?a=commitdiff_plain;h=46826aaee0062f803b14136625033082f154326f;p=koha.git Mod C4::Labels::add_batch to accept an array of items. Signed-off-by: Joshua Ferraro --- diff --git a/C4/Labels.pm b/C4/Labels.pm index c257c924ff..62fc873470 100644 --- a/C4/Labels.pm +++ b/C4/Labels.pm @@ -257,28 +257,40 @@ sub by_order { $$a{order} <=> $$b{order}; } +=head2 sub add_batch +=over 4 + add_batch($batch_type,\@batch_list); + if $batch_list is supplied, + create a new batch with those items. + else, return the next available batch_id. +=return +=cut sub add_batch { - my ( $batch_type ) = @_; + my ( $batch_type,$batch_list ) = @_; my $new_batch; my $dbh = C4::Context->dbh; - my $q = - "SELECT DISTINCT batch_id FROM $batch_type ORDER BY batch_id desc LIMIT 1"; + my $q ="SELECT MAX(DISTINCT batch_id) FROM $batch_type"; my $sth = $dbh->prepare($q); $sth->execute(); - my $data = $sth->fetchrow_hashref; + my ($batch_id) = $sth->fetchrow_array; $sth->finish; - - if ( !$data->{'batch_id'} ) { - $new_batch = 1; - } - else { - $new_batch = ( $data->{'batch_id'} + 1 ); - } - - return $new_batch; + if($batch_id) { + $batch_id++; + } else { + $batch_id = 1; + } + # TODO: let this block use $batch_type + if(ref($batch_list) && ($batch_type eq 'labels') ) { + my $sth = $dbh->prepare("INSERT INTO labels (`batch_id`,`itemnumber`) VALUES (?,?)"); + for my $item (@$batch_list) { + $sth->execute($batch_id,$item); + } + } + return $batch_id; } #FIXME: Needs to be ported to receive $batch_type +# ... this looks eerily like add_batch() ... sub get_highest_batch { my $new_batch; my $dbh = C4::Context->dbh; diff --git a/tools/manage-marc-import.pl b/tools/manage-marc-import.pl index 9f93266cba..7dcef8aab3 100755 --- a/tools/manage-marc-import.pl +++ b/tools/manage-marc-import.pl @@ -33,6 +33,7 @@ use C4::Biblio; use C4::ImportBatch; use C4::Matcher; use C4::BackgroundJob; +use C4::Labels qw(add_batch); my $script_name = "/cgi-bin/koha/tools/manage-marc-import.pl"; @@ -132,8 +133,8 @@ sub redo_matching { sub create_labelbatch_from_importbatch { my ($batch_id) = @_; my @items = GetItemNumbersFromImportBatch($batch_id); - warn join("/",@items); - return 0; # dummy return until C4::Labels::add_batch() takes an array + my $labelbatch = add_batch('labels',\@items); + return $labelbatch; } sub import_batches_list {