Code for Spectre.

This commit is contained in:
James Cole
2018-05-16 21:31:45 +02:00
parent 9f26757e8a
commit dd44a1e517
3 changed files with 15 additions and 3 deletions

View File

@@ -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.');

View File

@@ -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;
}
}

View File

@@ -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);