From dd44a1e51795924bd3c86bfe8db8e75f87c5870b Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 16 May 2018 21:31:45 +0200 Subject: [PATCH] Code for Spectre. --- app/Http/Controllers/Import/JobStatusController.php | 2 +- app/Import/Routine/SpectreRoutine.php | 7 +++++-- app/Support/Import/Routine/Spectre/StageNewHandler.php | 9 +++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Import/JobStatusController.php b/app/Http/Controllers/Import/JobStatusController.php index 54fa516f05..c9b53a4eb9 100644 --- a/app/Http/Controllers/Import/JobStatusController.php +++ b/app/Http/Controllers/Import/JobStatusController.php @@ -114,7 +114,7 @@ class JobStatusController extends Controller public function start(ImportJob $importJob): JsonResponse { // 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)) { Log::error('Job is not ready.'); diff --git a/app/Import/Routine/SpectreRoutine.php b/app/Import/Routine/SpectreRoutine.php index 616dd0a1ab..639351ccf5 100644 --- a/app/Import/Routine/SpectreRoutine.php +++ b/app/Import/Routine/SpectreRoutine.php @@ -54,17 +54,20 @@ class SpectreRoutine implements RoutineInterface */ 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) { default: throw new FireflyException(sprintf('SpectreRoutine cannot handle stage "%s".', $this->importJob->stage)); case 'new': + case 'authenticate': /** @var StageNewHandler $handler */ $handler = app(StageNewHandler::class); $handler->setImportJob($this->importJob); $handler->run(); $this->repository->setStage($this->importJob, 'authenticate'); + var_dump($this->repository->getConfiguration($this->importJob)); + exit; break; } } diff --git a/app/Support/Import/Routine/Spectre/StageNewHandler.php b/app/Support/Import/Routine/Spectre/StageNewHandler.php index 823354632b..a7380462d7 100644 --- a/app/Support/Import/Routine/Spectre/StageNewHandler.php +++ b/app/Support/Import/Routine/Spectre/StageNewHandler.php @@ -59,6 +59,7 @@ class StageNewHandler */ public function run(): void { + Log::debug('Now in stageNewHandler::run()'); $customer = $this->getCustomer(); // get token using customer. $token = $this->getToken($customer); @@ -83,12 +84,15 @@ class StageNewHandler */ private function getCustomer(): Customer { + Log::debug('Now in stageNewHandler::getCustomer()'); $customer = $this->getExistingCustomer(); if (null === $customer) { + Log::debug('The customer is NULL, will fire a newCustomerRequest.'); $newCustomerRequest = new NewCustomerRequest($this->importJob->user); $customer = $newCustomerRequest->getCustomer(); } + Log::debug('The customer is not null.'); return $customer; } @@ -99,14 +103,18 @@ class StageNewHandler */ private function getExistingCustomer(): ?Customer { + Log::debug('Now in getExistingCustomer()'); $customer = null; $getCustomerRequest = new ListCustomersRequest($this->importJob->user); $getCustomerRequest->call(); $customers = $getCustomerRequest->getCustomers(); + + Log::debug(sprintf('Found %d customer(s)', \count($customers))); /** @var Customer $current */ foreach ($customers as $current) { if ('default_ff3_customer' === $current->getIdentifier()) { $customer = $current; + Log::debug('Found the correct customer.'); break; } } @@ -122,6 +130,7 @@ class StageNewHandler */ private function getToken(Customer $customer): Token { + Log::debug('Now in getToken()'); $request = new CreateTokenRequest($this->importJob->user); $request->setUri(route('import.job.status.index', [$this->importJob->key])); $request->setCustomer($customer);