X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FBackgroundJob.pm;h=9f2f7cb05f6630b19e51ae9ce39aee7f8c45adfb;hb=8a40e3dd0f638557b8c666fe708ccbc1ac709c4e;hp=743a6b5eac5dd55f4f9724abbeecd03d5be0845e;hpb=3ceb381944924a7b6a14d69361754422b8b49589;p=kivitendo-erp.git diff --git a/SL/DB/BackgroundJob.pm b/SL/DB/BackgroundJob.pm index 743a6b5ea..9f2f7cb05 100644 --- a/SL/DB/BackgroundJob.pm +++ b/SL/DB/BackgroundJob.pm @@ -10,7 +10,16 @@ use SL::DB::Manager::BackgroundJob; use SL::DB::BackgroundJobHistory; -use SL::BackgroundJob::Test; +use SL::System::Process; + +__PACKAGE__->before_save('_before_save_set_next_run_at'); + +sub _before_save_set_next_run_at { + my ($self) = @_; + + $self->update_next_run_at if !$self->next_run_at; + return 1; +} sub update_next_run_at { my $self = shift; @@ -28,6 +37,7 @@ sub run { my $history; my $ok = eval { + eval "require $package" or die $@; my $result = $package->new->run($self); $history = SL::DB::BackgroundJobHistory @@ -67,4 +77,24 @@ sub data_as_hash { return {}; } +sub validate { + my ($self) = @_; + + my @errors; + + push @errors, $::locale->text('The execution type is invalid.') if ($self->type || '') !~ m/^(?: once | interval )$/x; + + if ( (($self->package_name || '') !~ m/^ [A-Z][A-Za-z0-9]+ $/x) + || ! -f (SL::System::Process::exe_dir() . "/SL/BackgroundJob/" . $self->package_name . ".pm")) { + push @errors, $::locale->text('The package name is invalid.'); + } + + eval { + DateTime::Event::Cron->new_from_cron($self->cron_spec || '* * * * *')->next(DateTime->now_local); + 1; + } or push @errors, $::locale->text('The execution schedule is invalid.'); + + return @errors; +} + 1;