Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Create a fake routine, check for its progress.
James Colecd75224cddda
diff --git a/app/Http/Controllers/Import/JobStatusController.php b/app/Http/Controllers/Import/JobStatusController.phpindex 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 Controllerfunction ($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 Controllerif (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 ControllerLog::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.phpnew file mode 100644index 0000000000..6fef517d3c--- /dev/null+++ b/app/Import/Routine/FakeRoutine.php@@ -0,0 +1,83 @@+<?php+/**+ * FakeRoutine.php+ * Copyright (c) 2018 [email protected]+ *+ * This file is part of Firefly III.+ *+ * Firefly III is free software: you can redistribute it and/or modify+ * it under the terms of the GNU General Public License as published by+ * the Free Software Foundation, either version 3 of the License, or+ * (at your option) any later version.+ *+ * Firefly III is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU General Public License for more details.+ *+ * You should have received a copy of the GNU General Public License+ * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.+ */++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 filediff --git a/app/Repositories/ImportJob/ImportJobRepository.php b/app/Repositories/ImportJob/ImportJobRepository.phpindex 8589785f84..8bb8af480e 100644--- a/app/Repositories/ImportJob/ImportJobRepository.php+++ b/app/Repositories/ImportJob/ImportJobRepository.php@@ -334,6 +334,20 @@ class ImportJobRepository implements ImportJobRepositoryInterfacereturn $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 $statusdiff --git a/app/Repositories/ImportJob/ImportJobRepositoryInterface.php b/app/Repositories/ImportJob/ImportJobRepositoryInterface.phpindex 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 $stepsdiff --git a/app/Support/Import/Routine/Fake/StageNewHandler.php b/app/Support/Import/Routine/Fake/StageNewHandler.phpnew file mode 100644index 0000000000..fbbfbc4dfd--- /dev/null+++ b/app/Support/Import/Routine/Fake/StageNewHandler.php@@ -0,0 +1,44 @@+<?php+/**+ * StageNewHandler.php+ * Copyright (c) 2018 [email protected]+ *+ * This file is part of Firefly III.+ *+ * Firefly III is free software: you can redistribute it and/or modify+ * it under the terms of the GNU General Public License as published by+ * the Free Software Foundation, either version 3 of the License, or+ * (at your option) any later version.+ *+ * Firefly III is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU General Public License for more details.+ *+ * You should have received a copy of the GNU General Public License+ * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.+ */++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 filediff --git a/config/import.php b/config/import.phpindex 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.jsindex 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.twigindex 3d2832f2c0..288a290f70 100644--- a/resources/views/import/status.twig+++ b/resources/views/import/status.twig@@ -42,6 +42,26 @@</div></div></div>+ {# box to show when job is running ... #}+ <div class="row status_running statusbox" style="display: none;">+ <div class="col-lg-8 col-lg-offset-2 col-md-12 col-sm-12">+ <div class="box box-primary">+ <div class="box-header with-border">+ <h3 class="box-title" id="import-status-title">{{ trans('import.status_running_title') }}</h3>+ </div>+ <div class="box-body">+ <div id="import-status-holder">+ <div class="progress">+ <div class="progress-bar progress-bar-info active progress-bar-striped" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: 100%">+ <span class="sr-only">Running...</span>+ </div>+ </div>+ <p id="import-status-txt">Some text here</p>+ </div>+ </div>+ </div>+ </div>+ </div>{# Box for when the job is ready to start<div class="row status_configured statusbox" style="display:none;">diff --git a/routes/web.php b/routes/web.phpindex 0fe2713fc4..aa76bfcdf2 100755--- a/routes/web.php+++ b/routes/web.php@@ -461,7 +461,7 @@ Route::group(Route::get('job/json/{importJob}', ['uses' => 'Import\JobStatusController@json', 'as' => 'job.status.json']);// start the job!- Route::post('job/start/{importJob}', ['uses' => 'Import\JobStatusController@start', 'as' => 'job.start']);+ Route::any('job/start/{importJob}', ['uses' => 'Import\JobStatusController@start', 'as' => 'job.start']);// import method prerequisites:#