mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Improved logging for bunq routine. #1607
This commit is contained in:
@@ -32,6 +32,7 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class ChooseAccountsHandler
|
||||
@@ -119,6 +120,9 @@ class ChooseAccountsHandler implements BunqJobConfigurationInterface
|
||||
$config['apply-rules'] = $applyRules;
|
||||
$this->repository->setConfiguration($this->importJob, $config);
|
||||
|
||||
Log::info('Account mapping: ', $final);
|
||||
Log::info('Bunq IBAN array: ', $ibanToAsset);
|
||||
|
||||
return new MessageBag;
|
||||
}
|
||||
|
||||
|
@@ -104,8 +104,8 @@ class StageImportDataHandler
|
||||
foreach ($accounts as $bunqAccount) {
|
||||
$bunqAccountId = $bunqAccount['id'] ?? 0;
|
||||
$localId = $mapping[$bunqAccountId] ?? 0;
|
||||
Log::debug(sprintf('Looping accounts, now at bunq account #%d and local account #%d', $bunqAccountId, $localId));
|
||||
if (0 !== $localId && 0 !== $bunqAccountId) {
|
||||
Log::info(sprintf('Now at bunq account #%d and local account #%d', $bunqAccountId, $localId));
|
||||
$localAccount = $this->getLocalAccount((int)$localId);
|
||||
$collection[] = $this->getTransactionsFromBunq($bunqAccountId, $localAccount);
|
||||
}
|
||||
@@ -205,6 +205,7 @@ class StageImportDataHandler
|
||||
],
|
||||
],
|
||||
];
|
||||
Log::info(sprintf('Parsed %s: "%s" (%s).', $created->format('Y-m-d'), $storeData['description'], $storeData['transactions'][0]['amount']));
|
||||
|
||||
return $storeData;
|
||||
}
|
||||
@@ -267,7 +268,7 @@ class StageImportDataHandler
|
||||
$account = $this->accountFactory->create($data);
|
||||
Log::debug(
|
||||
sprintf(
|
||||
'Converted label monetary account %s to %s account %s (#%d)',
|
||||
'Converted label monetary account "%s" to "%s" account "%s" (#%d)',
|
||||
$party->getLabelUser()->getDisplayName(),
|
||||
$expectedType,
|
||||
$account->name, $account->id
|
||||
@@ -362,6 +363,7 @@ class StageImportDataHandler
|
||||
$direction = $this->getDirection($bunqAccountId);
|
||||
$return = [];
|
||||
if (self::DOWNLOAD_BACKWARDS === $direction) {
|
||||
Log::info('For this account we go backwards in time.');
|
||||
// go back either from NULL or from ID.
|
||||
// ID is the very last transaction downloaded from bunq.
|
||||
$preference = \Preferences::getForUser($this->importJob->user, sprintf('bunq-oldest-transaction-%d', $bunqAccountId), 0);
|
||||
@@ -369,6 +371,7 @@ class StageImportDataHandler
|
||||
$return = $this->goBackInTime($bunqAccountId, $localAccount, $transactionId);
|
||||
}
|
||||
if (self::DOWNLOAD_FORWARDS === $direction) {
|
||||
Log::info('For this account we go forwards in time.');
|
||||
// go forward from ID. There is no NULL, young padawan
|
||||
$return = $this->goForwardInTime($bunqAccountId, $localAccount);
|
||||
}
|
||||
@@ -415,7 +418,7 @@ class StageImportDataHandler
|
||||
*/
|
||||
/** @var Payment $paymentRequest */
|
||||
$paymentRequest = app(Payment::class);
|
||||
$params = ['count' => 53, 'older_id' => $olderId];
|
||||
$params = ['count' => 79, 'older_id' => $olderId];
|
||||
$response = $paymentRequest->listing($bunqAccountId, $params);
|
||||
$pagination = $response->getPagination();
|
||||
Log::debug('Params for the request to bunq are: ', $params);
|
||||
@@ -472,13 +475,13 @@ class StageImportDataHandler
|
||||
*/
|
||||
$oldestTransaction = 0;
|
||||
}
|
||||
sleep(1);
|
||||
|
||||
|
||||
// half a second.
|
||||
usleep(500000);
|
||||
}
|
||||
// store newest and oldest tranasction ID to be used later:
|
||||
\Preferences::setForUser($this->importJob->user, sprintf('bunq-oldest-transaction-%d', $bunqAccountId), $oldestTransaction);
|
||||
\Preferences::setForUser($this->importJob->user, sprintf('bunq-newest-transaction-%d', $bunqAccountId), $newestTransaction);
|
||||
Log::info(sprintf('Downloaded and parsed %d transactions from bunq.', \count($return)));
|
||||
|
||||
return $return;
|
||||
}
|
||||
@@ -567,11 +570,12 @@ class StageImportDataHandler
|
||||
$hasMoreTransactions = false;
|
||||
$this->stillRunning = false;
|
||||
}
|
||||
sleep(1);
|
||||
usleep(500000);
|
||||
}
|
||||
|
||||
// store newest tranasction ID to be used later:
|
||||
\Preferences::setForUser($this->importJob->user, sprintf('bunq-newest-transaction-%d', $bunqAccountId), $newestTransaction);
|
||||
Log::info(sprintf('Downloaded and parsed %d transactions from bunq.', \count($return)));
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
@@ -53,6 +53,7 @@ class StageNewHandler
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
Log::info('Now in StageNewHandler::run()');
|
||||
/** @var Preference $preference */
|
||||
$preference = app('preferences')->getForUser($this->importJob->user, 'bunq_api_context', null);
|
||||
if (null !== $preference && '' !== (string)$preference->data) {
|
||||
@@ -68,6 +69,7 @@ class StageNewHandler
|
||||
$config = $this->repository->getConfiguration($this->importJob);
|
||||
$config['accounts'] = $accounts;
|
||||
$this->repository->setConfiguration($this->importJob, $config);
|
||||
|
||||
return;
|
||||
}
|
||||
throw new FireflyException('The bunq API context is unexpectedly empty.'); // @codeCoverageIgnore
|
||||
@@ -127,9 +129,11 @@ class StageNewHandler
|
||||
}
|
||||
if (null !== $array) {
|
||||
$accounts[] = $array;
|
||||
$this->reportFinding($array);
|
||||
}
|
||||
}
|
||||
}
|
||||
Log::info(sprintf('Found %d account(s) at bunq', \count($accounts)));
|
||||
|
||||
return $accounts;
|
||||
}
|
||||
@@ -274,4 +278,27 @@ class StageNewHandler
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic report method.
|
||||
*
|
||||
* @param array $array
|
||||
*/
|
||||
private function reportFinding(array $array): void
|
||||
{
|
||||
$bunqId = $array['id'] ?? '';
|
||||
$bunqDescription = $array['description'] ?? '';
|
||||
$bunqIBAN = '';
|
||||
|
||||
// find IBAN:
|
||||
$aliases = $array['aliases'] ?? [];
|
||||
foreach ($aliases as $alias) {
|
||||
$type = $alias['type'] ?? 'none';
|
||||
if ('IBAN' === $type) {
|
||||
$bunqIBAN = $alias['value'] ?? '';
|
||||
}
|
||||
}
|
||||
|
||||
Log::info(sprintf('Found account at bunq. ID #%d, title "%s" and IBAN "%s" ', $bunqId, $bunqDescription, $bunqIBAN));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user