. */ declare(strict_types=1); namespace FireflyIII\Support\Import\JobConfiguration\Spectre; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\ImportJob; use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface; use FireflyIII\Services\Spectre\Object\Token; use Illuminate\Support\MessageBag; /** * Class AuthenticateConfig * * @package FireflyIII\Support\Import\JobConfiguration\Spectre */ class AuthenticateConfig implements SpectreJobConfig { /** @var ImportJob */ private $importJob; /** @var ImportJobRepositoryInterface */ private $repository; /** * Return true when this stage is complete. * * always returns false. * * @return bool */ public function configurationComplete(): bool { return false; } /** * Store the job configuration. * * @param array $data * * @return MessageBag */ public function configureJob(array $data): MessageBag { // does nothing return new MessageBag; } /** * Get data for config view. * * @return array * @throws FireflyException */ public function getNextData(): array { // next data only makes sure the job is ready for the next stage. $this->repository->setStatus($this->importJob, 'ready_to_run'); $this->repository->setStage($this->importJob, 'authenticated'); $config = $this->importJob->configuration; $token = isset($config['token']) ? new Token($config['token']) : null; if (null !== $token) { return ['token-url' => $token->getConnectUrl()]; } throw new FireflyException('The import routine cannot continue without a Spectre token. Apologies.'); } /** * Get the view for this stage. * * @return string */ public function getNextView(): string { return 'import.spectre.redirect'; } /** * Set the import job. * * @param ImportJob $importJob */ public function setImportJob(ImportJob $importJob): void { $this->importJob = $importJob; $this->repository = app(ImportJobRepositoryInterface::class); $this->repository->setUser($importJob->user); } }