First start for CSV file import.

This commit is contained in:
James Cole
2018-05-06 20:42:30 +02:00
parent a4524b3c2c
commit 1209f3b39a
13 changed files with 663 additions and 420 deletions

View File

@@ -37,19 +37,10 @@ use Log;
class FakeRoutine implements RoutineInterface
{
/** @var ImportJob */
private $job;
private $importJob;
/** @var ImportJobRepositoryInterface */
private $repository;
/**
* FakeRoutine constructor.
*/
public function __construct()
{
$this->repository = app(ImportJobRepositoryInterface::class);
}
/**
* Fake import routine has three stages:
*
@@ -63,49 +54,50 @@ class FakeRoutine implements RoutineInterface
*/
public function run(): void
{
Log::debug(sprintf('Now in run() for fake routine with status: %s', $this->job->status));
if ($this->job->status !== 'running') {
Log::debug(sprintf('Now in run() for fake routine with status: %s', $this->importJob->status));
if ($this->importJob->status !== 'running') {
throw new FireflyException('This fake job should not be started.'); // @codeCoverageIgnore
}
switch ($this->job->stage) {
switch ($this->importJob->stage) {
default:
throw new FireflyException(sprintf('Fake routine cannot handle stage "%s".', $this->job->stage)); // @codeCoverageIgnore
throw new FireflyException(sprintf('Fake routine cannot handle stage "%s".', $this->importJob->stage)); // @codeCoverageIgnore
case 'new':
/** @var StageNewHandler $handler */
$handler = app(StageNewHandler::class);
$handler->run();
$this->repository->setStage($this->job, 'ahoy');
$this->repository->setStage($this->importJob, 'ahoy');
// set job finished this step:
$this->repository->setStatus($this->job, 'ready_to_run');
$this->repository->setStatus($this->importJob, 'ready_to_run');
return;
case 'ahoy':
/** @var StageAhoyHandler $handler */
$handler = app(StageAhoyHandler::class);
$handler->run();
$this->repository->setStatus($this->job, 'need_job_config');
$this->repository->setStage($this->job, 'final');
$this->repository->setStatus($this->importJob, 'need_job_config');
$this->repository->setStage($this->importJob, 'final');
break;
case 'final':
/** @var StageFinalHandler $handler */
$handler = app(StageFinalHandler::class);
$handler->setJob($this->job);
$handler->setJob($this->importJob);
$transactions = $handler->getTransactions();
$this->repository->setStatus($this->job, 'provider_finished');
$this->repository->setStage($this->job, 'final');
$this->repository->setTransactions($this->job, $transactions);
$this->repository->setStatus($this->importJob, 'provider_finished');
$this->repository->setStage($this->importJob, 'final');
$this->repository->setTransactions($this->importJob, $transactions);
}
}
/**
* @param ImportJob $job
*
* @return mixed
* @return
*/
public function setJob(ImportJob $job)
public function setJob(ImportJob $job): void
{
$this->job = $job;
$this->importJob = $job;
$this->repository = app(ImportJobRepositoryInterface::class);
$this->repository->setUser($job->user);
}
}