diff --git a/app/Http/Controllers/Import/JobStatusController.php b/app/Http/Controllers/Import/JobStatusController.php index ece8a4cdea..53307c51da 100644 --- a/app/Http/Controllers/Import/JobStatusController.php +++ b/app/Http/Controllers/Import/JobStatusController.php @@ -27,6 +27,7 @@ use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Middleware\IsDemoUser; use FireflyIII\Import\Routine\RoutineInterface; use FireflyIII\Models\ImportJob; +use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface; use Illuminate\Http\JsonResponse; use Log; @@ -35,6 +36,9 @@ use Log; */ class JobStatusController extends Controller { + /** @var ImportJobRepositoryInterface */ + private $repository; + /** * */ @@ -46,6 +50,7 @@ class JobStatusController extends Controller function ($request, $next) { app('view')->share('mainTitleIcon', 'fa-archive'); app('view')->share('title', trans('firefly.import_index_title')); + $this->repository = app(ImportJobRepositoryInterface::class); return $next($request); } @@ -104,6 +109,8 @@ class JobStatusController extends Controller if (null === $className || !class_exists($className)) { return response()->json(['status' => 'NOK', 'message' => sprintf('Cannot find import routine class for job of type "%s".', $importProvider)]); } + // set job to be running: + $this->repository->setStatus($job, 'running'); /** @var RoutineInterface $routine */ $routine = app($className); @@ -115,9 +122,15 @@ class JobStatusController extends Controller Log::error($message); Log::error($e->getTraceAsString()); + // set job errored out: + $this->repository->setStatus($job, 'errored'); + 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']); } diff --git a/app/Import/Routine/FakeRoutine.php b/app/Import/Routine/FakeRoutine.php new file mode 100644 index 0000000000..6fef517d3c --- /dev/null +++ b/app/Import/Routine/FakeRoutine.php @@ -0,0 +1,83 @@ +. + */ + +declare(strict_types=1); + +namespace FireflyIII\Import\Routine; + +use FireflyIII\Exceptions\FireflyException; +use FireflyIII\Models\ImportJob; +use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface; +use FireflyIII\Support\Import\Routine\Fake\StageNewHandler; + + +/** + * Class FakeRoutine + */ +class FakeRoutine implements RoutineInterface +{ + /** @var ImportJob */ + private $job; + /** @var ImportJobRepositoryInterface */ + private $repository; + + /** + * FakeRoutine constructor. + */ + public function __construct() + { + $this->repository = app(ImportJobRepositoryInterface::class); + } + + + /** + * Fake import routine has three stages: + * + * "new": will quietly log gibberish for 15 seconds, then switch to stage "ahoy" + * unless "ahoy" has been done already. If so, jump to stage "final". + * "ahoy": will log some nonsense and then drop job into "need_extra_config" to force it back to the job config routine. + * "final": will do some logging, sleep for 10 seconds and then finish. Generates 5 random transactions. + * + * @return bool + * @throws FireflyException + */ + public function run(): void + { + switch ($this->job->stage) { + default: + throw new FireflyException(sprintf('Fake routine cannot handle stage "%s".', $this->job->stage)); + case 'new': + $handler = new StageNewHandler; + $handler->run(); + } + } + + /** + * @param ImportJob $job + * + * @return mixed + */ + public function setJob(ImportJob $job) + { + $this->job = $job; + $this->repository->setUser($job->user); + } +} \ No newline at end of file diff --git a/app/Repositories/ImportJob/ImportJobRepository.php b/app/Repositories/ImportJob/ImportJobRepository.php index 8589785f84..8bb8af480e 100644 --- a/app/Repositories/ImportJob/ImportJobRepository.php +++ b/app/Repositories/ImportJob/ImportJobRepository.php @@ -334,6 +334,20 @@ class ImportJobRepository implements ImportJobRepositoryInterface return $job; } + /** + * @param ImportJob $job + * @param string $stage + * + * @return ImportJob + */ + public function setStage(ImportJob $job, string $stage): ImportJob + { + $job->stage = $stage; + $job->save(); + + return $job; + } + /** * @param ImportJob $job * @param string $status diff --git a/app/Repositories/ImportJob/ImportJobRepositoryInterface.php b/app/Repositories/ImportJob/ImportJobRepositoryInterface.php index bb56921445..e72e6ce752 100644 --- a/app/Repositories/ImportJob/ImportJobRepositoryInterface.php +++ b/app/Repositories/ImportJob/ImportJobRepositoryInterface.php @@ -145,6 +145,14 @@ interface ImportJobRepositoryInterface */ public function setStatus(ImportJob $job, string $status): ImportJob; + /** + * @param ImportJob $job + * @param string $stage + * + * @return ImportJob + */ + public function setStage(ImportJob $job, string $stage): ImportJob; + /** * @param ImportJob $job * @param int $steps diff --git a/app/Support/Import/Routine/Fake/StageNewHandler.php b/app/Support/Import/Routine/Fake/StageNewHandler.php new file mode 100644 index 0000000000..fbbfbc4dfd --- /dev/null +++ b/app/Support/Import/Routine/Fake/StageNewHandler.php @@ -0,0 +1,44 @@ +. + */ + +declare(strict_types=1); + +namespace FireflyIII\Support\Import\Routine\Fake; + +use Log; + +/** + * Class StageNewHandler + */ +class StageNewHandler +{ + /** + * + */ + public function run(): void + { + for ($i = 0; $i < 15; $i++) { + Log::debug(sprintf('Am now in stage new hander, sleeping... (%d)', $i)); + sleep(1); + } + } + +} \ No newline at end of file diff --git a/config/import.php b/config/import.php index 390edfab10..a5f56fdb78 100644 --- a/config/import.php +++ b/config/import.php @@ -11,6 +11,7 @@ use FireflyIII\Import\Prerequisites\FakePrerequisites; use FireflyIII\Import\Prerequisites\FilePrerequisites; use FireflyIII\Import\Prerequisites\SpectrePrerequisites; use FireflyIII\Import\Routine\BunqRoutine; +use FireflyIII\Import\Routine\FakeRoutine; use FireflyIII\Import\Routine\FileRoutine; use FireflyIII\Import\Routine\SpectreRoutine; @@ -59,7 +60,7 @@ return [ 'file' => FilePrerequisites::class, 'bunq' => BunqPrerequisites::class, 'spectre' => SpectrePrerequisites::class, - 'plaid' => 'FireflyIII\Import\Prerequisites\PlaidPrerequisites', + 'plaid' => false, 'quovo' => false, 'yodlee' => false, ], @@ -77,13 +78,18 @@ return [ 'file' => FileConfigurator::class, 'bunq' => BunqConfigurator::class, 'spectre' => SpectreConfigurator::class, - 'plaid' => 'FireflyIII\Import\Configuration\PlaidConfigurator', + 'plaid' => false, + 'quovo' => false, + 'yodlee' => false, ], 'routine' => [ + 'fake' => FakeRoutine::class, 'file' => FileRoutine::class, 'bunq' => BunqRoutine::class, 'spectre' => SpectreRoutine::class, - 'plaid' => 'FireflyIII\Import\Routine\PlaidRoutine', + 'plaid' => false, + 'quovo' => false, + 'yodlee' => false, ], 'options' => [ diff --git a/public/js/ff/import/status_v2.js b/public/js/ff/import/status_v2.js index b1a2d00a8f..421627de6f 100644 --- a/public/js/ff/import/status_v2.js +++ b/public/js/ff/import/status_v2.js @@ -52,8 +52,10 @@ function reportOnJobStatus(data) { case "ready_to_run": startJob(); checkOnJob(); - - + break; + case "running": + showProgressBox(); + checkOnJob(); break; default: console.error('Cannot handle status ' + data.status); @@ -108,6 +110,17 @@ function reportFailure(xhr, status, error) { // show error box. } +function showProgressBox() { + // hide fatal error box: + $('.fatal_error').hide(); + + // hide initial status box: + $('.status_initial').hide(); + + // show running box: + $('.status_running').show(); +} + /** * Function is called when the job could not be started. * diff --git a/resources/views/import/status.twig b/resources/views/import/status.twig index 3d2832f2c0..288a290f70 100644 --- a/resources/views/import/status.twig +++ b/resources/views/import/status.twig @@ -42,6 +42,26 @@ + {# box to show when job is running ... #} +
{# Box for when the job is ready to start