mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 08:35:00 +00:00
More code for spectre.
This commit is contained in:
@@ -22,13 +22,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Import\Configuration;
|
namespace FireflyIII\Import\Configuration;
|
||||||
|
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
|
||||||
use FireflyIII\Models\ImportJob;
|
use FireflyIII\Models\ImportJob;
|
||||||
use FireflyIII\Support\Import\Configuration\ConfigurationInterface;
|
|
||||||
use FireflyIII\Support\Import\Configuration\Spectre\InputMandatory;
|
|
||||||
use FireflyIII\Support\Import\Configuration\Spectre\SelectCountry;
|
|
||||||
use FireflyIII\Support\Import\Configuration\Spectre\SelectProvider;
|
|
||||||
use Log;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class SpectreConfigurator.
|
* Class SpectreConfigurator.
|
||||||
@@ -54,58 +48,35 @@ class SpectreConfigurator implements ConfiguratorInterface
|
|||||||
* @param array $data
|
* @param array $data
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*
|
|
||||||
* @throws FireflyException
|
|
||||||
*/
|
*/
|
||||||
public function configureJob(array $data): bool
|
public function configureJob(array $data): bool
|
||||||
{
|
{
|
||||||
$class = $this->getConfigurationClass();
|
die('cannot store config');
|
||||||
$job = $this->job;
|
|
||||||
/** @var ConfigurationInterface $object */
|
|
||||||
$object = new $class($this->job);
|
|
||||||
$object->setJob($job);
|
|
||||||
$result = $object->storeConfiguration($data);
|
|
||||||
$this->warning = $object->getWarningMessage();
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the data required for the next step in the job configuration.
|
* Return the data required for the next step in the job configuration.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*
|
|
||||||
* @throws FireflyException
|
|
||||||
*/
|
*/
|
||||||
public function getNextData(): array
|
public function getNextData(): array
|
||||||
{
|
{
|
||||||
$class = $this->getConfigurationClass();
|
// update config to tell Firefly we've redirected the user.
|
||||||
$job = $this->job;
|
$config = $this->job->configuration;
|
||||||
/** @var ConfigurationInterface $object */
|
$config['is-redirected'] = true;
|
||||||
$object = app($class);
|
$this->job->configuration = $config;
|
||||||
$object->setJob($job);
|
$this->job->status = 'configured';
|
||||||
|
$this->job->save();
|
||||||
|
|
||||||
return $object->getData();
|
return $this->job->configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*
|
|
||||||
* @throws FireflyException
|
|
||||||
*/
|
*/
|
||||||
public function getNextView(): string
|
public function getNextView(): string
|
||||||
{
|
{
|
||||||
if (!$this->job->configuration['selected-country']) {
|
return 'import.spectre.redirect';
|
||||||
return 'import.spectre.select-country';
|
|
||||||
}
|
|
||||||
if (!$this->job->configuration['selected-provider']) {
|
|
||||||
return 'import.spectre.select-provider';
|
|
||||||
}
|
|
||||||
if (!$this->job->configuration['has-input-mandatory']) {
|
|
||||||
return 'import.spectre.input-fields';
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new FireflyException('No view for state');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -123,16 +94,9 @@ class SpectreConfigurator implements ConfiguratorInterface
|
|||||||
*/
|
*/
|
||||||
public function isJobConfigured(): bool
|
public function isJobConfigured(): bool
|
||||||
{
|
{
|
||||||
$config = $this->job->configuration;
|
// job is configured (and can start) when token is empty:
|
||||||
$config['selected-country'] = $config['selected-country'] ?? false;
|
$config = $this->job->configuration;
|
||||||
$config['selected-provider'] = $config['selected-provider'] ?? false;
|
if ($config['has-token'] === false) {
|
||||||
$config['has-input-mandatory'] = $config['has-input-mandatory'] ?? false;
|
|
||||||
$config['has-input-interactive'] = $config['has-input-interactive'] ?? true; // defaults to true.
|
|
||||||
$this->job->configuration = $config;
|
|
||||||
$this->job->save();
|
|
||||||
|
|
||||||
if ($config['selected-country'] && $config['selected-provider'] && $config['has-input-mandatory'] && $config['has-input-interactive']) {
|
|
||||||
// give job another status
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,45 +108,19 @@ class SpectreConfigurator implements ConfiguratorInterface
|
|||||||
*/
|
*/
|
||||||
public function setJob(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;
|
$this->job = $job;
|
||||||
if (null === $this->job->configuration || 0 === count($this->job->configuration)) {
|
|
||||||
Log::debug(sprintf('Gave import job %s initial configuration.', $this->job->key));
|
|
||||||
$this->job->configuration = [
|
|
||||||
'selected-country' => false,
|
|
||||||
];
|
|
||||||
$this->job->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @throws FireflyException
|
|
||||||
*/
|
|
||||||
private function getConfigurationClass(): string
|
|
||||||
{
|
|
||||||
$class = false;
|
|
||||||
switch (true) {
|
|
||||||
case !$this->job->configuration['selected-country']:
|
|
||||||
$class = SelectCountry::class;
|
|
||||||
break;
|
|
||||||
case !$this->job->configuration['selected-provider']:
|
|
||||||
$class = SelectProvider::class;
|
|
||||||
break;
|
|
||||||
case !$this->job->configuration['has-input-mandatory']:
|
|
||||||
$class = InputMandatory::class;
|
|
||||||
// no break
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (false === $class || 0 === strlen($class)) {
|
|
||||||
throw new FireflyException('Cannot handle current job state in getConfigurationClass().');
|
|
||||||
}
|
|
||||||
if (!class_exists($class)) {
|
|
||||||
throw new FireflyException(sprintf('Class %s does not exist in getConfigurationClass().', $class));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $class;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -22,7 +22,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Import\Prerequisites;
|
namespace FireflyIII\Import\Prerequisites;
|
||||||
|
|
||||||
use FireflyIII\Jobs\GetSpectreProviders;
|
|
||||||
use FireflyIII\Models\Preference;
|
use FireflyIII\Models\Preference;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
@@ -86,10 +85,6 @@ class SpectrePrerequisites implements PrerequisitesInterface
|
|||||||
}
|
}
|
||||||
Log::debug('All prerequisites are here!');
|
Log::debug('All prerequisites are here!');
|
||||||
|
|
||||||
// at this point, check if all providers are present. Providers are shared amongst
|
|
||||||
// users in a multi-user environment.
|
|
||||||
GetSpectreProviders::dispatch($this->user);
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user