. */ declare(strict_types=1); namespace FireflyIII\Import\Configuration; use FireflyIII\Models\ImportJob; /** * Class SpectreConfigurator. */ class SpectreConfigurator implements ConfiguratorInterface { /** @var ImportJob */ private $job; /** @var string */ private $warning = ''; /** * ConfiguratorInterface constructor. */ public function __construct() { } /** * Store any data from the $data array into the job. * * @param array $data * * @return bool */ public function configureJob(array $data): bool { die('cannot store config'); } /** * Return the data required for the next step in the job configuration. * * @return array */ public function getNextData(): array { // update config to tell Firefly we've redirected the user. $config = $this->job->configuration; $config['is-redirected'] = true; $this->job->configuration = $config; $this->job->status = 'configured'; $this->job->save(); return $this->job->configuration; } /** * @return string */ public function getNextView(): string { return 'import.spectre.redirect'; } /** * Return possible warning to user. * * @return string */ public function getWarningMessage(): string { return $this->warning; } /** * @return bool */ public function isJobConfigured(): bool { // job is configured (and can start) when token is empty: $config = $this->job->configuration; if ($config['has-token'] === false) { return true; } return false; } /** * @param ImportJob $job */ public function setJob(ImportJob $job) { $defaultConfig = [ 'has-token' => false, 'token' => '', 'token-expires' => 0, 'token-url' => '', 'is-redirected' => false, ]; $config = $job->configuration; $finalConfig = array_merge($defaultConfig, $config); $job->configuration = $finalConfig; $job->save(); $this->job = $job; } }