2017-12-09 12:13:00 -06:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* SpectreConfigurator.php
|
|
|
|
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
|
|
|
*
|
|
|
|
* This file is part of Firefly III.
|
|
|
|
*
|
|
|
|
* Firefly III is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Firefly III is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2017-12-17 07:44:05 -06:00
|
|
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
2017-12-09 12:13:00 -06:00
|
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2017-12-16 01:03:35 -06:00
|
|
|
namespace FireflyIII\Import\Configuration;
|
2017-12-09 12:13:00 -06:00
|
|
|
|
|
|
|
use FireflyIII\Models\ImportJob;
|
2018-01-02 08:17:31 -06:00
|
|
|
use Log;
|
2017-12-09 12:13:00 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
{
|
2017-12-28 11:39:30 -06:00
|
|
|
die('cannot store config');
|
2017-12-09 12:13:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the data required for the next step in the job configuration.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getNextData(): array
|
|
|
|
{
|
2018-01-02 08:17:31 -06:00
|
|
|
Log::debug('in getNextData(), user will be redirected next.');
|
|
|
|
// update config to tell Firefly the user is redirected.
|
2017-12-28 11:39:30 -06:00
|
|
|
$config = $this->job->configuration;
|
|
|
|
$config['is-redirected'] = true;
|
2018-01-03 00:35:29 -06:00
|
|
|
$config['stage'] = 'redirected';
|
2017-12-28 11:39:30 -06:00
|
|
|
$this->job->configuration = $config;
|
|
|
|
$this->job->status = 'configured';
|
|
|
|
$this->job->save();
|
2017-12-09 12:13:00 -06:00
|
|
|
|
2017-12-28 11:39:30 -06:00
|
|
|
return $this->job->configuration;
|
2017-12-09 12:13:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getNextView(): string
|
|
|
|
{
|
2018-01-02 08:17:31 -06:00
|
|
|
Log::debug('Send user redirect view');
|
|
|
|
|
|
|
|
// sends the user to spectre.
|
2017-12-28 11:39:30 -06:00
|
|
|
return 'import.spectre.redirect';
|
2017-12-09 12:13:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return possible warning to user.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getWarningMessage(): string
|
|
|
|
{
|
|
|
|
return $this->warning;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isJobConfigured(): bool
|
|
|
|
{
|
2018-01-02 08:17:31 -06:00
|
|
|
Log::debug('in isJobConfigured');
|
2017-12-28 11:39:30 -06:00
|
|
|
// job is configured (and can start) when token is empty:
|
|
|
|
$config = $this->job->configuration;
|
2018-01-02 08:17:31 -06:00
|
|
|
if ($config['has-token'] === false && $config['is-redirected'] === true) {
|
|
|
|
Log::debug('has-token is false, is-redirected is true, return true');
|
|
|
|
|
2017-12-09 12:13:00 -06:00
|
|
|
return true;
|
|
|
|
}
|
2018-01-02 08:17:31 -06:00
|
|
|
Log::debug('return false');
|
2017-12-09 12:13:00 -06:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param ImportJob $job
|
|
|
|
*/
|
|
|
|
public function setJob(ImportJob $job)
|
|
|
|
{
|
2018-01-03 00:35:29 -06:00
|
|
|
$defaultConfig = [
|
2017-12-28 11:39:30 -06:00
|
|
|
'has-token' => false,
|
|
|
|
'token' => '',
|
|
|
|
'token-expires' => 0,
|
|
|
|
'token-url' => '',
|
|
|
|
'is-redirected' => false,
|
2018-01-02 08:17:31 -06:00
|
|
|
'customer' => null,
|
|
|
|
'login' => null,
|
2018-01-03 00:35:29 -06:00
|
|
|
'stage' => 'initial',
|
|
|
|
'accounts' => [],
|
2017-12-28 11:39:30 -06:00
|
|
|
];
|
2018-01-03 00:35:29 -06:00
|
|
|
$extendedStatus = $job->extended_status;
|
|
|
|
$extendedStatus['steps'] = 100;
|
|
|
|
|
2017-12-28 11:39:30 -06:00
|
|
|
|
2018-01-03 00:35:29 -06:00
|
|
|
$config = $job->configuration;
|
|
|
|
$finalConfig = array_merge($defaultConfig, $config);
|
|
|
|
$job->configuration = $finalConfig;
|
|
|
|
$job->extended_status = $extendedStatus;
|
2017-12-28 11:39:30 -06:00
|
|
|
$job->save();
|
2017-12-09 12:13:00 -06:00
|
|
|
$this->job = $job;
|
|
|
|
}
|
|
|
|
}
|