1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

INA-5 | Add prepareForValidation |code cleanup

This commit is contained in:
Nikola Cirkovic 2022-05-23 21:57:48 +02:00
parent 270166b050
commit 05ff9531ab
3 changed files with 21 additions and 8 deletions

View File

@ -14,6 +14,7 @@ namespace App\Http\Requests\TaskScheduler;
use App\Http\Requests\Request;
use App\Models\ScheduledJob;
use Carbon\Carbon;
use Illuminate\Validation\Rule;
class UpdateScheduleRequest extends Request
@ -34,7 +35,20 @@ class UpdateScheduleRequest extends Request
'paused' => 'sometimes|bool',
'archived' => 'sometimes|bool',
'repeat_every' => 'sometimes|string|in:DAY,WEEK,MONTH,3MONTHS,YEAR',
'start_from' => 'sometimes|string',
'start_from' => 'sometimes',
'scheduled_run'=>'sometimes'
];
}
public function prepareForValidation()
{
$request = $this->all();
if (isset($request['start_from'])) {
$request['scheduled_run'] = Carbon::parse((int)$request['start_from']);
$request['start_from'] = Carbon::parse((int)$request['start_from']);
}
$this->replace($request);
}
}

View File

@ -143,7 +143,7 @@ class TaskScheduler implements ShouldQueue
return Scheduler::where('paused', false)
->where('archived', false)
->whereDate('scheduled_run', '<=', Carbon::now())
->get();
->cursor();
}
}

View File

@ -45,6 +45,7 @@ class TaskSchedulerService
$scheduler->start_from = $request->get('start_from') ? Carbon::parse((int)$request->get('start_from')) : Carbon::now();
$scheduler->repeat_every = $request->get('repeat_every');
$scheduler->scheduled_run = $request->get('start_from') ? Carbon::parse((int)$request->get('start_from')) : Carbon::now();;
$scheduler->company_id = auth()->user()->company()->id;
$scheduler->save();
if ($this->createJob($request, $scheduler)) {
@ -55,14 +56,12 @@ class TaskSchedulerService
public function update(Scheduler $scheduler, UpdateScheduleRequest $request)
{
$data = $request->validated();
if ($request->has('start_from')) {
$data['start_from'] = Carbon::parse((int)$request->get('start_from'));
$data['scheduled_run'] = Carbon::parse((int)$request->get('start_from'));
}
$update = $this->scheduler->update($data);
if ($update) {
return response(['successfully_updated_scheduler'],200);
return response(['successfully_updated_scheduler'], 200);
}
return response(['failed_to_update_scheduler'], 400);
}
@ -209,7 +208,7 @@ class TaskSchedulerService
$job = $this->setJobParameters($job, $request);
$job->save();
return response(['job_successfully_updated'],200);
return response(['job_successfully_updated'], 200);
}