Lines 21-28
use Getopt::Long qw( GetOptions );
Link Here
|
21 |
use Pod::Usage qw( pod2usage ); |
21 |
use Pod::Usage qw( pod2usage ); |
22 |
|
22 |
|
23 |
use Koha::Script -cron; |
23 |
use Koha::Script -cron; |
24 |
|
24 |
use C4::Biblio qw( DelBiblio ); |
25 |
use C4::Context; |
25 |
use C4::Context; |
|
|
26 |
use Koha::Biblios; |
26 |
use Koha::Items; |
27 |
use Koha::Items; |
27 |
|
28 |
|
28 |
my $dbh = C4::Context->dbh(); |
29 |
my $dbh = C4::Context->dbh(); |
Lines 44-49
my $OPTIONS = {
Link Here
|
44 |
, help => '' |
45 |
, help => '' |
45 |
, manual => '' |
46 |
, manual => '' |
46 |
, version => '' |
47 |
, version => '' |
|
|
48 |
, del_bibs => '' |
47 |
} |
49 |
} |
48 |
}; |
50 |
}; |
49 |
|
51 |
|
Lines 54-59
GetOptions(
Link Here
|
54 |
, 'h|help' => sub { $OPTIONS->{flags}->{help} = 1 } |
56 |
, 'h|help' => sub { $OPTIONS->{flags}->{help} = 1 } |
55 |
, 'm|manual' => sub { $OPTIONS->{flags}->{manual} = 1 } |
57 |
, 'm|manual' => sub { $OPTIONS->{flags}->{manual} = 1 } |
56 |
, 'c|commit' => sub { $OPTIONS->{flags}->{commit} = 1 } # aka DO-EET! |
58 |
, 'c|commit' => sub { $OPTIONS->{flags}->{commit} = 1 } # aka DO-EET! |
|
|
59 |
, 'del_bibs' => sub { $OPTIONS->{flags}->{del_bibs} = 1 } |
57 |
); |
60 |
); |
58 |
|
61 |
|
59 |
my @where = @{ $OPTIONS->{where} }; |
62 |
my @where = @{ $OPTIONS->{where} }; |
Lines 69-74
sub verbose {
Link Here
|
69 |
my $where_clause = ' where ' . join ( " and ", @where ); |
72 |
my $where_clause = ' where ' . join ( " and ", @where ); |
70 |
|
73 |
|
71 |
verbose "Where statement: $where_clause"; |
74 |
verbose "Where statement: $where_clause"; |
|
|
75 |
if( $OPTIONS->{flags}->{del_bibs} ) { |
76 |
verbose "Deleting empty bib records!" |
77 |
} |
72 |
|
78 |
|
73 |
# FIXME Use Koha::Items instead |
79 |
# FIXME Use Koha::Items instead |
74 |
$GLOBAL->{sth}->{target_items} = $dbh->prepare( $query->{target_items} . $where_clause ); |
80 |
$GLOBAL->{sth}->{target_items} = $dbh->prepare( $query->{target_items} . $where_clause ); |
Lines 76-93
$GLOBAL->{sth}->{target_items}->execute();
Link Here
|
76 |
|
82 |
|
77 |
DELITEM: while ( my $item = $GLOBAL->{sth}->{target_items}->fetchrow_hashref() ) { |
83 |
DELITEM: while ( my $item = $GLOBAL->{sth}->{target_items}->fetchrow_hashref() ) { |
78 |
|
84 |
|
79 |
my $item_object = Koha::Items->find($item->{itemnumber}); |
85 |
my $item_object = Koha::Items->find( $item->{itemnumber} ); |
|
|
86 |
my $bibs_object = Koha::Biblios->find( $item_object->biblionumber ); |
87 |
my $holdings_count = $bibs_object->items->count; |
88 |
my $error; |
89 |
|
80 |
my $safe_to_delete = $item_object->safe_to_delete; |
90 |
my $safe_to_delete = $item_object->safe_to_delete; |
81 |
if( $safe_to_delete ) { |
91 |
if ($safe_to_delete) { |
82 |
$item_object->safe_delete |
92 |
$item_object->safe_delete |
83 |
if $OPTIONS->{flags}->{commit}; |
93 |
if $OPTIONS->{flags}->{commit}; |
84 |
verbose "Deleting '$item->{itemnumber}'"; |
94 |
verbose "Deleting item '$item->{itemnumber}' (of $holdings_count)"; |
|
|
95 |
|
96 |
if ( $OPTIONS->{flags}->{del_bibs} && $holdings_count == 1 ) { # aka DO-EET for empty bibs! |
97 |
$error = &DelBiblio( $item->{biblionumber} ); |
98 |
if ($error) { |
99 |
verbose "Could not delete bib '$item->{biblionumber}': $error"; |
100 |
} else { |
101 |
verbose "Last item deleted - deleting bib '$item->{biblionumber}'"; |
102 |
} |
103 |
} |
85 |
} else { |
104 |
} else { |
86 |
verbose sprintf "Item '%s' (Barcode: '%s', Title: '%s') not deleted: %s", |
105 |
verbose sprintf "Item '%s' (Barcode: '%s', Title: '%s') not deleted: %s", |
87 |
$item->{itemnumber}, |
106 |
$item->{itemnumber}, |
88 |
$item_object->barcode, |
107 |
$item_object->barcode, |
89 |
$item_object->biblio->title, |
108 |
$item_object->biblio->title, |
90 |
@{$safe_to_delete->messages}[0]->message; |
109 |
@{ $safe_to_delete->messages }[0]->message; |
91 |
} |
110 |
} |
92 |
} |
111 |
} |
93 |
|
112 |
|
Lines 130-135
clause querying the items table. These are joined by C<AND>.
Link Here
|
130 |
|
149 |
|
131 |
No items will be deleted unless the C<--commit> flag is present. |
150 |
No items will be deleted unless the C<--commit> flag is present. |
132 |
|
151 |
|
|
|
152 |
=item B<--del_bibs> |
153 |
|
154 |
Deletes the bibliographic record if the last item is deleted. |
155 |
|
133 |
=back |
156 |
=back |
134 |
|
157 |
|
135 |
=cut |
158 |
=cut |
136 |
- |
|
|