From: Moritz Bunkus Date: Tue, 28 Aug 2012 12:08:53 +0000 (+0200) Subject: Validierungsfunktion für BackgroundJobs X-Git-Tag: release-3.0.0beta1~269^2~3 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=3be85e174a63158503c333e7f0682abfc969bf8b;p=kivitendo-erp.git Validierungsfunktion für BackgroundJobs --- diff --git a/SL/DB/BackgroundJob.pm b/SL/DB/BackgroundJob.pm index 743a6b5ea..18f8e428f 100644 --- a/SL/DB/BackgroundJob.pm +++ b/SL/DB/BackgroundJob.pm @@ -11,6 +11,7 @@ use SL::DB::Manager::BackgroundJob; use SL::DB::BackgroundJobHistory; use SL::BackgroundJob::Test; +use SL::System::Process; sub update_next_run_at { my $self = shift; @@ -67,4 +68,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;