View | Details | Raw Unified | Return to bug 30410
Collapse All | Expand All

(-)a/Koha/BackgroundJob.pm (-1 / +68 lines)
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 245-253 sub _derived_class { Link Here
245
246
246
=head3 type_to_class_mapping
247
=head3 type_to_class_mapping
247
248
249
    my $mapping = Koha::BackgrounJob->new->type_to_class_mapping;
250
251
Returns the available types to class mappings.
252
248
=cut
253
=cut
249
254
250
sub type_to_class_mapping {
255
sub type_to_class_mapping {
256
    my ($self) = @_;
257
258
    my $plugins_mapping = $self->plugin_type_to_class;
259
260
    return ($plugins_mapping)
261
      ? { %{ $self->core_type_to_class }, %{ $self->plugin_type_to_class } }
262
      : $self->core_type_to_class;
263
}
264
265
=head3 core_type_to_class
266
267
    my $mappings = Koha::BackgrounJob->new->core_type_to_class
268
269
Returns the core background jobs types to class mappings.
270
271
=cut
272
273
sub core_type_to_class {
251
    return {
274
    return {
252
        batch_authority_record_deletion     => 'Koha::BackgroundJob::BatchDeleteAuthority',
275
        batch_authority_record_deletion     => 'Koha::BackgroundJob::BatchDeleteAuthority',
253
        batch_authority_record_modification => 'Koha::BackgroundJob::BatchUpdateAuthority',
276
        batch_authority_record_modification => 'Koha::BackgroundJob::BatchUpdateAuthority',
Lines 259-264 sub type_to_class_mapping { Link Here
259
    };
282
    };
260
}
283
}
261
284
285
=head3 plugin_type_to_class
286
287
    my $mappings = Koha::BackgroundJob->new->plugin_type_to_class
288
289
Returns the plugin-refined background jobs types to class mappings.
290
291
=cut
292
293
sub plugin_type_to_class {
294
    my ($self) = @_;
295
296
    unless ( exists $self->{_plugin_mapping} ) {
297
        my @plugins = Koha::Plugins->new()->GetPlugins( { method => 'background_tasks', } );
298
299
        foreach my $plugin (@plugins) {
300
301
            my $tasks    = $plugin->background_tasks;
302
            my $metadata = $plugin->get_metadata;
303
304
            unless ( $metadata->{namespace} ) {
305
                Koha::Logger->get->warn(
306
"The plugin includes the 'background_tasks' method, but doesn't provide the required 'namespace' method ("
307
                      . $plugin->{class}
308
                      . ')' );
309
                next;
310
            }
311
312
            my $namespace = $metadata->{namespace};
313
314
            foreach my $type ( keys %{$tasks} ) {
315
                my $class = $tasks->{$type};
316
317
                # skip if conditions not met
318
                next unless $type and $class;
319
320
                my $key = "plugin_$namespace" . "_$type";
321
322
                $self->{_plugin_mapping}->{$key} = $tasks->{$type};
323
            }
324
        }
325
    }
326
327
    return $self->{_plugin_mapping};
328
}
329
262
=head3 _type
330
=head3 _type
263
331
264
=cut
332
=cut
265
- 

Return to bug 30410