Browse Source

Add more debug information to resolve https://github.com/firefly-iii/firefly-iii/issues/5407

pull/24/head
James Cole 4 years ago
parent
commit
2faf371a03
No known key found for this signature in database GPG Key ID: BDE6667570EADBD5
  1. 34
      app/Http/Controllers/Import/ConversionController.php
  2. 16
      app/Http/Middleware/IsReadyForStep.php

34
app/Http/Controllers/Import/ConversionController.php

@ -75,24 +75,26 @@ class ConversionController extends Controller
Log::debug('Will now verify configuration content.');
$jobBackUrl = route('back.mapping');
if (empty($configuration->getDoMapping())) {
if (empty($configuration->getDoMapping()) && 'csv' === $configuration->getFlow()) {
// no mapping, back to roles
Log::debug('NO role info in config, will send you back to roles..');
Log::debug('Pressing "back" will send you to roles.');
$jobBackUrl = route('back.roles');
}
if (empty($configuration->getMapping())) {
// back to mapping
Log::debug('NO mapping in file, will send you back to mapping..');
Log::debug('Pressing "back" will send you to mapping.');
$jobBackUrl = route('back.mapping');
}
if (true === $configuration->isMapAllData()) {
Log::debug('Pressing "back" will send you to mapping.');
$jobBackUrl = route('back.mapping');
}
// job ID may be in session:
$identifier = session()->get(Constants::CONVERSION_JOB_IDENTIFIER);
$flow = $configuration->getFlow();
$nextUrl = route('008-submit.index');
Log::debug('Will redirect to submission after conversion.');
$nextUrl = route('008-submit.index');
// switch based on flow:
if (!in_array($flow, config('importer.flows'), true)) {
@ -100,15 +102,19 @@ class ConversionController extends Controller
}
/** @var RoutineManagerInterface $routine */
if ('csv' === $flow) {
Log::debug('Create CSV routine manager.');
$routine = new CSVRoutineManager($identifier);
}
if ('nordigen' === $flow) {
Log::debug('Create Nordigen routine manager.');
$routine = new NordigenRoutineManager($identifier);
}
if ('spectre' === $flow) {
Log::debug('Create Spectre routine manager.');
$routine = new SpectreRoutineManager($identifier);
}
if ($configuration->isMapAllData() && in_array($flow, ['spectre', 'nordigen'], true)) {
Log::debug('Will redirect to mapping after conversion.');
$nextUrl = route('006-mapping.index');
}
@ -158,22 +164,20 @@ class ConversionController extends Controller
// then push stuff into the routine:
$routine->setConfiguration($configuration);
$result = false;
$transactions = [];
try {
$transactions = $routine->start();
$result = true;
} catch (ImporterErrorException $e) {
Log::error($e->getMessage());
RoutineStatusManager::setConversionStatus(ConversionStatus::CONVERSION_ERRORED);
return response()->json($importJobStatus->toArray());
}
Log::debug(sprintf('Conversion routine "%s" was started successfully.', $flow));
if (0 === count($transactions)) {
Log::error('Zero transactions!');
RoutineStatusManager::setConversionStatus(ConversionStatus::CONVERSION_ERRORED);
return response()->json($importJobStatus->toArray());
}
Log::debug(sprintf('Conversion routine "%s" yielded %d transaction(s).', $flow, count($transactions)));
// save transactions in 'jobs' directory under the same key as the conversion thing.
$disk = Storage::disk(self::DISK_NAME);
try {
@ -183,15 +187,15 @@ class ConversionController extends Controller
RoutineStatusManager::setConversionStatus(ConversionStatus::CONVERSION_ERRORED);
return response()->json($importJobStatus->toArray());
}
Log::debug(sprintf('Transactions are stored on disk "%s" in file "%s.json"', self::DISK_NAME, $identifier));
if (true === $result) {
// set done:
RoutineStatusManager::setConversionStatus(ConversionStatus::CONVERSION_DONE);
// set config as complete.
session()->put(Constants::CONVERSION_COMPLETE_INDICATOR, true);
}
// set done:
RoutineStatusManager::setConversionStatus(ConversionStatus::CONVERSION_DONE);
// set config as complete.
session()->put(Constants::CONVERSION_COMPLETE_INDICATOR, true);
Log::debug('Set conversion as complete.');
return response()->json($importJobStatus->toArray());
}
@ -203,7 +207,7 @@ class ConversionController extends Controller
*/
public function status(Request $request): JsonResponse
{
Log::debug(sprintf('Now at %s', __METHOD__));
$identifier = $request->get('identifier');
Log::debug(sprintf('Now at %s(%s)', __METHOD__, $identifier));
if (null === $identifier) {

16
app/Http/Middleware/IsReadyForStep.php

@ -151,19 +151,24 @@ trait IsReadyForStep
throw new ImporterErrorException(sprintf('isReadyForNordigenStep: Cannot handle Nordigen step "%s"', self::STEP));
case 'authenticate':
case 'service-validation':
Log::debug('return true');
return true;
case 'define-roles':
Log::debug('return false');
return false;
case 'upload-files':
if (session()->has(Constants::HAS_UPLOAD) && true === session()->get(Constants::HAS_UPLOAD)) {
Log::debug('return false');
return false;
}
return true;
case 'nordigen-selection':
// must have upload, thats it
if (session()->has(Constants::HAS_UPLOAD) && true === session()->get(Constants::HAS_UPLOAD)) {
Log::debug('return true');
return true;
}
Log::debug('return false');
return false;
case 'map':
// mapping must be complete, or not ready for this step.
@ -180,7 +185,7 @@ trait IsReadyForStep
// must already have the conversion, or not ready for this step:
if (session()->has(Constants::READY_FOR_CONVERSION) && true === session()->get(Constants::READY_FOR_CONVERSION)) {
Log::debug('Return false, not yet ready for step [2].');
Log::debug('Nordigen: return false, not yet ready for step [2].');
return false;
}
// otherwise return false.
@ -189,8 +194,10 @@ trait IsReadyForStep
case 'nordigen-link':
// must have upload, thats it
if (session()->has(Constants::SELECTED_BANK_COUNTRY) && true === session()->get(Constants::SELECTED_BANK_COUNTRY)) {
Log::debug('return true');
return true;
}
Log::debug('return false');
return false;
case 'conversion':
if (session()->has(Constants::READY_FOR_SUBMISSION) && true === session()->get(Constants::READY_FOR_SUBMISSION)) {
@ -199,21 +206,26 @@ trait IsReadyForStep
}
// if/else is in reverse!
if (session()->has(Constants::READY_FOR_CONVERSION) && true === session()->get(Constants::READY_FOR_CONVERSION)) {
Log::debug('return true');
return true;
}
Log::debug('return false');
// will probably never return false, but OK.
return false;
case 'configuration':
if (session()->has(Constants::SELECTED_BANK_COUNTRY) && true === session()->get(Constants::SELECTED_BANK_COUNTRY)) {
Log::debug('return true');
return true;
}
Log::debug('return false');
return false;
case 'submit':
// if/else is in reverse!
if (session()->has(Constants::CONVERSION_COMPLETE_INDICATOR) && true === session()->get(Constants::CONVERSION_COMPLETE_INDICATOR)) {
Log::debug('return true');
return true;
}
Log::debug('return false');
return false;
}
}

Loading…
Cancel
Save