|
Lines 52-57
my ($template, $loggedinuser, $cookie) = get_template_and_user({
Link Here
|
| 52 |
|
52 |
|
| 53 |
my @records; |
53 |
my @records; |
| 54 |
my @messages; |
54 |
my @messages; |
|
|
55 |
|
| 56 |
my $enqueue_job = sub { |
| 57 |
my ($record_ids, $recordtype) = @_; |
| 58 |
|
| 59 |
try { |
| 60 |
my $params = { |
| 61 |
record_ids => $record_ids, |
| 62 |
}; |
| 63 |
|
| 64 |
my $job_id = |
| 65 |
$recordtype eq 'biblio' |
| 66 |
? Koha::BackgroundJob::BatchDeleteBiblio->new->enqueue($params) |
| 67 |
: Koha::BackgroundJob::BatchDeleteAuthority->new->enqueue($params); |
| 68 |
|
| 69 |
$template->param( |
| 70 |
op => 'enqueued', |
| 71 |
job_id => $job_id, |
| 72 |
); |
| 73 |
} catch { |
| 74 |
push @messages, { |
| 75 |
type => 'error', |
| 76 |
code => 'cannot_enqueue_job', |
| 77 |
error => $_, |
| 78 |
}; |
| 79 |
$template->param( view => 'errors' ); |
| 80 |
}; |
| 81 |
}; |
| 82 |
|
| 55 |
if ( $op eq 'form' ) { |
83 |
if ( $op eq 'form' ) { |
| 56 |
# Display the form |
84 |
# Display the form |
| 57 |
$template->param( |
85 |
$template->param( |
|
Lines 63-69
if ( $op eq 'form' ) {
Link Here
|
| 63 |
] |
91 |
] |
| 64 |
) |
92 |
) |
| 65 |
); |
93 |
); |
| 66 |
} elsif ( $op eq 'cud-list' ) { |
94 |
} elsif ( $op eq 'cud-list' || $op eq 'delete_all' ) { |
| 67 |
# List all records to process |
95 |
# List all records to process |
| 68 |
my @record_ids; |
96 |
my @record_ids; |
| 69 |
if ( my $bib_list = $input->param('bib_list') ) { |
97 |
if ( my $bib_list = $input->param('bib_list') ) { |
|
Lines 90-171
if ( $op eq 'form' ) {
Link Here
|
| 90 |
push @record_ids, split( /\s\n/, scalar $input->param('recordnumber_list') ); |
118 |
push @record_ids, split( /\s\n/, scalar $input->param('recordnumber_list') ); |
| 91 |
} |
119 |
} |
| 92 |
|
120 |
|
| 93 |
for my $record_id ( uniq @record_ids ) { |
121 |
if ( $op eq 'delete_all' ) { |
| 94 |
if ( $recordtype eq 'biblio' ) { |
122 |
$enqueue_job->(\@record_ids, $recordtype); |
| 95 |
# Retrieve biblio information |
123 |
} |
| 96 |
my $biblio_object = Koha::Biblios->find( $record_id ); |
124 |
else { |
| 97 |
unless ( $biblio_object ) { |
125 |
for my $record_id ( uniq @record_ids ) { |
| 98 |
push @messages, { |
126 |
if ( $recordtype eq 'biblio' ) { |
| 99 |
type => 'warning', |
127 |
# Retrieve biblio information |
| 100 |
code => 'biblio_not_exists', |
128 |
my $biblio_object = Koha::Biblios->find( $record_id ); |
| 101 |
biblionumber => $record_id, |
129 |
unless ( $biblio_object ) { |
| 102 |
}; |
130 |
push @messages, { |
| 103 |
next; |
131 |
type => 'warning', |
| 104 |
} |
132 |
code => 'biblio_not_exists', |
| 105 |
my $biblio = $biblio_object->unblessed; |
133 |
biblionumber => $record_id, |
| 106 |
my $record = $biblio_object->metadata->record; |
134 |
}; |
| 107 |
$biblio->{itemnumbers} = [Koha::Items->search({ biblionumber => $record_id })->get_column('itemnumber')]; |
135 |
next; |
| 108 |
$biblio->{holds_count} = $biblio_object->holds->count; |
136 |
} |
| 109 |
$biblio->{issues_count} = C4::Biblio::CountItemsIssued( $record_id ); |
137 |
my $biblio = $biblio_object->unblessed; |
| 110 |
$biblio->{subscriptions_count} = $biblio_object->subscriptions->count; |
138 |
my $record = $biblio_object->metadata->record; |
| 111 |
|
139 |
$biblio->{itemnumbers} = [Koha::Items->search({ biblionumber => $record_id })->get_column('itemnumber')]; |
| 112 |
# Respect skip_open_orders |
140 |
$biblio->{holds_count} = $biblio_object->holds->count; |
| 113 |
next |
141 |
$biblio->{issues_count} = C4::Biblio::CountItemsIssued( $record_id ); |
| 114 |
if $skip_open_orders |
142 |
$biblio->{subscriptions_count} = $biblio_object->subscriptions->count; |
| 115 |
&& Koha::Acquisition::Orders->search( |
143 |
|
| 116 |
{ biblionumber => $record_id, orderstatus => [ 'new', 'ordered', 'partial' ] } )->count; |
144 |
# Respect skip_open_orders |
| 117 |
|
145 |
next |
| 118 |
push @records, $biblio; |
146 |
if $skip_open_orders |
| 119 |
} else { |
147 |
&& Koha::Acquisition::Orders->search( |
| 120 |
# Retrieve authority information |
148 |
{ biblionumber => $record_id, orderstatus => [ 'new', 'ordered', 'partial' ] } )->count; |
| 121 |
my $authority = C4::AuthoritiesMarc::GetAuthority( $record_id ); |
149 |
|
| 122 |
unless ( $authority ) { |
150 |
push @records, $biblio; |
| 123 |
push @messages, { |
151 |
} else { |
| 124 |
type => 'warning', |
152 |
# Retrieve authority information |
| 125 |
code => 'authority_not_exists', |
153 |
my $authority = C4::AuthoritiesMarc::GetAuthority( $record_id ); |
|
|
154 |
unless ( $authority ) { |
| 155 |
push @messages, { |
| 156 |
type => 'warning', |
| 157 |
code => 'authority_not_exists', |
| 158 |
authid => $record_id, |
| 159 |
}; |
| 160 |
next; |
| 161 |
} |
| 162 |
|
| 163 |
$authority = { |
| 126 |
authid => $record_id, |
164 |
authid => $record_id, |
|
|
165 |
summary => C4::AuthoritiesMarc::BuildSummary( $authority, $record_id ), |
| 166 |
count_usage => Koha::Authorities->get_usage_count({ authid => $record_id }), |
| 127 |
}; |
167 |
}; |
| 128 |
next; |
168 |
push @records, $authority; |
| 129 |
} |
169 |
} |
| 130 |
|
|
|
| 131 |
$authority = { |
| 132 |
authid => $record_id, |
| 133 |
summary => C4::AuthoritiesMarc::BuildSummary( $authority, $record_id ), |
| 134 |
count_usage => Koha::Authorities->get_usage_count({ authid => $record_id }), |
| 135 |
}; |
| 136 |
push @records, $authority; |
| 137 |
} |
170 |
} |
|
|
171 |
$template->param( |
| 172 |
records => \@records, |
| 173 |
op => 'list', |
| 174 |
); |
| 138 |
} |
175 |
} |
| 139 |
$template->param( |
|
|
| 140 |
records => \@records, |
| 141 |
op => 'list', |
| 142 |
); |
| 143 |
} elsif ( $op eq 'cud-delete' ) { |
176 |
} elsif ( $op eq 'cud-delete' ) { |
| 144 |
# We want to delete selected records! |
177 |
# We want to delete selected records! |
| 145 |
my @record_ids = $input->multi_param('record_id'); |
178 |
my @record_ids = $input->multi_param('record_id'); |
| 146 |
|
179 |
$enqueue_job->(\@record_ids, $recordtype); |
| 147 |
try { |
|
|
| 148 |
my $params = { |
| 149 |
record_ids => \@record_ids, |
| 150 |
}; |
| 151 |
|
| 152 |
my $job_id = |
| 153 |
$recordtype eq 'biblio' |
| 154 |
? Koha::BackgroundJob::BatchDeleteBiblio->new->enqueue($params) |
| 155 |
: Koha::BackgroundJob::BatchDeleteAuthority->new->enqueue($params); |
| 156 |
|
| 157 |
$template->param( |
| 158 |
op => 'enqueued', |
| 159 |
job_id => $job_id, |
| 160 |
); |
| 161 |
} catch { |
| 162 |
push @messages, { |
| 163 |
type => 'error', |
| 164 |
code => 'cannot_enqueue_job', |
| 165 |
error => $_, |
| 166 |
}; |
| 167 |
$template->param( view => 'errors' ); |
| 168 |
}; |
| 169 |
} |
180 |
} |
| 170 |
|
181 |
|
| 171 |
$template->param( |
182 |
$template->param( |