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