Lines 94-185
sub process {
Link Here
|
94 |
@deleted_biblionumbers ); |
94 |
@deleted_biblionumbers ); |
95 |
|
95 |
|
96 |
try { |
96 |
try { |
97 |
my (@biblionumbers); |
97 |
my (@biblionumbers); |
98 |
for my $record_id ( sort { $a <=> $b } @record_ids ) { |
98 |
for my $record_id ( sort { $a <=> $b } @record_ids ) { |
99 |
|
99 |
|
100 |
last if $self->get_from_storage->status eq 'cancelled'; |
100 |
last if $self->get_from_storage->status eq 'cancelled'; |
101 |
|
101 |
|
102 |
my $item = Koha::Items->find($record_id) || next; |
102 |
my $item = Koha::Items->find($record_id) || next; |
103 |
|
103 |
|
104 |
my $return = $item->safe_delete({ skip_record_index => 1, skip_holds_queue => 1 }); |
104 |
my $return = $item->safe_delete( { skip_record_index => 1, skip_holds_queue => 1 } ); |
105 |
unless ( $return ) { |
105 |
unless ($return) { |
106 |
|
106 |
|
107 |
push @not_deleted_itemnumbers, $item->itemnumber; |
107 |
push @not_deleted_itemnumbers, $item->itemnumber; |
108 |
push @messages, |
108 |
push @messages, |
109 |
{ |
109 |
{ |
110 |
type => 'error', |
110 |
type => 'error', |
111 |
code => 'item_not_deleted', |
111 |
code => 'item_not_deleted', |
112 |
itemnumber => $item->itemnumber, |
112 |
itemnumber => $item->itemnumber, |
113 |
biblionumber => $item->biblionumber, |
113 |
biblionumber => $item->biblionumber, |
114 |
barcode => $item->barcode, |
114 |
barcode => $item->barcode, |
115 |
title => $item->biblio->title, |
115 |
title => $item->biblio->title, |
116 |
reason => @{$return->messages}[0]->message, |
116 |
reason => @{ $return->messages }[0]->message, |
117 |
}; |
117 |
}; |
118 |
|
118 |
|
119 |
next; |
119 |
next; |
120 |
} |
120 |
} |
121 |
|
121 |
|
122 |
push @deleted_itemnumbers, $item->itemnumber; |
122 |
push @deleted_itemnumbers, $item->itemnumber; |
123 |
push @biblionumbers, $item->biblionumber; |
123 |
push @biblionumbers, $item->biblionumber; |
124 |
|
124 |
|
125 |
$report->{total_success}++; |
125 |
$report->{total_success}++; |
126 |
$self->step; |
126 |
$self->step; |
127 |
} |
127 |
} |
128 |
|
128 |
|
129 |
# If there are no items left, delete the biblio |
129 |
# If there are no items left, delete the biblio |
130 |
my @updated_biblionumbers; |
130 |
my @updated_biblionumbers; |
131 |
for my $biblionumber ( uniq @biblionumbers ) { |
131 |
for my $biblionumber ( uniq @biblionumbers ) { |
132 |
my $items_count = |
132 |
my $items_count = Koha::Biblios->find($biblionumber)->items->count; |
133 |
Koha::Biblios->find($biblionumber)->items->count; |
133 |
if ( $delete_biblios && $items_count == 0 ) { |
134 |
if ( $delete_biblios && $items_count == 0 ) { |
134 |
my $error = C4::Biblio::DelBiblio( |
135 |
my $error = C4::Biblio::DelBiblio( $biblionumber, |
135 |
$biblionumber, |
136 |
{ skip_record_index => 1, skip_holds_queue => 1 } ); |
136 |
{ skip_record_index => 1, skip_holds_queue => 1 } |
137 |
unless ($error) { |
137 |
); |
138 |
push @deleted_biblionumbers, $biblionumber; |
138 |
unless ($error) { |
139 |
} |
139 |
push @deleted_biblionumbers, $biblionumber; |
140 |
} else { |
|
|
141 |
push @updated_biblionumbers, $biblionumber; |
142 |
} |
143 |
} |
140 |
} |
|
|
141 |
} else { |
142 |
push @updated_biblionumbers, $biblionumber; |
143 |
} |
144 |
} |
144 |
|
145 |
|
145 |
if (@deleted_biblionumbers) { |
146 |
if (@deleted_biblionumbers) { |
146 |
my $indexer = Koha::SearchEngine::Indexer->new( |
147 |
my $indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); |
147 |
{ index => $Koha::SearchEngine::BIBLIOS_INDEX } ); |
|
|
148 |
|
148 |
|
149 |
$indexer->index_records( \@deleted_biblionumbers, |
149 |
$indexer->index_records( |
150 |
'recordDelete', "biblioserver", undef ); |
150 |
\@deleted_biblionumbers, |
|
|
151 |
'recordDelete', "biblioserver", undef |
152 |
); |
151 |
|
153 |
|
152 |
Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( |
154 |
Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( { biblio_ids => \@deleted_biblionumbers } ) |
153 |
{ |
155 |
if C4::Context->preference('RealTimeHoldsQueue'); |
154 |
biblio_ids => \@deleted_biblionumbers |
156 |
} |
155 |
} |
|
|
156 |
) if C4::Context->preference('RealTimeHoldsQueue'); |
157 |
} |
158 |
|
157 |
|
159 |
if (@updated_biblionumbers) { |
158 |
if (@updated_biblionumbers) { |
160 |
my $indexer = Koha::SearchEngine::Indexer->new( |
159 |
my $indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); |
161 |
{ index => $Koha::SearchEngine::BIBLIOS_INDEX } ); |
|
|
162 |
|
160 |
|
163 |
$indexer->index_records( \@updated_biblionumbers, |
161 |
$indexer->index_records( |
164 |
'specialUpdate', "biblioserver", undef ); |
162 |
\@updated_biblionumbers, |
|
|
163 |
'specialUpdate', "biblioserver", undef |
164 |
); |
165 |
|
165 |
|
166 |
Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( |
166 |
Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( { biblio_ids => \@updated_biblionumbers } ) |
167 |
{ |
167 |
if C4::Context->preference('RealTimeHoldsQueue'); |
168 |
biblio_ids => \@updated_biblionumbers |
168 |
} |
169 |
} |
169 |
} catch { |
170 |
) if C4::Context->preference('RealTimeHoldsQueue'); |
|
|
171 |
} |
172 |
} |
173 |
catch { |
174 |
|
170 |
|
175 |
warn $_; |
171 |
warn $_; |
176 |
|
172 |
|
177 |
push @messages, |
173 |
push @messages, |
178 |
{ |
174 |
{ |
179 |
type => 'error', |
175 |
type => 'error', |
180 |
code => 'unknown', |
176 |
code => 'unknown', |
181 |
error => $_, |
177 |
error => $_, |
182 |
}; |
178 |
}; |
183 |
|
179 |
|
184 |
}; |
180 |
}; |
185 |
|
181 |
|
186 |
- |
|
|