Browse Source

Merge pull request #844 from firefly-iii/release-1750878357

🤖 Automatically merge the PR into the develop branch.
pull/845/head develop-20250625.3
github-actions[bot] 4 months ago
committed by GitHub
parent
commit
d181765d54
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 41
      app/Services/Shared/Import/Routine/ApiSubmitter.php
  2. 7
      app/Services/SimpleFIN/Conversion/RoutineManager.php

41
app/Services/Shared/Import/Routine/ApiSubmitter.php

@ -71,12 +71,12 @@ class ApiSubmitter
$uniqueCount = 0;
Log::info(sprintf('Going to submit %d transactions to your Firefly III instance.', $count));
$this->vanityURL = SecretManager::getVanityURL();
$this->vanityURL = SecretManager::getVanityURL();
Log::debug(sprintf('Vanity URL : "%s"', $this->vanityURL));
/**
* @var int $index
* @var int $index
* @var array $line
*/
foreach ($lines as $index => $line) {
@ -86,7 +86,7 @@ class ApiSubmitter
SubmissionStatusManager::updateProgress($this->identifier, $index + 1, $count);
// first do local duplicate transaction check (the "cell" method):
$unique = $this->uniqueTransaction($index, $line);
$unique = $this->uniqueTransaction($index, $line);
if (null === $unique) {
Log::debug(sprintf('Transaction #%d is not checked beforehand on uniqueness.', $index + 1));
++$uniqueCount;
@ -160,7 +160,7 @@ class ApiSubmitter
$field = 'note' === $field ? 'notes' : $field;
$value = '';
foreach ($transactions as $transactionIndex => $transaction) {
$value = (string)($transaction[$field] ?? '');
$value = (string)($transaction[$field] ?? '');
if ('' === $value) {
Log::debug(sprintf('Identifier-based duplicate detection found no value ("") for field "%s" in transaction #%d (index #%d).', $field, $index, $transactionIndex));
@ -193,9 +193,9 @@ class ApiSubmitter
Log::debug(sprintf('Going to search for %s:%s using query %s', $field, $value, $query));
$url = SecretManager::getBaseUrl();
$token = SecretManager::getAccessToken();
$request = new GetSearchTransactionsRequest($url, $token);
$url = SecretManager::getBaseUrl();
$token = SecretManager::getAccessToken();
$request = new GetSearchTransactionsRequest($url, $token);
$request->setTimeOut(config('importer.connection.timeout'));
$request->setVerify(config('importer.connection.verify'));
$request->setQuery($query);
@ -211,7 +211,7 @@ class ApiSubmitter
if (0 === $response->count()) {
return 0;
}
$first = $response->current();
$first = $response->current();
Log::debug(sprintf('Found %d transaction(s). Return group ID #%d.', $response->count(), $first->id));
return $first->id;
@ -253,7 +253,7 @@ class ApiSubmitter
return $return;
}
$message = sprintf('[a116]: Submission HTTP error: %s', e($e->getMessage()));
$message = sprintf('[a116]: Submission HTTP error: %s', e($e->getMessage()));
Log::error($e->getMessage());
$this->addError($index, $message);
@ -277,7 +277,7 @@ class ApiSubmitter
if ($response instanceof PostTransactionResponse) {
/** @var TransactionGroup $group */
$group = $response->getTransactionGroup();
$group = $response->getTransactionGroup();
if (null === $group) {
$message = '[a118]: Could not create transaction. Unexpected empty response from Firefly III. Check the logs.';
Log::error($message, $response->getRawData());
@ -295,9 +295,16 @@ class ApiSubmitter
return $return;
}
$return = ['group_id' => $group->id, 'journals' => [],];
$return = ['group_id' => $group->id, 'journals' => []];
foreach ($group->transactions as $transaction) {
$message = sprintf('Created %s <a target="_blank" href="%s">#%d "%s"</a> (%s %s)', $transaction->type, sprintf('%s/transactions/show/%d', $this->vanityURL, $group->id), $group->id, e($transaction->description), $transaction->currencyCode, round((float)$transaction->amount, (int)$transaction->currencyDecimalPlaces) // float but only for display purposes
$message = sprintf(
'Created %s <a target="_blank" href="%s">#%d "%s"</a> (%s %s)',
$transaction->type,
sprintf('%s/transactions/show/%d', $this->vanityURL, $group->id),
$group->id,
e($transaction->description),
$transaction->currencyCode,
round((float)$transaction->amount, (int)$transaction->currencyDecimalPlaces) // float but only for display purposes
);
// plus 1 to keep the count.
$this->addMessage($index, $message);
@ -317,7 +324,7 @@ class ApiSubmitter
Log::debug('Configuration has mapping for opposing account name!');
/**
* @var int $index
* @var int $index
* @var array $transaction
*/
foreach ($line['transactions'] as $index => $transaction) {
@ -431,15 +438,15 @@ class ApiSubmitter
$groupId = (int)$groupInfo['group_id'];
Log::debug(sprintf('Going to add import tag to transaction group #%d', $groupId));
$body = ['transactions' => [],];
$body = ['transactions' => []];
/**
* @var int $journalId
* @var int $journalId
* @var array $currentTags
*/
foreach ($groupInfo['journals'] as $journalId => $currentTags) {
$currentTags[] = $this->tag;
$body['transactions'][] = ['transaction_journal_id' => $journalId, 'tags' => $currentTags,];
$body['transactions'][] = ['transaction_journal_id' => $journalId, 'tags' => $currentTags];
}
$url = SecretManager::getBaseUrl();
$token = SecretManager::getAccessToken();
@ -470,7 +477,7 @@ class ApiSubmitter
$request = new PostTagRequest($url, $token);
$request->setVerify(config('importer.connection.verify'));
$request->setTimeOut(config('importer.connection.timeout'));
$body = ['tag' => $this->tag, 'date' => $this->tagDate,];
$body = ['tag' => $this->tag, 'date' => $this->tagDate];
$request->setBody($body);
try {

7
app/Services/SimpleFIN/Conversion/RoutineManager.php

@ -109,7 +109,7 @@ class RoutineManager implements RoutineManagerInterface
if (0 === $fireflyAccountId) {
$newAccountData = $this->configuration->getNewAccounts()[$simplefinAccountId] ?? null;
if (!$newAccountData) {
Log::error(sprintf('No new account data found for SimpleFIN account: %s',$simplefinAccountId));
Log::error(sprintf('No new account data found for SimpleFIN account: %s', $simplefinAccountId));
continue;
}
@ -173,14 +173,15 @@ class RoutineManager implements RoutineManagerInterface
}
if (null === $createdAccount) {
// Account creation failed - this is a critical error that must be reported
$errorMessage = sprintf('Failed to create Firefly III account "%s" (type: %s, currency: %s). Cannot proceed with transaction import for this account.', $accountConfig['name'], $accountConfig['type'], $accountConfig['currency']);
$errorMessage = sprintf('Failed to create Firefly III account "%s" (type: %s, currency: %s). Cannot proceed with transaction import for this account.', $accountConfig['name'], $accountConfig['type'], $accountConfig['currency']);
Log::warning($errorMessage, ['simplefin_account_id' => $simplefinAccountId, 'account_name' => $accountConfig['name'], 'account_type' => $accountConfig['type'], 'currency' => $accountConfig['currency']]);
// try to find a matching account.
$createdAccount = $accountMapper->findMatchingFireflyAccount($simplefinAccount);
if(null ===$createdAccount) {
if (null === $createdAccount) {
Log::error('Could also not find a matching account for SimpleFIN account.', $simplefinAccount);
throw new ImporterErrorException($errorMessage);
}
}

Loading…
Cancel
Save