. */ declare(strict_types=1); namespace FireflyIII\Import\Routine; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Import\JobConfiguration\FinTSConfigurationSteps; use FireflyIII\Models\ImportJob; use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface; use FireflyIII\Support\Import\Routine\FinTS\StageImportDataHandler; use Illuminate\Support\Facades\Log; /** * * Class FinTSRoutine */ class FinTSRoutine implements RoutineInterface { /** @var ImportJob */ private $importJob; /** @var ImportJobRepositoryInterface */ private $repository; /** * At the end of each run(), the import routine must set the job to the expected status. * * The final status of the routine must be "provider_finished". * * @throws FireflyException */ public function run(): void { Log::debug(sprintf('Now in FinTSRoutine::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, true)) { switch ($this->importJob->stage) { default: throw new FireflyException(sprintf('FinTSRoutine cannot handle stage "%s".', $this->importJob->stage)); // @codeCoverageIgnore case FinTSConfigurationSteps::GO_FOR_IMPORT: $this->repository->setStatus($this->importJob, 'running'); /** @var StageImportDataHandler $handler */ $handler = app(StageImportDataHandler::class); $handler->setImportJob($this->importJob); $handler->run(); $transactions = $handler->getTransactions(); $this->repository->setTransactions($this->importJob, $transactions); $this->repository->setStatus($this->importJob, 'provider_finished'); $this->repository->setStage($this->importJob, 'final'); } } } /** * @param ImportJob $importJob * * @return void */ public function setImportJob(ImportJob $importJob): void { $this->importJob = $importJob; $this->repository = app(ImportJobRepositoryInterface::class); $this->repository->setUser($importJob->user); } }