mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-15 19:09:50 +00:00
First working version of a working Spectre import.
This commit is contained in:
@@ -33,6 +33,7 @@ use FireflyIII\Support\Import\JobConfiguration\Spectre\ChooseLoginHandler;
|
||||
use FireflyIII\Support\Import\JobConfiguration\Spectre\NewConfig;
|
||||
use FireflyIII\Support\Import\JobConfiguration\Spectre\SpectreJobConfig;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class SpectreJobConfiguration
|
||||
@@ -117,6 +118,7 @@ class SpectreJobConfiguration implements JobConfigurationInterface
|
||||
*/
|
||||
private function getHandler(): SpectreJobConfig
|
||||
{
|
||||
Log::debug(sprintf('Now in SpectreJobConfiguration::getHandler() with stage "%s"', $this->importJob->stage));
|
||||
$handler = null;
|
||||
switch ($this->importJob->stage) {
|
||||
case 'new':
|
||||
|
||||
@@ -29,10 +29,10 @@ use FireflyIII\Support\Import\Routine\Spectre\ImportDataHandler;
|
||||
use FireflyIII\Support\Import\Routine\Spectre\ManageLoginsHandler;
|
||||
use FireflyIII\Support\Import\Routine\Spectre\StageAuthenticatedHandler;
|
||||
use FireflyIII\Support\Import\Routine\Spectre\StageNewHandler;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* Class FileRoutine
|
||||
* Class SpectreRoutine
|
||||
*/
|
||||
class SpectreRoutine implements RoutineInterface
|
||||
{
|
||||
@@ -57,28 +57,19 @@ class SpectreRoutine implements RoutineInterface
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
Log::debug(sprintf('Now in SpectreRoutine::run() with status "%s" and stage "%s".', $this->importJob->status, $this->importJob->stage));
|
||||
$valid = ['ready_to_run']; // should be only ready_to_run
|
||||
if (in_array($this->importJob->status, $valid)) {
|
||||
if (\in_array($this->importJob->status, $valid, true)) {
|
||||
switch ($this->importJob->stage) {
|
||||
default:
|
||||
throw new FireflyException(sprintf('SpectreRoutine cannot handle stage "%s".', $this->importJob->stage));
|
||||
case 'new':
|
||||
// list all of the users logins.
|
||||
$this->repository->setStatus($this->importJob, 'running');
|
||||
/** @var StageNewHandler $handler */
|
||||
$handler = app(StageNewHandler::class);
|
||||
$handler->setImportJob($this->importJob);
|
||||
$handler->run();
|
||||
$this->repository->setStage($this->importJob, 'manage-logins');
|
||||
break;
|
||||
case 'authenticate':
|
||||
// set job to require config.
|
||||
$this->repository->setStatus($this->importJob, 'need_job_config');
|
||||
|
||||
return;
|
||||
case 'manage-logins':
|
||||
// list all of the users logins.
|
||||
$handler = new ManageLoginsHandler;
|
||||
$handler->setImportJob($this->importJob);
|
||||
$handler->run();
|
||||
|
||||
// if count logins is zero, go to authenticate stage
|
||||
if ($handler->countLogins === 0) {
|
||||
@@ -91,9 +82,16 @@ class SpectreRoutine implements RoutineInterface
|
||||
$this->repository->setStage($this->importJob, 'choose-login');
|
||||
$this->repository->setStatus($this->importJob, 'need_job_config');
|
||||
break;
|
||||
case 'authenticate':
|
||||
// set job to require config.
|
||||
$this->repository->setStatus($this->importJob, 'need_job_config');
|
||||
|
||||
return;
|
||||
case 'authenticated':
|
||||
$this->repository->setStatus($this->importJob, 'running');
|
||||
// get accounts from login, store in job.
|
||||
$handler = new StageAuthenticatedHandler;
|
||||
/** @var StageAuthenticatedHandler $handler */
|
||||
$handler = app(StageAuthenticatedHandler::class);
|
||||
$handler->setImportJob($this->importJob);
|
||||
$handler->run();
|
||||
|
||||
@@ -103,9 +101,10 @@ class SpectreRoutine implements RoutineInterface
|
||||
break;
|
||||
case 'go-for-import':
|
||||
// user has chosen account mapping. Should now be ready to import data.
|
||||
//$this->repository->setStatus($this->importJob, 'running');
|
||||
//$this->repository->setStage($this->importJob, 'do_import');
|
||||
$handler = new ImportDataHandler;
|
||||
$this->repository->setStatus($this->importJob, 'running');
|
||||
$this->repository->setStage($this->importJob, 'do_import');
|
||||
/** @var ImportDataHandler $handler */
|
||||
$handler = app(ImportDataHandler::class);
|
||||
$handler->setImportJob($this->importJob);
|
||||
$handler->run();
|
||||
$this->repository->setStatus($this->importJob, 'provider_finished');
|
||||
|
||||
@@ -382,7 +382,9 @@ class ImportArrayStorage
|
||||
$store['date'] = Carbon::createFromFormat('Y-m-d', $store['date']);
|
||||
$store['description'] = $store['description'] === '' ? '(empty description)' : $store['description'];
|
||||
// store the journal.
|
||||
$collection->push($this->journalRepos->store($store));
|
||||
$journal = $this->journalRepos->store($store);
|
||||
Log::debug(sprintf('Stored as journal #%d', $journal->id));
|
||||
$collection->push($journal);
|
||||
}
|
||||
Log::debug('DONE storing!');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user