mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-24 22:48:18 +00:00
New code for updated import routine.
This commit is contained in:
@@ -86,10 +86,10 @@ class JobStatusController extends Controller
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function json(ImportJob $job): JsonResponse
|
||||
public function json(ImportJob $importJob): JsonResponse
|
||||
{
|
||||
$json = [
|
||||
'status' => $job->status,
|
||||
'status' => $importJob->status,
|
||||
];
|
||||
|
||||
return response()->json($json);
|
||||
@@ -101,20 +101,34 @@ class JobStatusController extends Controller
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function start(ImportJob $job): JsonResponse
|
||||
public function start(ImportJob $importJob): JsonResponse
|
||||
{
|
||||
$importProvider = $job->provider;
|
||||
// catch impossible status:
|
||||
$allowed = ['ready_to_run'];
|
||||
if (null !== $importJob && !in_array($importJob->status, $allowed)) {
|
||||
Log::error('Job is not ready.');
|
||||
session()->flash('error', trans('import.bad_job_status'));
|
||||
return redirect(route('import.index'));
|
||||
}
|
||||
|
||||
$importProvider = $importJob->provider;
|
||||
$key = sprintf('import.routine.%s', $importProvider);
|
||||
$className = config($key);
|
||||
if (null === $className || !class_exists($className)) {
|
||||
return response()->json(['status' => 'NOK', 'message' => sprintf('Cannot find import routine class for job of type "%s".', $importProvider)]);
|
||||
}
|
||||
|
||||
|
||||
// if the job is set to "provider_finished", we should be able to store transactions
|
||||
// generated by the provider.
|
||||
// otherwise, just continue.
|
||||
|
||||
// set job to be running:
|
||||
$this->repository->setStatus($job, 'running');
|
||||
$this->repository->setStatus($importJob, 'running');
|
||||
|
||||
/** @var RoutineInterface $routine */
|
||||
$routine = app($className);
|
||||
$routine->setJob($job);
|
||||
$routine->setJob($importJob);
|
||||
try {
|
||||
$routine->run();
|
||||
} catch (FireflyException $e) {
|
||||
@@ -123,16 +137,13 @@ class JobStatusController extends Controller
|
||||
Log::error($e->getTraceAsString());
|
||||
|
||||
// set job errored out:
|
||||
$this->repository->setStatus($job, 'errored');
|
||||
$this->repository->setStatus($importJob, 'error');
|
||||
|
||||
return response()->json(['status' => 'NOK', 'message' => $message]);
|
||||
}
|
||||
|
||||
// set job finished this step:
|
||||
$this->repository->setStatus($job, 'stage_finished');
|
||||
|
||||
// expect nothing from routine, just return OK to user.
|
||||
return response()->json(['status' => 'OK', 'message' => 'finished']);
|
||||
return response()->json(['status' => 'OK', 'message' => 'stage_finished']);
|
||||
}
|
||||
|
||||
// /**
|
||||
|
Reference in New Issue
Block a user