|
Lines 25-30
use Try::Tiny qw( catch try );
Link Here
|
| 25 |
use C4::Context; |
25 |
use C4::Context; |
| 26 |
use Koha::DateUtils qw( dt_from_string ); |
26 |
use Koha::DateUtils qw( dt_from_string ); |
| 27 |
use Koha::Exceptions; |
27 |
use Koha::Exceptions; |
|
|
28 |
use Koha::Plugins; |
| 28 |
|
29 |
|
| 29 |
use base qw( Koha::Object ); |
30 |
use base qw( Koha::Object ); |
| 30 |
|
31 |
|
|
Lines 250-258
sub _derived_class {
Link Here
|
| 250 |
|
251 |
|
| 251 |
=head3 type_to_class_mapping |
252 |
=head3 type_to_class_mapping |
| 252 |
|
253 |
|
|
|
254 |
my $mapping = Koha::BackgrounJob->new->type_to_class_mapping; |
| 255 |
|
| 256 |
Returns the available types to class mappings. |
| 257 |
|
| 253 |
=cut |
258 |
=cut |
| 254 |
|
259 |
|
| 255 |
sub type_to_class_mapping { |
260 |
sub type_to_class_mapping { |
|
|
261 |
my ($self) = @_; |
| 262 |
|
| 263 |
my $plugins_mapping = $self->plugin_type_to_class; |
| 264 |
|
| 265 |
return ($plugins_mapping) |
| 266 |
? { %{ $self->core_type_to_class }, %{ $self->plugin_type_to_class } } |
| 267 |
: $self->core_type_to_class; |
| 268 |
} |
| 269 |
|
| 270 |
=head3 core_type_to_class |
| 271 |
|
| 272 |
my $mappings = Koha::BackgrounJob->new->core_type_to_class |
| 273 |
|
| 274 |
Returns the core background jobs types to class mappings. |
| 275 |
|
| 276 |
=cut |
| 277 |
|
| 278 |
sub core_type_to_class { |
| 256 |
return { |
279 |
return { |
| 257 |
batch_authority_record_deletion => 'Koha::BackgroundJob::BatchDeleteAuthority', |
280 |
batch_authority_record_deletion => 'Koha::BackgroundJob::BatchDeleteAuthority', |
| 258 |
batch_authority_record_modification => 'Koha::BackgroundJob::BatchUpdateAuthority', |
281 |
batch_authority_record_modification => 'Koha::BackgroundJob::BatchUpdateAuthority', |
|
Lines 264-269
sub type_to_class_mapping {
Link Here
|
| 264 |
}; |
287 |
}; |
| 265 |
} |
288 |
} |
| 266 |
|
289 |
|
|
|
290 |
=head3 plugin_type_to_class |
| 291 |
|
| 292 |
my $mappings = Koha::BackgroundJob->new->plugin_type_to_class |
| 293 |
|
| 294 |
Returns the plugin-refined background jobs types to class mappings. |
| 295 |
|
| 296 |
=cut |
| 297 |
|
| 298 |
sub plugin_type_to_class { |
| 299 |
my ($self) = @_; |
| 300 |
|
| 301 |
unless ( exists $self->{_plugin_mapping} ) { |
| 302 |
my @plugins = Koha::Plugins->new()->GetPlugins( { method => 'background_tasks', } ); |
| 303 |
|
| 304 |
foreach my $plugin (@plugins) { |
| 305 |
|
| 306 |
my $tasks = $plugin->background_tasks; |
| 307 |
my $metadata = $plugin->get_metadata; |
| 308 |
|
| 309 |
unless ( $metadata->{namespace} ) { |
| 310 |
Koha::Logger->get->warn( |
| 311 |
"The plugin includes the 'background_tasks' method, but doesn't provide the required 'namespace' method (" |
| 312 |
. $plugin->{class} |
| 313 |
. ')' ); |
| 314 |
next; |
| 315 |
} |
| 316 |
|
| 317 |
my $namespace = $metadata->{namespace}; |
| 318 |
|
| 319 |
foreach my $type ( keys %{$tasks} ) { |
| 320 |
my $class = $tasks->{$type}; |
| 321 |
|
| 322 |
# skip if conditions not met |
| 323 |
next unless $type and $class; |
| 324 |
|
| 325 |
my $key = "plugin_$namespace" . "_$type"; |
| 326 |
|
| 327 |
$self->{_plugin_mapping}->{$key} = $tasks->{$type}; |
| 328 |
} |
| 329 |
} |
| 330 |
} |
| 331 |
|
| 332 |
return $self->{_plugin_mapping}; |
| 333 |
} |
| 334 |
|
| 267 |
=head3 _type |
335 |
=head3 _type |
| 268 |
|
336 |
|
| 269 |
=cut |
337 |
=cut |
| 270 |
- |
|
|