From 3be85e174a63158503c333e7f0682abfc969bf8b Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 28 Aug 2012 14:08:53 +0200 Subject: [PATCH] =?utf8?q?Validierungsfunktion=20f=C3=BCr=20BackgroundJobs?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/DB/BackgroundJob.pm | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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; -- 2.20.1