ffzg/recall_notices.pl: added --interval and --dedup
[koha.git] / tools / batch_delete_records.pl
index 8804e62..34c6b5a 100755 (executable)
@@ -27,9 +27,11 @@ use C4::Auth;
 use C4::Output;
 use C4::AuthoritiesMarc;
 use C4::Biblio;
+use Koha::Virtualshelves;
 
 use Koha::Authorities;
 use Koha::Biblios;
+use Koha::Items;
 
 my $input = new CGI;
 my $op = $input->param('op') // q|form|;
@@ -43,6 +45,8 @@ my ($template, $loggedinuser, $cookie) = get_template_and_user({
         flagsrequired => { tools => 'records_batchdel' },
 });
 
+$template->param( lists => scalar Koha::Virtualshelves->search([{ category => 1, owner => $loggedinuser }, { category => 2 }]) );
+
 my @records;
 my @messages;
 if ( $op eq 'form' ) {
@@ -57,11 +61,19 @@ if ( $op eq 'form' ) {
         $recordtype = 'biblio';
     } elsif ( my $uploadfile = $input->param('uploadfile') ) {
         # A file of id is given
+        binmode $uploadfile, ':encoding(UTF-8)';
         while ( my $content = <$uploadfile> ) {
             next unless $content;
             $content =~ s/[\r\n]*$//;
             push @record_ids, $content if $content;
         }
+    } elsif ( my $shelf_number = $input->param('shelf_number') ) {
+        my $shelf = Koha::Virtualshelves->find($shelf_number);
+        my $contents = $shelf->get_contents;
+        while ( my $content = $contents->next ) {
+            my $biblionumber = $content->biblionumber;
+            push @record_ids, $biblionumber;
+        }
     } else {
         # The user enters manually the list of id
         push @record_ids, split( /\s\n/, $input->param('recordnumber_list') );
@@ -83,7 +95,7 @@ if ( $op eq 'form' ) {
             $biblio = $biblio->unblessed;
             my $record = &GetMarcBiblio({ biblionumber => $record_id });
             $biblio->{subtitle} = GetRecordValue( 'subtitle', $record, GetFrameworkCode( $record_id ) );
-            $biblio->{itemnumbers} = C4::Items::GetItemnumbersForBiblio( $record_id );
+            $biblio->{itemnumbers} = [Koha::Items->search({ biblionumber => $record_id })->get_column('itemnumber')];
             $biblio->{holds_count} = $holds_count;
             $biblio->{issues_count} = C4::Biblio::CountItemsIssued( $record_id );
             push @records, $biblio;
@@ -164,7 +176,7 @@ if ( $op eq 'form' ) {
             }
 
             # Delete items
-            my @itemnumbers = @{ C4::Items::GetItemnumbersForBiblio( $biblionumber ) };
+            my @itemnumbers = Koha::Items->search({ biblionumber => $biblionumber })->get_column('itemnumber');
             ITEMNUMBER: for my $itemnumber ( @itemnumbers ) {
                 my $error = eval { C4::Items::DelItemCheck( $biblionumber, $itemnumber ) };
                 if ( $error != 1 or $@ ) {