Expand some code for Spectre import.

This commit is contained in:
James Cole 2018-01-10 16:49:32 +01:00
parent 2e495c38d1
commit 87dae6ea18
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
5 changed files with 81 additions and 30 deletions

View File

@ -130,6 +130,7 @@ class SpectreConfigurator implements ConfiguratorInterface
switch ($stage) { switch ($stage) {
case 'has-token': case 'has-token':
// redirect to Spectre. // redirect to Spectre.
Log::info('User is being redirected to Spectre.');
return 'import.spectre.redirect'; return 'import.spectre.redirect';
break; break;
case 'have-accounts': case 'have-accounts':

View File

@ -315,7 +315,12 @@ class SpectreRoutine implements RoutineInterface
} }
} }
if (is_null($final)) { if (is_null($final)) {
throw new FireflyException('No valid login attempt found.'); Log::error('Could not find a valid login for this user.');
$this->repository->addError($this->job, 0, 'Spectre connection failed. Did you use invalid credentials, press Cancel or failed the 2FA challenge?');
$this->repository->setTotalSteps($this->job, 1);
$this->repository->setStepsDone($this->job, 1);
$this->repository->setStatus($this->job,'error');
return;
} }
// add some steps done // add some steps done
@ -457,6 +462,7 @@ class SpectreRoutine implements RoutineInterface
// update job: // update job:
$this->job->status = 'finished'; $this->job->status = 'finished';
$this->job->save(); $this->job->save();
return; return;
} }

View File

@ -42,6 +42,20 @@ class ImportJobRepository implements ImportJobRepositoryInterface
/** @var User */ /** @var User */
private $user; private $user;
/**
* @param ImportJob $job
* @param int $index
* @param string $error
*
* @return ImportJob
*/
public function addError(ImportJob $job, int $index, string $error): ImportJob
{
$job->addError($index, $error);
return $job;
}
/** /**
* @param ImportJob $job * @param ImportJob $job
* @param int $steps * @param int $steps
@ -277,6 +291,46 @@ class ImportJobRepository implements ImportJobRepositoryInterface
return $job; return $job;
} }
/**
* @param ImportJob $job
* @param string $status
*
* @return ImportJob
*/
public function setStatus(ImportJob $job, string $status): ImportJob
{
$job->status = $status;
$job->save();
return $job;
}
/**
* @param ImportJob $job
* @param int $count
*
* @return ImportJob
*/
public function setStepsDone(ImportJob $job, int $steps): ImportJob
{
$job->setStepsDone($steps);
return $job;
}
/**
* @param ImportJob $job
* @param int $count
*
* @return ImportJob
*/
public function setTotalSteps(ImportJob $job, int $count): ImportJob
{
$job->setTotalSteps($count);
return $job;
}
/** /**
* @param User $user * @param User $user
*/ */
@ -311,30 +365,4 @@ class ImportJobRepository implements ImportJobRepositoryInterface
{ {
return $job->uploadFileContents(); return $job->uploadFileContents();
} }
/**
* @param ImportJob $job
* @param int $count
*
* @return ImportJob
*/
public function setStepsDone(ImportJob $job, int $steps): ImportJob
{
$job->setStepsDone($steps);
return $job;
}
/**
* @param ImportJob $job
* @param int $count
*
* @return ImportJob
*/
public function setTotalSteps(ImportJob $job, int $count): ImportJob
{
$job->setTotalSteps($count);
return $job;
}
} }

View File

@ -32,6 +32,15 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
interface ImportJobRepositoryInterface interface ImportJobRepositoryInterface
{ {
/**
* @param ImportJob $job
* @param int $index
* @param string $error
*
* @return ImportJob
*/
public function addError(ImportJob $job, int $index, string $error): ImportJob;
/** /**
* @param ImportJob $job * @param ImportJob $job
* @param int $steps * @param int $steps
@ -113,6 +122,14 @@ interface ImportJobRepositoryInterface
*/ */
public function setExtendedStatus(ImportJob $job, array $array): ImportJob; public function setExtendedStatus(ImportJob $job, array $array): ImportJob;
/**
* @param ImportJob $job
* @param string $status
*
* @return ImportJob
*/
public function setStatus(ImportJob $job, string $status): ImportJob;
/** /**
* @param ImportJob $job * @param ImportJob $job
* @param int $count * @param int $count

View File

@ -118,13 +118,12 @@ function reportOnJobStatus(data) {
// show text: // show text:
$('#import-status-more-info').html(data.finishedText); $('#import-status-more-info').html(data.finishedText);
break; break;
case "errored": case "error":
// TODO this view is not yet used.
// hide all possible boxes: // hide all possible boxes:
$('.statusbox').hide(); $('.statusbox').hide();
// fill in some details: // fill in some details:
var errorMessage = data.error_message; var errorMessage = data.errors.join(", ");
$('.fatal_error_txt').text(errorMessage); $('.fatal_error_txt').text(errorMessage);