X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=misc%2Fcronjobs%2Fdelete_records_via_leader.pl;h=030b1475dd756f5ad85d206ec042260abc11fc98;hb=3e2b55f64ced64cab71065de8562b998209c3522;hp=11dc33d4e5c35c1430de1346dfb802aa366fa014;hpb=125de75517b64a95b93dead4b1fa5c2326f007eb;p=srvgit diff --git a/misc/cronjobs/delete_records_via_leader.pl b/misc/cronjobs/delete_records_via_leader.pl index 11dc33d4e5..030b1475dd 100755 --- a/misc/cronjobs/delete_records_via_leader.pl +++ b/misc/cronjobs/delete_records_via_leader.pl @@ -5,40 +5,32 @@ # # This file is part of Koha. # -# Koha is free software; you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation; either version 3 of the License, or (at your option) any later -# version. +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. # -# Koha is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License along -# with Koha; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . #----------------------------------- use Modern::Perl; binmode( STDOUT, ":encoding(UTF-8)" ); -BEGIN { - - # find Koha's Perl modules - # test carefully before changing this - use FindBin; - eval { require "$FindBin::Bin/../kohalib.pl" }; -} - -use Getopt::Long; -use Pod::Usage; -use Koha::Cron; -use C4::Biblio; -use C4::Items; +use Getopt::Long qw( GetOptions ); +use Pod::Usage qw( pod2usage ); +use Koha::Script -cron; +use C4::Biblio qw( DelBiblio ); use Koha::Database; use Koha::Biblios; use Koha::Biblio::Metadatas; +use Koha::Items; my $delete_items; my $confirm; @@ -86,7 +78,6 @@ my $total_records_count = @metadatas; my $deleted_records_count = 0; my $total_items_count = 0; my $deleted_items_count = 0; - foreach my $m (@metadatas) { my $biblionumber = $m->get_column('biblionumber'); @@ -95,24 +86,30 @@ foreach my $m (@metadatas) { if ($delete_items) { my $deleted_count = 0; my $biblio = Koha::Biblios->find( $biblionumber ); - my @items = $biblio ? $biblio->items : (); + my @items = Koha::Items->search( { biblionumber => $biblionumber } )->as_list; foreach my $item ( @items ) { - my $itemnumber = $item->itemnumber(); - - my $error = $test ? "Test mode enabled" : DelItemCheck( $biblionumber, $itemnumber ); - $error = undef if $error eq '1'; - - if ($error) { - say "ERROR DELETING ITEM $itemnumber: $error"; - } - else { - say "DELETED ITEM $itemnumber" if $verbose; - $deleted_items_count++; + my $itemnumber = $item->itemnumber; + + if( $test ){ + my $deleted = $item->safe_to_delete; + if ( $deleted ) { + say "TEST MODE: Item $itemnumber would have been deleted"; + } else { + my $error = @{$deleted->messages}[0]->message; + say "TEST MODE: ERROR DELETING ITEM $itemnumber: $error"; + } + } else { + my $deleted = $item->safe_to_delete; + if ( $deleted ) { + say "DELETED ITEM $itemnumber" if $verbose; + $deleted_items_count++; + } else { + my $error = @{$deleted->messages}[0]->message; + say "ERROR DELETING ITEM $itemnumber: $error"; + } } - $total_items_count++; } - } my $error = $test ? q{Test mode enabled} : DelBiblio($biblionumber);