mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-03 11:08:28 +00:00
Code for Spectre.
This commit is contained in:
@@ -114,7 +114,7 @@ class JobStatusController extends Controller
|
|||||||
public function start(ImportJob $importJob): JsonResponse
|
public function start(ImportJob $importJob): JsonResponse
|
||||||
{
|
{
|
||||||
// catch impossible status:
|
// catch impossible status:
|
||||||
$allowed = ['ready_to_run', 'need_job_config'];
|
$allowed = ['ready_to_run', 'need_job_config','error']; // todo remove error
|
||||||
|
|
||||||
if (null !== $importJob && !\in_array($importJob->status, $allowed, true)) {
|
if (null !== $importJob && !\in_array($importJob->status, $allowed, true)) {
|
||||||
Log::error('Job is not ready.');
|
Log::error('Job is not ready.');
|
||||||
|
@@ -54,17 +54,20 @@ class SpectreRoutine implements RoutineInterface
|
|||||||
*/
|
*/
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
if ($this->importJob->status === 'ready_to_run') {
|
$valid = ['ready_to_run','error']; // should be only ready_to_run
|
||||||
|
if(in_array($this->importJob->status, $valid)) {
|
||||||
switch ($this->importJob->stage) {
|
switch ($this->importJob->stage) {
|
||||||
default:
|
default:
|
||||||
throw new FireflyException(sprintf('SpectreRoutine cannot handle stage "%s".', $this->importJob->stage));
|
throw new FireflyException(sprintf('SpectreRoutine cannot handle stage "%s".', $this->importJob->stage));
|
||||||
case 'new':
|
case 'new':
|
||||||
|
case 'authenticate':
|
||||||
/** @var StageNewHandler $handler */
|
/** @var StageNewHandler $handler */
|
||||||
$handler = app(StageNewHandler::class);
|
$handler = app(StageNewHandler::class);
|
||||||
$handler->setImportJob($this->importJob);
|
$handler->setImportJob($this->importJob);
|
||||||
$handler->run();
|
$handler->run();
|
||||||
$this->repository->setStage($this->importJob, 'authenticate');
|
$this->repository->setStage($this->importJob, 'authenticate');
|
||||||
|
var_dump($this->repository->getConfiguration($this->importJob));
|
||||||
|
exit;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -59,6 +59,7 @@ class StageNewHandler
|
|||||||
*/
|
*/
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
|
Log::debug('Now in stageNewHandler::run()');
|
||||||
$customer = $this->getCustomer();
|
$customer = $this->getCustomer();
|
||||||
// get token using customer.
|
// get token using customer.
|
||||||
$token = $this->getToken($customer);
|
$token = $this->getToken($customer);
|
||||||
@@ -83,12 +84,15 @@ class StageNewHandler
|
|||||||
*/
|
*/
|
||||||
private function getCustomer(): Customer
|
private function getCustomer(): Customer
|
||||||
{
|
{
|
||||||
|
Log::debug('Now in stageNewHandler::getCustomer()');
|
||||||
$customer = $this->getExistingCustomer();
|
$customer = $this->getExistingCustomer();
|
||||||
if (null === $customer) {
|
if (null === $customer) {
|
||||||
|
Log::debug('The customer is NULL, will fire a newCustomerRequest.');
|
||||||
$newCustomerRequest = new NewCustomerRequest($this->importJob->user);
|
$newCustomerRequest = new NewCustomerRequest($this->importJob->user);
|
||||||
$customer = $newCustomerRequest->getCustomer();
|
$customer = $newCustomerRequest->getCustomer();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Log::debug('The customer is not null.');
|
||||||
|
|
||||||
return $customer;
|
return $customer;
|
||||||
}
|
}
|
||||||
@@ -99,14 +103,18 @@ class StageNewHandler
|
|||||||
*/
|
*/
|
||||||
private function getExistingCustomer(): ?Customer
|
private function getExistingCustomer(): ?Customer
|
||||||
{
|
{
|
||||||
|
Log::debug('Now in getExistingCustomer()');
|
||||||
$customer = null;
|
$customer = null;
|
||||||
$getCustomerRequest = new ListCustomersRequest($this->importJob->user);
|
$getCustomerRequest = new ListCustomersRequest($this->importJob->user);
|
||||||
$getCustomerRequest->call();
|
$getCustomerRequest->call();
|
||||||
$customers = $getCustomerRequest->getCustomers();
|
$customers = $getCustomerRequest->getCustomers();
|
||||||
|
|
||||||
|
Log::debug(sprintf('Found %d customer(s)', \count($customers)));
|
||||||
/** @var Customer $current */
|
/** @var Customer $current */
|
||||||
foreach ($customers as $current) {
|
foreach ($customers as $current) {
|
||||||
if ('default_ff3_customer' === $current->getIdentifier()) {
|
if ('default_ff3_customer' === $current->getIdentifier()) {
|
||||||
$customer = $current;
|
$customer = $current;
|
||||||
|
Log::debug('Found the correct customer.');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -122,6 +130,7 @@ class StageNewHandler
|
|||||||
*/
|
*/
|
||||||
private function getToken(Customer $customer): Token
|
private function getToken(Customer $customer): Token
|
||||||
{
|
{
|
||||||
|
Log::debug('Now in getToken()');
|
||||||
$request = new CreateTokenRequest($this->importJob->user);
|
$request = new CreateTokenRequest($this->importJob->user);
|
||||||
$request->setUri(route('import.job.status.index', [$this->importJob->key]));
|
$request->setUri(route('import.job.status.index', [$this->importJob->key]));
|
||||||
$request->setCustomer($customer);
|
$request->setCustomer($customer);
|
||||||
|
Reference in New Issue
Block a user