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