Browse Source

Replace log calls.

pull/844/head
James Cole 4 months ago
parent
commit
b2156dfd17
  1. 7
      app/Services/CSV/Configuration/ConfigFileProcessor.php
  2. 33
      app/Services/CSV/Conversion/Routine/CSVFileProcessor.php
  3. 3
      app/Services/CSV/Conversion/Routine/ColumnValue.php
  4. 25
      app/Services/CSV/Conversion/Routine/ColumnValueConverter.php
  5. 47
      app/Services/CSV/Conversion/Routine/LineProcessor.php
  6. 18
      app/Services/CSV/Conversion/Routine/PseudoTransactionProcessor.php
  7. 3
      app/Services/CSV/Conversion/RoutineManager.php
  8. 20
      app/Services/CSV/Conversion/Support/DeterminesTransactionType.php
  9. 155
      app/Services/CSV/Conversion/Task/Accounts.php
  10. 26
      app/Services/CSV/Conversion/Task/Amount.php
  11. 4
      app/Services/CSV/Conversion/Task/Currency.php
  12. 12
      app/Services/CSV/Conversion/Task/EmptyAccounts.php
  13. 46
      app/Services/CSV/Converter/Amount.php
  14. 4
      app/Services/CSV/Converter/BankDebitCredit.php
  15. 4
      app/Services/CSV/Converter/CleanId.php
  16. 4
      app/Services/CSV/Converter/ConverterService.php
  17. 11
      app/Services/CSV/Converter/Date.php
  18. 12
      app/Services/CSV/Converter/Iban.php
  19. 3
      app/Services/CSV/File/FileReader.php
  20. 5
      app/Services/CSV/Mapper/Bills.php
  21. 5
      app/Services/CSV/Mapper/Budgets.php
  22. 5
      app/Services/CSV/Mapper/Categories.php
  23. 7
      app/Services/CSV/Mapper/ExpenseRevenueAccounts.php
  24. 19
      app/Services/CSV/Mapper/GetAccounts.php
  25. 13
      app/Services/CSV/Mapper/MapperService.php
  26. 5
      app/Services/CSV/Mapper/TransactionCurrencies.php
  27. 13
      app/Services/CSV/Roles/RoleService.php
  28. 15
      app/Services/Camt/Conversion/RoutineManager.php
  29. 19
      app/Services/Camt/Conversion/TransactionConverter.php
  30. 13
      app/Services/Camt/Conversion/TransactionExtractor.php
  31. 151
      app/Services/Camt/Conversion/TransactionMapper.php
  32. 23
      app/Services/Camt/Transaction.php
  33. 5
      app/Services/Nordigen/Authentication/SecretManager.php
  34. 3
      app/Services/Nordigen/AuthenticationValidator.php
  35. 35
      app/Services/Nordigen/Conversion/Routine/TransactionProcessor.php
  36. 41
      app/Services/Nordigen/Conversion/RoutineManager.php
  37. 14
      app/Services/Nordigen/Model/Account.php
  38. 4
      app/Services/Nordigen/Model/Balance.php
  39. 5
      app/Services/Nordigen/Request/GetTransactionsRequest.php
  40. 5
      app/Services/Nordigen/Request/PostNewRequisitionRequest.php
  41. 3
      app/Services/Nordigen/Request/PostNewTokenRequest.php
  42. 5
      app/Services/Nordigen/Request/PostNewUserAgreement.php
  43. 57
      app/Services/Nordigen/Request/Request.php
  44. 5
      app/Services/Nordigen/Response/ListAccountsResponse.php
  45. 31
      app/Services/Nordigen/Services/AccountInformationCollector.php
  46. 25
      app/Services/Nordigen/TokenManager.php
  47. 8
      app/Services/Shared/Conversion/GeneratesIdentifier.php
  48. 51
      app/Services/Shared/Conversion/RoutineStatusManager.php
  49. 13
      app/Services/Shared/File/FileContentSherlock.php
  50. 405
      app/Services/Shared/Import/Routine/ApiSubmitter.php
  51. 4
      app/Services/Shared/Import/Routine/InfoCollector.php
  52. 13
      app/Services/Shared/Import/Routine/RoutineManager.php
  53. 59
      app/Services/Shared/Import/Status/SubmissionStatusManager.php
  54. 11
      app/Services/Shared/Model/ImportServiceAccount.php
  55. 8
      app/Services/Shared/Submission/GeneratesIdentifier.php
  56. 29
      app/Services/SimpleFIN/Conversion/AccountMapper.php
  57. 31
      app/Services/SimpleFIN/Conversion/TransactionTransformer.php
  58. 3
      app/Services/SimpleFIN/Request/AccountsRequest.php
  59. 13
      app/Services/SimpleFIN/Request/SimpleFINRequest.php
  60. 3
      app/Services/SimpleFIN/Request/TransactionsRequest.php
  61. 7
      app/Services/SimpleFIN/Response/AccountsResponse.php
  62. 13
      app/Services/SimpleFIN/Response/SimpleFINResponse.php
  63. 7
      app/Services/SimpleFIN/Response/TransactionsResponse.php
  64. 6
      app/Services/Spectre/Authentication/SecretManager.php
  65. 7
      app/Services/Spectre/AuthenticationValidator.php
  66. 4
      app/Services/Spectre/Conversion/Routine/FilterTransactions.php
  67. 35
      app/Services/Spectre/Conversion/Routine/GenerateTransactions.php
  68. 25
      app/Services/Spectre/Conversion/Routine/TransactionProcessor.php
  69. 7
      app/Services/Spectre/Conversion/RoutineManager.php
  70. 43
      app/Services/Spectre/Model/Transaction.php
  71. 7
      app/Services/Spectre/Model/TransactionExtra.php
  72. 3
      app/Services/Spectre/Request/GetAccountsRequest.php
  73. 7
      app/Services/Spectre/Request/GetTransactionsRequest.php
  74. 3
      app/Services/Spectre/Request/ListConnectionsRequest.php
  75. 3
      app/Services/Spectre/Request/ListCustomersRequest.php
  76. 33
      app/Services/Spectre/Request/Request.php
  77. 13
      app/Services/Storage/StorageService.php

7
app/Services/CSV/Configuration/ConfigFileProcessor.php

@ -29,6 +29,7 @@ use App\Exceptions\ImporterErrorException;
use App\Services\Shared\Configuration\Configuration;
use App\Services\Storage\StorageService;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Support\Facades\Log;
/**
* Class ConfigFileProcessor
@ -42,12 +43,12 @@ class ConfigFileProcessor
*/
public static function convertConfigFile(string $fileName): Configuration
{
app('log')->debug('Now in ConfigFileProcessor::convertConfigFile');
Log::debug('Now in ConfigFileProcessor::convertConfigFile');
try {
$content = StorageService::getContent($fileName);
} catch (FileNotFoundException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
throw new ImporterErrorException(sprintf('Could not find config file: %s', $e->getMessage()));
}
@ -55,7 +56,7 @@ class ConfigFileProcessor
try {
$json = json_decode($content, true, 512, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
throw new ImporterErrorException(sprintf('Invalid JSON configuration file: %s', $e->getMessage()));
}

33
app/Services/CSV/Conversion/Routine/CSVFileProcessor.php

@ -28,6 +28,7 @@ namespace App\Services\CSV\Conversion\Routine;
use App\Exceptions\ImporterErrorException;
use App\Services\Shared\Configuration\Configuration;
use App\Services\Shared\Conversion\ProgressInformation;
use Illuminate\Support\Facades\Log;
use League\Csv\Exception;
use League\Csv\Reader;
use League\Csv\ResultSet;
@ -58,27 +59,27 @@ class CSVFileProcessor
*/
public function processCSVFile(): array
{
app('log')->debug('Now in processCSVFile()');
Log::debug('Now in processCSVFile()');
$offset = $this->hasHeaders ? 1 : 0;
try {
$this->reader->setDelimiter($this->delimiter);
} catch (Exception $e) {
app('log')->error($e->getMessage());
// app('log')->error($e->getTraceAsString());
Log::error($e->getMessage());
// Log::error($e->getTraceAsString());
$message = sprintf('[a106]: Could not set delimiter: %s', $e->getMessage());
$this->addError(0, $message);
return [];
}
app('log')->debug(sprintf('Offset is %d', $offset));
Log::debug(sprintf('Offset is %d', $offset));
try {
$stmt = (new Statement())->offset($offset);
$records = $stmt->process($this->reader);
} catch (Exception $e) {
app('log')->error($e->getMessage());
// app('log')->error($e->getTraceAsString());
Log::error($e->getMessage());
// Log::error($e->getTraceAsString());
$message = sprintf('[a107]: Could not read CSV: %s', $e->getMessage());
$this->addError(0, $message);
@ -88,8 +89,8 @@ class CSVFileProcessor
try {
return $this->processCSVLines($records);
} catch (ImporterErrorException $e) {
app('log')->error($e->getMessage());
// app('log')->error($e->getTraceAsString());
Log::error($e->getMessage());
// Log::error($e->getTraceAsString());
$message = sprintf('[a108]: Could not parse CSV: %s', $e->getMessage());
$this->addError(0, $message);
@ -117,20 +118,20 @@ class CSVFileProcessor
{
$updatedRecords = [];
$count = $records->count();
app('log')->info(sprintf('Now in %s with %d records', __METHOD__, $count));
Log::info(sprintf('Now in %s with %d records', __METHOD__, $count));
$currentIndex = 1;
foreach ($records as $line) {
$line = $this->sanitize($line);
app('log')->debug(sprintf('Parsing line %d/%d', $currentIndex, $count));
Log::debug(sprintf('Parsing line %d/%d', $currentIndex, $count));
$updatedRecords[] = $line;
++$currentIndex;
}
app('log')->info(sprintf('Parsed all %d lines.', $count));
Log::info(sprintf('Parsed all %d lines.', $count));
// exclude double lines.
if ($this->configuration->isIgnoreDuplicateLines()) {
app('log')->info('Going to remove duplicate lines.');
Log::info('Going to remove duplicate lines.');
$updatedRecords = $this->removeDuplicateLines($updatedRecords);
}
@ -164,14 +165,14 @@ class CSVFileProcessor
try {
$hash = hash('sha256', json_encode($line, JSON_THROW_ON_ERROR));
} catch (\JsonException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
// app('log')->error($e->getTraceAsString());
// Log::error($e->getTraceAsString());
throw new ImporterErrorException(sprintf('Could not decode JSON line #%d: %s', $index, $e->getMessage()));
}
if (in_array($hash, $hashes, true)) {
$message = sprintf('Going to skip line #%d because it\'s in the file twice. This may reset the count below.', $index);
app('log')->warning($message);
Log::warning($message);
$this->addWarning($index, $message);
}
if (!in_array($hash, $hashes, true)) {
@ -179,7 +180,7 @@ class CSVFileProcessor
$return[] = $line;
}
}
app('log')->info(sprintf('Went from %d line(s) to %d line(s)', count($array), count($return)));
Log::info(sprintf('Went from %d line(s) to %d line(s)', count($array), count($return)));
return $return;
}

3
app/Services/CSV/Conversion/Routine/ColumnValue.php

@ -26,6 +26,7 @@ declare(strict_types=1);
namespace App\Services\CSV\Conversion\Routine;
use App\Services\CSV\Converter\ConverterService;
use Illuminate\Support\Facades\Log;
/**
* Class ColumnValue
@ -80,7 +81,7 @@ class ColumnValue
// run converter on data:
$converterClass = (string) config(sprintf('csv.import_roles.%s.converter', $this->role));
app('log')->debug(sprintf('getParsedValue will run "%s"', $converterClass));
Log::debug(sprintf('getParsedValue will run "%s"', $converterClass));
return ConverterService::convert($converterClass, $this->value, $this->configuration);
}

25
app/Services/CSV/Conversion/Routine/ColumnValueConverter.php

@ -28,6 +28,7 @@ namespace App\Services\CSV\Conversion\Routine;
use App\Exceptions\ImporterErrorException;
use App\Services\Shared\Configuration\Configuration;
use App\Services\Shared\Conversion\ProgressInformation;
use Illuminate\Support\Facades\Log;
/**
* Class ColumnValueConverter
@ -56,16 +57,16 @@ class ColumnValueConverter
*/
public function processValueArrays(array $lines): array
{
app('log')->debug(sprintf('Now in %s', __METHOD__));
Log::debug(sprintf('Now in %s', __METHOD__));
$processed = [];
$count = count($lines);
app('log')->info(sprintf('Now parsing and combining %d lines.', $count));
Log::info(sprintf('Now parsing and combining %d lines.', $count));
foreach ($lines as $index => $line) {
app('log')->debug(sprintf('Now processing line %d/%d', $index + 1, $count));
Log::debug(sprintf('Now processing line %d/%d', $index + 1, $count));
$processed[] = $this->processValueArray($line);
}
app('log')->info(sprintf('Done parsing and combining %d lines.', $count));
Log::info(sprintf('Done parsing and combining %d lines.', $count));
return $processed;
}
@ -76,7 +77,7 @@ class ColumnValueConverter
private function processValueArray(array $line): array
{
$count = count($line);
app('log')->debug(sprintf('Now in %s with %d columns in this line.', __METHOD__, $count));
Log::debug(sprintf('Now in %s with %d columns in this line.', __METHOD__, $count));
// make a new transaction:
$transaction = [
// 'user' => 1, // ??
@ -118,11 +119,11 @@ class ColumnValueConverter
throw new \UnexpectedValueException(sprintf('No place for role "%s"', $value->getRole()));
}
if (null === $parsedValue) {
app('log')->debug(sprintf('Skip column #%d with role "%s" (in field "%s")', $columnIndex + 1, $role, $transactionField));
Log::debug(sprintf('Skip column #%d with role "%s" (in field "%s")', $columnIndex + 1, $role, $transactionField));
continue;
}
app('log')->debug(
Log::debug(
sprintf(
'Stored column #%d with value "%s" and role "%s" in field "%s"',
$columnIndex + 1,
@ -134,14 +135,14 @@ class ColumnValueConverter
// if append, append.
if (true === $value->isAppendValue()) {
app('log')->debug(
Log::debug(
sprintf('Column #%d with role "%s" (in field "%s") must be appended to the previous value.', $columnIndex + 1, $role, $transactionField),
[$parsedValue]
);
if (is_array($parsedValue)) {
$transaction['transactions'][0][$transactionField] ??= [];
$transaction['transactions'][0][$transactionField] = array_merge($transaction['transactions'][0][$transactionField], $parsedValue);
app('log')->debug(
Log::debug(
sprintf('Value for [transactions][#0][%s] is now ', $transactionField),
$transaction['transactions'][0][$transactionField]
);
@ -155,7 +156,7 @@ class ColumnValueConverter
}
// if not, not.
if (false === $value->isAppendValue()) {
app('log')->debug(
Log::debug(
sprintf('Column #%d with role "%s" (in field "%s") must NOT be appended to the previous value.', $columnIndex + 1, $role, $transactionField)
);
$transaction['transactions'][0][$transactionField] = $parsedValue;
@ -163,7 +164,7 @@ class ColumnValueConverter
// if this is an account field, AND the column is mapped, store the original value just in case.
$saveRoles = ['account-name', 'opposing-name', 'account-iban', 'opposing-iban', 'account-number', 'opposing-number'];
if (0 !== $value->getMappedValue() && in_array($value->getOriginalRole(), $saveRoles, true)) {
app('log')->debug(
Log::debug(
sprintf(
'The original value ("%s") in column "%s" (originally stored in "%s") was saved just in case.',
$value->getValue(),
@ -174,7 +175,7 @@ class ColumnValueConverter
$transaction['transactions'][0][sprintf('original-%s', $value->getOriginalRole())] = $value->getValue();
}
}
app('log')->debug('Almost final transaction', $transaction);
Log::debug('Almost final transaction', $transaction);
return $transaction;
}

47
app/Services/CSV/Conversion/Routine/LineProcessor.php

@ -28,6 +28,7 @@ namespace App\Services\CSV\Conversion\Routine;
use App\Exceptions\ImporterErrorException;
use App\Services\Shared\Configuration\Configuration;
use App\Services\Shared\Conversion\ProgressInformation;
use Illuminate\Support\Facades\Log;
/**
* Class LineProcessor
@ -51,9 +52,9 @@ class LineProcessor
*/
public function __construct(Configuration $configuration)
{
app('log')->debug('Created LineProcessor()');
app('log')->debug('Roles', $configuration->getRoles());
app('log')->debug('Mapping (will not be printed)');
Log::debug('Created LineProcessor()');
Log::debug('Roles', $configuration->getRoles());
Log::debug('Mapping (will not be printed)');
$this->roles = $configuration->getRoles();
$this->mapping = $configuration->getMapping();
$this->doMapping = $configuration->getDoMapping();
@ -65,21 +66,21 @@ class LineProcessor
$processed = [];
$count = count($lines);
app('log')->info(sprintf('Now processing the data in the %d CSV lines...', $count));
Log::info(sprintf('Now processing the data in the %d CSV lines...', $count));
foreach ($lines as $index => $line) {
app('log')->debug(sprintf('Now processing CSV line #%d/#%d', $index + 1, $count));
Log::debug(sprintf('Now processing CSV line #%d/#%d', $index + 1, $count));
try {
$processed[] = $this->process($line);
} catch (ImporterErrorException $e) {
app('log')->error($e->getMessage());
// app('log')->error($e->getTraceAsString());
Log::error($e->getMessage());
// Log::error($e->getTraceAsString());
$this->addError(0, $e->getMessage());
}
}
app('log')->info(sprintf('Done processing data in %d CSV lines...', $count));
Log::info(sprintf('Done processing data in %d CSV lines...', $count));
return $processed;
}
@ -92,30 +93,30 @@ class LineProcessor
*/
private function process(array $line): array
{
app('log')->debug(sprintf('Now in %s', __METHOD__));
Log::debug(sprintf('Now in %s', __METHOD__));
$count = count($line);
$return = [];
foreach ($line as $columnIndex => $value) {
app('log')->debug(sprintf('Now at column %d/%d', $columnIndex + 1, $count));
Log::debug(sprintf('Now at column %d/%d', $columnIndex + 1, $count));
$value = trim($value);
$originalRole = $this->roles[$columnIndex] ?? '_ignore';
app('log')->debug(sprintf('Now at column #%d (%s), value "%s"', $columnIndex + 1, $originalRole, $value));
Log::debug(sprintf('Now at column #%d (%s), value "%s"', $columnIndex + 1, $originalRole, $value));
if ('_ignore' === $originalRole) {
app('log')->debug(sprintf('Ignore column #%d because role is "_ignore".', $columnIndex + 1));
Log::debug(sprintf('Ignore column #%d because role is "_ignore".', $columnIndex + 1));
continue;
}
if ('' === $value) {
app('log')->debug(sprintf('Ignore column #%d because value is "".', $columnIndex + 1));
Log::debug(sprintf('Ignore column #%d because value is "".', $columnIndex + 1));
continue;
}
// is a mapped value present?
$mapped = $this->mapping[$columnIndex][$value] ?? 0;
app('log')->debug(sprintf('ColumnIndex is %s', var_export($columnIndex, true)));
app('log')->debug(sprintf('Value is %s', var_export($value, true)));
// app('log')->debug('Local mapping (will not be printed)');
Log::debug(sprintf('ColumnIndex is %s', var_export($columnIndex, true)));
Log::debug(sprintf('Value is %s', var_export($value, true)));
// Log::debug('Local mapping (will not be printed)');
// the role might change because of the mapping.
$role = $this->getRoleForColumn($columnIndex, $mapped);
$appendValue = config(sprintf('csv.import_roles.%s.append_value', $originalRole));
@ -124,7 +125,7 @@ class LineProcessor
$appendValue = false;
}
// app('log')->debug(sprintf('Append value config: %s', sprintf('csv.import_roles.%s.append_value', $originalRole)));
// Log::debug(sprintf('Append value config: %s', sprintf('csv.import_roles.%s.append_value', $originalRole)));
$columnValue = new ColumnValue();
$columnValue->setValue($value);
@ -135,7 +136,7 @@ class LineProcessor
// if column role is 'date', add the date config for conversion:
if (in_array($originalRole, ['date_transaction', 'date_interest', 'date_due', 'date_payment', 'date_process', 'date_book', 'date_invoice'], true)) {
app('log')->debug(sprintf('Because role is %s, set date format to "%s" (via setConfiguration).', $originalRole, $this->dateFormat));
Log::debug(sprintf('Because role is %s, set date format to "%s" (via setConfiguration).', $originalRole, $this->dateFormat));
$columnValue->setConfiguration($this->dateFormat);
}
@ -148,7 +149,7 @@ class LineProcessor
$columnValue->setAppendValue(false);
$columnValue->setRole('original-source');
$return[] = $columnValue;
app('log')->debug(sprintf('Added column #%d to denote the original source.', count($return)));
Log::debug(sprintf('Added column #%d to denote the original source.', count($return)));
return $return;
}
@ -166,14 +167,14 @@ class LineProcessor
{
$role = $this->roles[$column] ?? '_ignore';
if (0 === $mapped) {
app('log')->debug(sprintf('Column #%d with role "%s" is not mapped.', $column + 1, $role));
Log::debug(sprintf('Column #%d with role "%s" is not mapped.', $column + 1, $role));
return $role;
}
if (!(isset($this->doMapping[$column]) && true === $this->doMapping[$column])) {
// if the mapping has been filled in already by a role with a higher priority,
// ignore the mapping.
app('log')->debug(sprintf('Column #%d ("%s") has something already.', $column, $role));
Log::debug(sprintf('Column #%d ("%s") has something already.', $column, $role));
return $role;
}
@ -204,14 +205,14 @@ class LineProcessor
}
$newRole = $roleMapping[$role];
if ($newRole !== $role) {
app('log')->debug(sprintf('Role was "%s", but because of mapping (mapped to #%d), role becomes "%s"', $role, $mapped, $newRole));
Log::debug(sprintf('Role was "%s", but because of mapping (mapped to #%d), role becomes "%s"', $role, $mapped, $newRole));
}
// also store the $mapped values in a "mappedValues" array.
// used to validate whatever has been set as mapping
$this->mappedValues[$newRole][] = $mapped;
$this->mappedValues[$newRole] = array_unique($this->mappedValues[$newRole]);
app('log')->debug(sprintf('Values mapped to role "%s" are: ', $newRole), $this->mappedValues[$newRole]);
Log::debug(sprintf('Values mapped to role "%s" are: ', $newRole), $this->mappedValues[$newRole]);
return $newRole;
}

18
app/Services/CSV/Conversion/Routine/PseudoTransactionProcessor.php

@ -88,7 +88,7 @@ class PseudoTransactionProcessor
try {
$result = $accountRequest->get();
} catch (ApiHttpException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
throw new ImporterErrorException(sprintf('The default account in your configuration file (%d) does not exist.', $accountId));
}
@ -115,7 +115,7 @@ class PseudoTransactionProcessor
$result = $currencyRequest->get();
$this->defaultCurrency = $result->getCurrency();
} catch (ApiHttpException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
throw new ImporterErrorException('The default currency could not be loaded.');
}
@ -124,29 +124,29 @@ class PseudoTransactionProcessor
public function processPseudo(array $lines): array
{
app('log')->debug(sprintf('Now in %s', __METHOD__));
Log::debug(sprintf('Now in %s', __METHOD__));
$count = count($lines);
$processed = [];
app('log')->info(sprintf('Converting %d line(s) into transactions.', $count));
Log::info(sprintf('Converting %d line(s) into transactions.', $count));
/** @var array $line */
foreach ($lines as $index => $line) {
app('log')->info(sprintf('Now processing line %d/%d.', $index + 1, $count));
Log::info(sprintf('Now processing line %d/%d.', $index + 1, $count));
$processed[] = $this->processPseudoLine($line);
// $this->addMessage($index, sprintf('Converted CSV line %d into a transaction.', $index + 1));
}
app('log')->info(sprintf('Done converting %d line(s) into transactions.', $count));
Log::info(sprintf('Done converting %d line(s) into transactions.', $count));
return $processed;
}
private function processPseudoLine(array $line): array
{
app('log')->debug(sprintf('Now in %s', __METHOD__));
Log::debug(sprintf('Now in %s', __METHOD__));
foreach ($this->tasks as $task) {
/** @var AbstractTask $object */
$object = app($task);
app('log')->debug(sprintf('Now running task %s', $task));
Log::debug(sprintf('Now running task %s', $task));
if ($object->requiresDefaultAccount()) {
$object->setAccount($this->defaultAccount);
}
@ -156,7 +156,7 @@ class PseudoTransactionProcessor
$line = $object->process($line);
}
app('log')->debug('Final transaction: ', $line);
Log::debug('Final transaction: ', $line);
return $line;
}

3
app/Services/CSV/Conversion/RoutineManager.php

@ -37,6 +37,7 @@ use App\Services\Shared\Conversion\CombinedProgressInformation;
use App\Services\Shared\Conversion\GeneratesIdentifier;
use App\Services\Shared\Conversion\ProgressInformation;
use App\Services\Shared\Conversion\RoutineManagerInterface;
use Illuminate\Support\Facades\Log;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
@ -116,7 +117,7 @@ class RoutineManager implements RoutineManagerInterface
*/
public function start(): array
{
app('log')->debug(sprintf('Now in %s', __METHOD__));
Log::debug(sprintf('Now in %s', __METHOD__));
// convert CSV file into raw lines (arrays)
$this->csvFileProcessor->setHasHeaders($this->configuration->isHeaders());

20
app/Services/CSV/Conversion/Support/DeterminesTransactionType.php

@ -25,6 +25,8 @@ declare(strict_types=1);
namespace App\Services\CSV\Conversion\Support;
use Illuminate\Support\Facades\Log;
/**
* Trait DeterminesTransactionType
*/
@ -32,34 +34,34 @@ trait DeterminesTransactionType
{
protected function determineType(?string $sourceType, ?string $destinationType): string
{
app('log')->debug(sprintf('Now in determineType::determineType("%s", "%s")', $sourceType, $destinationType));
Log::debug(sprintf('Now in determineType::determineType("%s", "%s")', $sourceType, $destinationType));
if (null === $sourceType && null === $destinationType) {
app('log')->debug('Return withdrawal, both are NULL');
Log::debug('Return withdrawal, both are NULL');
return 'withdrawal';
}
if ('revenue' === $sourceType) {
app('log')->debug('Return deposit, source is a revenue account.');
Log::debug('Return deposit, source is a revenue account.');
return 'deposit';
}
// if source is an asset and dest is NULL, it's a withdrawal
if ('asset' === $sourceType && null === $destinationType) {
app('log')->debug('Return withdrawal, source is asset');
Log::debug('Return withdrawal, source is asset');
return 'withdrawal';
}
// if source is liabilities and destination is NULL, it's a withdrawal
if ('liabilities' === $sourceType && null === $destinationType) {
app('log')->debug('Return withdrawal, source is "liabilities".');
Log::debug('Return withdrawal, source is "liabilities".');
return 'withdrawal';
}
// if destination is asset and source is NULL, it's a deposit
if (null === $sourceType && 'asset' === $destinationType) {
app('log')->debug('Return deposit, destination is asset');
Log::debug('Return deposit, destination is asset');
return 'deposit';
}
@ -67,21 +69,21 @@ trait DeterminesTransactionType
// if the source is an expense account and the destination is an asset
// it could be a bad mapping. We return "deposit"
if ('expense' === $sourceType && 'asset' === $destinationType) {
app('log')->warning('Return "deposit" but the source type is not correct.');
Log::warning('Return "deposit" but the source type is not correct.');
return 'deposit';
}
// if destination is liabilities and source is NULL, it's a deposit
if (null === $sourceType && 'liabilities' === $destinationType) {
app('log')->debug('Return liabilities, destination is asset');
Log::debug('Return liabilities, destination is asset');
return 'deposit';
}
$key = sprintf('transaction_types.account_to_transaction.%s.%s', $sourceType, $destinationType);
$type = config($key);
$value = $type ?? 'withdrawal';
app('log')->debug(sprintf('Check config for "%s" and found "%s". Returning "%s"', $key, $type, $value));
Log::debug(sprintf('Check config for "%s" and found "%s". Returning "%s"', $key, $type, $value));
return $value;
}

155
app/Services/CSV/Conversion/Task/Accounts.php

@ -33,6 +33,7 @@ use GrumpyDictator\FFIIIApiSupport\Exceptions\ApiHttpException as GrumpyApiHttpE
use GrumpyDictator\FFIIIApiSupport\Model\Account;
use GrumpyDictator\FFIIIApiSupport\Model\AccountType;
use GrumpyDictator\FFIIIApiSupport\Request\GetSearchAccountRequest;
use Illuminate\Support\Facades\Log;
/**
* Class Accounts
@ -46,10 +47,10 @@ class Accounts extends AbstractTask
*/
public function process(array $group): array
{
app('log')->debug('Now in Accounts::process()');
Log::debug('Now in Accounts::process()');
$total = count($group['transactions']);
foreach ($group['transactions'] as $index => $transaction) {
app('log')->debug(sprintf('Now processing transaction %d of %d', $index + 1, $total));
Log::debug(sprintf('Now processing transaction %d of %d', $index + 1, $total));
$group['transactions'][$index] = $this->processTransaction($transaction);
}
@ -61,7 +62,7 @@ class Accounts extends AbstractTask
*/
private function processTransaction(array $transaction): array
{
app('log')->debug('Now in Accounts::processTransaction()');
Log::debug('Now in Accounts::processTransaction()');
/*
* Try to find the source and destination accounts in the transaction.
@ -78,15 +79,15 @@ class Accounts extends AbstractTask
$transaction = $this->setSource($transaction, $source);
$transaction = $this->setDestination($transaction, $destination);
$transaction['type'] = $this->determineType($source['type'], $destination['type']);
app('log')->debug(sprintf('Transaction type is set to "%s"', $transaction['type']));
app('log')->debug('Source is now:', $source);
app('log')->debug('Destination is now:', $destination);
Log::debug(sprintf('Transaction type is set to "%s"', $transaction['type']));
Log::debug('Source is now:', $source);
Log::debug('Destination is now:', $destination);
$amount = (string) $transaction['amount'];
$amount = '' === $amount ? '0' : $amount;
if ('0' === $amount) {
app('log')->error('Amount is ZERO. This will give trouble further down the line.');
Log::error('Amount is ZERO. This will give trouble further down the line.');
}
/*
@ -97,12 +98,12 @@ class Accounts extends AbstractTask
*/
if ('withdrawal' === $transaction['type'] && 1 === bccomp($amount, '0')) {
// amount is positive
app('log')->debug(sprintf('%s is positive and type is "%s", switch source/destination', $amount, $transaction['type']));
Log::debug(sprintf('%s is positive and type is "%s", switch source/destination', $amount, $transaction['type']));
$transaction = $this->setSource($transaction, $destination);
$transaction = $this->setDestination($transaction, $source);
$transaction['type'] = $this->determineType($destination['type'], $source['type']);
app('log')->debug('Source is now:', $destination); // yes this is correct.
app('log')->debug('Destination is now:', $source); // yes this is correct.
Log::debug('Source is now:', $destination); // yes this is correct.
Log::debug('Destination is now:', $source); // yes this is correct.
// switch variables because processing further ahead will otherwise be messed up:
[$source, $destination] = [$destination, $source];
@ -110,23 +111,23 @@ class Accounts extends AbstractTask
// If the amount is positive and the type is a transfer, switch accounts around.
if ('transfer' === $transaction['type'] && 1 === bccomp($amount, '0')) {
app('log')->debug('Transaction is a transfer, and amount is positive, will switch accounts.');
Log::debug('Transaction is a transfer, and amount is positive, will switch accounts.');
$transaction = $this->setSource($transaction, $destination);
$transaction = $this->setDestination($transaction, $source);
app('log')->debug('Source is now:', $destination); // yes this is correct!
app('log')->debug('Destination is now:', $source); // yes this is correct!
Log::debug('Source is now:', $destination); // yes this is correct!
Log::debug('Destination is now:', $source); // yes this is correct!
// also switch amount and foreign currency amount, if both are present.
// if this data is missing, Firefly III will break later either way.
if ($this->hasAllAmountInformation($transaction)) {
app('log')->debug('This transfer has all necessary (foreign) currency + amount information, so swap these too.');
Log::debug('This transfer has all necessary (foreign) currency + amount information, so swap these too.');
$transaction = $this->swapCurrencyInformation($transaction);
}
}
// If deposit and amount is positive, do nothing.
if ('deposit' === $transaction['type'] && 1 === bccomp($amount, '0')) {
app('log')->debug('Transaction is a deposit, and amount is positive. Will not change account types.');
Log::debug('Transaction is a deposit, and amount is positive. Will not change account types.');
}
/*
@ -136,7 +137,7 @@ class Accounts extends AbstractTask
if (
'deposit' === $transaction['type'] && 1 === bccomp($amount, '0') && 'revenue' !== $source['type'] && '' !== (string) $source['type']
) {
app('log')->warning(
Log::warning(
sprintf(
'Transaction is a deposit, and amount is positive, but source is not a revenue ("%s"). Will fall back to original field names.',
$source['type']
@ -154,11 +155,11 @@ class Accounts extends AbstractTask
// If amount is negative and type is transfer, make sure accounts are "original".
if ('transfer' === $transaction['type'] && -1 === bccomp($amount, '0')) {
app('log')->debug('Transaction is a transfer, and amount is negative, must not change accounts.');
Log::debug('Transaction is a transfer, and amount is negative, must not change accounts.');
$transaction = $this->setSource($transaction, $source);
$transaction = $this->setDestination($transaction, $destination);
app('log')->debug('Source is now:', $source);
app('log')->debug('Destination is now:', $destination);
Log::debug('Source is now:', $source);
Log::debug('Destination is now:', $destination);
}
/*
@ -166,8 +167,8 @@ class Accounts extends AbstractTask
* we found the wrong one. Just submit the name and hope for the best.
*/
if ('revenue' === $destination['type'] && 'withdrawal' === $transaction['type']) {
app('log')->warning('The found destination account is of type revenue but this is a withdrawal. Out of cheese error.');
app('log')->debug(
Log::warning('The found destination account is of type revenue but this is a withdrawal. Out of cheese error.');
Log::debug(
sprintf('Data importer will submit name "%s" and IBAN "%s" and let Firefly III sort it out.', $destination['name'], $destination['iban'])
);
$transaction['destination_id'] = null;
@ -181,8 +182,8 @@ class Accounts extends AbstractTask
* Submit just the name.
*/
if ('expense' === $source['type'] && 'deposit' === $transaction['type']) {
app('log')->warning('The found source account is of type expense but this is a deposit. Out of cheese error.');
app('log')->debug(sprintf('Data importer will submit name "%s" and IBAN "%s" and let Firefly III sort it out.', $source['name'], $source['iban']));
Log::warning('The found source account is of type expense but this is a deposit. Out of cheese error.');
Log::debug(sprintf('Data importer will submit name "%s" and IBAN "%s" and let Firefly III sort it out.', $source['name'], $source['iban']));
$transaction['source_id'] = null;
$transaction['source_name'] = $source['name'];
$transaction['source_iban'] = $source['iban'];
@ -200,14 +201,14 @@ class Accounts extends AbstractTask
$transaction['destination_number'] = null;
}
if ($this->hasAllCurrencies($transaction)) {
app('log')->debug('Final validation of foreign amount and or normal transaction amount');
Log::debug('Final validation of foreign amount and or normal transaction amount');
// withdrawal
if ('withdrawal' === $transaction['type']) {
// currency info must match $source
// so if we can switch them around we will.
if ($transaction['currency_code'] !== $source['currency_code']
&& $transaction['foreign_currency_code'] === $source['currency_code']) {
app('log')->debug('Source account accepts %s, so foreign / native numbers are switched now.');
Log::debug('Source account accepts %s, so foreign / native numbers are switched now.');
$amount = $transaction['amount'] ?? '0';
$currency = $transaction['currency_code'] ?? '';
$transaction['amount'] = $transaction['foreign_amount'] ?? '0';
@ -222,7 +223,7 @@ class Accounts extends AbstractTask
// so if we can switch them around we will.
if ($transaction['currency_code'] !== $destination['currency_code']
&& $transaction['foreign_currency_code'] === $destination['currency_code']) {
app('log')->debug('Destination account accepts %s, so foreign / native numbers are switched now.');
Log::debug('Destination account accepts %s, so foreign / native numbers are switched now.');
$amount = $transaction['amount'] ?? '0';
$currency = $transaction['currency_code'] ?? '';
$transaction['amount'] = $transaction['foreign_amount'] ?? '0';
@ -232,7 +233,7 @@ class Accounts extends AbstractTask
}
}
app('log')->debug('Final validation of foreign amount and or normal transaction amount finished.');
Log::debug('Final validation of foreign amount and or normal transaction amount finished.');
}
return $transaction;
@ -269,80 +270,80 @@ class Accounts extends AbstractTask
*/
private function findAccount(array $array, ?Account $defaultAccount): array
{
app('log')->debug('Now in findAccount', $array);
Log::debug('Now in findAccount', $array);
if (null === $defaultAccount) {
app('log')->debug('findAccount() default account is NULL.');
Log::debug('findAccount() default account is NULL.');
}
if (null !== $defaultAccount) {
app('log')->debug(sprintf('Default account is #%d ("%s")', $defaultAccount->id, $defaultAccount->name));
Log::debug(sprintf('Default account is #%d ("%s")', $defaultAccount->id, $defaultAccount->name));
}
$result = null;
// if the ID is set, at least search for the ID.
if (is_int($array['id']) && $array['id'] > 0) {
app('log')->debug('Will search by ID field.');
Log::debug('Will search by ID field.');
$result = $this->findById((string) $array['id']);
}
if (null !== $result) {
$return = $result->toArray();
app('log')->debug('Result of findById is not null, returning:', $return);
Log::debug('Result of findById is not null, returning:', $return);
return $return;
}
if (array_key_exists('id', $array) && null === $array['id']) {
app('log')->debug('ID field is NULL, will not search for it.');
Log::debug('ID field is NULL, will not search for it.');
}
// if the IBAN is set, search for the IBAN.
if (isset($array['iban']) && '' !== (string) $array['iban']) {
app('log')->debug('Will search by IBAN.');
Log::debug('Will search by IBAN.');
$transactionType = (string) ($array['transaction_type'] ?? null);
$result = $this->findByIban((string) $array['iban'], $transactionType);
}
if (null !== $result) {
$return = $result->toArray();
app('log')->debug('Result of findByIBAN is not null, returning:', $return);
Log::debug('Result of findByIBAN is not null, returning:', $return);
return $return;
}
if (array_key_exists('iban', $array) && null === $array['iban']) {
app('log')->debug('IBAN field is NULL, will not search for it.');
Log::debug('IBAN field is NULL, will not search for it.');
}
// If the IBAN search result is NULL, but the IBAN itself is not null,
// data importer will return an array with the IBAN (and optionally the name).
// if the account number is set, search for the account number.
if (isset($array['number']) && '' !== (string) $array['number']) {
app('log')->debug('Search by account number.');
Log::debug('Search by account number.');
$transactionType = (string) ($array['transaction_type'] ?? null);
$result = $this->findByNumber((string) $array['number'], $transactionType);
}
if (null !== $result) {
$return = $result->toArray();
app('log')->debug('Result of findByNumber is not null, returning:', $return);
Log::debug('Result of findByNumber is not null, returning:', $return);
return $return;
}
if (array_key_exists('number', $array) && null === $array['number']) {
app('log')->debug('Number field is NULL, will not search for it.');
Log::debug('Number field is NULL, will not search for it.');
}
// find by name, return only if it's an asset or liability account.
if (isset($array['name']) && '' !== (string) $array['name']) {
app('log')->debug('Search by name.');
Log::debug('Search by name.');
$result = $this->findByName((string) $array['name']);
}
if (null !== $result) {
$return = $result->toArray();
app('log')->debug('Result of findByName is not null, returning:', $return);
Log::debug('Result of findByName is not null, returning:', $return);
return $return;
}
if (array_key_exists('name', $array) && null === $array['name']) {
app('log')->debug('Name field is NULL, will not search for it.');
Log::debug('Name field is NULL, will not search for it.');
}
app('log')->debug('Found no account or haven\'t searched for one because of missing data.');
Log::debug('Found no account or haven\'t searched for one because of missing data.');
// append an empty type to the array for consistency's sake.
$array['type'] ??= null;
@ -350,21 +351,21 @@ class Accounts extends AbstractTask
// Return ID or name if not null
if (null !== $array['id'] || '' !== (string) $array['name']) {
app('log')->debug('At least the array with account-info has some name info, return that.', $array);
Log::debug('At least the array with account-info has some name info, return that.', $array);
return $array;
}
// Return ID or IBAN if not null
if ('' !== (string) $array['iban']) {
app('log')->debug('At least the with account-info has some IBAN info, return that.', $array);
Log::debug('At least the with account-info has some IBAN info, return that.', $array);
return $array;
}
// Return ID or number if not null
if ('' !== (string) $array['number']) {
app('log')->debug('At least the array with account-info has some account number info, return that.', $array);
Log::debug('At least the array with account-info has some account number info, return that.', $array);
return $array;
}
@ -372,11 +373,11 @@ class Accounts extends AbstractTask
// if the default account is not NULL, return that one instead:
if (null !== $defaultAccount) {
$default = $defaultAccount->toArray();
app('log')->debug('At least the default account is not null, so will return that:', $default);
Log::debug('At least the default account is not null, so will return that:', $default);
return $default;
}
app('log')->debug('The default account is NULL, so will return what we started with: ', $array);
Log::debug('The default account is NULL, so will return what we started with: ', $array);
return $array;
}
@ -386,7 +387,7 @@ class Accounts extends AbstractTask
*/
private function findById(string $value): ?Account
{
app('log')->debug(sprintf('Going to search account with ID "%s"', $value));
Log::debug(sprintf('Going to search account with ID "%s"', $value));
$url = SecretManager::getBaseUrl();
$token = SecretManager::getAccessToken();
$request = new GetSearchAccountRequest($url, $token);
@ -409,12 +410,12 @@ class Accounts extends AbstractTask
throw new ImporterErrorException($e->getMessage());
}
app('log')->debug(sprintf('[a] Found %s account #%d based on ID "%s"', $account->type, $account->id, $value));
Log::debug(sprintf('[a] Found %s account #%d based on ID "%s"', $account->type, $account->id, $value));
return $account;
}
app('log')->debug('Found NOTHING in findById.');
Log::debug('Found NOTHING in findById.');
return null;
}
@ -424,7 +425,7 @@ class Accounts extends AbstractTask
*/
private function findByIban(string $iban, string $transactionType): ?Account
{
app('log')->debug(sprintf('Going to search account with IBAN "%s"', $iban));
Log::debug(sprintf('Going to search account with IBAN "%s"', $iban));
$url = SecretManager::getBaseUrl();
$token = SecretManager::getAccessToken();
$request = new GetSearchAccountRequest($url, $token);
@ -440,7 +441,7 @@ class Accounts extends AbstractTask
throw new ImporterErrorException($e->getMessage());
}
if (0 === count($response)) {
app('log')->debug('Found NOTHING in findbyiban.');
Log::debug('Found NOTHING in findbyiban.');
return null;
}
@ -454,7 +455,7 @@ class Accounts extends AbstractTask
}
// catch impossible combination "expense" with "deposit"
if ('expense' === $account->type && 'deposit' === $transactionType) {
app('log')->debug(
Log::debug(
sprintf(
'Out of cheese error (IBAN). Found Found %s account #%d based on IBAN "%s". But not going to use expense/deposit combi.',
$account->type,
@ -462,15 +463,15 @@ class Accounts extends AbstractTask
$iban
)
);
app('log')->debug('Firefly III will have to make the correct decision.');
Log::debug('Firefly III will have to make the correct decision.');
return null;
}
app('log')->debug(sprintf('[a] Found %s account #%d based on IBAN "%s"', $account->type, $account->id, $iban));
Log::debug(sprintf('[a] Found %s account #%d based on IBAN "%s"', $account->type, $account->id, $iban));
// to fix issue #4293, Firefly III will ignore this account if it's an expense or a revenue account.
if (in_array($account->type, ['expense', 'revenue'], true)) {
app('log')->debug('[a] Data importer will pretend not to have found anything. Firefly III must handle the IBAN.');
Log::debug('[a] Data importer will pretend not to have found anything. Firefly III must handle the IBAN.');
return null;
}
@ -479,11 +480,11 @@ class Accounts extends AbstractTask
}
if (2 === count($response)) {
app('log')->debug('Found 2 results, Firefly III will have to make the correct decision.');
Log::debug('Found 2 results, Firefly III will have to make the correct decision.');
return null;
}
app('log')->debug(sprintf('Found %d result(s), Firefly III will have to make the correct decision.', count($response)));
Log::debug(sprintf('Found %d result(s), Firefly III will have to make the correct decision.', count($response)));
return null;
}
@ -493,7 +494,7 @@ class Accounts extends AbstractTask
*/
private function findByNumber(string $accountNumber, string $transactionType): ?Account
{
app('log')->debug(sprintf('Going to search account with account number "%s"', $accountNumber));
Log::debug(sprintf('Going to search account with account number "%s"', $accountNumber));
$url = SecretManager::getBaseUrl();
$token = SecretManager::getAccessToken();
$request = new GetSearchAccountRequest($url, $token);
@ -509,7 +510,7 @@ class Accounts extends AbstractTask
throw new ImporterErrorException($e->getMessage());
}
if (0 === count($response)) {
app('log')->debug('Found NOTHING in findbynumber.');
Log::debug('Found NOTHING in findbynumber.');
return null;
}
@ -523,7 +524,7 @@ class Accounts extends AbstractTask
}
// catch impossible combination "expense" with "deposit"
if ('expense' === $account->type && 'deposit' === $transactionType) {
app('log')->debug(
Log::debug(
sprintf(
'Out of cheese error (account number). Found Found %s account #%d based on account number "%s". But not going to use expense/deposit combi.',
$account->type,
@ -531,15 +532,15 @@ class Accounts extends AbstractTask
$accountNumber
)
);
app('log')->debug('Firefly III will have to make the correct decision.');
Log::debug('Firefly III will have to make the correct decision.');
return null;
}
app('log')->debug(sprintf('[a] Found %s account #%d based on account number "%s"', $account->type, $account->id, $accountNumber));
Log::debug(sprintf('[a] Found %s account #%d based on account number "%s"', $account->type, $account->id, $accountNumber));
// to fix issue #4293, Firefly III will ignore this account if it's an expense or a revenue account.
if (in_array($account->type, ['expense', 'revenue'], true)) {
app('log')->debug('[a] Data importer will pretend not to have found anything. Firefly III must handle the account number.');
Log::debug('[a] Data importer will pretend not to have found anything. Firefly III must handle the account number.');
return null;
}
@ -548,11 +549,11 @@ class Accounts extends AbstractTask
}
if (2 === count($response)) {
app('log')->debug('Found 2 results, Firefly III will have to make the correct decision.');
Log::debug('Found 2 results, Firefly III will have to make the correct decision.');
return null;
}
app('log')->debug(sprintf('Found %d result(s), Firefly III will have to make the correct decision.', count($response)));
Log::debug(sprintf('Found %d result(s), Firefly III will have to make the correct decision.', count($response)));
return null;
}
@ -562,7 +563,7 @@ class Accounts extends AbstractTask
*/
private function findByName(string $name): ?Account
{
app('log')->debug(sprintf('Going to search account with name "%s"', $name));
Log::debug(sprintf('Going to search account with name "%s"', $name));
$url = SecretManager::getBaseUrl();
$token = SecretManager::getAccessToken();
$request = new GetSearchAccountRequest($url, $token);
@ -578,7 +579,7 @@ class Accounts extends AbstractTask
throw new ImporterErrorException($e->getMessage());
}
if (0 === count($response)) {
app('log')->debug('Found NOTHING in findbyname.');
Log::debug('Found NOTHING in findbyname.');
return null;
}
@ -587,12 +588,12 @@ class Accounts extends AbstractTask
foreach ($response as $account) {
if (in_array($account->type, [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE], true)
&& strtolower($account->name) === strtolower($name)) {
app('log')->debug(sprintf('[b] Found "%s" account #%d based on name "%s"', $account->type, $account->id, $name));
Log::debug(sprintf('[b] Found "%s" account #%d based on name "%s"', $account->type, $account->id, $name));
return $account;
}
}
app('log')->debug(
Log::debug(
sprintf('Found %d account(s) searching for "%s" but not going to use them. Firefly III must handle the values.', count($response), $name)
);
@ -638,24 +639,24 @@ class Accounts extends AbstractTask
$amount = $transaction['amount'];
$transaction['amount'] = $transaction['foreign_amount'];
$transaction['foreign_amount'] = $amount;
app('log')->debug(sprintf('Amount is now %s', $transaction['amount']));
app('log')->debug(sprintf('Foreign is now %s', $transaction['foreign_amount']));
Log::debug(sprintf('Amount is now %s', $transaction['amount']));
Log::debug(sprintf('Foreign is now %s', $transaction['foreign_amount']));
// swap currency ID and foreign currency ID, if both exist:
if (array_key_exists('currency_id', $transaction) && array_key_exists('foreign_currency_id', $transaction)) {
$currencyId = $transaction['currency_id'];
$transaction['currency_id'] = $transaction['foreign_currency_id'];
$transaction['foreign_currency_id'] = $currencyId;
app('log')->debug(sprintf('Currency ID is now %d', $transaction['currency_id']));
app('log')->debug(sprintf('Foreign currency ID is now %d', $transaction['foreign_currency_id']));
Log::debug(sprintf('Currency ID is now %d', $transaction['currency_id']));
Log::debug(sprintf('Foreign currency ID is now %d', $transaction['foreign_currency_id']));
}
// swap currency code and foreign currency code, if both exist:
if (array_key_exists('currency_code', $transaction) && array_key_exists('foreign_currency_code', $transaction)) {
$currencyCode = $transaction['currency_code'];
$transaction['currency_code'] = $transaction['foreign_currency_code'];
$transaction['foreign_currency_code'] = $currencyCode;
app('log')->debug(sprintf('Currency code is now %s', $transaction['currency_code']));
app('log')->debug(sprintf('Foreign currency code is now %s', $transaction['foreign_currency_code']));
Log::debug(sprintf('Currency code is now %s', $transaction['currency_code']));
Log::debug(sprintf('Foreign currency code is now %s', $transaction['foreign_currency_code']));
}
return $transaction;

26
app/Services/CSV/Conversion/Task/Amount.php

@ -25,6 +25,8 @@ declare(strict_types=1);
namespace App\Services\CSV\Conversion\Task;
use Illuminate\Support\Facades\Log;
/**
* Class Amount
*/
@ -41,46 +43,46 @@ class Amount extends AbstractTask
private function processAmount(array $transaction): array
{
app('log')->debug(sprintf('Now at the start of processAmount("%s")', $transaction['amount']));
Log::debug(sprintf('Now at the start of processAmount("%s")', $transaction['amount']));
$amount = null;
if (null === $amount && $this->validAmount((string) $transaction['amount'])) {
app('log')->debug('Transaction["amount"] value is not NULL, assume this is the correct value.');
Log::debug('Transaction["amount"] value is not NULL, assume this is the correct value.');
$amount = $transaction['amount'];
}
if (null === $amount && $this->validAmount((string) $transaction['amount_debit'])) {
app('log')->debug(sprintf('Transaction["amount_debit"] value is not NULL ("%s"), assume this is the correct value.', $transaction['amount_debit']));
Log::debug(sprintf('Transaction["amount_debit"] value is not NULL ("%s"), assume this is the correct value.', $transaction['amount_debit']));
$amount = $transaction['amount_debit'];
}
if (null === $amount && $this->validAmount((string) $transaction['amount_credit'])) {
app('log')->debug(
Log::debug(
sprintf('Transaction["amount_credit"] value is not NULL ("%s"), assume this is the correct value.', $transaction['amount_credit'])
);
$amount = $transaction['amount_credit'];
}
if (null === $amount && $this->validAmount((string) $transaction['amount_negated'])) {
app('log')->debug(
Log::debug(
sprintf('Transaction["amount_negated"] value is not NULL ("%s"), assume this is the correct value.', $transaction['amount_negated'])
);
$amount = $transaction['amount_negated'];
}
if (!array_key_exists('amount_modifier', $transaction)) {
app('log')->debug('Missing default amount modifier: amount modifier is now "1".');
Log::debug('Missing default amount modifier: amount modifier is now "1".');
$transaction['amount_modifier'] = '1';
}
if (array_key_exists('amount_modifier', $transaction)) {
$transaction['amount_modifier'] = (string) $transaction['amount_modifier'];
app('log')->debug(sprintf('Amount modifier is "%s".', $transaction['amount_modifier']));
Log::debug(sprintf('Amount modifier is "%s".', $transaction['amount_modifier']));
}
if (array_key_exists('foreign_amount', $transaction)) {
$transaction['foreign_amount'] = (string) $transaction['foreign_amount'];
}
$amount = (string) $amount;
if ('' === $amount) {
app('log')->error('Amount is EMPTY. This will give problems further ahead.', $transaction);
Log::error('Amount is EMPTY. This will give problems further ahead.', $transaction);
unset($transaction['amount_modifier']);
return $transaction;
@ -88,12 +90,12 @@ class Amount extends AbstractTask
// modify amount:
$amount = bcmul($amount, $transaction['amount_modifier']);
app('log')->debug(sprintf('Amount is now %s.', $amount));
Log::debug(sprintf('Amount is now %s.', $amount));
// modify foreign amount
if (isset($transaction['foreign_amount'])) {
$transaction['foreign_amount'] = bcmul($transaction['foreign_amount'], $transaction['amount_modifier']);
app('log')->debug(sprintf('FOREIGN amount is now %s.', $transaction['foreign_amount']));
Log::debug(sprintf('FOREIGN amount is now %s.', $transaction['foreign_amount']));
}
// unset those fields:
@ -102,11 +104,11 @@ class Amount extends AbstractTask
// depending on pos or min, also pre-set the expected type.
if (1 === bccomp('0', $amount)) {
app('log')->debug(sprintf('Amount %s is negative, so this is probably a withdrawal.', $amount));
Log::debug(sprintf('Amount %s is negative, so this is probably a withdrawal.', $amount));
$transaction['type'] = 'withdrawal';
}
if (-1 === bccomp('0', $amount)) {
app('log')->debug(sprintf('Amount %s is positive, so this is probably a deposit.', $amount));
Log::debug(sprintf('Amount %s is positive, so this is probably a deposit.', $amount));
$transaction['type'] = 'deposit';
}
unset($transaction['amount_modifier']);

4
app/Services/CSV/Conversion/Task/Currency.php

@ -25,6 +25,8 @@ declare(strict_types=1);
namespace App\Services\CSV\Conversion\Task;
use Illuminate\Support\Facades\Log;
/**
* Class Currency
*/
@ -46,7 +48,7 @@ class Currency extends AbstractTask
&& (null === $transaction['currency_code'] || '' === $transaction['currency_code'])) {
$transaction['currency_id'] = $this->transactionCurrency->id;
$transaction['currency_code'] = null;
app('log')->debug(sprintf('Set currency to %d because it was NULL or empty.', $this->transactionCurrency->id));
Log::debug(sprintf('Set currency to %d because it was NULL or empty.', $this->transactionCurrency->id));
}
return $transaction;

12
app/Services/CSV/Conversion/Task/EmptyAccounts.php

@ -25,6 +25,8 @@ declare(strict_types=1);
namespace App\Services\CSV\Conversion\Task;
use Illuminate\Support\Facades\Log;
/**
* Class EmptyAccounts
*
@ -35,10 +37,10 @@ class EmptyAccounts extends AbstractTask
{
public function process(array $group): array
{
app('log')->debug('Now in EmptyAccounts::process()');
Log::debug('Now in EmptyAccounts::process()');
$total = count($group['transactions']);
foreach ($group['transactions'] as $index => $transaction) {
app('log')->debug(sprintf('Now processing transaction %d of %d', $index + 1, $total));
Log::debug(sprintf('Now processing transaction %d of %d', $index + 1, $total));
$group['transactions'][$index] = $this->processTransaction($transaction);
}
@ -47,14 +49,14 @@ class EmptyAccounts extends AbstractTask
private function processTransaction(array $transaction): array
{
app('log')->debug('Now in EmptyAccounts::processTransaction()');
Log::debug('Now in EmptyAccounts::processTransaction()');
if ('withdrawal' === $transaction['type']) {
$destName = $transaction['destination_name'] ?? '';
$destId = (int) ($transaction['destination_id'] ?? 0);
$destIban = $transaction['destination_iban'] ?? '';
if ('' === $destName && 0 === $destId && '' === $destIban) {
app('log')->debug('Destination name + ID + IBAN of withdrawal are empty, set to "(no name)".');
Log::debug('Destination name + ID + IBAN of withdrawal are empty, set to "(no name)".');
$transaction['destination_name'] = '(no name)';
}
}
@ -63,7 +65,7 @@ class EmptyAccounts extends AbstractTask
$sourceId = (int) ($transaction['source_id'] ?? 0);
$sourceIban = $transaction['source_iban'] ?? '';
if ('' === $sourceName && 0 === $sourceId && '' === $sourceIban) {
app('log')->debug('Source name + IBAN + ID of deposit are empty, set to "(no name)".');
Log::debug('Source name + IBAN + ID of deposit are empty, set to "(no name)".');
$transaction['source_name'] = '(no name)';
}
}

46
app/Services/CSV/Converter/Amount.php

@ -24,6 +24,8 @@ declare(strict_types=1);
namespace App\Services\CSV\Converter;
use Illuminate\Support\Facades\Log;
/**
* Class Amount.
*/
@ -60,7 +62,7 @@ class Amount implements ConverterInterface
return '0';
}
app('log')->debug(sprintf('Start with amount "%s"', $value));
Log::debug(sprintf('Start with amount "%s"', $value));
$original = $value;
$value = $this->stripAmount((string) $value);
$decimal = null;
@ -68,62 +70,62 @@ class Amount implements ConverterInterface
if ($this->decimalIsDot($value)) {
$decimal = '.';
app('log')->debug(sprintf('Decimal character in "%s" seems to be a dot.', $value));
Log::debug(sprintf('Decimal character in "%s" seems to be a dot.', $value));
}
if ($this->decimalIsComma($value)) {
$decimal = ',';
app('log')->debug(sprintf('Decimal character in "%s" seems to be a comma.', $value));
Log::debug(sprintf('Decimal character in "%s" seems to be a comma.', $value));
}
// decimal character is null? find out if "0.1" or ".1" or "0,1" or ",1"
if ($this->alternativeDecimalSign($value)) {
$decimal = $this->getAlternativeDecimalSign($value);
app('log')->debug(sprintf('Decimal character in "%s" seems to be "%s".', $value, $decimal));
Log::debug(sprintf('Decimal character in "%s" seems to be "%s".', $value, $decimal));
}
// string ends with a dash? strip it
if (str_ends_with($value, '-')) {
$trail = substr($value, -1);
$value = substr($value, 0, -1);
app('log')->debug(sprintf('Removed trailing character "%s", results in "%s".', $trail, $value));
Log::debug(sprintf('Removed trailing character "%s", results in "%s".', $trail, $value));
}
// string ends with dot or comma? strip it.
if (str_ends_with($value, '.') || str_ends_with($value, ',')) {
$trail = substr($value, -1);
$value = substr($value, 0, -1);
app('log')->debug(sprintf('Removed trailing decimal character "%s", results in "%s".', $trail, $value));
Log::debug(sprintf('Removed trailing decimal character "%s", results in "%s".', $trail, $value));
}
// some shitty banks decided that "25.00000" is a normal way to write down numbers.
// five decimals in the export, WHY
if (null === $decimal) {
app('log')->debug('No decimal point, try to find a dot.');
Log::debug('No decimal point, try to find a dot.');
$index = strripos($value, '.');
if (false === $index) {
app('log')->debug('No decimal point, try to find a comma.');
Log::debug('No decimal point, try to find a comma.');
$index = strpos($value, ',');
if (false === $index) {
app('log')->debug('Found neither, continue.');
Log::debug('Found neither, continue.');
}
}
if (false !== $index) {
$len = strlen($value);
$pos = $len - $index;
app('log')->debug(sprintf('Found decimal point at position %d, length of string is %d, diff is %d.', $index, $len, $pos));
Log::debug(sprintf('Found decimal point at position %d, length of string is %d, diff is %d.', $index, $len, $pos));
if (4 === $pos) {
if (',' === $value[$index]) {
app('log')->debug('Thousands separator seems to be a comma, decimal separator must be a dot.');
Log::debug('Thousands separator seems to be a comma, decimal separator must be a dot.');
$decimal = '.';
}
if ('.' === $value[$index]) {
app('log')->debug('Thousands separator seems to be a dot, decimal separator must be a comma.');
Log::debug('Thousands separator seems to be a dot, decimal separator must be a comma.');
$decimal = ',';
}
}
if (4 !== $pos) {
app('log')->debug('Decimal point is not at position 4, so probably not a thousands separator.');
Log::debug('Decimal point is not at position 4, so probably not a thousands separator.');
}
}
}
@ -132,34 +134,34 @@ class Amount implements ConverterInterface
if (null === $decimal) {
// See issue #8404
$decimal = $this->findFromLeft($value);
// app('log')->debug('Disabled "findFromLeft" because it happens more often that "1.000" is thousand than "1.000" is 1 with three zeroes.');
// Log::debug('Disabled "findFromLeft" because it happens more often that "1.000" is thousand than "1.000" is 1 with three zeroes.');
}
// if decimal is dot, replace all comma's and spaces with nothing
if (null !== $decimal) {
$value = $this->replaceDecimal($decimal, $value);
app('log')->debug(sprintf('Converted amount from "%s" to "%s".', $original, $value));
Log::debug(sprintf('Converted amount from "%s" to "%s".', $original, $value));
}
if (null === $decimal) {
// replace all:
$search = ['.', ' ', ','];
$value = str_replace($search, '', $value);
app('log')->debug(sprintf('No decimal character found. Converted amount from "%s" to "%s".', $original, $value));
Log::debug(sprintf('No decimal character found. Converted amount from "%s" to "%s".', $original, $value));
}
if (str_starts_with($value, '.')) {
$value = '0'.$value;
}
if (is_numeric($value)) {
app('log')->debug(sprintf('Final NUMERIC value is: "%s"', $value));
Log::debug(sprintf('Final NUMERIC value is: "%s"', $value));
return $value;
}
// @codeCoverageIgnoreStart
app('log')->debug(sprintf('Final value is: "%s"', $value));
Log::debug(sprintf('Final value is: "%s"', $value));
$formatted = sprintf('%01.12f', $value);
app('log')->debug(sprintf('Is formatted to : "%s"', $formatted));
Log::debug(sprintf('Is formatted to : "%s"', $formatted));
return $formatted;
// @codeCoverageIgnoreEnd
@ -184,7 +186,7 @@ class Amount implements ConverterInterface
}
$str = trim($str);
app('log')->debug(sprintf('Stripped "%s" to "%s"', $value, $str));
Log::debug(sprintf('Stripped "%s" to "%s"', $value, $str));
return $str;
}
@ -250,11 +252,11 @@ class Amount implements ConverterInterface
private function findFromLeft(string $value): ?string
{
$decimal = null;
app('log')->debug('Decimal is still NULL, probably number with >2 decimals. Search for a dot.');
Log::debug('Decimal is still NULL, probably number with >2 decimals. Search for a dot.');
$res = strrpos($value, '.');
if (false !== $res) {
// blandly assume this is the one.
app('log')->debug(sprintf('Searched from the left for "." in amount "%s", assume this is the decimal sign.', $value));
Log::debug(sprintf('Searched from the left for "." in amount "%s", assume this is the decimal sign.', $value));
$decimal = '.';
}

4
app/Services/CSV/Converter/BankDebitCredit.php

@ -25,6 +25,8 @@ declare(strict_types=1);
namespace App\Services\CSV\Converter;
use Illuminate\Support\Facades\Log;
/**
* Class BankDebitCredit
*/
@ -39,7 +41,7 @@ class BankDebitCredit implements ConverterInterface
*/
public function convert($value): int
{
app('log')->debug('Going to convert ', ['value' => $value]);
Log::debug('Going to convert ', ['value' => $value]);
// Note: the array values should be all lowercase
$negative = [

4
app/Services/CSV/Converter/CleanId.php

@ -25,6 +25,8 @@ declare(strict_types=1);
namespace App\Services\CSV\Converter;
use Illuminate\Support\Facades\Log;
/**
* Class CleanId
*/
@ -39,7 +41,7 @@ class CleanId implements ConverterInterface
*/
public function convert($value)
{
app('log')->debug(sprintf('Now applying CleanId converter on "%s"', $value));
Log::debug(sprintf('Now applying CleanId converter on "%s"', $value));
$value = (int) $value;
return 0 === $value ? null : $value;

4
app/Services/CSV/Converter/ConverterService.php

@ -25,6 +25,8 @@ declare(strict_types=1);
namespace App\Services\CSV\Converter;
use Illuminate\Support\Facades\Log;
/**
* Class ConverterService
*/
@ -41,7 +43,7 @@ class ConverterService
if (self::exists($class)) {
/** @var ConverterInterface $object */
$object = app(self::fullName($class));
app('log')->debug(sprintf('Created converter class %s', $class));
Log::debug(sprintf('Created converter class %s', $class));
if (null !== $configuration) {
$object->setConfiguration($configuration);
}

11
app/Services/CSV/Converter/Date.php

@ -27,6 +27,7 @@ namespace App\Services\CSV\Converter;
use Carbon\Carbon;
use Carbon\Language;
use Illuminate\Support\Facades\Log;
/**
* Class Date
@ -64,24 +65,24 @@ class Date implements ConverterInterface
}
if ('' === $string) {
app('log')->warning('Empty date string, so date is set to today.');
Log::warning('Empty date string, so date is set to today.');
$carbon = today();
$carbon->startOfDay();
}
if ('' !== $string) {
app('log')->debug(sprintf('Date converter is going to work on "%s" using format "%s"', $string, $this->dateFormat));
Log::debug(sprintf('Date converter is going to work on "%s" using format "%s"', $string, $this->dateFormat));
try {
$carbon = Carbon::createFromLocaleFormat($this->dateFormat, $this->dateLocale, $string);
} catch (\Exception|\InvalidArgumentException $e) {
app('log')->error(sprintf('%s converting the date: %s', get_class($e), $e->getMessage()));
app('log')->debug('Date parsing error, will return today instead.');
Log::error(sprintf('%s converting the date: %s', get_class($e), $e->getMessage()));
Log::debug('Date parsing error, will return today instead.');
return Carbon::today()->startOfDay()->format('Y-m-d H:i:s');
}
}
if ($carbon->year < 1984) {
app('log')->warning(sprintf('Date year is before than 1984 ("%s"), so year is set to today.', $carbon->format('Y-m-d H:i:s')));
Log::warning(sprintf('Date year is before than 1984 ("%s"), so year is set to today.', $carbon->format('Y-m-d H:i:s')));
$carbon->year = now()->year;
$carbon->startOfDay();
}

12
app/Services/CSV/Converter/Iban.php

@ -25,6 +25,8 @@ declare(strict_types=1);
namespace App\Services\CSV\Converter;
use Illuminate\Support\Facades\Log;
/**
* Class Iban
*/
@ -42,21 +44,21 @@ class Iban implements ConverterInterface
if (self::isValidIban($value)) {
// strip spaces from IBAN and make upper case.
$result = str_replace("\x20", '', strtoupper(app('steam')->cleanStringAndNewlines($value)));
app('log')->debug(sprintf('Converted "%s" to "%s"', $value, $result));
Log::debug(sprintf('Converted "%s" to "%s"', $value, $result));
return trim($result);
}
app('log')->info(sprintf('"%s" is not a valid IBAN.', $value));
Log::info(sprintf('"%s" is not a valid IBAN.', $value));
return '';
}
public static function isValidIban(string $value): bool
{
app('log')->debug(sprintf('isValidIBAN("%s")', $value));
Log::debug(sprintf('isValidIBAN("%s")', $value));
$value = strtoupper(trim(app('steam')->cleanStringAndNewlines($value)));
$value = str_replace("\x20", '', $value);
app('log')->debug(sprintf('Trim: isValidIBAN("%s")', $value));
Log::debug(sprintf('Trim: isValidIBAN("%s")', $value));
$search = [' ', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
$replace = [
'',
@ -96,7 +98,7 @@ class Iban implements ConverterInterface
try {
$checksum = bcmod($iban, '97');
} catch (\ValueError $e) {
app('log')->error(sprintf('Bad IBAN: %s', $e->getMessage()));
Log::error(sprintf('Bad IBAN: %s', $e->getMessage()));
$checksum = 2;
}

3
app/Services/CSV/File/FileReader.php

@ -27,6 +27,7 @@ namespace App\Services\CSV\File;
use App\Services\Session\Constants;
use App\Services\Storage\StorageService;
use Illuminate\Support\Facades\Log;
use League\Csv\Reader;
/**
@ -39,7 +40,7 @@ class FileReader
if (true === $convert) {
$encoding = mb_detect_encoding($content, config('importer.encoding'), true);
if (false !== $encoding && 'ASCII' !== $encoding && 'UTF-8' !== $encoding) {
app('log')->warning(sprintf('Content is detected as "%s" and will be converted to UTF-8. Your milage may vary.', $encoding));
Log::warning(sprintf('Content is detected as "%s" and will be converted to UTF-8. Your milage may vary.', $encoding));
$content = mb_convert_encoding($content, 'UTF-8', $encoding);
}
}

5
app/Services/CSV/Mapper/Bills.php

@ -30,6 +30,7 @@ use App\Services\Shared\Authentication\SecretManager;
use GrumpyDictator\FFIIIApiSupport\Exceptions\ApiHttpException;
use GrumpyDictator\FFIIIApiSupport\Model\Bill;
use GrumpyDictator\FFIIIApiSupport\Request\GetBillsRequest;
use Illuminate\Support\Facades\Log;
/**
* Class Bills
@ -54,9 +55,9 @@ class Bills implements MapperInterface
try {
$response = $request->get();
} catch (ApiHttpException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
// app('log')->error($e->getTraceAsString());
// Log::error($e->getTraceAsString());
throw new ImporterErrorException(sprintf('Could not download bills: %s', $e->getMessage()));
}

5
app/Services/CSV/Mapper/Budgets.php

@ -30,6 +30,7 @@ use App\Services\Shared\Authentication\SecretManager;
use GrumpyDictator\FFIIIApiSupport\Exceptions\ApiHttpException;
use GrumpyDictator\FFIIIApiSupport\Model\Budget;
use GrumpyDictator\FFIIIApiSupport\Request\GetBudgetsRequest;
use Illuminate\Support\Facades\Log;
/**
* Class Budgets
@ -54,9 +55,9 @@ class Budgets implements MapperInterface
try {
$response = $request->get();
} catch (ApiHttpException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
// app('log')->error($e->getTraceAsString());
// Log::error($e->getTraceAsString());
throw new ImporterErrorException(sprintf('Could not download budgets: %s', $e->getMessage()));
}

5
app/Services/CSV/Mapper/Categories.php

@ -30,6 +30,7 @@ use App\Services\Shared\Authentication\SecretManager;
use GrumpyDictator\FFIIIApiSupport\Exceptions\ApiHttpException;
use GrumpyDictator\FFIIIApiSupport\Model\Category;
use GrumpyDictator\FFIIIApiSupport\Request\GetCategoriesRequest;
use Illuminate\Support\Facades\Log;
/**
* Class Categories
@ -54,9 +55,9 @@ class Categories implements MapperInterface
try {
$response = $request->get();
} catch (ApiHttpException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
// app('log')->error($e->getTraceAsString());
// Log::error($e->getTraceAsString());
throw new ImporterErrorException(sprintf('Could not download categories: %s', $e->getMessage()));
}

7
app/Services/CSV/Mapper/ExpenseRevenueAccounts.php

@ -31,6 +31,7 @@ use GrumpyDictator\FFIIIApiSupport\Exceptions\ApiHttpException;
use GrumpyDictator\FFIIIApiSupport\Model\Account;
use GrumpyDictator\FFIIIApiSupport\Request\GetAccountsRequest;
use GrumpyDictator\FFIIIApiSupport\Response\GetAccountsResponse;
use Illuminate\Support\Facades\Log;
/**
* Class ExpenseRevenueAccounts
@ -54,7 +55,7 @@ class ExpenseRevenueAccounts implements MapperInterface
*/
protected function getExpenseRevenueAccounts(): array
{
app('log')->debug('getExpenseRevenueAccounts: Fetching expense and revenue accounts.');
Log::debug('getExpenseRevenueAccounts: Fetching expense and revenue accounts.');
$url = SecretManager::getBaseUrl();
$token = SecretManager::getAccessToken();
@ -68,7 +69,7 @@ class ExpenseRevenueAccounts implements MapperInterface
try {
$response = $request->get();
} catch (ApiHttpException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
throw new ImporterErrorException(sprintf('Could not download accounts: %s', $e->getMessage()));
}
@ -84,7 +85,7 @@ class ExpenseRevenueAccounts implements MapperInterface
return in_array($account->type, ['expense', 'revenue'], true);
});
app('log')->debug(sprintf('getExpenseRevenueAccounts: Found %d expense/revenue accounts', count($expenseRevenueAccounts)));
Log::debug(sprintf('getExpenseRevenueAccounts: Found %d expense/revenue accounts', count($expenseRevenueAccounts)));
return $expenseRevenueAccounts;
}

19
app/Services/CSV/Mapper/GetAccounts.php

@ -31,6 +31,7 @@ use GrumpyDictator\FFIIIApiSupport\Exceptions\ApiHttpException;
use GrumpyDictator\FFIIIApiSupport\Model\Account;
use GrumpyDictator\FFIIIApiSupport\Request\GetAccountsRequest;
use GrumpyDictator\FFIIIApiSupport\Response\GetAccountsResponse;
use Illuminate\Support\Facades\Log;
/**
* Trait GetAccounts
@ -44,7 +45,7 @@ trait GetAccounts
*/
protected function getAllAccounts(): array
{
app('log')->debug('getAllAccounts: return a list of Firefly III accounts.');
Log::debug('getAllAccounts: return a list of Firefly III accounts.');
// get list of asset accounts:
$accounts = [];
$url = SecretManager::getBaseUrl();
@ -59,9 +60,9 @@ trait GetAccounts
try {
$response = $request->get();
} catch (ApiHttpException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
// app('log')->error($e->getTraceAsString());
// Log::error($e->getTraceAsString());
throw new ImporterErrorException(sprintf('Could not download accounts: %s', $e->getMessage()));
}
@ -73,7 +74,7 @@ trait GetAccounts
throw new ImporterErrorException('Could not get list of ALL accounts.');
}
$result = array_merge($accounts);
app('log')->debug(sprintf('getAllAccounts: Done collecting, found %d account(s)', count($result)));
Log::debug(sprintf('getAllAccounts: Done collecting, found %d account(s)', count($result)));
return $result;
}
@ -82,7 +83,7 @@ trait GetAccounts
{
$return = [];
foreach ($list as $account) {
app('log')->debug(sprintf('Downloaded account: %s', json_encode($account->toArray())));
Log::debug(sprintf('Downloaded account: %s', json_encode($account->toArray())));
$return[] = $account;
}
@ -111,9 +112,9 @@ trait GetAccounts
try {
$response = $request->get();
} catch (ApiHttpException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
// app('log')->error($e->getTraceAsString());
// Log::error($e->getTraceAsString());
throw new ImporterErrorException(sprintf('Could not download asset accounts: %s', $e->getMessage()));
}
@ -135,9 +136,9 @@ trait GetAccounts
try {
$response = $request->get();
} catch (ApiHttpException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
// app('log')->error($e->getTraceAsString());
// Log::error($e->getTraceAsString());
throw new ImporterErrorException(sprintf('Could not download liability accounts: %s', $e->getMessage()));
}

13
app/Services/CSV/Mapper/MapperService.php

@ -31,6 +31,7 @@ use App\Services\Shared\Configuration\Configuration;
use Genkgo\Camt\Camt053\DTO\Statement as CamtStatement;
use Genkgo\Camt\Config;
use Genkgo\Camt\Reader as CamtReader;
use Illuminate\Support\Facades\Log;
use League\Csv\Exception;
use League\Csv\Reader;
use League\Csv\Statement;
@ -48,7 +49,7 @@ class MapperService
*/
public static function getMapData(string $content, string $delimiter, bool $hasHeaders, array $specifics, array $data): array
{
app('log')->debug('Now in getMapData');
Log::debug('Now in getMapData');
// make file reader first.
$reader = Reader::createFromString($content);
@ -56,9 +57,9 @@ class MapperService
try {
$reader->setDelimiter($delimiter);
} catch (Exception $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
// app('log')->error($e->getTraceAsString());
// Log::error($e->getTraceAsString());
throw new ImporterErrorException(sprintf('Could not set delimiter: %s', $e->getMessage()));
}
@ -71,12 +72,12 @@ class MapperService
$stmt = (new Statement())->offset($offset);
$records = $stmt->process($reader);
} catch (Exception $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
throw new ImporterErrorException($e->getMessage());
}
// loop each row, apply specific:
app('log')->debug('Going to loop all records to collect information');
Log::debug('Going to loop all records to collect information');
foreach ($records as $row) {
// $row = SpecificService::runSpecifics($row, $specifics);
// loop each column, put in $data
@ -126,7 +127,7 @@ class MapperService
*/
public static function getMapDataForCamt(Configuration $configuration, string $content, array $data): array
{
app('log')->debug('Now in getMapDataForCamt');
Log::debug('Now in getMapDataForCamt');
// make file reader first.
$camtReader = new CamtReader(Config::getDefault());

5
app/Services/CSV/Mapper/TransactionCurrencies.php

@ -30,6 +30,7 @@ use App\Services\Shared\Authentication\SecretManager;
use GrumpyDictator\FFIIIApiSupport\Exceptions\ApiHttpException;
use GrumpyDictator\FFIIIApiSupport\Model\TransactionCurrency;
use GrumpyDictator\FFIIIApiSupport\Request\GetCurrenciesRequest;
use Illuminate\Support\Facades\Log;
/**
* Class TransactionCurrencies
@ -54,9 +55,9 @@ class TransactionCurrencies implements MapperInterface
try {
$response = $request->get();
} catch (ApiHttpException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
// app('log')->error($e->getTraceAsString());
// Log::error($e->getTraceAsString());
throw new ImporterErrorException(sprintf('Could not download currencies: %s', $e->getMessage()));
}

13
app/Services/CSV/Roles/RoleService.php

@ -32,6 +32,7 @@ use App\Services\Storage\StorageService;
use Genkgo\Camt\Camt053\DTO\Statement as CamtStatement;
use Genkgo\Camt\Config;
use Genkgo\Camt\Reader as CamtReader;
use Illuminate\Support\Facades\Log;
use League\Csv\Exception;
use League\Csv\InvalidArgument;
use League\Csv\Reader;
@ -83,27 +84,27 @@ class RoleService
$headers = $records->fetchOne();
// @codeCoverageIgnoreStart
} catch (Exception $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
throw new \InvalidArgumentException($e->getMessage());
}
// @codeCoverageIgnoreEnd
app('log')->debug('Detected file headers:', $headers);
Log::debug('Detected file headers:', $headers);
}
if (false === $configuration->isHeaders()) {
app('log')->debug('Role service: file has no headers');
Log::debug('Role service: file has no headers');
try {
$stmt = (new Statement())->limit(1)->offset(0);
$records = $stmt->process($reader);
$count = count($records->fetchOne());
app('log')->debug(sprintf('Role service: first row has %d columns', $count));
Log::debug(sprintf('Role service: first row has %d columns', $count));
for ($i = 0; $i < $count; ++$i) {
$headers[] = sprintf('Column #%d', $i + 1);
}
// @codeCoverageIgnoreStart
} catch (Exception $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
throw new \InvalidArgumentException($e->getMessage());
}
@ -148,7 +149,7 @@ class RoleService
$stmt = (new Statement())->limit(self::EXAMPLE_COUNT)->offset($offset);
// @codeCoverageIgnoreStart
} catch (Exception $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
throw new \InvalidArgumentException($e->getMessage());
}

15
app/Services/Camt/Conversion/RoutineManager.php

@ -38,6 +38,7 @@ use Genkgo\Camt\Config;
use Genkgo\Camt\DTO\Message;
use Genkgo\Camt\Exception\InvalidMessageException;
use Genkgo\Camt\Reader;
use Illuminate\Support\Facades\Log;
/**
* Class RoutineManager
@ -57,7 +58,7 @@ class RoutineManager implements RoutineManagerInterface
public function __construct(?string $identifier)
{
app('log')->debug('Constructed CAMT RoutineManager');
Log::debug('Constructed CAMT RoutineManager');
$this->content = ''; // used in CLI
$this->allErrors = [];
$this->allWarnings = [];
@ -100,12 +101,12 @@ class RoutineManager implements RoutineManagerInterface
public function start(): array
{
app('log')->debug(sprintf('Now in %s', __METHOD__));
Log::debug(sprintf('Now in %s', __METHOD__));
// get XML file
$camtMessage = $this->getCamtMessage();
if (null === $camtMessage) {
app('log')->error('The CAMT object is NULL, probably due to a previous error');
Log::error('The CAMT object is NULL, probably due to a previous error');
$this->addError(0, '[a102]: The CAMT object is NULL, probably due to a previous error');
// at this point there are very few (if not zero) errors from other steps in the routine.
// Still: merge errors so they can be reported to the user:
@ -125,7 +126,7 @@ class RoutineManager implements RoutineManagerInterface
$transactions = $this->transactionMapper->map($pseudoTransactions);
if (0 === count($transactions)) {
app('log')->error('No transactions found in CAMT file');
Log::error('No transactions found in CAMT file');
$this->addError(0, '[a103]: No transactions found in CAMT file.');
$this->mergeMessages(1);
@ -144,7 +145,7 @@ class RoutineManager implements RoutineManagerInterface
private function getCamtMessage(): ?Message
{
app('log')->debug('Now in getCamtMessage');
Log::debug('Now in getCamtMessage');
$camtReader = new Reader(Config::getDefault());
$camtMessage = null;
@ -158,8 +159,8 @@ class RoutineManager implements RoutineManagerInterface
$camtMessage = $camtReader->readString(StorageService::getContent(session()->get(Constants::UPLOAD_DATA_FILE))); // -> Level A
}
} catch (InvalidMessageException $e) {
app('log')->error('Conversion error in RoutineManager::getCamtMessage');
app('log')->error($e->getMessage());
Log::error('Conversion error in RoutineManager::getCamtMessage');
Log::error($e->getMessage());
$this->addError(0, sprintf('[a104]: Could not convert CAMT.053 file: %s', $e->getMessage()));
return null;

19
app/Services/Camt/Conversion/TransactionConverter.php

@ -8,6 +8,7 @@ use App\Exceptions\ImporterErrorException;
use App\Services\Camt\Transaction;
use App\Services\Shared\Configuration\Configuration;
use App\Services\Shared\Conversion\ProgressInformation;
use Illuminate\Support\Facades\Log;
class TransactionConverter
{
@ -17,7 +18,7 @@ class TransactionConverter
public function __construct(Configuration $configuration)
{
app('log')->debug('Constructed TransactionConverter.');
Log::debug('Constructed TransactionConverter.');
$this->configuration = $configuration;
}
@ -27,16 +28,16 @@ class TransactionConverter
public function convert(array $transactions): array
{
$total = count($transactions);
app('log')->debug(sprintf('Convert all %d transactions into pseudo-transactions.', $total));
Log::debug(sprintf('Convert all %d transactions into pseudo-transactions.', $total));
$result = [];
/** @var Transaction $transaction */
foreach ($transactions as $index => $transaction) {
app('log')->debug(sprintf('[%d/%d] Now working on transaction.', $index + 1, $total));
Log::debug(sprintf('[%d/%d] Now working on transaction.', $index + 1, $total));
$result[] = $this->convertSingle($transaction);
app('log')->debug(sprintf('[%d/%d] Now done with transaction.', $index + 1, $total));
Log::debug(sprintf('[%d/%d] Now done with transaction.', $index + 1, $total));
}
app('log')->debug(sprintf('Done converting all %d transactions into pseudo-transactions.', $total));
Log::debug(sprintf('Done converting all %d transactions into pseudo-transactions.', $total));
return $result;
}
@ -46,7 +47,7 @@ class TransactionConverter
*/
private function convertSingle(Transaction $transaction): array
{
app('log')->debug('Convert single transaction into pseudo-transaction.');
Log::debug('Convert single transaction into pseudo-transaction.');
$result = [
'transactions' => [],
];
@ -66,10 +67,10 @@ class TransactionConverter
foreach ($fieldNames as $field) {
$role = $allRoles[$field] ?? '_ignore';
if ('_ignore' !== $role) {
app('log')->debug(sprintf('Field "%s" was given role "%s".', $field, $role));
Log::debug(sprintf('Field "%s" was given role "%s".', $field, $role));
}
if ('_ignore' === $role) {
app('log')->debug(sprintf('Field "%s" is ignored!', $field));
Log::debug(sprintf('Field "%s" is ignored!', $field));
}
// get by index, so grab it from the appropriate split or get the first one.
$value = trim($transaction->getFieldByIndex($field, $i));
@ -87,7 +88,7 @@ class TransactionConverter
}
$result['transactions'][] = $current;
}
app('log')->debug(sprintf('Pseudo-transaction is: %s', json_encode($result)));
Log::debug(sprintf('Pseudo-transaction is: %s', json_encode($result)));
return $result;
}

13
app/Services/Camt/Conversion/TransactionExtractor.php

@ -9,6 +9,7 @@ use App\Services\Shared\Configuration\Configuration;
use App\Services\Shared\Conversion\ProgressInformation;
use Genkgo\Camt\Camt053\DTO\Statement as CamtStatement;
use Genkgo\Camt\DTO\Message;
use Illuminate\Support\Facades\Log;
class TransactionExtractor
{
@ -18,13 +19,13 @@ class TransactionExtractor
public function __construct(Configuration $configuration)
{
app('log')->debug('Now in TransactionExtractor.');
Log::debug('Now in TransactionExtractor.');
$this->configuration = $configuration;
}
public function extractTransactions(Message $message): array
{
app('log')->debug('Now in extractTransactions.');
Log::debug('Now in extractTransactions.');
// get transactions from XML file
$transactions = [];
$statements = $message->getRecords();
@ -37,10 +38,10 @@ class TransactionExtractor
foreach ($statements as $i => $statement) { // -> Level B
$entries = $statement->getEntries();
$entryCount = count($entries);
app('log')->debug(sprintf('[%d/%d] Now working on statement with %d entries.', $i + 1, $totalCount, $entryCount));
Log::debug(sprintf('[%d/%d] Now working on statement with %d entries.', $i + 1, $totalCount, $entryCount));
foreach ($entries as $ii => $entry) { // -> Level C
$count = count($entry->getTransactionDetails()); // count level D entries.
app('log')->debug(sprintf('[%d/%d] Now working on entry with %d detail entries.', $ii + 1, $entryCount, $count));
Log::debug(sprintf('[%d/%d] Now working on entry with %d detail entries.', $ii + 1, $entryCount, $count));
if (0 === $count) {
// TODO Create a single transaction, I guess?
$transactions[] = new Transaction($this->configuration, $message, $statement, $entry, []);
@ -64,10 +65,10 @@ class TransactionExtractor
}
}
}
app('log')->debug(sprintf('[%d/%d] Done working on entry with %d detail entries.', $ii + 1, $entryCount, $count));
Log::debug(sprintf('[%d/%d] Done working on entry with %d detail entries.', $ii + 1, $entryCount, $count));
}
}
app('log')->debug(sprintf('Extracted %d transaction(s)', count($transactions)));
Log::debug(sprintf('Extracted %d transaction(s)', count($transactions)));
return $transactions;
}

151
app/Services/Camt/Conversion/TransactionMapper.php

@ -9,6 +9,7 @@ use App\Services\CSV\Mapper\GetAccounts;
use App\Services\Shared\Configuration\Configuration;
use App\Services\Shared\Conversion\ProgressInformation;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
/**
* Class TransactionMapper
@ -27,7 +28,7 @@ class TransactionMapper
*/
public function __construct(Configuration $configuration)
{
app('log')->debug('Constructed TransactionMapper.');
Log::debug('Constructed TransactionMapper.');
$this->configuration = $configuration;
$this->allAccounts = $this->getAllAccounts();
$this->accountIdentificationSuffixes = ['id', 'iban', 'number', 'name'];
@ -35,17 +36,17 @@ class TransactionMapper
public function map(array $transactions): array
{
app('log')->debug(sprintf('Now mapping %d transaction(s)', count($transactions)));
Log::debug(sprintf('Now mapping %d transaction(s)', count($transactions)));
$result = [];
$total = count($transactions);
/** @var array $transaction */
foreach ($transactions as $index => $transaction) {
app('log')->debug(sprintf('[%d/%d] Now mapping.', $index + 1, $total));
Log::debug(sprintf('[%d/%d] Now mapping.', $index + 1, $total));
$result[] = $this->mapTransactionGroup($transaction);
app('log')->debug(sprintf('[%d/%d] Now done with mapping', $index + 1, $total));
Log::debug(sprintf('[%d/%d] Now done with mapping', $index + 1, $total));
}
app('log')->debug(sprintf('Mapped %d transaction(s)', count($result)));
Log::debug(sprintf('Mapped %d transaction(s)', count($result)));
return $result;
}
@ -60,12 +61,12 @@ class TransactionMapper
];
$splits = $transaction['splits'] ?? 1;
$groupHandling = $this->configuration->getGroupedTransactionHandling();
app('log')->debug(sprintf('Transaction has %d split(s)', $splits));
Log::debug(sprintf('Transaction has %d split(s)', $splits));
for ($i = 0; $i < $splits; ++$i) {
/** @var array|bool $split */
$split = $transaction['transactions'][$i] ?? false;
if (is_bool($split) && false === $split) {
app('log')->warning(sprintf('No split #%d found, break.', $i));
Log::warning(sprintf('No split #%d found, break.', $i));
continue;
}
@ -80,7 +81,7 @@ class TransactionMapper
// TODO loop over $current and clean up if necessary.
$result['transactions'][] = $polishedJournal;
}
app('log')->debug('Firefly III transaction is', $result);
Log::debug('Firefly III transaction is', $result);
return $result;
}
@ -102,42 +103,42 @@ class TransactionMapper
// we'll use this one, no exception. so the one from level-c can be dropped (if available)
if (array_key_exists('entryAccounterServiceReference', $data['data'])) {
unset($data['data']['entryAccounterServiceReference']);
app('log')->debug('Dropped entryAccounterServiceReference');
Log::debug('Dropped entryAccounterServiceReference');
}
}
if (array_key_exists('entryDetailBtcDomainCode', $data['data'])) {
// we'll use this one, no exception. so the one from level-c can be dropped (if available)
if (array_key_exists('entryBtcDomainCode', $data['data'])) {
unset($data['data']['entryBtcDomainCode']);
app('log')->debug('Dropped entryBtcDomainCode');
Log::debug('Dropped entryBtcDomainCode');
}
}
if (array_key_exists('entryDetailBtcFamilyCode', $data['data'])) {
// we'll use this one, no exception. so the one from level-c can be dropped (if available)
if (array_key_exists('entryBtcFamilyCode', $data['data'])) {
unset($data['data']['entryBtcFamilyCode']);
app('log')->debug('Dropped entryBtcFamilyCode');
Log::debug('Dropped entryBtcFamilyCode');
}
}
if (array_key_exists('entryDetailBtcSubFamilyCode', $data['data'])) {
// we'll use this one, no exception. so the one from level-c can be dropped (if available)
if (array_key_exists('entryBtcSubFamilyCode', $data['data'])) {
unset($data['data']['entryBtcSubFamilyCode']);
app('log')->debug('Dropped entryBtcSubFamilyCode');
Log::debug('Dropped entryBtcSubFamilyCode');
}
}
if (array_key_exists('entryDetailAmount', $data['data'])) {
// we'll use this one, no exception. so the one from level-c can be dropped (if available)
if (array_key_exists('entryAmount', $data['data'])) {
unset($data['data']['entryAmount']);
app('log')->debug('Dropped entryAmount');
Log::debug('Dropped entryAmount');
}
}
}
switch ($role) {
default:
app('log')->error(sprintf('Cannot handle role "%s" yet.', $role));
Log::error(sprintf('Cannot handle role "%s" yet.', $role));
break;
@ -220,16 +221,16 @@ class TransactionMapper
$addition = end($data['data']);
}
$current['description'] .= $addition;
app('log')->debug(sprintf('Description is "%s"', $current['description']));
Log::debug(sprintf('Description is "%s"', $current['description']));
break;
case 'amount':
// #8367 default amount = 0
$current['amount'] = 0;
app('log')->debug(sprintf('Start with amount at zero ("%s")', $current['amount']));
Log::debug(sprintf('Start with amount at zero ("%s")', $current['amount']));
if ('group' === $groupHandling || 'split' === $groupHandling) {
app('log')->debug(sprintf('Group handling is "%s"', $groupHandling));
Log::debug(sprintf('Group handling is "%s"', $groupHandling));
// if multiple values, use biggest (... at index 0?)
// TODO this will never work because $current['amount'] is NULL the first time and abs() can't handle that.
foreach ($data['data'] as $amount) {
@ -241,42 +242,42 @@ class TransactionMapper
$amount = (float) $amount;
}
if (abs($current['amount']) < abs($amount)) {
app('log')->debug(sprintf('Amount is now "%s" instead of "%s"', $amount, $current['amount']));
Log::debug(sprintf('Amount is now "%s" instead of "%s"', $amount, $current['amount']));
$current['amount'] = $amount;
}
}
}
if ('single' === $groupHandling) {
app('log')->debug(sprintf('Group handling is "%s"', $groupHandling));
Log::debug(sprintf('Group handling is "%s"', $groupHandling));
// if multiple values, use smallest (... at index 1?)
foreach ($data['data'] as $amount) {
// #8367 skip null values
if (null === $amount) {
app('log')->debug('Amount is NULL, continue.');
Log::debug('Amount is NULL, continue.');
continue;
}
if (is_string($amount)) {
$amount = (float) $amount;
}
app('log')->debug(sprintf('Amount is %s.', var_export($amount, true)));
Log::debug(sprintf('Amount is %s.', var_export($amount, true)));
// check for null first, should prevent null pointers in abs()
if (abs($current['amount'])
< abs($amount)) {
app('log')->debug(sprintf('Amount is now "%s" instead of "%s"', $amount, $current['amount']));
Log::debug(sprintf('Amount is now "%s" instead of "%s"', $amount, $current['amount']));
$current['amount'] = $amount;
}
}
}
if (0 === bccomp('0', (string) $current['amount'])) {
app('log')->debug('Amount is ZERO, set to NULL');
Log::debug('Amount is ZERO, set to NULL');
$current['amount'] = null;
}
if (null !== $current['amount'] && 0 !== bccomp('0', (string) $current['amount']) && !is_string($current['amount'])) {
app('log')->debug(sprintf('Amount is %s, turn into string', var_export($current['amount'], true)));
Log::debug(sprintf('Amount is %s, turn into string', var_export($current['amount'], true)));
$current['amount'] = (string) $current['amount'];
}
app('log')->debug(sprintf('Final amount is "%s"', $current['amount']));
Log::debug(sprintf('Final amount is "%s"', $current['amount']));
break;
@ -350,47 +351,47 @@ class TransactionMapper
*/
private function sanityCheck(array $current): ?array
{
app('log')->debug('Start of sanityCheck');
Log::debug('Start of sanityCheck');
// no amount?
if (!array_key_exists('amount', $current)) {
app('log')->error('Array has no amount information, cannot fix.');
Log::error('Array has no amount information, cannot fix.');
return null;
}
if ('' === $current['amount']) {
app('log')->error('Array has empty amount information, cannot fix.');
Log::error('Array has empty amount information, cannot fix.');
return null;
}
if (null === $current['amount']) {
app('log')->error('Array has NULL amount information, cannot fix.');
Log::error('Array has NULL amount information, cannot fix.');
return null;
}
// if there is no source information, add the default account now:
if ($this->accountDetailsEmpty('source', $current)) {
app('log')->debug('Array has no source information, added default info.');
Log::debug('Array has no source information, added default info.');
$current['source_id'] = $this->configuration->getDefaultAccount();
}
// if there is no destination information, add an empty account now:
$current['destination_is_empty'] = false;
if ($this->accountDetailsEmpty('destination', $current)) {
app('log')->debug('Array has no destination information, added default info.');
Log::debug('Array has no destination information, added default info.');
$current['destination_name'] = '(no name)';
$current['destination_is_empty'] = true;
}
// if is positive
if (1 === bccomp($current['amount'], '0')) {
app('log')->debug('Swap accounts because amount is positive');
Log::debug('Swap accounts because amount is positive');
// positive account is deposit (or transfer), so swap accounts.
$current = $this->swapAccounts($current);
}
$current = $this->determineTransactionType($current);
app('log')->debug(sprintf('Transaction type is %s', $current['type']));
Log::debug(sprintf('Transaction type is %s', $current['type']));
// the type is a withdrawal, but we did not recognize the type of the source account.
// if that did not succeed we did not FIND the source account, and must fall back
@ -399,14 +400,14 @@ class TransactionMapper
if ('withdrawal' === $current['type'] && '' === (string) $current['source_type']) {
$current['source_id'] = $this->configuration->getDefaultAccount();
unset($current['source_name'], $current['source_iban']);
app('log')->warning(sprintf('Withdrawal, but did not recognize the type of the source account. It will be replaced with the default account (#%d).', $current['source_id']));
Log::warning(sprintf('Withdrawal, but did not recognize the type of the source account. It will be replaced with the default account (#%d).', $current['source_id']));
$overruleAccount = true;
}
// same for deposit:
if ('deposit' === $current['type'] && '' === (string) $current['destination_type']) {
$current['destination_id'] = $this->configuration->getDefaultAccount();
unset($current['destination_name'], $current['destination_iban']);
app('log')->warning(sprintf('Deposit, but did not recognize the destination account. It will be replaced with the default account (#%d).', $current['destination_id']));
Log::warning(sprintf('Deposit, but did not recognize the destination account. It will be replaced with the default account (#%d).', $current['destination_id']));
$overruleAccount = true;
}
// at this point it is possible that either of the two actions above have accidentally
@ -421,21 +422,21 @@ class TransactionMapper
// no description?
if (!array_key_exists('description', $current)) {
app('log')->warning('Did not find a description in the transaction, added "(no description)"');
Log::warning('Did not find a description in the transaction, added "(no description)"');
$current['description'] = '(no description)';
}
if (array_key_exists('description', $current) && '' === (string) $current['description']) {
app('log')->warning('Did not find a description in the transaction, added "(no description)"');
Log::warning('Did not find a description in the transaction, added "(no description)"');
$current['description'] = '(no description)';
}
// no date?
if (!array_key_exists('date', $current)) {
app('log')->warning(sprintf('Did not find a date in the transaction, added "%s"', date('Y-m-d')));
Log::warning(sprintf('Did not find a date in the transaction, added "%s"', date('Y-m-d')));
$current['date'] = date('Y-m-d');
}
if (array_key_exists('date', $current) && '' === (string) $current['date']) {
app('log')->warning(sprintf('Did not find a date in the transaction, added "%s"', date('Y-m-d')));
Log::warning(sprintf('Did not find a date in the transaction, added "%s"', date('Y-m-d')));
$current['date'] = date('Y-m-d');
}
@ -457,7 +458,7 @@ class TransactionMapper
private function swapAccounts(array $currentTransaction): array
{
app('log')->debug('swapAccounts');
Log::debug('swapAccounts');
$return = $currentTransaction;
foreach ($this->accountIdentificationSuffixes as $suffix) {
@ -469,21 +470,21 @@ class TransactionMapper
$destValue = array_key_exists($destKey, $currentTransaction) ? $currentTransaction[$destKey] : null;
// always unset source value
app('log')->debug(sprintf('[1] Unset "%s" with value "%s"', $sourceKey, $sourceValue));
app('log')->debug(sprintf('[2] Unset "%s" with value "%s"', $destKey, $destValue));
Log::debug(sprintf('[1] Unset "%s" with value "%s"', $sourceKey, $sourceValue));
Log::debug(sprintf('[2] Unset "%s" with value "%s"', $destKey, $destValue));
unset($return[$sourceKey], $return[$destKey]);
// set opposite values
if (null !== $sourceValue) {
app('log')->debug(sprintf('[1] Set "%s" to "%s"', $destKey, $sourceValue));
Log::debug(sprintf('[1] Set "%s" to "%s"', $destKey, $sourceValue));
$return[$destKey] = $sourceValue;
}
// a small exception. Do not set the destination name to "no name" if it's set to "no name" because it was empty.
if (true === $currentTransaction['destination_is_empty']) {
app('log')->debug(sprintf('Will not set "%s" to "%s" because destination is empty.', $sourceKey, $destValue));
Log::debug(sprintf('Will not set "%s" to "%s" because destination is empty.', $sourceKey, $destValue));
}
if (null !== $destValue && false === $currentTransaction['destination_is_empty']) {
app('log')->debug(sprintf('[2] Set "%s" to "%s"', $sourceKey, $destValue));
Log::debug(sprintf('[2] Set "%s" to "%s"', $sourceKey, $destValue));
$return[$sourceKey] = $destValue;
}
}
@ -493,42 +494,42 @@ class TransactionMapper
private function determineTransactionType(array $current): array
{
app('log')->debug('Determine transaction type.');
Log::debug('Determine transaction type.');
$directions = ['source', 'destination'];
$accountType = [];
$lessThanZero = 1 === bccomp('0', $current['amount']);
app('log')->debug(sprintf('Amount is "%s", so lessThanZero is %s', $current['amount'], var_export($lessThanZero, true)));
Log::debug(sprintf('Amount is "%s", so lessThanZero is %s', $current['amount'], var_export($lessThanZero, true)));
foreach ($directions as $direction) {
app('log')->debug(sprintf('Now working on direction "%s".', $direction));
Log::debug(sprintf('Now working on direction "%s".', $direction));
$accountType[$direction] = null;
$accountTypeKey = sprintf('%s_type', $direction);
$current[$accountTypeKey] = '';
foreach ($this->accountIdentificationSuffixes as $suffix) {
$key = sprintf('%s_%s', $direction, $suffix);
app('log')->debug(sprintf('Now working on key "%s".', $key));
Log::debug(sprintf('Now working on key "%s".', $key));
// try to find the account
if (array_key_exists($key, $current) && '' !== (string) $current[$key]) {
$foundDirection = $this->getAccountType($suffix, (string) $current[$key], $lessThanZero);
app('log')->debug(
Log::debug(
sprintf('Transaction array has a "%s"-field with value "%s", and its type is "%s".', $key, $current[$key], $foundDirection)
);
// should this overrule any existing account type? Since we work down from ID,
// if it's already known it should not be overruled.
if (null === $foundDirection && null !== $accountType[$direction]) {
app('log')->debug(sprintf('Found direction is null, but accountType[%s] is not null, so we skip.', $direction));
Log::debug(sprintf('Found direction is null, but accountType[%s] is not null, so we skip.', $direction));
}
if (null !== $foundDirection && null !== $accountType[$direction] && $foundDirection !== $accountType[$direction]) {
app('log')->debug(sprintf('Found direction "%s" overrules accountType[%s] "%s".', $foundDirection, $direction, $accountType[$direction]));
Log::debug(sprintf('Found direction "%s" overrules accountType[%s] "%s".', $foundDirection, $direction, $accountType[$direction]));
$accountType[$direction] = $foundDirection;
$current[$accountTypeKey] = $foundDirection;
app('log')->debug(sprintf('"%s" = "%s"', $accountTypeKey, $foundDirection));
Log::debug(sprintf('"%s" = "%s"', $accountTypeKey, $foundDirection));
}
if (null === $accountType[$direction]) {
app('log')->debug(sprintf('accountType[%s] is set to found direction "%s"', $direction, $foundDirection));
Log::debug(sprintf('accountType[%s] is set to found direction "%s"', $direction, $foundDirection));
$accountType[$direction] = $foundDirection;
$current[$accountTypeKey] = $foundDirection;
app('log')->debug(sprintf('"%s" = "%s"', $accountTypeKey, $foundDirection));
Log::debug(sprintf('"%s" = "%s"', $accountTypeKey, $foundDirection));
}
}
}
@ -549,7 +550,7 @@ class TransactionMapper
case $sourceIsAsset && $destIsNull && $lessThanZero:
// there is no expense account, but the account was found under revenue, so we assume this is a withdrawal with a non-existing expense account
case $sourceIsAsset && $destIsRevenue && $lessThanZero:
app('log')->debug('Based on types, this is a withdrawal');
Log::debug('Based on types, this is a withdrawal');
$current['type'] = 'withdrawal';
break;
@ -559,47 +560,47 @@ class TransactionMapper
case $sourceIsNull && $destIsAsset:
case $sourceIsRevenue && $destIsAsset:
case $sourceIsAsset && $destIsExpense: // there is no revenue account, but the account was found under expense, so we assume this is a deposit with an non-existing revenue account
app('log')->debug('Based on types, this is a deposit');
Log::debug('Based on types, this is a deposit');
$current['type'] = 'deposit';
break;
case $sourceIsAsset && $destIsAsset:
app('log')->debug('Based on types, this is a transfer');
Log::debug('Based on types, this is a transfer');
$current['type'] = 'transfer'; // line 382 / 383
break;
case $sourceIsExpense && $destIsExpense:
app('log')->warning('Both types are expense. Impossible. Lets make source_type = "" and type="withdrawal"');
Log::warning('Both types are expense. Impossible. Lets make source_type = "" and type="withdrawal"');
$current['source_type'] = '';
$current['type'] = 'withdrawal';
break;
case $sourceIsRevenue && $destIsRevenue:
app('log')->warning('Both types are revenue. Impossible. Lets make destination_type = "" and type="deposit"');
Log::warning('Both types are revenue. Impossible. Lets make destination_type = "" and type="deposit"');
$current['destination_type'] = '';
$current['type'] = 'deposit';
break;
case $sourceIsExpense && $destIsNull:
app('log')->warning('The source is "expense" but the destination is a new account. Weird! Lets make source_type = "" and type="withdrawal"');
Log::warning('The source is "expense" but the destination is a new account. Weird! Lets make source_type = "" and type="withdrawal"');
$current['source_type'] = '';
$current['type'] = 'withdrawal';
break;
case $sourceIsExpense && $destIsAsset:
app('log')->warning('The source is "expense" but the destination is an asset. Weird! Lets make source_type = "" and type="deposit"');
Log::warning('The source is "expense" but the destination is an asset. Weird! Lets make source_type = "" and type="deposit"');
$current['source_type'] = '';
$current['type'] = 'deposit';
break;
default:
app('log')->error(
Log::error(
sprintf(
'Unknown transaction type: source = "%s", destination = "%s". Fall back to "withdrawal"',
$accountType['source'] ?: null,
@ -625,31 +626,31 @@ class TransactionMapper
if ((string) $account->{$field} === (string) $value) {
// never found a match before!
if (0 === $count) {
app('log')->debug(sprintf('Recognized "%s" as a "%s"-account by its "%s".', $value, $account->type, $field));
Log::debug(sprintf('Recognized "%s" as a "%s"-account by its "%s".', $value, $account->type, $field));
$result = $account->type;
$hitField = $field;
++$count;
}
// we found a match before, and it's different too.
if (0 !== $count && $account->type !== $result) {
app('log')->warning(sprintf('Recognized "%s" as a "%s"-account (on the "%s"-field) but ALSO as a "%s"-account (previous match was on the "%s"-field)!', $value, $result, $field, $account->type, $hitField));
Log::warning(sprintf('Recognized "%s" as a "%s"-account (on the "%s"-field) but ALSO as a "%s"-account (previous match was on the "%s"-field)!', $value, $result, $field, $account->type, $hitField));
// the previous result always trumps the current result because the order of accountIdentificationSuffixes
app('log')->debug(sprintf('System will keep the previous match and assume account with %s "%s" is a "%s" account', $field, $value, $result));
Log::debug(sprintf('System will keep the previous match and assume account with %s "%s" is a "%s" account', $field, $value, $result));
++$count;
}
// we found a match before and it's different. But the data importer has found both "revenue" AND "expense" accounts. What to do?
$set = [$account->type, $result];
if (0 !== $count && $account->type !== $result && in_array('revenue', $set, true) && in_array('expense', $set, true) && $lessThanZero) {
app('log')->warning(sprintf('Recognized "%s" as a "%s"-account (on the "%s"-field) but ALSO as a "%s"-account (previous match was on the "%s"-field)!', $value, $result, $field, $account->type, $hitField));
app('log')->debug('Because amount is less than zero, we assume "expense" is the correct type.');
Log::warning(sprintf('Recognized "%s" as a "%s"-account (on the "%s"-field) but ALSO as a "%s"-account (previous match was on the "%s"-field)!', $value, $result, $field, $account->type, $hitField));
Log::debug('Because amount is less than zero, we assume "expense" is the correct type.');
$result = 'expense';
++$count;
}
// we found a match before and it's different. But: previous result was "expense", current result is "revenue"
if (0 !== $count && $account->type !== $result && in_array('revenue', $set, true) && in_array('expense', $set, true) && !$lessThanZero) {
app('log')->warning(sprintf('Recognized "%s" as a "%s"-account (on the "%s"-field) but ALSO as a "%s"-account (previous match was on the "%s"-field)!', $value, $result, $field, $account->type, $hitField));
app('log')->debug('Because amount is more than zero, we assume "revenue" is the correct type.');
Log::warning(sprintf('Recognized "%s" as a "%s"-account (on the "%s"-field) but ALSO as a "%s"-account (previous match was on the "%s"-field)!', $value, $result, $field, $account->type, $hitField));
Log::debug('Because amount is more than zero, we assume "revenue" is the correct type.');
$result = 'revenue';
++$count;
@ -657,7 +658,7 @@ class TransactionMapper
}
}
if (null === $result) {
app('log')->debug(sprintf('Unable to recognize the account type of "%s" "%s", or skipped because unsure.', $field, $value));
Log::debug(sprintf('Unable to recognize the account type of "%s" "%s", or skipped because unsure.', $field, $value));
}
return $result;
@ -665,7 +666,7 @@ class TransactionMapper
private function getAccountId($direction, $current): string
{
app('log')->debug('getAccountId');
Log::debug('getAccountId');
foreach ($this->accountIdentificationSuffixes as $suffix) {
$field = sprintf('%s_%s', $direction, $suffix);
if (array_key_exists($field, $current)) {
@ -689,14 +690,14 @@ class TransactionMapper
return (string) $account->id;
}
}
app('log')->warning(sprintf('Just mapped account "%s" (%s)', $account->id, $account->type));
Log::warning(sprintf('Just mapped account "%s" (%s)', $account->id, $account->type));
return (string) $account->id;
}
}
// app('log')->warning(sprintf('Unable to map an account for "%s"',$current[$field]));
// Log::warning(sprintf('Unable to map an account for "%s"',$current[$field]));
}
// app('log')->warning(sprintf('There is no field for "%s" in the transaction',$direction));
// Log::warning(sprintf('There is no field for "%s" in the transaction',$direction));
}
return '';

23
app/Services/Camt/Transaction.php

@ -22,6 +22,7 @@ use Genkgo\Camt\DTO\ProprietaryAccount;
use Genkgo\Camt\DTO\RelatedParty;
use Genkgo\Camt\DTO\UnstructuredRemittanceInformation;
use Genkgo\Camt\DTO\UPICAccount;
use Illuminate\Support\Facades\Log;
use Money\Currencies\ISOCurrencies;
use Money\Formatter\DecimalMoneyFormatter;
use Money\Money;
@ -42,7 +43,7 @@ class Transaction
Entry $levelC,
array $levelD
) {
app('log')->debug('Constructed a CAMT Transaction');
Log::debug('Constructed a CAMT Transaction');
$this->configuration = $configuration;
$this->levelA = $levelA;
$this->levelB = $levelB;
@ -89,7 +90,7 @@ class Transaction
*/
public function getFieldByIndex(string $field, int $index): string
{
app('log')->debug(sprintf('getFieldByIndex("%s", %d)', $field, $index));
Log::debug(sprintf('getFieldByIndex("%s", %d)', $field, $index));
switch ($field) {
default:
@ -212,7 +213,7 @@ class Transaction
// this is level D, so grab from level C or loop.
if (0 === count($this->levelD) || !array_key_exists($index, $this->levelD)) {
app('log')->debug('There is no info for this thing.');
Log::debug('There is no info for this thing.');
// TODO return nothing?
return $result;
@ -381,7 +382,7 @@ class Transaction
$info = $this->levelD[$index];
$opposingParty = $this->getOpposingParty($info);
if (null === $opposingParty) {
app('log')->debug('In entryDetailOpposingName, opposing party is NULL, return "".');
Log::debug('In entryDetailOpposingName, opposing party is NULL, return "".');
}
if (null !== $opposingParty) {
$result = $this->getOpposingName($opposingParty);
@ -396,33 +397,33 @@ class Transaction
*/
private function getOpposingParty(EntryTransactionDetail $transactionDetail): ?RelatedParty
{
app('log')->debug('getOpposingParty(), interested in Creditor.');
Log::debug('getOpposingParty(), interested in Creditor.');
$relatedParties = $transactionDetail->getRelatedParties();
$targetRelatedPartyObject = 'Genkgo\Camt\DTO\Creditor';
// get amount from "getAmount":
$amount = $transactionDetail?->getAmount()?->getAmount();
if (null !== $amount) {
app('log')->debug(sprintf('Amount in getAmount() is "%s"', $amount));
Log::debug(sprintf('Amount in getAmount() is "%s"', $amount));
}
if (null === $amount) {
$amount = $transactionDetail->getAmountDetails()?->getAmount();
app('log')->debug(sprintf('Amount in getAmountDetails() is "%s"', $amount));
Log::debug(sprintf('Amount in getAmountDetails() is "%s"', $amount));
}
if (null !== $amount && $amount > 0) { // which part in this array is the interesting one?
app('log')->debug('getOpposingParty(), interested in Debtor!');
Log::debug('getOpposingParty(), interested in Debtor!');
$targetRelatedPartyObject = 'Genkgo\Camt\DTO\Debtor';
}
foreach ($relatedParties as $relatedParty) {
app('log')->debug(sprintf('Found related party of type "%s"', get_class($relatedParty->getRelatedPartyType())));
Log::debug(sprintf('Found related party of type "%s"', get_class($relatedParty->getRelatedPartyType())));
if (get_class($relatedParty->getRelatedPartyType()) === $targetRelatedPartyObject) {
app('log')->debug('This is the type we are looking for!');
Log::debug('This is the type we are looking for!');
return $relatedParty;
}
}
app('log')->debug('getOpposingParty(), no opposing party found, return NULL.');
Log::debug('getOpposingParty(), no opposing party found, return NULL.');
return null;
}

5
app/Services/Nordigen/Authentication/SecretManager.php

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace App\Services\Nordigen\Authentication;
use Illuminate\Support\Facades\Log;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
@ -42,7 +43,7 @@ class SecretManager
public static function getId(): string
{
if (!self::hasId()) {
app('log')->debug('No Nordigen ID in hasId() session, will return config variable.');
Log::debug('No Nordigen ID in hasId() session, will return config variable.');
return (string) config('nordigen.id');
}
@ -76,7 +77,7 @@ class SecretManager
public static function getKey(): string
{
if (!self::hasKey()) {
app('log')->debug('No Nordigen key in hasKey() session, will return config variable.');
Log::debug('No Nordigen key in hasKey() session, will return config variable.');
return (string) config('nordigen.key');
}

3
app/Services/Nordigen/AuthenticationValidator.php

@ -30,6 +30,7 @@ use App\Services\Enums\AuthenticationStatus;
use App\Services\Nordigen\Authentication\SecretManager;
use App\Services\Shared\Authentication\AuthenticationValidatorInterface;
use App\Services\Shared\Authentication\IsRunningCli;
use Illuminate\Support\Facades\Log;
/**
* Class AuthenticationValidator
@ -40,7 +41,7 @@ class AuthenticationValidator implements AuthenticationValidatorInterface
public function validate(): AuthenticationStatus
{
app('log')->debug(sprintf('Now at %s', __METHOD__));
Log::debug(sprintf('Now at %s', __METHOD__));
$identifier = SecretManager::getId();
$key = SecretManager::getKey();

35
app/Services/Nordigen/Conversion/Routine/TransactionProcessor.php

@ -37,6 +37,7 @@ use App\Services\Nordigen\TokenManager;
use App\Services\Shared\Configuration\Configuration;
use App\Services\Shared\Conversion\ProgressInformation;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
/**
* Class TransactionProcessor
@ -57,7 +58,7 @@ class TransactionProcessor
*/
public function download(): array
{
app('log')->debug(sprintf('Now in %s', __METHOD__));
Log::debug(sprintf('Now in %s', __METHOD__));
$this->notBefore = null;
$this->notAfter = null;
$this->accounts = [];
@ -72,10 +73,10 @@ class TransactionProcessor
$accounts = array_keys($this->configuration->getAccounts());
$return = [];
app('log')->debug(sprintf('Found %d accounts to download from.', count($accounts)));
Log::debug(sprintf('Found %d accounts to download from.', count($accounts)));
foreach ($accounts as $key => $account) {
$account = (string) $account;
app('log')->debug(sprintf('Going to download transactions for account #%d "%s"', $key, $account));
Log::debug(sprintf('Going to download transactions for account #%d "%s"', $key, $account));
$object = new Account();
$object->setIdentifier($account);
$fullInfo = null;
@ -97,7 +98,7 @@ class TransactionProcessor
continue;
}
app('log')->debug('Done downloading information for debug purposes.');
Log::debug('Done downloading information for debug purposes.');
$this->accounts[] = $fullInfo;
try {
@ -115,9 +116,9 @@ class TransactionProcessor
// @var GetTransactionsResponse $transactions
try {
$transactions = $request->get();
app('log')->debug(sprintf('GetTransactionsResponse: count %d transaction(s)', count($transactions)));
Log::debug(sprintf('GetTransactionsResponse: count %d transaction(s)', count($transactions)));
} catch (ImporterHttpException|RateLimitException $e) {
app('log')->debug(sprintf('Ran into %s instead of GetTransactionsResponse', get_class($e)));
Log::debug(sprintf('Ran into %s instead of GetTransactionsResponse', get_class($e)));
$this->addError(0, $e->getMessage());
$return[$account] = [];
@ -129,7 +130,7 @@ class TransactionProcessor
continue;
} catch (AgreementExpiredException $e) {
app('log')->debug(sprintf('Ran into %s instead of GetTransactionsResponse', get_class($e)));
Log::debug(sprintf('Ran into %s instead of GetTransactionsResponse', get_class($e)));
// agreement expired, whoops.
$return[$account] = [];
$this->addError(0, $e->json['detail'] ?? '[a114]: Your EUA has expired.');
@ -147,9 +148,9 @@ class TransactionProcessor
];
$return[$account] = $this->filterTransactions($transactions);
app('log')->debug(sprintf('Done downloading transactions for account %s "%s"', $key, $account));
Log::debug(sprintf('Done downloading transactions for account %s "%s"', $key, $account));
}
app('log')->debug('Done with download');
Log::debug('Done with download');
return $return;
}
@ -166,19 +167,19 @@ class TransactionProcessor
private function filterTransactions(GetTransactionsResponse $transactions): array
{
app('log')->info(sprintf('Going to filter downloaded transactions. Original set length is %d', count($transactions)));
Log::info(sprintf('Going to filter downloaded transactions. Original set length is %d', count($transactions)));
if (null !== $this->notBefore) {
app('log')->info(sprintf('Will not grab transactions before "%s"', $this->notBefore->format('Y-m-d H:i:s')));
Log::info(sprintf('Will not grab transactions before "%s"', $this->notBefore->format('Y-m-d H:i:s')));
}
if (null !== $this->notAfter) {
app('log')->info(sprintf('Will not grab transactions after "%s"', $this->notAfter->format('Y-m-d H:i:s')));
Log::info(sprintf('Will not grab transactions after "%s"', $this->notAfter->format('Y-m-d H:i:s')));
}
$return = [];
foreach ($transactions as $transaction) {
$madeOn = $transaction->getDate();
if (null !== $this->notBefore && $madeOn->lt($this->notBefore)) {
app('log')->debug(
Log::debug(
sprintf(
'Skip transaction because "%s" is before "%s".',
$madeOn->format(self::DATE_TIME_FORMAT),
@ -189,7 +190,7 @@ class TransactionProcessor
continue;
}
if (null !== $this->notAfter && $madeOn->gt($this->notAfter)) {
app('log')->debug(
Log::debug(
sprintf(
'Skip transaction because "%s" is after "%s".',
$madeOn->format(self::DATE_TIME_FORMAT),
@ -208,16 +209,16 @@ class TransactionProcessor
$transaction->getDestinationName(),
$transaction->getDescription()
));
app('log')->debug(sprintf('Skip transaction because amount is zero: "%s".', $transaction->transactionAmount));
Log::debug(sprintf('Skip transaction because amount is zero: "%s".', $transaction->transactionAmount));
continue;
}
app('log')->debug(sprintf('Include transaction because date is "%s".', $madeOn->format(self::DATE_TIME_FORMAT)));
Log::debug(sprintf('Include transaction because date is "%s".', $madeOn->format(self::DATE_TIME_FORMAT)));
$return[] = $transaction;
}
app('log')->info(sprintf('After filtering, set is %d transaction(s)', count($return)));
Log::info(sprintf('After filtering, set is %d transaction(s)', count($return)));
return $return;
}

41
app/Services/Nordigen/Conversion/RoutineManager.php

@ -38,6 +38,7 @@ use App\Services\Shared\Conversion\GeneratesIdentifier;
use App\Services\Shared\Conversion\ProgressInformation;
use App\Services\Shared\Conversion\RoutineManagerInterface;
use GrumpyDictator\FFIIIApiSupport\Exceptions\ApiHttpException;
use Illuminate\Support\Facades\Log;
/**
* Class RoutineManager
@ -101,8 +102,8 @@ class RoutineManager implements RoutineManagerInterface
*/
public function start(): array
{
app('log')->debug(sprintf('Now in %s', __METHOD__));
app('log')->debug(sprintf('The GoCardless API URL is %s', config('nordigen.url')));
Log::debug(sprintf('Now in %s', __METHOD__));
Log::debug(sprintf('The GoCardless API URL is %s', config('nordigen.url')));
// Step 1: get transactions from GoCardless
$this->downloadFromGoCardless();
@ -127,11 +128,11 @@ class RoutineManager implements RoutineManagerInterface
// then generate the transactions
$transactions = $this->transactionGenerator->getTransactions($this->downloaded);
app('log')->debug(sprintf('Generated %d Firefly III transactions.', count($transactions)));
Log::debug(sprintf('Generated %d Firefly III transactions.', count($transactions)));
// filter the transactions
$filtered = $this->transactionFilter->filter($transactions);
app('log')->debug(sprintf('Filtered down to %d Firefly III transactions.', count($filtered)));
Log::debug(sprintf('Filtered down to %d Firefly III transactions.', count($filtered)));
// collect errors from transactionProcessor.
$this->mergeMessages(count($transactions));
@ -183,7 +184,7 @@ class RoutineManager implements RoutineManagerInterface
private function generateRateLimitMessage(array $account, array $rateLimit): string
{
app('log')->debug('generateRateLimitMessage');
Log::debug('generateRateLimitMessage');
$message = '';
if (0 === $rateLimit['remaining'] && $rateLimit['reset'] > 1) {
$message = sprintf('You have no requests left for bank account "%s"', $account['name']);
@ -214,7 +215,7 @@ class RoutineManager implements RoutineManagerInterface
$message .= '. ';
}
$message .= '[Read more about GoCardless rate limits](https://docs.firefly-iii.org/references/faq/data-importer/salt-edge-gocardless/#i-am-rate-limited-by-gocardless).';
app('log')->debug(sprintf('Generated rate limit message: %s', $message));
Log::debug(sprintf('Generated rate limit message: %s', $message));
return $message;
}
@ -235,13 +236,13 @@ class RoutineManager implements RoutineManagerInterface
*/
private function downloadFromGoCardless(): void
{
app('log')->debug('Call transaction processor download.');
Log::debug('Call transaction processor download.');
try {
$this->downloaded = $this->transactionProcessor->download();
} catch (ImporterErrorException $e) {
app('log')->error('Could not download transactions from GoCardless.');
app('log')->error($e->getMessage());
Log::error('Could not download transactions from GoCardless.');
Log::error($e->getMessage());
// add error to current error thing:
$this->addError(0, sprintf('[a109]: Could not download from GoCardless: %s', $e->getMessage()));
@ -258,9 +259,9 @@ class RoutineManager implements RoutineManagerInterface
// collect accounts from the configuration, and join them with the rate limits
$configAccounts = $this->configuration->getAccounts();
foreach ($this->transactionProcessor->getRateLimits() as $account => $rateLimit) {
app('log')->debug(sprintf('Rate limit for account %s: %d request(s) left, %d second(s)', $account, $rateLimit['remaining'], $rateLimit['reset']));
Log::debug(sprintf('Rate limit for account %s: %d request(s) left, %d second(s)', $account, $rateLimit['remaining'], $rateLimit['reset']));
if (!array_key_exists($account, $configAccounts)) {
app('log')->error(sprintf('Account "%s" was not found in your configuration.', $account));
Log::error(sprintf('Account "%s" was not found in your configuration.', $account));
continue;
}
@ -270,7 +271,7 @@ class RoutineManager implements RoutineManagerInterface
private function collectTargetAccounts(): void
{
app('log')->debug('Generating Firefly III transactions.');
Log::debug('Generating Firefly III transactions.');
try {
$this->transactionGenerator->collectTargetAccounts();
@ -290,25 +291,25 @@ class RoutineManager implements RoutineManagerInterface
$userAccounts = $this->transactionGenerator->getUserAccounts();
// now we can report on target limits:
app('log')->debug('Add message about rate limits.');
Log::debug('Add message about rate limits.');
foreach ($this->rateLimits as $accountId => $rateLimit) {
// do not report if the remaining value is zero, but the reset time 1 or less.
// this seems to be some kind of default value.
// change: do not report when the reset time is less than 60 seconds.
if ($rateLimit['reset'] <= 60) {
app('log')->debug(sprintf('Account "%s" has no interesting rate limit information.', $accountId));
Log::debug(sprintf('Account "%s" has no interesting rate limit information.', $accountId));
continue;
}
app('log')->debug(sprintf('Add message about rate limits for account %s.', $accountId));
Log::debug(sprintf('Add message about rate limits for account %s.', $accountId));
$fireflyIIIAccount = $this->findAccountInfo($userAccounts, $accountId);
if (null === $fireflyIIIAccount) {
app('log')->debug('Found NO Firefly III account to report on, will not report rate limit.');
Log::debug('Found NO Firefly III account to report on, will not report rate limit.');
continue;
}
app('log')->debug(sprintf('Found Firefly III account #%d ("%s") to report on.', $fireflyIIIAccount['id'], $fireflyIIIAccount['name']));
Log::debug(sprintf('Found Firefly III account #%d ("%s") to report on.', $fireflyIIIAccount['id'], $fireflyIIIAccount['name']));
$message = $this->generateRateLimitMessage($fireflyIIIAccount, $rateLimit);
if (0 === $rateLimit['remaining']) {
$this->addWarning(0, $message);
@ -326,7 +327,7 @@ class RoutineManager implements RoutineManagerInterface
$total += count($transactions);
}
if (0 === $total) {
app('log')->warning('Downloaded nothing, will return nothing.');
Log::warning('Downloaded nothing, will return nothing.');
// add error to current error thing:
$this->addError(0, '[a111]: No transactions were downloaded from GoCardless. You may be rate limited or something else went wrong.');
$this->mergeMessages(1);
@ -344,8 +345,8 @@ class RoutineManager implements RoutineManagerInterface
try {
$this->transactionGenerator->collectNordigenAccounts();
} catch (ImporterErrorException $e) {
app('log')->error('Could not collect info on all GoCardless accounts, but this info isn\'t used at the moment anyway.');
app('log')->error($e->getMessage());
Log::error('Could not collect info on all GoCardless accounts, but this info isn\'t used at the moment anyway.');
Log::error($e->getMessage());
} catch (AgreementExpiredException $e) {
$this->addError(0, '[a112]: The connection between your bank and GoCardless has expired.');
$this->mergeMessages(1);

14
app/Services/Nordigen/Model/Account.php

@ -25,6 +25,8 @@ declare(strict_types=1);
namespace App\Services\Nordigen\Model;
use Illuminate\Support\Facades\Log;
/**
* Class Account
*/
@ -175,28 +177,28 @@ class Account
public function getFullName(): string
{
app('log')->debug('Account::getFullName()');
Log::debug('Account::getFullName()');
if ('' !== $this->getName()) {
app('log')->debug(sprintf('Return getName(): "%s"', $this->getName()));
Log::debug(sprintf('Return getName(): "%s"', $this->getName()));
return $this->getName();
}
if ('' !== $this->getDisplayName()) {
app('log')->debug(sprintf('Return getDisplayName(): "%s"', $this->getDisplayName()));
Log::debug(sprintf('Return getDisplayName(): "%s"', $this->getDisplayName()));
return $this->getDisplayName();
}
if ('' !== $this->getOwnerName()) {
app('log')->debug(sprintf('Return getOwnerName(): "%s"', $this->getOwnerName()));
Log::debug(sprintf('Return getOwnerName(): "%s"', $this->getOwnerName()));
return $this->getOwnerName();
}
if ('' !== $this->getIban()) {
app('log')->debug(sprintf('Return getIban(): "%s"', $this->getIban()));
Log::debug(sprintf('Return getIban(): "%s"', $this->getIban()));
return $this->getIban();
}
app('log')->warning('Account::getFullName(): no field with name, return "(no name)"');
Log::warning('Account::getFullName(): no field with name, return "(no name)"');
return '(no name)';
}

4
app/Services/Nordigen/Model/Balance.php

@ -25,6 +25,8 @@ declare(strict_types=1);
namespace App\Services\Nordigen\Model;
use Illuminate\Support\Facades\Log;
/**
* Class Balance
*/
@ -42,7 +44,7 @@ class Balance
public static function createFromArray(array $data): self
{
if (count($data) > 0) {
app('log')->debug('Create Balance from array', $data);
Log::debug('Create Balance from array', $data);
}
$self = new self();
$self->amount = trim($data['balanceAmount']['amount'] ?? '0');

5
app/Services/Nordigen/Request/GetTransactionsRequest.php

@ -31,6 +31,7 @@ use App\Exceptions\ImporterHttpException;
use App\Exceptions\RateLimitException;
use App\Services\Nordigen\Response\GetTransactionsResponse;
use App\Services\Shared\Response\Response;
use Illuminate\Support\Facades\Log;
/**
* Class GetTransactionsRequest
@ -67,7 +68,7 @@ class GetTransactionsRequest extends Request
$count = 0;
$transactions = $response['transactions'] ?? [];
if (!array_key_exists('transactions', $response)) {
app('log')->error('No transactions found in response');
Log::error('No transactions found in response');
}
foreach ($keys as $key) {
if (array_key_exists($key, $transactions)) {
@ -82,7 +83,7 @@ class GetTransactionsRequest extends Request
}
}
$total = count($return);
app('log')->debug(sprintf('Downloaded [%d:%d] transactions', $count, $total));
Log::debug(sprintf('Downloaded [%d:%d] transactions', $count, $total));
return new GetTransactionsResponse($return);
}

5
app/Services/Nordigen/Request/PostNewRequisitionRequest.php

@ -28,6 +28,7 @@ namespace App\Services\Nordigen\Request;
use App\Services\Nordigen\Response\NewRequisitionResponse;
use App\Services\Shared\Response\Response;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Facades\Log;
/**
* Class PostNewRequisitionRequest
@ -58,7 +59,7 @@ class PostNewRequisitionRequest extends Request
*/
public function post(): Response
{
app('log')->debug(sprintf('Now at %s', __METHOD__));
Log::debug(sprintf('Now at %s', __METHOD__));
$array
= [
'redirect' => route('010-build-link.callback'),
@ -68,7 +69,7 @@ class PostNewRequisitionRequest extends Request
];
$result = $this->authenticatedJsonPost($array);
app('log')->debug('Returned from POST: ', $result);
Log::debug('Returned from POST: ', $result);
return new NewRequisitionResponse($result);
}

3
app/Services/Nordigen/Request/PostNewTokenRequest.php

@ -30,6 +30,7 @@ use App\Services\Nordigen\Response\TokenSetResponse;
use App\Services\Shared\Response\Response;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Facades\Log;
/**
* Class PostNewTokenRequest
@ -68,7 +69,7 @@ class PostNewTokenRequest extends Request
]
);
} catch (GuzzleException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
throw new ImporterHttpException($e->getMessage(), 0, $e);
}

5
app/Services/Nordigen/Request/PostNewUserAgreement.php

@ -28,6 +28,7 @@ namespace App\Services\Nordigen\Request;
use App\Services\Nordigen\Response\NewUserAgreementResponse;
use App\Services\Shared\Response\Response;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Facades\Log;
/**
* Class PostNewUserAgreement
@ -59,7 +60,7 @@ class PostNewUserAgreement extends Request
*/
public function post(): Response
{
app('log')->debug(sprintf('Now at %s', __METHOD__));
Log::debug(sprintf('Now at %s', __METHOD__));
$array
= [
'institution_id' => $this->bank,
@ -68,7 +69,7 @@ class PostNewUserAgreement extends Request
];
$result = $this->authenticatedJsonPost($array);
app('log')->debug('Returned from POST: ', $result);
Log::debug('Returned from POST: ', $result);
return new NewUserAgreementResponse($result);
}

57
app/Services/Nordigen/Request/Request.php

@ -34,6 +34,7 @@ use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\TransferException;
use Illuminate\Support\Facades\Log;
use Psr\Http\Message\ResponseInterface;
/**
@ -74,7 +75,7 @@ abstract class Request
public function setParameters(array $parameters): void
{
app('log')->debug('Request parameters will be set to: ', $parameters);
Log::debug('Request parameters will be set to: ', $parameters);
$this->parameters = $parameters;
}
@ -96,7 +97,7 @@ abstract class Request
if (0 !== count($this->parameters)) {
$fullUrl = sprintf('%s?%s', $fullUrl, http_build_query($this->parameters));
}
app('log')->debug(sprintf('authenticatedGet(%s)', $fullUrl));
Log::debug(sprintf('authenticatedGet(%s)', $fullUrl));
$client = $this->getClient();
$body = null;
@ -116,19 +117,19 @@ abstract class Request
} catch (ClientException|GuzzleException|TransferException $e) {
$statusCode = $e->getCode();
if (429 === $statusCode) {
app('log')->debug(sprintf('Ran into exception: %s', get_class($e)));
Log::debug(sprintf('Ran into exception: %s', get_class($e)));
$this->logRateLimitHeaders($e->getResponse(), true);
// $this->reportRateLimit($fullUrl, $e);
$this->pauseForRateLimit($e->getResponse(), true);
return [];
}
app('log')->error(sprintf('Original error: %s: %s', get_class($e), $e->getMessage()));
Log::error(sprintf('Original error: %s: %s', get_class($e), $e->getMessage()));
// crash but there is a response, log it.
if (method_exists($e, 'getResponse') && method_exists($e, 'hasResponse') && $e->hasResponse()) {
$response = $e->getResponse();
app('log')->error(sprintf('%s', $response->getBody()->getContents()));
Log::error(sprintf('%s', $response->getBody()->getContents()));
}
// if no response, parse as normal error response
@ -161,7 +162,7 @@ abstract class Request
if (200 !== $res->getStatusCode()) {
// return body, class must handle this
app('log')->error(sprintf('[1] Status code is %d', $res->getStatusCode()));
Log::error(sprintf('[1] Status code is %d', $res->getStatusCode()));
$body = (string) $res->getBody();
}
@ -185,7 +186,7 @@ abstract class Request
throw new ImporterHttpException(sprintf('Body is empty. [2] Status code is %d.', $res->getStatusCode()));
}
if (config('importer.log_return_json')) {
app('log')->debug('JSON', $json);
Log::debug('JSON', $json);
}
return $json;
@ -238,7 +239,7 @@ abstract class Request
*/
protected function authenticatedJsonPost(array $json): array
{
app('log')->debug(sprintf('Now at %s', __METHOD__));
Log::debug(sprintf('Now at %s', __METHOD__));
$fullUrl = sprintf('%s/%s', $this->getBase(), $this->getUrl());
if (0 !== count($this->parameters)) {
@ -283,23 +284,23 @@ abstract class Request
$headers = $res->getHeaders();
$method = $fromErrorSituation ? 'error' : 'debug';
if (array_key_exists('http_x_ratelimit_limit', $headers)) {
app('log')->{$method}(sprintf('Rate limit: %s', trim(implode(' ', $headers['http_x_ratelimit_limit']))));
Log::{$method}(sprintf('Rate limit: %s', trim(implode(' ', $headers['http_x_ratelimit_limit']))));
}
if (array_key_exists('http_x_ratelimit_remaining', $headers)) {
app('log')->{$method}(sprintf('Rate limit remaining: %s', trim(implode(' ', $headers['http_x_ratelimit_remaining']))));
Log::{$method}(sprintf('Rate limit remaining: %s', trim(implode(' ', $headers['http_x_ratelimit_remaining']))));
}
if (array_key_exists('http_x_ratelimit_reset', $headers)) {
app('log')->{$method}(sprintf('Rate limit reset: %s', trim(implode(' ', $headers['http_x_ratelimit_reset']))));
Log::{$method}(sprintf('Rate limit reset: %s', trim(implode(' ', $headers['http_x_ratelimit_reset']))));
}
if (array_key_exists('http_x_ratelimit_account_success_limit', $headers)) {
app('log')->{$method}(sprintf('Account success rate limit: %s', trim(implode(' ', $headers['http_x_ratelimit_account_success_limit']))));
Log::{$method}(sprintf('Account success rate limit: %s', trim(implode(' ', $headers['http_x_ratelimit_account_success_limit']))));
}
if (array_key_exists('http_x_ratelimit_account_success_remaining', $headers)) {
app('log')->{$method}(sprintf('Account success rate limit remaining: %s', trim(implode(' ', $headers['http_x_ratelimit_account_success_remaining']))));
Log::{$method}(sprintf('Account success rate limit remaining: %s', trim(implode(' ', $headers['http_x_ratelimit_account_success_remaining']))));
}
if (array_key_exists('http_x_ratelimit_account_success_reset', $headers)) {
app('log')->{$method}(sprintf('Account success rate limit reset: %s', trim(implode(' ', $headers['http_x_ratelimit_account_success_reset']))));
Log::{$method}(sprintf('Account success rate limit reset: %s', trim(implode(' ', $headers['http_x_ratelimit_account_success_reset']))));
}
}
@ -309,14 +310,14 @@ abstract class Request
private function pauseForRateLimit(ResponseInterface $res, bool $fromErrorSituation): void
{
$method = $fromErrorSituation ? 'error' : 'debug';
app('log')->{$method}('Now in pauseForRateLimit');
Log::{$method}('Now in pauseForRateLimit');
$headers = $res->getHeaders();
// raw header values for debugging:
app('log')->debug(sprintf('http_x_ratelimit_remaining: %s', json_encode($headers['http_x_ratelimit_remaining'] ?? false)));
app('log')->debug(sprintf('http_x_ratelimit_reset: %s', json_encode($headers['http_x_ratelimit_reset'] ?? false)));
app('log')->debug(sprintf('http_x_ratelimit_account_success_remaining: %s', json_encode($headers['http_x_ratelimit_account_success_remaining'] ?? false)));
app('log')->debug(sprintf('http_x_ratelimit_account_success_reset: %s', json_encode($headers['http_x_ratelimit_account_success_reset'] ?? false)));
Log::debug(sprintf('http_x_ratelimit_remaining: %s', json_encode($headers['http_x_ratelimit_remaining'] ?? false)));
Log::debug(sprintf('http_x_ratelimit_reset: %s', json_encode($headers['http_x_ratelimit_reset'] ?? false)));
Log::debug(sprintf('http_x_ratelimit_account_success_remaining: %s', json_encode($headers['http_x_ratelimit_account_success_remaining'] ?? false)));
Log::debug(sprintf('http_x_ratelimit_account_success_reset: %s', json_encode($headers['http_x_ratelimit_account_success_reset'] ?? false)));
// first the normal rate limit:
$remaining = (int) ($headers['http_x_ratelimit_remaining'][0] ?? -2);
@ -330,11 +331,11 @@ abstract class Request
// save the remaining info in the object.
$this->reset = $reset;
if ($remaining > -1) { // zero or more.
app('log')->{$method}('Save the account success limits? YES');
Log::{$method}('Save the account success limits? YES');
$this->remaining = $remaining;
}
if ($remaining < 0) { // less than zero.
app('log')->{$method}('Save the account success limits? NO');
Log::{$method}('Save the account success limits? NO');
}
$this->reportAndPause('Account success limit', $remaining, $reset, $fromErrorSituation);
@ -344,7 +345,7 @@ abstract class Request
{
$return = '';
if ($reset < 0) {
app('log')->warning('The reset time is negative!');
Log::warning('The reset time is negative!');
$return = '-';
$reset = abs($reset);
}
@ -382,19 +383,19 @@ abstract class Request
}
$resetString = self::formatTime($reset);
if ($remaining >= 5) {
app('log')->debug(sprintf('%s: %d requests left, and %s before the limit resets.', $type, $remaining, $resetString));
Log::debug(sprintf('%s: %d requests left, and %s before the limit resets.', $type, $remaining, $resetString));
return;
}
if ($remaining >= 1) {
app('log')->warning(sprintf('%s: %d requests remaining, it will take %s for the limit to reset.', $type, $remaining, $resetString));
Log::warning(sprintf('%s: %d requests remaining, it will take %s for the limit to reset.', $type, $remaining, $resetString));
return;
}
// extra message if error.
if ($reset > 1) {
app('log')->error(sprintf('%s: Have zero requests left!', $type));
Log::error(sprintf('%s: Have zero requests left!', $type));
}
// do exit?
@ -404,16 +405,16 @@ abstract class Request
// no exit. Do sleep?
if ($reset < 300 && $reset > 0) {
app('log')->info(sprintf('%s reached, sleep %s for reset.', $type, $resetString));
Log::info(sprintf('%s reached, sleep %s for reset.', $type, $resetString));
sleep($reset + 1);
return;
}
if ($reset >= 300) {
app('log')->error(sprintf('%s: Refuse to sleep for %s, throw exception instead.', $type, $resetString));
Log::error(sprintf('%s: Refuse to sleep for %s, throw exception instead.', $type, $resetString));
}
if ($reset < 0) {
app('log')->error(sprintf('%s: Reset time is a negative number (%d = %s), this is an issue.', $type, $reset, $resetString));
Log::error(sprintf('%s: Reset time is a negative number (%d = %s), this is an issue.', $type, $reset, $resetString));
}
if ($fromErrorSituation) {
throw new RateLimitException(sprintf('%s reached: %d requests remaining, and %s before the limit resets.', $type, $remaining, $resetString));

5
app/Services/Nordigen/Response/ListAccountsResponse.php

@ -29,6 +29,7 @@ use App\Services\Nordigen\Model\Account;
use App\Services\Shared\Response\Response;
use Countable;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use Iterator;
/**
@ -44,11 +45,11 @@ class ListAccountsResponse extends Response implements \Iterator, \Countable
{
$this->accounts = [];
app('log')->debug('ListAccountsResponse:', $data ?? []);
Log::debug('ListAccountsResponse:', $data ?? []);
/** @var string $account */
foreach ($data['accounts'] as $account) {
app('log')->debug(sprintf('ListAccountsResponse includes account "%s"', $account));
Log::debug(sprintf('ListAccountsResponse includes account "%s"', $account));
$this->accounts[] = Account::createFromIdentifier($account);
}
$this->collection = new Collection($this->accounts);

31
app/Services/Nordigen/Services/AccountInformationCollector.php

@ -36,6 +36,7 @@ use App\Services\Nordigen\Request\GetAccountBasicRequest;
use App\Services\Nordigen\Request\GetAccountInformationRequest;
use App\Services\Nordigen\Response\ArrayResponse;
use App\Services\Nordigen\TokenManager;
use Illuminate\Support\Facades\Log;
/**
* Class AccountInformationCollector
@ -49,17 +50,17 @@ class AccountInformationCollector
*/
public static function collectInformation(Account $account, bool $overruleSettings = false): Account
{
app('log')->debug(sprintf('Now in %s', __METHOD__));
Log::debug(sprintf('Now in %s', __METHOD__));
// you know nothing, Jon Snow
$detailedAccount = $account;
if (config('nordigen.get_account_details') || $overruleSettings) {
try {
app('log')->debug('Get account details is ENABLED.');
Log::debug('Get account details is ENABLED.');
$detailedAccount = self::getAccountDetails($detailedAccount);
} catch (ImporterErrorException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
// ignore error otherwise for now.
$detailedAccount->setStatus('no-info');
$detailedAccount->setName('Unknown account');
@ -68,12 +69,12 @@ class AccountInformationCollector
if (config('nordigen.get_balance_details') || $overruleSettings) {
app('log')->debug('Get account balance is ENABLED.');
Log::debug('Get account balance is ENABLED.');
try {
$detailedAccount = self::getBalanceDetails($detailedAccount);
} catch (ImporterErrorException|ImporterHttpException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
// ignore error otherwise for now.
$status = $detailedAccount->getStatus();
if ('no-info' === $status) {
@ -86,11 +87,11 @@ class AccountInformationCollector
}
if (!config('nordigen.get_account_details') && !$overruleSettings) {
app('log')->debug('Get account details is DISABLED.');
Log::debug('Get account details is DISABLED.');
}
if (!config('nordigen.get_balance_details') && !$overruleSettings) {
app('log')->debug('Get account balance is DISABLED.');
Log::debug('Get account balance is DISABLED.');
}
// also collect some extra information, but don't use it right now.
@ -102,7 +103,7 @@ class AccountInformationCollector
*/
protected static function getAccountDetails(Account $account): Account
{
app('log')->debug(sprintf('Now in %s(%s)', __METHOD__, $account->getIdentifier()));
Log::debug(sprintf('Now in %s(%s)', __METHOD__, $account->getIdentifier()));
$url = config('nordigen.url');
$accessToken = TokenManager::getAccessToken();
@ -120,14 +121,14 @@ class AccountInformationCollector
}
if (!array_key_exists('account', $response->data)) {
app('log')->error('Missing account array', $response->data);
Log::error('Missing account array', $response->data);
throw new ImporterErrorException('No account array received, perhaps rate limited.');
}
$information = $response->data['account'];
app('log')->debug('getAccountDetails: Collected information for account', $information);
Log::debug('getAccountDetails: Collected information for account', $information);
$account->setResourceId($information['resource_id'] ?? '');
$account->setBban($information['bban'] ?? '');
@ -162,7 +163,7 @@ class AccountInformationCollector
private static function getBalanceDetails(Account $account): Account
{
app('log')->debug(sprintf('Now in %s(%s)', __METHOD__, $account->getIdentifier()));
Log::debug(sprintf('Now in %s(%s)', __METHOD__, $account->getIdentifier()));
$url = config('nordigen.url');
$accessToken = TokenManager::getAccessToken();
@ -179,7 +180,7 @@ class AccountInformationCollector
}
if (array_key_exists('balances', $response->data)) {
foreach ($response->data['balances'] as $array) {
app('log')->debug(sprintf('Added "%s" balance "%s"', $array['balanceType'], $array['balanceAmount']['amount']));
Log::debug(sprintf('Added "%s" balance "%s"', $array['balanceType'], $array['balanceAmount']['amount']));
$account->addBalance(Balance::createFromArray($array));
}
}
@ -189,7 +190,7 @@ class AccountInformationCollector
private static function getBasicDetails(Account $account): Account
{
app('log')->debug(sprintf('Now in %s(%s)', __METHOD__, $account->getIdentifier()));
Log::debug(sprintf('Now in %s(%s)', __METHOD__, $account->getIdentifier()));
$url = config('nordigen.url');
$accessToken = TokenManager::getAccessToken();
@ -199,11 +200,11 @@ class AccountInformationCollector
/** @var ArrayResponse $response */
$response = $request->get();
$array = $response->data;
app('log')->debug('Response for basic information request:', $array);
Log::debug('Response for basic information request:', $array);
// save IBAN if not already present
if (array_key_exists('iban', $array) && '' !== $array['iban'] && '' === $account->getIban()) {
app('log')->debug('Set new IBAN from basic details.');
Log::debug('Set new IBAN from basic details.');
$account->setIban($array['iban']);
}

25
app/Services/Nordigen/TokenManager.php

@ -31,6 +31,7 @@ use App\Services\Nordigen\Authentication\SecretManager;
use App\Services\Nordigen\Request\PostNewTokenRequest;
use App\Services\Nordigen\Response\TokenSetResponse;
use App\Services\Session\Constants;
use Illuminate\Support\Facades\Log;
use JetBrains\PhpStorm\NoReturn;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
@ -45,7 +46,7 @@ class TokenManager
*/
public static function getAccessToken(): string
{
// app('log')->debug(sprintf('Now at %s', __METHOD__));
// Log::debug(sprintf('Now at %s', __METHOD__));
self::validateAllTokens();
try {
@ -62,7 +63,7 @@ class TokenManager
*/
public static function validateAllTokens(): void
{
// app('log')->debug(sprintf('Now at %s', __METHOD__));
// Log::debug(sprintf('Now at %s', __METHOD__));
// is there a valid access and refresh token?
if (self::hasValidRefreshToken() && self::hasValidAccessToken()) {
return;
@ -87,8 +88,8 @@ class TokenManager
{
$hasToken = session()->has(Constants::NORDIGEN_REFRESH_TOKEN);
if (false === $hasToken) {
app('log')->debug(sprintf('Now at %s', __METHOD__));
app('log')->debug('No Nordigen refresh token, so return false.');
Log::debug(sprintf('Now at %s', __METHOD__));
Log::debug('No Nordigen refresh token, so return false.');
return false;
}
@ -106,8 +107,8 @@ class TokenManager
{
$hasAccessToken = session()->has(Constants::NORDIGEN_ACCESS_TOKEN);
if (false === $hasAccessToken) {
app('log')->debug(sprintf('Now at %s', __METHOD__));
app('log')->debug('No Nordigen token is present, so no valid access token');
Log::debug(sprintf('Now at %s', __METHOD__));
Log::debug('No Nordigen token is present, so no valid access token');
return false;
}
@ -117,25 +118,25 @@ class TokenManager
} catch (ContainerExceptionInterface|NotFoundExceptionInterface $e) {
$tokenValidity = 0;
}
// app('log')->debug(sprintf('Nordigen token is valid until %s', date('Y-m-d H:i:s', $tokenValidity)));
// Log::debug(sprintf('Nordigen token is valid until %s', date('Y-m-d H:i:s', $tokenValidity)));
$result = time() < $tokenValidity;
if (false === $result) {
app('log')->debug('Nordigen token is no longer valid');
Log::debug('Nordigen token is no longer valid');
return false;
}
// app('log')->debug('Nordigen token is valid.');
// Log::debug('Nordigen token is valid.');
return true;
}
public static function hasExpiredRefreshToken(): bool
{
// app('log')->debug(sprintf('Now at %s', __METHOD__));
// Log::debug(sprintf('Now at %s', __METHOD__));
$hasToken = session()->has(Constants::NORDIGEN_REFRESH_TOKEN);
if (false === $hasToken) {
app('log')->debug('No refresh token, so return false.');
Log::debug('No refresh token, so return false.');
return false;
}
@ -156,7 +157,7 @@ class TokenManager
*/
public static function getNewTokenSet(string $identifier, string $key): void
{
app('log')->debug(sprintf('Now at %s', __METHOD__));
Log::debug(sprintf('Now at %s', __METHOD__));
$client = new PostNewTokenRequest($identifier, $key);
$client->setTimeOut(config('importer.connection.timeout'));

8
app/Services/Shared/Conversion/GeneratesIdentifier.php

@ -25,6 +25,8 @@ declare(strict_types=1);
namespace App\Services\Shared\Conversion;
use Illuminate\Support\Facades\Log;
/**
* Trait GeneratesIdentifier
*/
@ -40,15 +42,15 @@ trait GeneratesIdentifier
protected function generateIdentifier(): void
{
app('log')->debug('Going to generate conversion routine identifier.');
Log::debug('Going to generate conversion routine identifier.');
$disk = \Storage::disk($this->diskName);
$count = 0;
do {
$generatedId = sprintf('conversion-%s', \Str::random(12));
++$count;
app('log')->debug(sprintf('Attempt #%d results in "%s"', $count, $generatedId));
Log::debug(sprintf('Attempt #%d results in "%s"', $count, $generatedId));
} while ($count < 30 && $disk->exists($generatedId));
$this->identifier = $generatedId;
app('log')->info(sprintf('Job identifier is "%s"', $generatedId));
Log::info(sprintf('Job identifier is "%s"', $generatedId));
}
}

51
app/Services/Shared/Conversion/RoutineStatusManager.php

@ -28,6 +28,7 @@ namespace App\Services\Shared\Conversion;
use App\Exceptions\ImporterErrorException;
use App\Services\Session\Constants;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Support\Facades\Log;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
@ -41,7 +42,7 @@ class RoutineStatusManager
public static function addError(string $identifier, int $index, string $error): void
{
$lineNo = $index + 1;
app('log')->debug(sprintf('Add error on index #%d (line no. %d): %s', $index, $lineNo, $error));
Log::debug(sprintf('Add error on index #%d (line no. %d): %s', $index, $lineNo, $error));
$disk = \Storage::disk(self::DISK_NAME);
@ -50,7 +51,7 @@ class RoutineStatusManager
try {
$status = ConversionStatus::fromArray(json_decode($disk->get($identifier), true, 512, JSON_THROW_ON_ERROR));
} catch (\JsonException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
$status = new ConversionStatus();
}
$status->errors[$index] ??= [];
@ -58,14 +59,14 @@ class RoutineStatusManager
self::storeConversionStatus($identifier, $status);
}
} catch (FileNotFoundException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
}
}
public static function addRateLimit(string $identifier, int $index, string $message): void
{
$lineNo = $index + 1;
app('log')->debug(sprintf('Add rate limit message on index #%d (line no. %d): %s', $index, $lineNo, $message));
Log::debug(sprintf('Add rate limit message on index #%d (line no. %d): %s', $index, $lineNo, $message));
$disk = \Storage::disk(self::DISK_NAME);
@ -74,7 +75,7 @@ class RoutineStatusManager
try {
$status = ConversionStatus::fromArray(json_decode($disk->get($identifier), true, 512, JSON_THROW_ON_ERROR));
} catch (\JsonException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
$status = new ConversionStatus();
}
$status->rateLimits[$index] ??= [];
@ -82,28 +83,28 @@ class RoutineStatusManager
self::storeConversionStatus($identifier, $status);
}
} catch (FileNotFoundException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
}
}
private static function storeConversionStatus(string $identifier, ConversionStatus $status): void
{
app('log')->debug(sprintf('Now in storeConversionStatus(%s): %s', $identifier, $status->status));
app('log')->debug(sprintf('Messages: %d, warnings: %d, errors: %d', count($status->messages), count($status->warnings), count($status->errors)));
Log::debug(sprintf('Now in storeConversionStatus(%s): %s', $identifier, $status->status));
Log::debug(sprintf('Messages: %d, warnings: %d, errors: %d', count($status->messages), count($status->warnings), count($status->errors)));
$disk = \Storage::disk(self::DISK_NAME);
try {
$disk->put($identifier, json_encode($status->toArray(), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT));
} catch (\JsonException $e) {
// do nothing
app('log')->error($e->getMessage());
Log::error($e->getMessage());
}
}
public static function addMessage(string $identifier, int $index, string $message): void
{
$lineNo = $index + 1;
app('log')->debug(sprintf('Add message on index #%d (line no. %d): %s', $index, $lineNo, $message));
Log::debug(sprintf('Add message on index #%d (line no. %d): %s', $index, $lineNo, $message));
$disk = \Storage::disk(self::DISK_NAME);
@ -112,7 +113,7 @@ class RoutineStatusManager
try {
$status = ConversionStatus::fromArray(json_decode($disk->get($identifier), true, 512, JSON_THROW_ON_ERROR));
} catch (\JsonException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
$status = new ConversionStatus();
}
$status->messages[$index] ??= [];
@ -120,14 +121,14 @@ class RoutineStatusManager
self::storeConversionStatus($identifier, $status);
}
} catch (FileNotFoundException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
}
}
public static function addWarning(string $identifier, int $index, string $warning): void
{
$lineNo = $index + 1;
app('log')->debug(sprintf('Add warning on index #%d (line no. %d): %s', $index, $lineNo, $warning));
Log::debug(sprintf('Add warning on index #%d (line no. %d): %s', $index, $lineNo, $warning));
$disk = \Storage::disk(self::DISK_NAME);
@ -136,7 +137,7 @@ class RoutineStatusManager
try {
$status = ConversionStatus::fromArray(json_decode($disk->get($identifier), true, 512, JSON_THROW_ON_ERROR));
} catch (\JsonException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
$status = new ConversionStatus();
}
$status->warnings[$index] ??= [];
@ -144,7 +145,7 @@ class RoutineStatusManager
self::storeConversionStatus($identifier, $status);
}
} catch (FileNotFoundException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
}
}
@ -160,8 +161,8 @@ class RoutineStatusManager
throw new ImporterErrorException('No identifier found');
}
}
app('log')->debug(sprintf('Now in setConversionStatus(%s)', $status));
app('log')->debug(sprintf('Found "%s" in the session', $identifier));
Log::debug(sprintf('Now in setConversionStatus(%s)', $status));
Log::debug(sprintf('Found "%s" in the session', $identifier));
$jobStatus = self::startOrFindConversion($identifier);
$jobStatus->status = $status;
@ -173,32 +174,32 @@ class RoutineStatusManager
public static function startOrFindConversion(string $identifier): ConversionStatus
{
app('log')->debug(sprintf('Now in startOrFindConversion(%s)', $identifier));
Log::debug(sprintf('Now in startOrFindConversion(%s)', $identifier));
$disk = \Storage::disk(self::DISK_NAME);
// app('log')->debug(sprintf('Try to see if file exists for conversion "%s".', $identifier));
// Log::debug(sprintf('Try to see if file exists for conversion "%s".', $identifier));
if ($disk->exists($identifier)) {
// app('log')->debug(sprintf('Status file exists for conversion "%s".', $identifier));
// Log::debug(sprintf('Status file exists for conversion "%s".', $identifier));
try {
$array = json_decode($disk->get($identifier), true, 512, JSON_THROW_ON_ERROR);
$status = ConversionStatus::fromArray($array);
} catch (FileNotFoundException|\JsonException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
$status = new ConversionStatus();
}
app('log')->debug(sprintf('Conversion status is "%s"', $status->status));
Log::debug(sprintf('Conversion status is "%s"', $status->status));
return $status;
}
app('log')->debug('File does not exist or error, create a new one.');
Log::debug('File does not exist or error, create a new one.');
$status = new ConversionStatus();
try {
$disk->put($identifier, json_encode($status->toArray(), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT));
} catch (\JsonException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
}
app('log')->debug('Return status.', $status->toArray());
Log::debug('Return status.', $status->toArray());
return $status;
}

13
app/Services/Shared/File/FileContentSherlock.php

@ -26,6 +26,7 @@ namespace App\Services\Shared\File;
use Genkgo\Camt\Config;
use Genkgo\Camt\Reader;
use Illuminate\Support\Facades\Log;
/**
* Class FileContentSherlock
@ -47,12 +48,12 @@ class FileContentSherlock
try {
$message = $this->camtReader->readFile($file);
app('log')->debug('CAMT.053 Check on file: positive');
Log::debug('CAMT.053 Check on file: positive');
return 'camt';
} catch (\Exception $e) {
app('log')->debug('CAMT.053 Check on file: negative');
app('log')->debug($e->getMessage());
Log::debug('CAMT.053 Check on file: negative');
Log::debug($e->getMessage());
}
return 'csv';
@ -66,12 +67,12 @@ class FileContentSherlock
try {
$this->camtReader->readString($content);
app('log')->debug('CAMT.053 Check of content: positive');
Log::debug('CAMT.053 Check of content: positive');
return 'camt';
} catch (\Exception $e) {
app('log')->debug('CAMT.053 Check of content: negative');
// app('log')->debug($e->getMessage());
Log::debug('CAMT.053 Check of content: negative');
// Log::debug($e->getMessage());
}
return 'csv';

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

@ -50,14 +50,14 @@ class ApiSubmitter
{
use ProgressInformation;
private array $accountInfo;
private bool $addTag;
private array $accountInfo;
private bool $addTag;
private Configuration $configuration;
private bool $createdTag;
private array $mapping;
private string $tag;
private string $tagDate;
private string $vanityURL;
private bool $createdTag;
private array $mapping;
private string $tag;
private string $tagDate;
private string $vanityURL;
/**
* @throws ImporterErrorException
@ -69,54 +69,34 @@ class ApiSubmitter
$this->tagDate = date('Y-m-d');
$count = count($lines);
$uniqueCount = 0;
app('log')->info(
sprintf(
'Going to submit %d transactions to your Firefly III instance.',
$count
)
);
Log::info(sprintf('Going to submit %d transactions to your Firefly III instance.', $count));
$this->vanityURL = SecretManager::getVanityURL();
$this->vanityURL = SecretManager::getVanityURL();
app('log')->debug(sprintf('Vanity URL : "%s"', $this->vanityURL));
Log::debug(sprintf('Vanity URL : "%s"', $this->vanityURL));
/**
* @var int $index
* @var int $index
* @var array $line
*/
foreach ($lines as $index => $line) {
app('log')->debug(
sprintf('Now submitting transaction %d/%d', $index + 1, $count)
);
Log::debug(sprintf('Now submitting transaction %d/%d', $index + 1, $count));
// Update progress tracking
SubmissionStatusManager::updateProgress(
$this->identifier,
$index + 1,
$count
);
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) {
app('log')->debug(
sprintf(
'Transaction #%d is not checked beforehand on uniqueness.',
$index + 1
)
);
Log::debug(sprintf('Transaction #%d is not checked beforehand on uniqueness.', $index + 1));
++$uniqueCount;
}
if (true === $unique) {
app('log')->debug(
sprintf('Transaction #%d is unique.', $index + 1)
);
Log::debug(sprintf('Transaction #%d is unique.', $index + 1));
++$uniqueCount;
}
if (false === $unique) {
app('log')->debug(
sprintf('Transaction #%d is NOT unique.', $index + 1)
);
Log::debug(sprintf('Transaction #%d is NOT unique.', $index + 1));
continue;
}
@ -124,15 +104,8 @@ class ApiSubmitter
$this->addTagToGroups($groupInfo);
}
app('log')->info(
sprintf(
'Done submitting %d transactions to your Firefly III instance.',
$count
)
);
app('log')->info(
sprintf('Actually imported and not duplicate: %d.', $uniqueCount)
);
Log::info(sprintf('Done submitting %d transactions to your Firefly III instance.', $count));
Log::info(sprintf('Actually imported and not duplicate: %d.', $uniqueCount));
}
private function parseTag(): string
@ -176,12 +149,7 @@ class ApiSubmitter
private function uniqueTransaction(int $index, array $line): ?bool
{
if ('cell' !== $this->configuration->getDuplicateDetectionMethod()) {
app('log')->debug(
sprintf(
'Duplicate detection method is "%s", so this method is skipped (return true).',
$this->configuration->getDuplicateDetectionMethod()
)
);
Log::debug(sprintf('Duplicate detection method is "%s", so this method is skipped (return true).', $this->configuration->getDuplicateDetectionMethod()));
return null;
}
@ -192,36 +160,16 @@ class ApiSubmitter
$field = 'note' === $field ? 'notes' : $field;
$value = '';
foreach ($transactions as $transactionIndex => $transaction) {
$value = (string) ($transaction[$field] ?? '');
$value = (string)($transaction[$field] ?? '');
if ('' === $value) {
app('log')->debug(
sprintf(
'Identifier-based duplicate detection found no value ("") for field "%s" in transaction #%d (index #%d).',
$field,
$index,
$transactionIndex
)
);
Log::debug(sprintf('Identifier-based duplicate detection found no value ("") for field "%s" in transaction #%d (index #%d).', $field, $index, $transactionIndex));
continue;
}
$searchResult = $this->searchField($field, $value);
if (0 !== $searchResult) {
app('log')->debug(
sprintf(
'Looks like field "%s" with value "%s" is not unique, found in group #%d. Return false',
$field,
$value,
$searchResult
)
);
$message = sprintf(
'[a115]: There is already a transaction with %s "%s" (<a href="%s/transactions/show/%d">link</a>).',
$field,
$value,
$this->vanityURL,
$searchResult
);
Log::debug(sprintf('Looks like field "%s" with value "%s" is not unique, found in group #%d. Return false', $field, $value, $searchResult));
$message = sprintf('[a115]: There is already a transaction with %s "%s" (<a href="%s/transactions/show/%d">link</a>).', $field, $value, $this->vanityURL, $searchResult);
if (false === config('importer.ignore_duplicate_errors')) {
$this->addError($index, $message);
}
@ -229,13 +177,7 @@ class ApiSubmitter
return false;
}
}
app('log')->debug(
sprintf(
'Looks like field "%s" with value "%s" is unique, return false.',
$field,
$value
)
);
Log::debug(sprintf('Looks like field "%s" with value "%s" is unique, return false.', $field, $value));
return true;
}
@ -249,18 +191,11 @@ class ApiSubmitter
$searchModifier = config(sprintf('csv.search_modifier.%s', $field));
$query = sprintf('%s:"%s"', $searchModifier, $value);
app('log')->debug(
sprintf(
'Going to search for %s:%s using query %s',
$field,
$value,
$query
)
);
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);
@ -269,21 +204,15 @@ class ApiSubmitter
/** @var GetTransactionsResponse $response */
$response = $request->get();
} catch (ApiHttpException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
return 0;
}
if (0 === $response->count()) {
return 0;
}
$first = $response->current();
app('log')->debug(
sprintf(
'Found %d transaction(s). Return group ID #%d.',
$response->count(),
$first->id
)
);
$first = $response->current();
Log::debug(sprintf('Found %d transaction(s). Return group ID #%d.', $response->count(), $first->id));
return $first->id;
}
@ -298,9 +227,7 @@ class ApiSubmitter
$request = new PostTransactionRequest($url, $token);
$request->setVerify(config('importer.connection.verify'));
$request->setTimeOut(config('importer.connection.timeout'));
app('log')->debug(
sprintf('Submitting to Firefly III: %s', json_encode($line))
);
Log::debug(sprintf('Submitting to Firefly III: %s', json_encode($line)));
$request->setBody($line);
try {
@ -315,33 +242,19 @@ class ApiSubmitter
$isDeleted = true;
}
}
if (
true === $isDeleted
&& false === config('importer.ignore_not_found_transactions')
) {
$this->addWarning(
$index,
'The transaction was created, but deleted by a rule.'
);
app('log')->error($e->getMessage());
if (true === $isDeleted && false === config('importer.ignore_not_found_transactions')) {
$this->addWarning($index, 'The transaction was created, but deleted by a rule.');
Log::error($e->getMessage());
return $return;
}
if (
true === $isDeleted
&& true === config('importer.ignore_not_found_transactions')
) {
Log::info(
'The transaction was deleted by a rule, but this is ignored by the importer.'
);
if (true === $isDeleted && true === config('importer.ignore_not_found_transactions')) {
Log::info('The transaction was deleted by a rule, but this is ignored by the importer.');
return $return;
}
$message = sprintf(
'[a116]: Submission HTTP error: %s',
e($e->getMessage())
);
app('log')->error($e->getMessage());
$message = sprintf('[a116]: Submission HTTP error: %s', e($e->getMessage()));
Log::error($e->getMessage());
$this->addError($index, $message);
return $return;
@ -349,24 +262,13 @@ class ApiSubmitter
if ($response instanceof ValidationErrorResponse) {
foreach ($response->errors->messages() as $key => $errors) {
app('log')->error(
sprintf('Submission error: %d', $key),
$errors
);
Log::error(sprintf('Submission error: %d', $key), $errors);
foreach ($errors as $error) {
$msg = sprintf(
'[a117]: %s: %s (original value: "%s")',
$key,
$error,
$this->getOriginalValue($key, $line)
);
if (
false === $this->isDuplicationError($key, $error)
|| false === config('importer.ignore_duplicate_errors')
) {
$msg = sprintf('[a117]: %s: %s (original value: "%s")', $key, $error, $this->getOriginalValue($key, $line));
if (false === $this->isDuplicationError($key, $error) || false === config('importer.ignore_duplicate_errors')) {
$this->addError($index, $msg);
}
app('log')->error($msg);
Log::error($msg);
}
}
@ -375,11 +277,10 @@ 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.';
app('log')->error($message, $response->getRawData());
$message = '[a118]: Could not create transaction. Unexpected empty response from Firefly III. Check the logs.';
Log::error($message, $response->getRawData());
$this->addError($index, $message);
return $return;
@ -387,39 +288,21 @@ class ApiSubmitter
// perhaps zero transactions in the array.
if (0 === count($group->transactions)) {
$message
= '[a119]: Could not create transaction. Transaction-count from Firefly III is zero. Check the logs.';
app('log')->error($message, $response->getRawData());
$message = '[a119]: Could not create transaction. Transaction-count from Firefly III is zero. Check the logs.';
Log::error($message, $response->getRawData());
$this->addError($index, $message);
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);
$this->compareArrays($index, $line, $group);
app('log')->info($message);
Log::info($message);
$return['journals'][$transaction->id] = $transaction->tags;
}
}
@ -429,14 +312,12 @@ class ApiSubmitter
private function cleanupLine(array $line): array
{
app('log')->debug('Going to map data for this line.');
Log::debug('Going to map data for this line.');
if (array_key_exists(0, $this->mapping)) {
app('log')->debug(
'Configuration has mapping for opposing account name!'
);
Log::debug('Configuration has mapping for opposing account name!');
/**
* @var int $index
* @var int $index
* @var array $transaction
*/
foreach ($line['transactions'] as $index => $transaction) {
@ -444,47 +325,26 @@ class ApiSubmitter
// replace destination_name with destination_id
$destination = $transaction['destination_name'] ?? '';
if (array_key_exists($destination, $this->mapping[0])) {
unset(
$transaction['destination_name'],
$transaction['destination_iban']
);
$transaction['destination_id']
= $this->mapping[0][$destination];
app('log')->debug(
sprintf(
'Replaced destination name "%s" with a reference to account id #%d',
$destination,
$this->mapping[0][$destination]
)
);
unset($transaction['destination_name'], $transaction['destination_iban']);
$transaction['destination_id'] = $this->mapping[0][$destination];
Log::debug(sprintf('Replaced destination name "%s" with a reference to account id #%d', $destination, $this->mapping[0][$destination]));
}
}
if ('deposit' === $transaction['type']) {
// replace source_name with source_id
$source = $transaction['source_name'] ?? '';
if (array_key_exists($source, $this->mapping[0])) {
unset(
$transaction['source_name'],
$transaction['source_iban']
);
unset($transaction['source_name'], $transaction['source_iban']);
$transaction['source_id'] = $this->mapping[0][$source];
app('log')->debug(
sprintf(
'Replaced source name "%s" with a reference to account id #%d',
$source,
$this->mapping[0][$source]
)
);
Log::debug(sprintf('Replaced source name "%s" with a reference to account id #%d', $source, $this->mapping[0][$source]));
}
}
if ('' === trim((string)$transaction['description'] ?? '')) {
$transaction['description'] = '(no description)';
}
$line['transactions'][$index] = $this->updateTransactionType(
$transaction
);
$line['transactions'][$index] = $this->updateTransactionType($transaction);
}
}
@ -493,23 +353,16 @@ class ApiSubmitter
private function updateTransactionType(array $transaction): array
{
if (
array_key_exists('source_id', $transaction)
&& array_key_exists('destination_id', $transaction)
) {
app('log')->debug('Transaction has source_id/destination_id');
if (array_key_exists('source_id', $transaction) && array_key_exists('destination_id', $transaction)) {
Log::debug('Transaction has source_id/destination_id');
$sourceId = (int)$transaction['source_id'];
$destinationId = (int)$transaction['destination_id'];
$sourceType = $this->accountInfo[$sourceId] ?? 'unknown';
$destinationType = $this->accountInfo[$destinationId] ?? 'unknown';
$combi = sprintf('%s-%s', $sourceType, $destinationType);
app('log')->debug(
sprintf('Account type combination is "%s"', $combi)
);
Log::debug(sprintf('Account type combination is "%s"', $combi));
if ('asset-asset' === $combi) {
app('log')->debug(
'Both accounts are assets, so this transaction is a transfer.'
);
Log::debug('Both accounts are assets, so this transaction is a transfer.');
$transaction['type'] = 'transfer';
}
}
@ -526,74 +379,35 @@ class ApiSubmitter
if (3 !== count($parts)) {
return '(unknown)';
}
$index = (int) $parts[1];
$index = (int)$parts[1];
return (string) ($transaction['transactions'][$index][$parts[2]]
?? '(not found)');
return (string)($transaction['transactions'][$index][$parts[2]] ?? '(not found)');
}
private function isDuplicationError(string $key, string $error): bool
{
if (
'transactions.0.description' === $key
&& str_contains($error, 'Duplicate of transaction #')
) {
app('log')->debug('This is a duplicate transaction error');
if ('transactions.0.description' === $key && str_contains($error, 'Duplicate of transaction #')) {
Log::debug('This is a duplicate transaction error');
return true;
}
app('log')->debug('This is not a duplicate transaction error');
Log::debug('This is not a duplicate transaction error');
return false;
}
private function compareArrays(
int $lineIndex,
array $line,
TransactionGroup $group
): void {
private function compareArrays(int $lineIndex, array $line, TransactionGroup $group): void
{
// some fields may not have survived. Be sure to warn the user about this.
/** @var Transaction $transaction */
foreach ($group->transactions as $index => $transaction) {
// compare currency ID
if (
array_key_exists(
'currency_id',
$line['transactions'][$index]
)
&& null !== $line['transactions'][$index]['currency_id']
&& (int)$line['transactions'][$index]['currency_id']
!== (int) $transaction->currencyId
) {
$this->addWarning(
$lineIndex,
sprintf(
'Line #%d may have had its currency changed (from ID #%d to ID #%d). This happens because the associated asset account overrules the currency of the transaction.',
$lineIndex,
$line['transactions'][$index]['currency_id'],
(int) $transaction->currencyId
)
);
if (array_key_exists('currency_id', $line['transactions'][$index]) && null !== $line['transactions'][$index]['currency_id'] && (int)$line['transactions'][$index]['currency_id'] !== (int)$transaction->currencyId) {
$this->addWarning($lineIndex, sprintf('Line #%d may have had its currency changed (from ID #%d to ID #%d). This happens because the associated asset account overrules the currency of the transaction.', $lineIndex, $line['transactions'][$index]['currency_id'], (int)$transaction->currencyId));
}
// compare currency code:
if (
array_key_exists(
'currency_code',
$line['transactions'][$index]
)
&& null !== $line['transactions'][$index]['currency_code']
&& $line['transactions'][$index]['currency_code']
!== $transaction->currencyCode
) {
$this->addWarning(
$lineIndex,
sprintf(
'Line #%d may have had its currency changed (from "%s" to "%s"). This happens because the associated asset account overrules the currency of the transaction.',
$lineIndex,
$line['transactions'][$index]['currency_code'],
$transaction->currencyCode
)
);
if (array_key_exists('currency_code', $line['transactions'][$index]) && null !== $line['transactions'][$index]['currency_code'] && $line['transactions'][$index]['currency_code'] !== $transaction->currencyCode) {
$this->addWarning($lineIndex, sprintf('Line #%d may have had its currency changed (from "%s" to "%s"). This happens because the associated asset account overrules the currency of the transaction.', $lineIndex, $line['transactions'][$index]['currency_code'], $transaction->currencyCode));
}
}
}
@ -601,14 +415,12 @@ class ApiSubmitter
private function addTagToGroups(array $groupInfo): void
{
if ([] === $groupInfo) {
app('log')->debug(
'Group is empty, may not have been stored correctly.'
);
Log::debug('Group is empty, may not have been stored correctly.');
return;
}
if (false === $this->addTag) {
app('log')->debug('Will not add import tag.');
Log::debug('Will not add import tag.');
return;
}
@ -618,26 +430,16 @@ class ApiSubmitter
}
$groupId = (int)$groupInfo['group_id'];
app('log')->debug(
sprintf(
'Going to add import tag to transaction group #%d',
$groupId
)
);
$body = [
'transactions' => [],
];
Log::debug(sprintf('Going to add import tag to transaction group #%d', $groupId));
$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();
@ -649,24 +451,17 @@ class ApiSubmitter
try {
$request->put();
} catch (ApiHttpException $e) {
app('log')->error($e->getMessage());
// app('log')->error($e->getTraceAsString());
$this->addError(
0,
'[a120]: Could not store transaction: see the log files.'
);
Log::error($e->getMessage());
// Log::error($e->getTraceAsString());
$this->addError(0, '[a120]: Could not store transaction: see the log files.');
}
app('log')->debug(
sprintf('Added import tag to transaction group #%d', $groupId)
);
Log::debug(sprintf('Added import tag to transaction group #%d', $groupId));
}
private function createTag(): void
{
if (false === $this->addTag) {
app('log')->debug(
'Not instructed to add a tag, so will not create one.'
);
Log::debug('Not instructed to add a tag, so will not create one.');
return;
}
@ -675,39 +470,27 @@ 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 {
/** @var PostTagResponse $response */
$response = $request->post();
} catch (ApiHttpException $e) {
$message = sprintf(
'[a121]: Could not create tag. %s',
$e->getMessage()
);
app('log')->error($message);
// app('log')->error($e->getTraceAsString());
$message = sprintf('[a121]: Could not create tag. %s', $e->getMessage());
Log::error($message);
// Log::error($e->getTraceAsString());
$this->addError(0, $message);
return;
}
if ($response instanceof ValidationErrorResponse) {
app('log')->error(json_encode($response->errors->toArray()));
Log::error(json_encode($response->errors->toArray()));
return;
}
if (null !== $response->getTag()) {
app('log')->info(
sprintf(
'Created tag #%d "%s"',
$response->getTag()->id,
$response->getTag()->tag
)
);
Log::info(sprintf('Created tag #%d "%s"', $response->getTag()->id, $response->getTag()->tag));
}
}

4
app/Services/Shared/Import/Routine/InfoCollector.php

@ -46,7 +46,7 @@ class InfoCollector
*/
public function collectAccountTypes(): array
{
app('log')->debug('Now in collectAccountTypes()');
Log::debug('Now in collectAccountTypes()');
// get list of asset accounts:
$url = SecretManager::getBaseUrl();
$token = SecretManager::getAccessToken();
@ -74,7 +74,7 @@ class InfoCollector
$return[$account->id] = $account->type;
++$count;
}
app('log')->debug(sprintf('Collected %d account(s) in collectAccountTypes()', $count));
Log::debug(sprintf('Collected %d account(s) in collectAccountTypes()', $count));
RequestCache::set($cacheKey, $token, $return);

13
app/Services/Shared/Import/Routine/RoutineManager.php

@ -27,6 +27,7 @@ namespace App\Services\Shared\Import\Routine;
use App\Exceptions\ImporterErrorException;
use App\Services\Shared\Configuration\Configuration;
use Illuminate\Support\Facades\Log;
/**
* Class RoutineManager
@ -72,13 +73,13 @@ class RoutineManager
$this->apiSubmitter->setIdentifier($this->identifier);
$this->apiSubmitter->setConfiguration($configuration);
app('log')->debug('Created APISubmitter in RoutineManager');
Log::debug('Created APISubmitter in RoutineManager');
}
public function setTransactions(array $transactions): void
{
$this->transactions = $transactions;
app('log')->debug(sprintf('Now have %d transaction(s) in RoutineManager', count($transactions)));
Log::debug(sprintf('Now have %d transaction(s) in RoutineManager', count($transactions)));
}
/**
@ -86,12 +87,12 @@ class RoutineManager
*/
public function start(): void
{
app('log')->debug('Start of shared import routine.');
Log::debug('Start of shared import routine.');
app('log')->debug('First collect account information from Firefly III.');
Log::debug('First collect account information from Firefly III.');
$accountInfo = $this->infoCollector->collectAccountTypes();
app('log')->debug('Now starting submission by calling API Submitter');
Log::debug('Now starting submission by calling API Submitter');
// submit transactions to API:
$this->apiSubmitter->setAccountInfo($accountInfo);
$this->apiSubmitter->setIdentifier($this->identifier);
@ -99,6 +100,6 @@ class RoutineManager
$this->allMessages = $this->apiSubmitter->getMessages();
$this->allWarnings = $this->apiSubmitter->getWarnings();
$this->allErrors = $this->apiSubmitter->getErrors();
app('log')->debug(sprintf('Routine manager: messages: %d, warnings: %d, errors: %d', count($this->allMessages), count($this->allWarnings), count($this->allErrors)));
Log::debug(sprintf('Routine manager: messages: %d, warnings: %d, errors: %d', count($this->allMessages), count($this->allWarnings), count($this->allErrors)));
}
}

59
app/Services/Shared/Import/Status/SubmissionStatusManager.php

@ -28,6 +28,7 @@ namespace App\Services\Shared\Import\Status;
use App\Services\Session\Constants;
use App\Services\Shared\Submission\GeneratesIdentifier;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Support\Facades\Log;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
@ -43,7 +44,7 @@ class SubmissionStatusManager
public static function addError(string $identifier, int $index, string $error): void
{
$lineNo = $index + 1;
app('log')->debug(sprintf('Add error on index #%d (line no. %d): %s', $index, $lineNo, $error));
Log::debug(sprintf('Add error on index #%d (line no. %d): %s', $index, $lineNo, $error));
$disk = \Storage::disk(self::DISK_NAME);
try {
@ -58,31 +59,31 @@ class SubmissionStatusManager
self::storeSubmissionStatus($identifier, $status);
}
if (!$disk->exists($identifier)) {
app('log')->error(sprintf('Could not find file for job %s.', $identifier));
Log::error(sprintf('Could not find file for job %s.', $identifier));
}
} catch (FileNotFoundException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
}
}
private static function storeSubmissionStatus(string $identifier, SubmissionStatus $status): void
{
app('log')->debug(sprintf('Now in %s(%s): %s', __METHOD__, $identifier, $status->status));
app('log')->debug(sprintf('Messages: %d, warnings: %d, errors: %d', count($status->messages), count($status->warnings), count($status->errors)));
Log::debug(sprintf('Now in %s(%s): %s', __METHOD__, $identifier, $status->status));
Log::debug(sprintf('Messages: %d, warnings: %d, errors: %d', count($status->messages), count($status->warnings), count($status->errors)));
$disk = \Storage::disk(self::DISK_NAME);
try {
$disk->put($identifier, json_encode($status->toArray(), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT));
} catch (\JsonException $e) {
// do nothing
app('log')->error($e->getMessage());
Log::error($e->getMessage());
}
}
public static function addMessage(string $identifier, int $index, string $message): void
{
$lineNo = $index + 1;
app('log')->debug(sprintf('Add message on index #%d (line no. %d): %s', $index, $lineNo, $message));
Log::debug(sprintf('Add message on index #%d (line no. %d): %s', $index, $lineNo, $message));
$disk = \Storage::disk(self::DISK_NAME);
@ -98,17 +99,17 @@ class SubmissionStatusManager
self::storeSubmissionStatus($identifier, $status);
}
if (!$disk->exists($identifier)) {
app('log')->error(sprintf('Could not find file for job %s.', $identifier));
Log::error(sprintf('Could not find file for job %s.', $identifier));
}
} catch (FileNotFoundException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
}
}
public static function addWarning(string $identifier, int $index, string $warning): void
{
$lineNo = $index + 1;
app('log')->debug(sprintf('Add warning on index #%d (line no. %d): %s', $index, $lineNo, $warning));
Log::debug(sprintf('Add warning on index #%d (line no. %d): %s', $index, $lineNo, $warning));
$disk = \Storage::disk(self::DISK_NAME);
@ -124,16 +125,16 @@ class SubmissionStatusManager
self::storeSubmissionStatus($identifier, $status);
}
if (!$disk->exists($identifier)) {
app('log')->error(sprintf('Could not find file for job %s.', $identifier));
Log::error(sprintf('Could not find file for job %s.', $identifier));
}
} catch (FileNotFoundException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
}
}
public static function updateProgress(string $identifier, int $currentTransaction, int $totalTransactions): void
{
app('log')->debug(sprintf('Update progress for %s: %d/%d transactions', $identifier, $currentTransaction, $totalTransactions));
Log::debug(sprintf('Update progress for %s: %d/%d transactions', $identifier, $currentTransaction, $totalTransactions));
$disk = \Storage::disk(self::DISK_NAME);
@ -152,10 +153,10 @@ class SubmissionStatusManager
self::storeSubmissionStatus($identifier, $status);
}
if (!$disk->exists($identifier)) {
app('log')->error(sprintf('Could not find file for job %s.', $identifier));
Log::error(sprintf('Could not find file for job %s.', $identifier));
}
} catch (FileNotFoundException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
}
}
@ -165,12 +166,12 @@ class SubmissionStatusManager
try {
$identifier = session()->get(Constants::IMPORT_JOB_IDENTIFIER);
} catch (ContainerExceptionInterface|NotFoundExceptionInterface $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
$identifier = 'error-setSubmissionStatus';
}
}
app('log')->debug(sprintf('Now in setSubmissionStatus(%s)', $status));
app('log')->debug(sprintf('Found "%s" in the session', $identifier));
Log::debug(sprintf('Now in setSubmissionStatus(%s)', $status));
Log::debug(sprintf('Found "%s" in the session', $identifier));
$jobStatus = self::startOrFindSubmission($identifier);
$jobStatus->status = $status;
@ -182,42 +183,42 @@ class SubmissionStatusManager
public static function startOrFindSubmission(string $identifier): SubmissionStatus
{
app('log')->debug(sprintf('Now in startOrFindJob(%s)', $identifier));
Log::debug(sprintf('Now in startOrFindJob(%s)', $identifier));
$disk = \Storage::disk(self::DISK_NAME);
try {
app('log')->debug(sprintf('Try to see if file exists for job %s.', $identifier));
Log::debug(sprintf('Try to see if file exists for job %s.', $identifier));
if ($disk->exists($identifier)) {
app('log')->debug(sprintf('Status file exists for job %s.', $identifier));
Log::debug(sprintf('Status file exists for job %s.', $identifier));
try {
$array = json_decode($disk->get($identifier), true, 512, JSON_THROW_ON_ERROR);
$status = SubmissionStatus::fromArray($array);
} catch (FileNotFoundException|\JsonException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
$status = new SubmissionStatus();
}
app('log')->debug(sprintf('Status: %s', $status->status));
app('log')->debug(sprintf('Messages: %d, warnings: %d, errors: %d', count($status->messages), count($status->warnings), count($status->errors)));
Log::debug(sprintf('Status: %s', $status->status));
Log::debug(sprintf('Messages: %d, warnings: %d, errors: %d', count($status->messages), count($status->warnings), count($status->errors)));
return $status;
}
} catch (FileNotFoundException $e) {
app('log')->error('Could not find file, write a new one.');
app('log')->error($e->getMessage());
Log::error('Could not find file, write a new one.');
Log::error($e->getMessage());
}
app('log')->debug('File does not exist or error, create a new one.');
Log::debug('File does not exist or error, create a new one.');
$status = new SubmissionStatus();
try {
$json = json_encode($status->toArray(), JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT);
} catch (\JsonException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
$json = '{}';
}
$disk->put($identifier, $json);
app('log')->debug('Return status.', $status->toArray());
Log::debug('Return status.', $status->toArray());
return $status;
}

11
app/Services/Shared/Model/ImportServiceAccount.php

@ -29,6 +29,7 @@ use App\Services\CSV\Converter\Iban as IbanConverter;
use App\Services\Nordigen\Model\Account as NordigenAccount;
use App\Services\Nordigen\Model\Balance;
use App\Services\Spectre\Model\Account as SpectreAccount;
use Illuminate\Support\Facades\Log;
class ImportServiceAccount
{
@ -42,14 +43,14 @@ class ImportServiceAccount
public static function convertNordigenArray(array $accounts): array
{
app('log')->debug(sprintf('Now in %s', __METHOD__));
Log::debug(sprintf('Now in %s', __METHOD__));
$return = [];
/** @var NordigenAccount $account */
foreach ($accounts as $account) {
$iban = $account->getIban();
if ('' !== $iban && false === IbanConverter::isValidIban($iban)) {
app('log')->debug(sprintf('IBAN "%s" is invalid so it will be ignored.', $iban));
Log::debug(sprintf('IBAN "%s" is invalid so it will be ignored.', $iban));
$iban = '';
}
@ -88,10 +89,10 @@ class ImportServiceAccount
*/
public static function fromArray(array $array): self
{
app('log')->debug('Create generic account from', $array);
Log::debug('Create generic account from', $array);
$iban = (string) ($array['iban'] ?? '');
if ('' !== $iban && false === IbanConverter::isValidIban($iban)) {
app('log')->debug(sprintf('IBAN "%s" is invalid so it will be ignored.', $iban));
Log::debug(sprintf('IBAN "%s" is invalid so it will be ignored.', $iban));
$iban = '';
}
$account = new self();
@ -114,7 +115,7 @@ class ImportServiceAccount
foreach ($spectre as $account) {
$iban = (string) $account->iban;
if ('' !== $iban && false === IbanConverter::isValidIban($iban)) {
app('log')->debug(sprintf('IBAN "%s" is invalid so it will be ignored.', $iban));
Log::debug(sprintf('IBAN "%s" is invalid so it will be ignored.', $iban));
$iban = '';
}
$return[] = self::fromArray(

8
app/Services/Shared/Submission/GeneratesIdentifier.php

@ -25,6 +25,8 @@ declare(strict_types=1);
namespace App\Services\Shared\Submission;
use Illuminate\Support\Facades\Log;
/**
* Trait GeneratesIdentifier
*/
@ -35,16 +37,16 @@ trait GeneratesIdentifier
public function generateIdentifier(): string
{
app('log')->debug('Going to generate submission routine identifier.');
Log::debug('Going to generate submission routine identifier.');
$disk = \Storage::disk($this->diskName);
$count = 0;
do {
$generatedId = sprintf('submission-%s', \Str::random(12));
++$count;
app('log')->debug(sprintf('Attempt #%d results in "%s"', $count, $generatedId));
Log::debug(sprintf('Attempt #%d results in "%s"', $count, $generatedId));
} while ($count < 30 && $disk->exists($generatedId));
$this->identifier = $generatedId;
app('log')->info(sprintf('Job identifier is "%s"', $generatedId));
Log::info(sprintf('Job identifier is "%s"', $generatedId));
return $generatedId;
}

29
app/Services/SimpleFIN/Conversion/AccountMapper.php

@ -39,6 +39,7 @@ use GrumpyDictator\FFIIIApiSupport\Request\GetSearchAccountRequest;
use GrumpyDictator\FFIIIApiSupport\Response\GetAccountsResponse;
use GrumpyDictator\FFIIIApiSupport\Response\Response;
use GrumpyDictator\FFIIIApiSupport\Response\ValidationErrorResponse;
use Illuminate\Support\Facades\Log;
/**
* Class AccountMapper
@ -164,7 +165,7 @@ class AccountMapper
}
}
} catch (ApiHttpException $e) {
app('log')->warning(sprintf('Could not search for account "%s": %s', $simplefinAccount->getName(), $e->getMessage()));
Log::warning(sprintf('Could not search for account "%s": %s', $simplefinAccount->getName(), $e->getMessage()));
}
return null;
@ -180,7 +181,7 @@ class AccountMapper
$currencyCode = $this->getCurrencyCode($simplefinAccount, $config);
$openingBalance = $config['opening_balance'] ?? '0.00';
app('log')->info(sprintf('Creating Firefly III account "%s" immediately via API', $accountName));
Log::info(sprintf('Creating Firefly III account "%s" immediately via API', $accountName));
try {
$request = new PostAccountRequest(SecretManager::getBaseUrl(), SecretManager::getAccessToken());
@ -234,7 +235,7 @@ class AccountMapper
$response = $this->makeApiCallWithRetry($request, $accountName);
if ($response instanceof ValidationErrorResponse) {
app('log')->error(sprintf('Failed to create account "%s": %s', $accountName, json_encode($response->errors->toArray())));
Log::error(sprintf('Failed to create account "%s": %s', $accountName, json_encode($response->errors->toArray())));
return null;
}
@ -242,7 +243,7 @@ class AccountMapper
if ($response instanceof PostAccountResponse) {
$account = $response->getAccount();
if ($account) {
app('log')->info(sprintf('Successfully created account "%s" with ID %d', $accountName, $account->id));
Log::info(sprintf('Successfully created account "%s" with ID %d', $accountName, $account->id));
// Add to our local cache
$this->fireflyAccounts[] = $account;
@ -252,16 +253,16 @@ class AccountMapper
}
}
app('log')->error(sprintf('Unexpected response type when creating account "%s"', $accountName));
Log::error(sprintf('Unexpected response type when creating account "%s"', $accountName));
return null;
} catch (ApiHttpException $e) {
app('log')->error(sprintf('API error creating account "%s": %s', $accountName, $e->getMessage()));
Log::error(sprintf('API error creating account "%s": %s', $accountName, $e->getMessage()));
return null;
} catch (\Exception $e) {
app('log')->error(sprintf('Unexpected error creating account "%s": %s', $accountName, $e->getMessage()));
Log::error(sprintf('Unexpected error creating account "%s": %s', $accountName, $e->getMessage()));
return null;
}
@ -333,7 +334,7 @@ class AccountMapper
$accessToken = SecretManager::getAccessToken();
if ('' === $baseUrl || '' === $accessToken) {
app('log')->warning('Missing authentication context for Firefly III account loading');
Log::warning('Missing authentication context for Firefly III account loading');
throw new ImporterErrorException('Authentication context not available for account loading');
}
@ -344,10 +345,10 @@ class AccountMapper
if ($response instanceof GetAccountsResponse) {
$this->fireflyAccounts = iterator_to_array($response);
app('log')->debug(sprintf('Loaded %d Firefly III accounts', count($this->fireflyAccounts)));
Log::debug(sprintf('Loaded %d Firefly III accounts', count($this->fireflyAccounts)));
}
} catch (ApiHttpException $e) {
app('log')->error(sprintf('Could not load Firefly III accounts: %s', $e->getMessage()));
Log::error(sprintf('Could not load Firefly III accounts: %s', $e->getMessage()));
throw new ImporterErrorException(sprintf('Could not load Firefly III accounts: %s', $e->getMessage()));
}
@ -366,7 +367,7 @@ class AccountMapper
foreach ($retryDelays as $attempt => $delay) {
try {
if ($delay > 0) {
app('log')->debug(sprintf('Retrying account creation for "%s" after %ds delay (attempt %d)', $accountName, $delay, $attempt + 1));
Log::debug(sprintf('Retrying account creation for "%s" after %ds delay (attempt %d)', $accountName, $delay, $attempt + 1));
sleep($delay);
}
@ -380,12 +381,12 @@ class AccountMapper
$shouldRetry = $this->shouldRetryApiCall($errorMessage, $attempt, count($retryDelays));
if (!$shouldRetry) {
app('log')->error(sprintf('Non-retryable API error for account "%s": %s', $accountName, $errorMessage));
Log::error(sprintf('Non-retryable API error for account "%s": %s', $accountName, $errorMessage));
throw $e;
}
app('log')->warning(sprintf('DNS/connection error for account "%s" (attempt %d): %s', $accountName, $attempt + 1, $errorMessage));
Log::warning(sprintf('DNS/connection error for account "%s" (attempt %d): %s', $accountName, $attempt + 1, $errorMessage));
// If this was the last attempt, we'll throw after the loop
if ($attempt === count($retryDelays) - 1) {
@ -395,7 +396,7 @@ class AccountMapper
}
// All retries exhausted
app('log')->error(sprintf('All retries exhausted for account "%s": %s', $accountName, $lastException->getMessage()));
Log::error(sprintf('All retries exhausted for account "%s": %s', $accountName, $lastException->getMessage()));
throw $lastException;
}

31
app/Services/SimpleFIN/Conversion/TransactionTransformer.php

@ -28,6 +28,7 @@ namespace App\Services\SimpleFIN\Conversion;
use App\Support\Http\CollectsAccounts;
use Carbon\Carbon;
use App\Services\Shared\Authentication\SecretManager;
use Illuminate\Support\Facades\Log;
// Removed SimpleFINModel imports as we now use arrays
@ -58,7 +59,7 @@ class TransactionTransformer
// Skip zero-amount transactions as they're invalid for Firefly III
if (0.0 === abs($amount)) {
app('log')->warning('Skipping zero-amount transaction', [
Log::warning('Skipping zero-amount transaction', [
'transaction_id' => $transactionData['id'] ?? 'unknown',
'description' => $transactionData['description'] ?? 'unknown',
]);
@ -219,7 +220,7 @@ class TransactionTransformer
// Check if automatic account creation is enabled
if (!config('simplefin.auto_create_expense_accounts', true)) {
app('log')->warning(sprintf(
Log::warning(sprintf(
'Auto-creation disabled. No %s account will be created for "%s"',
$isDeposit ? 'revenue' : 'expense',
$description
@ -240,7 +241,7 @@ class TransactionTransformer
// Fallback: extract meaningful counter account name from description
$counterAccountName = $this->extractCounterAccountName($description);
app('log')->info(sprintf(
Log::info(sprintf(
'Creating new %s account "%s" for transaction "%s"',
$isDeposit ? 'revenue' : 'expense',
$counterAccountName,
@ -449,7 +450,7 @@ class TransactionTransformer
// Check if smart matching is enabled before attempting collection
if (!config('simplefin.smart_expense_matching', true)) {
app('log')->debug('Smart expense matching is disabled, skipping account collection');
Log::debug('Smart expense matching is disabled, skipping account collection');
$this->expenseAccounts = [];
$this->revenueAccounts = [];
$this->accountsCollected = true;
@ -463,7 +464,7 @@ class TransactionTransformer
$accessToken = SecretManager::getAccessToken();
if ('' === $baseUrl || '' === $accessToken) {
app('log')->warning('Missing authentication context for account collection, skipping smart matching');
Log::warning('Missing authentication context for account collection, skipping smart matching');
$this->expenseAccounts = [];
$this->revenueAccounts = [];
$this->accountsCollected = true;
@ -471,13 +472,13 @@ class TransactionTransformer
return;
}
app('log')->debug('Collecting expense accounts from Firefly III');
Log::debug('Collecting expense accounts from Firefly III');
$this->expenseAccounts = $this->collectExpenseAccounts();
app('log')->debug('Collecting revenue accounts from Firefly III');
Log::debug('Collecting revenue accounts from Firefly III');
$this->revenueAccounts = $this->collectRevenueAccounts();
app('log')->debug(sprintf(
Log::debug(sprintf(
'Collected %d expense accounts and %d revenue accounts',
count($this->expenseAccounts),
count($this->revenueAccounts)
@ -485,8 +486,8 @@ class TransactionTransformer
$this->accountsCollected = true;
} catch (\Exception $e) {
app('log')->error(sprintf('Failed to collect accounts: %s', $e->getMessage()));
app('log')->debug('Continuing without smart expense matching due to collection failure');
Log::error(sprintf('Failed to collect accounts: %s', $e->getMessage()));
Log::debug('Continuing without smart expense matching due to collection failure');
$this->expenseAccounts = [];
$this->revenueAccounts = [];
$this->accountsCollected = true; // Mark as collected to avoid repeated failures
@ -502,7 +503,7 @@ class TransactionTransformer
$accountType = $isDeposit ? 'revenue' : 'expense';
if (0 === count($accountsToSearch)) {
app('log')->debug(sprintf('No %s accounts to search', $accountType));
Log::debug(sprintf('No %s accounts to search', $accountType));
return null;
}
@ -516,7 +517,7 @@ class TransactionTransformer
// Check for exact match
if ($normalizedAccountName === $normalizedDescription) {
app('log')->debug(sprintf('Exact match found: "%s" -> "%s"', $description, $account['name']));
Log::debug(sprintf('Exact match found: "%s" -> "%s"', $description, $account['name']));
return $account;
}
@ -525,7 +526,7 @@ class TransactionTransformer
// Try fuzzy matching if no exact match found
$bestMatch = $this->findBestFuzzyMatch($normalizedDescription, $accountsToSearch);
if ($bestMatch) {
app('log')->debug(sprintf(
Log::debug(sprintf(
'Fuzzy match found: "%s" -> "%s" (similarity: %.2f)',
$description,
$bestMatch['account']['name'],
@ -664,7 +665,7 @@ class TransactionTransformer
$similarity = $this->calculateSimilarity($normalizedDescription, $cluster['normalized_name']);
if ($similarity >= $threshold) {
app('log')->debug(sprintf(
Log::debug(sprintf(
'Clustering "%s" with existing cluster "%s" (similarity: %.2f)',
$description,
$clusterName,
@ -689,7 +690,7 @@ class TransactionTransformer
'created_at' => time(),
];
app('log')->debug(sprintf('Created new %s cluster "%s" for "%s"', $accountType, $clusterName, $description));
Log::debug(sprintf('Created new %s cluster "%s" for "%s"', $accountType, $clusterName, $description));
return $clusterName;
}

3
app/Services/SimpleFIN/Request/AccountsRequest.php

@ -27,6 +27,7 @@ namespace App\Services\SimpleFIN\Request;
use App\Exceptions\ImporterHttpException;
use App\Services\SimpleFIN\Response\AccountsResponse;
use Illuminate\Support\Facades\Log;
/**
* Class AccountsRequest
@ -38,7 +39,7 @@ class AccountsRequest extends SimpleFINRequest
*/
public function get(): AccountsResponse
{
app('log')->debug(sprintf('Now at %s', __METHOD__));
Log::debug(sprintf('Now at %s', __METHOD__));
$response = $this->authenticatedGet('/accounts');

13
app/Services/SimpleFIN/Request/SimpleFINRequest.php

@ -33,6 +33,7 @@ use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\ServerException;
use Illuminate\Support\Facades\Log;
use Psr\Http\Message\ResponseInterface;
/**
@ -62,7 +63,7 @@ abstract class SimpleFINRequest
public function setParameters(array $parameters): void
{
app('log')->debug('SimpleFIN request parameters set to: ', $parameters);
Log::debug('SimpleFIN request parameters set to: ', $parameters);
$this->parameters = $parameters;
}
@ -73,7 +74,7 @@ abstract class SimpleFINRequest
protected function authenticatedGet(string $endpoint): ResponseInterface
{
app('log')->debug(sprintf('SimpleFIN authenticated GET to %s%s', $this->apiUrl, $endpoint));
Log::debug(sprintf('SimpleFIN authenticated GET to %s%s', $this->apiUrl, $endpoint));
$client = new Client();
$fullUrl = sprintf('%s%s', $this->apiUrl, $endpoint);
@ -102,16 +103,16 @@ abstract class SimpleFINRequest
try {
$response = $client->get($fullUrl, $options);
} catch (ClientException $e) {
app('log')->error(sprintf('SimpleFIN ClientException: %s', $e->getMessage()));
Log::error(sprintf('SimpleFIN ClientException: %s', $e->getMessage()));
$this->handleClientException($e);
throw new ImporterHttpException($e->getMessage(), $e->getCode(), $e);
} catch (ServerException $e) {
app('log')->error(sprintf('SimpleFIN ServerException: %s', $e->getMessage()));
Log::error(sprintf('SimpleFIN ServerException: %s', $e->getMessage()));
throw new ImporterHttpException($e->getMessage(), $e->getCode(), $e);
} catch (GuzzleException $e) {
app('log')->error(sprintf('SimpleFIN GuzzleException: %s', $e->getMessage()));
Log::error(sprintf('SimpleFIN GuzzleException: %s', $e->getMessage()));
throw new ImporterHttpException($e->getMessage(), $e->getCode(), $e);
}
@ -124,7 +125,7 @@ abstract class SimpleFINRequest
$statusCode = $e->getResponse()->getStatusCode();
$body = (string) $e->getResponse()->getBody();
app('log')->error(sprintf('SimpleFIN HTTP %d error: %s', $statusCode, $body));
Log::error(sprintf('SimpleFIN HTTP %d error: %s', $statusCode, $body));
switch ($statusCode) {
case 401:

3
app/Services/SimpleFIN/Request/TransactionsRequest.php

@ -28,6 +28,7 @@ namespace App\Services\SimpleFIN\Request;
use App\Exceptions\ImporterHttpException;
use App\Services\SimpleFIN\Response\TransactionsResponse;
use App\Services\Shared\Response\ResponseInterface as SharedResponseInterface;
use Illuminate\Support\Facades\Log;
/**
* Class TransactionsRequest
@ -39,7 +40,7 @@ class TransactionsRequest extends SimpleFINRequest
*/
public function get(): SharedResponseInterface
{
app('log')->debug(sprintf('Now at %s', __METHOD__));
Log::debug(sprintf('Now at %s', __METHOD__));
$response = $this->authenticatedGet('');

7
app/Services/SimpleFIN/Response/AccountsResponse.php

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace App\Services\SimpleFIN\Response;
use Illuminate\Support\Facades\Log;
use Psr\Http\Message\ResponseInterface;
/**
@ -60,7 +61,7 @@ class AccountsResponse extends SimpleFINResponse
$data = $this->getData();
if (0 === count($data)) {
app('log')->warning('SimpleFIN AccountsResponse: No data to parse');
Log::warning('SimpleFIN AccountsResponse: No data to parse');
return;
}
@ -68,11 +69,11 @@ class AccountsResponse extends SimpleFINResponse
// SimpleFIN API returns accounts in the 'accounts' array
if (isset($data['accounts']) && is_array($data['accounts'])) {
$this->accounts = $data['accounts'];
app('log')->debug(sprintf('SimpleFIN AccountsResponse: Parsed %d accounts', count($this->accounts)));
Log::debug(sprintf('SimpleFIN AccountsResponse: Parsed %d accounts', count($this->accounts)));
return;
}
app('log')->warning('SimpleFIN AccountsResponse: No accounts array found in response');
Log::warning('SimpleFIN AccountsResponse: No accounts array found in response');
$this->accounts = [];
}
}

13
app/Services/SimpleFIN/Response/SimpleFINResponse.php

@ -26,6 +26,7 @@ declare(strict_types=1);
namespace App\Services\SimpleFIN\Response;
use App\Services\Shared\Response\ResponseInterface as SharedResponseInterface;
use Illuminate\Support\Facades\Log;
use Psr\Http\Message\ResponseInterface;
/**
@ -42,8 +43,8 @@ abstract class SimpleFINResponse implements SharedResponseInterface
$this->statusCode = $response->getStatusCode();
$this->rawBody = (string) $response->getBody();
app('log')->debug(sprintf('SimpleFIN Response: HTTP %d', $this->statusCode));
app('log')->debug(sprintf('SimpleFIN Response body: %s', $this->rawBody));
Log::debug(sprintf('SimpleFIN Response: HTTP %d', $this->statusCode));
Log::debug(sprintf('SimpleFIN Response body: %s', $this->rawBody));
$this->parseResponse();
}
@ -82,7 +83,7 @@ abstract class SimpleFINResponse implements SharedResponseInterface
private function parseResponse(): void
{
if ('' === $this->rawBody) {
app('log')->warning('SimpleFIN Response body is empty');
Log::warning('SimpleFIN Response body is empty');
$this->data = [];
return;
@ -91,20 +92,20 @@ abstract class SimpleFINResponse implements SharedResponseInterface
$decoded = json_decode($this->rawBody, true);
if (JSON_ERROR_NONE !== json_last_error()) {
app('log')->error(sprintf('SimpleFIN JSON decode error: %s', json_last_error_msg()));
Log::error(sprintf('SimpleFIN JSON decode error: %s', json_last_error_msg()));
$this->data = [];
return;
}
if (!is_array($decoded)) {
app('log')->error('SimpleFIN Response is not a valid JSON array');
Log::error('SimpleFIN Response is not a valid JSON array');
$this->data = [];
return;
}
$this->data = $decoded;
app('log')->debug('SimpleFIN Response parsed successfully');
Log::debug('SimpleFIN Response parsed successfully');
}
}

7
app/Services/SimpleFIN/Response/TransactionsResponse.php

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace App\Services\SimpleFIN\Response;
use Illuminate\Support\Facades\Log;
use Psr\Http\Message\ResponseInterface;
/**
@ -60,7 +61,7 @@ class TransactionsResponse extends SimpleFINResponse
$data = $this->getData();
if (0 === count($data)) {
app('log')->warning('SimpleFIN TransactionsResponse: No data to parse');
Log::warning('SimpleFIN TransactionsResponse: No data to parse');
return;
}
@ -74,11 +75,11 @@ class TransactionsResponse extends SimpleFINResponse
}
}
$this->transactions = $transactions;
app('log')->debug(sprintf('SimpleFIN TransactionsResponse: Parsed %d transactions', count($this->transactions)));
Log::debug(sprintf('SimpleFIN TransactionsResponse: Parsed %d transactions', count($this->transactions)));
return;
}
app('log')->warning('SimpleFIN TransactionsResponse: No accounts array found in response');
Log::warning('SimpleFIN TransactionsResponse: No accounts array found in response');
$this->transactions = [];
}
}

6
app/Services/Spectre/Authentication/SecretManager.php

@ -25,6 +25,8 @@ declare(strict_types=1);
namespace App\Services\Spectre\Authentication;
use Illuminate\Support\Facades\Log;
/**
* Class SecretManager
*/
@ -39,7 +41,7 @@ class SecretManager
public static function getAppId(): string
{
if (!self::hasAppId()) {
app('log')->debug('No Spectre App ID in hasAppId() session, will return config variable.');
Log::debug('No Spectre App ID in hasAppId() session, will return config variable.');
return (string) config('spectre.app_id');
}
@ -63,7 +65,7 @@ class SecretManager
public static function getSecret(): string
{
if (!self::hasSecret()) {
app('log')->debug('No Spectre secret in hasSecret(), will return config variable.');
Log::debug('No Spectre secret in hasSecret(), will return config variable.');
return (string) config('spectre.secret');
}

7
app/Services/Spectre/AuthenticationValidator.php

@ -32,6 +32,7 @@ use App\Services\Shared\Authentication\IsRunningCli;
use App\Services\Spectre\Authentication\SecretManager;
use App\Services\Spectre\Request\ListCustomersRequest;
use App\Services\Spectre\Response\ErrorResponse;
use Illuminate\Support\Facades\Log;
/**
* Class AuthenticationValidator
@ -42,7 +43,7 @@ class AuthenticationValidator implements AuthenticationValidatorInterface
public function validate(): AuthenticationStatus
{
app('log')->debug(sprintf('Now at %s', __METHOD__));
Log::debug(sprintf('Now at %s', __METHOD__));
$url = config('spectre.url');
$appId = SecretManager::getAppId();
@ -58,12 +59,12 @@ class AuthenticationValidator implements AuthenticationValidatorInterface
try {
$response = $request->get();
} catch (ImporterHttpException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
return AuthenticationStatus::error();
}
if ($response instanceof ErrorResponse) {
app('log')->error(sprintf('%s: %s', $response->class, $response->message));
Log::error(sprintf('%s: %s', $response->class, $response->message));
return AuthenticationStatus::error();
}

4
app/Services/Spectre/Conversion/Routine/FilterTransactions.php

@ -48,11 +48,11 @@ class FilterTransactions
unset($transaction['transactions'][0]['datetime']);
if (0 === (int) ($transaction['transactions'][0]['category_id'] ?? 0)) {
// app('log')->debug('IS NULL');
// Log::debug('IS NULL');
unset($transaction['transactions'][0]['category_id']);
}
$return[] = $transaction;
// app('log')->debug('Filtered ', $transaction);
// Log::debug('Filtered ', $transaction);
}
return $return;

35
app/Services/Spectre/Conversion/Routine/GenerateTransactions.php

@ -31,6 +31,7 @@ use App\Services\Spectre\Model\Transaction;
use App\Support\Http\CollectsAccounts;
use App\Support\Internal\DuplicateSafetyCatch;
use GrumpyDictator\FFIIIApiSupport\Exceptions\ApiHttpException;
use Illuminate\Support\Facades\Log;
/**
* Class GenerateTransactions.
@ -62,14 +63,14 @@ class GenerateTransactions
*/
public function collectTargetAccounts(): void
{
app('log')->debug('Spectre: Defer account search to trait.');
Log::debug('Spectre: Defer account search to trait.');
// defer to trait:
$array = $this->collectAllTargetAccounts();
foreach ($array as $number => $info) {
$this->targetAccounts[$number] = $info['id'];
$this->targetTypes[$number] = $info['type'];
}
app('log')->debug(sprintf('Spectre: Collected %d accounts.', count($this->targetAccounts)));
Log::debug(sprintf('Spectre: Collected %d accounts.', count($this->targetAccounts)));
}
public function getTransactions(array $spectre): array
@ -89,7 +90,7 @@ class GenerateTransactions
private function generateTransaction(Transaction $entry): array
{
app('log')->debug('Original Spectre transaction', $entry->toArray());
Log::debug('Original Spectre transaction', $entry->toArray());
$description = $entry->getDescription();
$spectreAccountId = $entry->getAccountId();
$madeOn = $entry->getMadeOn()->toW3cString();
@ -132,24 +133,24 @@ class GenerateTransactions
];
if ($this->configuration->isIgnoreSpectreCategories()) {
app('log')->debug('Remove Spectre categories and tags.');
Log::debug('Remove Spectre categories and tags.');
unset($transaction['tags'], $transaction['category_name'], $transaction['category_id']);
}
// amount is positive?
if (1 === bccomp($amount, '0')) {
app('log')->debug('Amount is positive: assume transfer or deposit.');
Log::debug('Amount is positive: assume transfer or deposit.');
$transaction = $this->processPositiveTransaction($entry, $transaction, $amount, $spectreAccountId);
}
if (-1 === bccomp($amount, '0')) {
app('log')->debug('Amount is negative: assume transfer or withdrawal.');
Log::debug('Amount is negative: assume transfer or withdrawal.');
$transaction = $this->processNegativeTransaction($entry, $transaction, $amount, $spectreAccountId);
}
$return['transactions'][] = $transaction;
app('log')->debug(sprintf('Parsed Spectre transaction #%d', $entry->getId()));
Log::debug(sprintf('Parsed Spectre transaction #%d', $entry->getId()));
return $return;
}
@ -169,29 +170,29 @@ class GenerateTransactions
$transaction['source_name'] = $entry->getPayer() ?? '(unknown source account)';
$transaction['source_iban'] = $entry->getPayerIban() ?? '';
app('log')->debug(sprintf('processPositiveTransaction: source_name = "%s", source_iban = "%s"', $transaction['source_name'], $transaction['source_iban']));
Log::debug(sprintf('processPositiveTransaction: source_name = "%s", source_iban = "%s"', $transaction['source_name'], $transaction['source_iban']));
// check if the source IBAN is a known account and what type it has: perhaps the
// transaction type needs to be changed:
$iban = $transaction['source_iban'];
$accountType = $this->targetTypes[$iban] ?? 'unknown';
$accountId = $this->targetAccounts[$iban] ?? 0;
app('log')->debug(sprintf('Found account type "%s" for IBAN "%s"', $accountType, $iban));
Log::debug(sprintf('Found account type "%s" for IBAN "%s"', $accountType, $iban));
if ('unknown' !== $accountType) {
if ('asset' === $accountType) {
app('log')->debug('Changing transaction type to "transfer"');
Log::debug('Changing transaction type to "transfer"');
$transaction['type'] = 'transfer';
}
}
if (0 !== $accountId) {
app('log')->debug(sprintf('Found account ID #%d for IBAN "%s"', $accountId, $iban));
Log::debug(sprintf('Found account ID #%d for IBAN "%s"', $accountId, $iban));
$transaction['source_id'] = (int) $accountId;
unset($transaction['source_name'], $transaction['source_iban']);
}
$transaction = $this->positiveTransactionSafetyCatch($transaction, (string) $entry->getPayer(), (string) $entry->getPayerIban());
app('log')->debug(sprintf('destination_id = %d, source_name = "%s", source_iban = "%s", source_id = "%s"', $transaction['destination_id'] ?? '', $transaction['source_name'] ?? '', $transaction['source_iban'] ?? '', $transaction['source_id'] ?? ''));
Log::debug(sprintf('destination_id = %d, source_name = "%s", source_iban = "%s", source_id = "%s"', $transaction['destination_id'] ?? '', $transaction['source_name'] ?? '', $transaction['source_iban'] ?? '', $transaction['source_id'] ?? ''));
return $transaction;
}
@ -208,29 +209,29 @@ class GenerateTransactions
$transaction['destination_name'] = $entry->getPayee() ?? '(unknown destination account)';
$transaction['destination_iban'] = $entry->getPayeeIban() ?? '';
app('log')->debug(sprintf('processNegativeTransaction: destination_name = "%s", destination_iban = "%s"', $transaction['destination_name'], $transaction['destination_iban']));
Log::debug(sprintf('processNegativeTransaction: destination_name = "%s", destination_iban = "%s"', $transaction['destination_name'], $transaction['destination_iban']));
// check if the destination IBAN is a known account and what type it has: perhaps the
// transaction type needs to be changed:
$iban = $transaction['destination_iban'];
$accountType = $this->targetTypes[$iban] ?? 'unknown';
$accountId = $this->targetAccounts[$iban] ?? 0;
app('log')->debug(sprintf('Found account type "%s" for IBAN "%s"', $accountType, $iban));
Log::debug(sprintf('Found account type "%s" for IBAN "%s"', $accountType, $iban));
if ('unknown' !== $accountType) {
if ('asset' === $accountType) {
app('log')->debug('Changing transaction type to "transfer"');
Log::debug('Changing transaction type to "transfer"');
$transaction['type'] = 'transfer';
}
}
if (0 !== $accountId) {
app('log')->debug(sprintf('Found account ID #%d for IBAN "%s"', $accountId, $iban));
Log::debug(sprintf('Found account ID #%d for IBAN "%s"', $accountId, $iban));
$transaction['destination_id'] = $accountId;
unset($transaction['destination_name'], $transaction['destination_iban']);
}
$transaction = $this->negativeTransactionSafetyCatch($transaction, (string) $entry->getPayee(), (string) $entry->getPayeeIban());
app('log')->debug(sprintf('source_id = %d, destination_id = "%s", destination_name = "%s", destination_iban = "%s"', $transaction['source_id'], $transaction['destination_id'] ?? '', $transaction['destination_name'] ?? '', $transaction['destination_iban'] ?? ''));
Log::debug(sprintf('source_id = %d, destination_id = "%s", destination_name = "%s", destination_iban = "%s"', $transaction['source_id'], $transaction['destination_id'] ?? '', $transaction['destination_name'] ?? '', $transaction['destination_iban'] ?? ''));
return $transaction;
}

25
app/Services/Spectre/Conversion/Routine/TransactionProcessor.php

@ -34,6 +34,7 @@ use App\Services\Spectre\Request\PutRefreshConnectionRequest;
use App\Services\Spectre\Response\ErrorResponse;
use App\Services\Spectre\Response\GetTransactionsResponse;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
/**
* Class TransactionProcessor
@ -64,13 +65,13 @@ class TransactionProcessor
$this->notAfter = new Carbon($this->configuration->getDateNotAfter());
}
app('log')->debug('Now in download()');
Log::debug('Now in download()');
$accounts = array_keys($this->configuration->getAccounts());
app('log')->debug(sprintf('Found %d accounts to download from.', count($this->configuration->getAccounts())));
Log::debug(sprintf('Found %d accounts to download from.', count($this->configuration->getAccounts())));
$return = [];
foreach ($accounts as $account) {
$account = (string) $account;
app('log')->debug(sprintf('Going to download transactions for account #%s', $account));
Log::debug(sprintf('Going to download transactions for account #%s', $account));
$url = config('spectre.url');
$appId = SpectreSecretManager::getAppId();
$secret = SpectreSecretManager::getSecret();
@ -111,26 +112,26 @@ class TransactionProcessor
$put->setConnection($this->configuration->getConnection());
$response = $put->put();
if ($response instanceof ErrorResponse) {
app('log')->alert('Could not refresh connection.');
app('log')->alert(sprintf('%s: %s', $response->class, $response->message));
Log::alert('Could not refresh connection.');
Log::alert(sprintf('%s: %s', $response->class, $response->message));
}
}
private function filterTransactions(GetTransactionsResponse $transactions): array
{
app('log')->info(sprintf('Going to filter downloaded transactions. Original set length is %d', count($transactions)));
Log::info(sprintf('Going to filter downloaded transactions. Original set length is %d', count($transactions)));
if (null !== $this->notBefore) {
app('log')->info(sprintf('Will not grab transactions before "%s"', $this->notBefore->format('Y-m-d H:i:s')));
Log::info(sprintf('Will not grab transactions before "%s"', $this->notBefore->format('Y-m-d H:i:s')));
}
if (null !== $this->notAfter) {
app('log')->info(sprintf('Will not grab transactions after "%s"', $this->notAfter->format('Y-m-d H:i:s')));
Log::info(sprintf('Will not grab transactions after "%s"', $this->notAfter->format('Y-m-d H:i:s')));
}
$return = [];
foreach ($transactions as $transaction) {
$madeOn = $transaction->madeOn;
if (null !== $this->notBefore && $madeOn->lt($this->notBefore)) {
app('log')->debug(
Log::debug(
sprintf(
'Skip transaction because "%s" is before "%s".',
$madeOn->format(self::DATE_TIME_FORMAT),
@ -141,7 +142,7 @@ class TransactionProcessor
continue;
}
if (null !== $this->notAfter && $madeOn->gt($this->notAfter)) {
app('log')->debug(
Log::debug(
sprintf(
'Skip transaction because "%s" is after "%s".',
$madeOn->format(self::DATE_TIME_FORMAT),
@ -151,10 +152,10 @@ class TransactionProcessor
continue;
}
app('log')->debug(sprintf('Include transaction because date is "%s".', $madeOn->format(self::DATE_TIME_FORMAT)));
Log::debug(sprintf('Include transaction because date is "%s".', $madeOn->format(self::DATE_TIME_FORMAT)));
$return[] = $transaction;
}
app('log')->info(sprintf('After filtering, set is %d transaction(s)', count($return)));
Log::info(sprintf('After filtering, set is %d transaction(s)', count($return)));
return $return;
}

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

@ -36,6 +36,7 @@ use App\Services\Spectre\Conversion\Routine\GenerateTransactions;
use App\Services\Spectre\Conversion\Routine\TransactionProcessor;
use App\Support\Http\CollectsAccounts;
use GrumpyDictator\FFIIIApiSupport\Exceptions\ApiHttpException;
use Illuminate\Support\Facades\Log;
/**
* Class RoutineManager
@ -99,7 +100,7 @@ class RoutineManager implements RoutineManagerInterface
$transactions = $this->transactionProcessor->download();
// generate Firefly III ready transactions:
app('log')->debug('Generating Firefly III transactions.');
Log::debug('Generating Firefly III transactions.');
try {
$this->transactionGenerator->collectTargetAccounts();
@ -113,7 +114,7 @@ class RoutineManager implements RoutineManagerInterface
}
$converted = $this->transactionGenerator->getTransactions($transactions);
app('log')->debug(sprintf('Generated %d Firefly III transactions.', count($converted)));
Log::debug(sprintf('Generated %d Firefly III transactions.', count($converted)));
if (0 === count($converted)) {
$this->addError(0, '[a123]: No transactions were converted, probably zero found at Spectre.');
$this->mergeMessages(1);
@ -124,7 +125,7 @@ class RoutineManager implements RoutineManagerInterface
}
$filtered = $this->transactionFilter->filter($converted);
app('log')->debug(sprintf('Filtered down to %d Firefly III transactions.', count($filtered)));
Log::debug(sprintf('Filtered down to %d Firefly III transactions.', count($filtered)));
$this->mergeMessages(count($transactions));
$this->mergeWarnings(count($transactions));

43
app/Services/Spectre/Model/Transaction.php

@ -27,6 +27,7 @@ namespace App\Services\Spectre\Model;
use App\Services\CSV\Converter\Iban as IbanConverter;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
/**
* Class Transaction
@ -78,7 +79,7 @@ class Transaction
public function getAccountId(): string
{
app('log')->debug(sprintf('Get getAccountId(): "%s"', $this->accountId));
Log::debug(sprintf('Get getAccountId(): "%s"', $this->accountId));
return $this->accountId;
}
@ -136,12 +137,12 @@ class Transaction
public function getPayeeIban(): ?string
{
app('log')->debug('getPayeeIban()');
Log::debug('getPayeeIban()');
$payee = $this->extra->getPayee();
$valid = IbanConverter::isValidIban((string) $payee);
// payee is valid IBAN:
if ($valid) {
app('log')->debug(sprintf('Payee IBAN is "%s", return this.', $payee));
Log::debug(sprintf('Payee IBAN is "%s", return this.', $payee));
return (string) $payee;
}
@ -149,44 +150,44 @@ class Transaction
$payeeInfo = $this->extra->getPayeeInformation();
$valid = IbanConverter::isValidIban((string) $payeeInfo);
if ($valid) {
app('log')->debug(sprintf('Payee IBAN (payee information) is "%s", return this.', $payeeInfo));
Log::debug(sprintf('Payee IBAN (payee information) is "%s", return this.', $payeeInfo));
return (string) $payeeInfo;
}
app('log')->debug('Payee IBAN is "" (empty fallback), return NULL');
Log::debug('Payee IBAN is "" (empty fallback), return NULL');
return null;
}
public function getPayee(): ?string
{
app('log')->debug('getPayee()');
Log::debug('getPayee()');
$payee = (string) $this->extra->getPayee();
$payeeInfo = (string) $this->extra->getPayeeInformation();
$valid = IbanConverter::isValidIban($payee);
// if payee is IBAN, first see if payee information may be a better field:
if ($valid && '' !== $payeeInfo) {
app('log')->debug(sprintf('Payee is "%s", payee info is "%s", return payee info.', $payee, $payeeInfo));
Log::debug(sprintf('Payee is "%s", payee info is "%s", return payee info.', $payee, $payeeInfo));
return $payeeInfo;
}
if (!$valid && '' === $payeeInfo) {
app('log')->debug(sprintf('Payee is "%s", payee info is "%s", return payee.', $payee, $payeeInfo));
Log::debug(sprintf('Payee is "%s", payee info is "%s", return payee.', $payee, $payeeInfo));
return $payee;
}
if ($valid && '' === $payeeInfo) {
app('log')->debug(sprintf('Payee is "%s", payee info is "%s", return payee.', $payee, $payeeInfo));
Log::debug(sprintf('Payee is "%s", payee info is "%s", return payee.', $payee, $payeeInfo));
return $payee;
}
if (!$valid && '' !== $payeeInfo) {
app('log')->debug(sprintf('Payee is "%s", payee info is "%s", return payee info.', $payee, $payeeInfo));
Log::debug(sprintf('Payee is "%s", payee info is "%s", return payee info.', $payee, $payeeInfo));
return $payeeInfo;
}
app('log')->debug(sprintf('Payee is "%s", payee info is "%s", return NULL.', $payee, $payeeInfo));
Log::debug(sprintf('Payee is "%s", payee info is "%s", return NULL.', $payee, $payeeInfo));
// I think this covers everything, but you never know, so:
return null;
@ -195,12 +196,12 @@ class Transaction
public function getPayerIban(): ?string
{
app('log')->debug('getPayerIban()');
Log::debug('getPayerIban()');
$payer = $this->extra->getpayer();
$valid = IbanConverter::isValidIban((string) $payer);
// payer is valid IBAN:
if ($valid) {
app('log')->debug(sprintf('Payer IBAN is "%s", return this.', $payer));
Log::debug(sprintf('Payer IBAN is "%s", return this.', $payer));
return (string) $payer;
}
@ -208,44 +209,44 @@ class Transaction
$payerInfo = $this->extra->getpayerInformation();
$valid = IbanConverter::isValidIban((string) $payerInfo);
if ($valid) {
app('log')->debug(sprintf('Payer IBAN (payer information) is "%s", return thuis.', $payerInfo));
Log::debug(sprintf('Payer IBAN (payer information) is "%s", return thuis.', $payerInfo));
return (string) $payerInfo;
}
app('log')->debug('Payer IBAN is "" (empty fallback), return NULL');
Log::debug('Payer IBAN is "" (empty fallback), return NULL');
return null;
}
public function getPayer(): ?string
{
app('log')->debug('getPayer()');
Log::debug('getPayer()');
$payer = (string) $this->extra->getPayer();
$payerInfo = (string) $this->extra->getPayerInformation();
$valid = IbanConverter::isValidIban($payer);
// if payer is IBAN, first see if payer information may be a better field:
if ($valid && '' !== $payerInfo) {
app('log')->debug(sprintf('Payer is "%s", payer info is "%s", return payer info.', $payer, $payerInfo));
Log::debug(sprintf('Payer is "%s", payer info is "%s", return payer info.', $payer, $payerInfo));
return $payerInfo;
}
if (!$valid && '' === $payerInfo) {
app('log')->debug(sprintf('Payer is "%s", payer info is "%s", return payer.', $payer, $payerInfo));
Log::debug(sprintf('Payer is "%s", payer info is "%s", return payer.', $payer, $payerInfo));
return $payer;
}
if ($valid && '' === $payerInfo) {
app('log')->debug(sprintf('Payer is "%s", payer info is "%s", return payer.', $payer, $payerInfo));
Log::debug(sprintf('Payer is "%s", payer info is "%s", return payer.', $payer, $payerInfo));
return $payer;
}
if (!$valid && '' !== $payerInfo) {
app('log')->debug(sprintf('Payer is "%s", payer info is "%s", return payer info.', $payer, $payerInfo));
Log::debug(sprintf('Payer is "%s", payer info is "%s", return payer info.', $payer, $payerInfo));
return $payerInfo;
}
app('log')->debug(sprintf('Payer is "%s", payer info is "%s", return NULL.', $payer, $payerInfo));
Log::debug(sprintf('Payer is "%s", payer info is "%s", return NULL.', $payer, $payerInfo));
// I think this covers everything, but you never know, so:
return null;

7
app/Services/Spectre/Model/TransactionExtra.php

@ -26,6 +26,7 @@ declare(strict_types=1);
namespace App\Services\Spectre\Model;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
/**
* Class TransactionExtra
@ -109,9 +110,9 @@ class TransactionExtra
$model->categorizationConfidence = array_key_exists('categorization_confidence', $data) ? (string) $data['categorization_confidence'] : null;
// if has posting time, then set this time in the posting date?
app('log')->debug(sprintf('Time is "%s"', $data['time'] ?? ''));
app('log')->debug(sprintf('Posting date is "%s"', $data['posting_date'] ?? ''));
app('log')->debug(sprintf('Posting time is "%s"', $data['posting_time'] ?? ''));
Log::debug(sprintf('Time is "%s"', $data['time'] ?? ''));
Log::debug(sprintf('Posting date is "%s"', $data['posting_date'] ?? ''));
Log::debug(sprintf('Posting time is "%s"', $data['posting_time'] ?? ''));
return $model;
}

3
app/Services/Spectre/Request/GetAccountsRequest.php

@ -30,6 +30,7 @@ use App\Services\Shared\Response\Response;
use App\Services\Spectre\Response\ErrorResponse;
use App\Services\Spectre\Response\GetAccountsResponse;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Facades\Log;
/**
* Class GetAccountsRequest
@ -56,7 +57,7 @@ class GetAccountsRequest extends Request
*/
public function get(): Response
{
app('log')->debug('GetAccountsRequest::get()');
Log::debug('GetAccountsRequest::get()');
$this->setParameters(
[
'connection_id' => $this->connection,

7
app/Services/Spectre/Request/GetTransactionsRequest.php

@ -27,6 +27,7 @@ namespace App\Services\Spectre\Request;
use App\Services\Shared\Response\Response;
use App\Services\Spectre\Response\GetTransactionsResponse;
use Illuminate\Support\Facades\Log;
/**
* Class GetTransactionsRequest
@ -53,7 +54,7 @@ class GetTransactionsRequest extends Request
$nextId = 0;
$transactions = [];
while ($hasNextPage) {
app('log')->debug(sprintf('Now calling GetTransactionsRequest for next_id %d', $nextId));
Log::debug(sprintf('Now calling GetTransactionsRequest for next_id %d', $nextId));
$this->setParameters(
[
@ -65,14 +66,14 @@ class GetTransactionsRequest extends Request
$response = $this->authenticatedGet();
// count entries:
app('log')->debug(sprintf('Found %d entries in data-array', count($response['data'])));
Log::debug(sprintf('Found %d entries in data-array', count($response['data'])));
// extract next ID
$hasNextPage = false;
if (isset($response['meta']['next_id']) && (int) $response['meta']['next_id'] > $nextId) {
$hasNextPage = true;
$nextId = $response['meta']['next_id'];
app('log')->debug(sprintf('Next ID is now %d.', $nextId));
Log::debug(sprintf('Next ID is now %d.', $nextId));
}
// store customers:

3
app/Services/Spectre/Request/ListConnectionsRequest.php

@ -30,6 +30,7 @@ use App\Services\Shared\Response\Response;
use App\Services\Spectre\Response\ErrorResponse;
use App\Services\Spectre\Response\ListConnectionsResponse;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Facades\Log;
/**
* Class ListConnectionsRequest
@ -55,7 +56,7 @@ class ListConnectionsRequest extends Request
*/
public function get(): Response
{
app('log')->debug('ListConnectionsRequest::get()');
Log::debug('ListConnectionsRequest::get()');
$this->setParameters(
[
'customer_id' => $this->customer,

3
app/Services/Spectre/Request/ListCustomersRequest.php

@ -31,6 +31,7 @@ use App\Services\Shared\Response\Response;
use App\Services\Spectre\Response\ErrorResponse;
use App\Services\Spectre\Response\ListCustomersResponse;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Facades\Log;
/**
* Class ListCustomersRequest
@ -56,7 +57,7 @@ class ListCustomersRequest extends Request
try {
$response = $this->authenticatedGet();
} catch (GuzzleException|ImporterErrorException|ImporterHttpException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
// JSON thing.
return new ErrorResponse($e->json ?? []);

33
app/Services/Spectre/Request/Request.php

@ -32,6 +32,7 @@ use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Exception\TransferException;
use Illuminate\Support\Facades\Log;
/**
* Class Request
@ -69,7 +70,7 @@ abstract class Request
public function setParameters(array $parameters): void
{
app('log')->debug('setParameters', $parameters);
Log::debug('setParameters', $parameters);
$this->parameters = $parameters;
}
@ -110,7 +111,7 @@ abstract class Request
]
);
} catch (TransferException $e) {
app('log')->error(sprintf('TransferException: %s', $e->getMessage()));
Log::error(sprintf('TransferException: %s', $e->getMessage()));
// if response, parse as error response.
if (method_exists($e, 'hasResponse') && !$e->hasResponse()) {
@ -122,7 +123,7 @@ abstract class Request
}
if (200 !== $res->getStatusCode()) {
// return body, class must handle this
app('log')->error(sprintf('[3] Status code is %d', $res->getStatusCode()));
Log::error(sprintf('[3] Status code is %d', $res->getStatusCode()));
$body = (string) $res->getBody();
}
@ -146,7 +147,7 @@ abstract class Request
throw new ImporterHttpException(sprintf('Body is empty. [4] Status code is %d.', $res->getStatusCode()));
}
if (config('importer.log_return_json')) {
app('log')->debug('JSON', $json);
Log::debug('JSON', $json);
}
return $json;
@ -221,7 +222,7 @@ abstract class Request
throw new ImporterErrorException($e->getMessage());
}
app('log')->debug('Final headers for spectre signed POST request:', $headers);
Log::debug('Final headers for spectre signed POST request:', $headers);
try {
$client = $this->getClient();
@ -233,7 +234,7 @@ abstract class Request
try {
$body = $res->getBody()->getContents();
} catch (\RuntimeException $e) {
app('log')->error(sprintf('sendSignedSpectrePost: Could not get body from SpectreRequest::POST result: %s', $e->getMessage()));
Log::error(sprintf('sendSignedSpectrePost: Could not get body from SpectreRequest::POST result: %s', $e->getMessage()));
$body = '{}';
}
@ -284,19 +285,19 @@ abstract class Request
try {
$body = json_encode($data, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
}
if ('{}' !== (string) $body) {
$opts['body'] = $body;
}
app('log')->debug('Final headers for spectre UNsigned POST request:', $headers);
Log::debug('Final headers for spectre UNsigned POST request:', $headers);
try {
$client = $this->getClient();
$res = $client->request('POST', $fullUrl, $opts);
} catch (\Exception|GuzzleException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
throw new ImporterHttpException(sprintf('Guzzle Exception: %s', $e->getMessage()));
}
@ -304,7 +305,7 @@ abstract class Request
try {
$body = $res->getBody()->getContents();
} catch (\RuntimeException $e) {
app('log')->error(sprintf('sendUnsignedSpectrePost: Could not get body from SpectreRequest::POST result: %s', $e->getMessage()));
Log::error(sprintf('sendUnsignedSpectrePost: Could not get body from SpectreRequest::POST result: %s', $e->getMessage()));
$body = '{}';
}
@ -339,13 +340,13 @@ abstract class Request
try {
$body = json_encode($data, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
}
if ('{}' !== (string) $body) {
$opts['body'] = $body;
}
// app('log')->debug('Final body + headers for spectre UNsigned PUT request:', $opts);
// Log::debug('Final body + headers for spectre UNsigned PUT request:', $opts);
try {
$client = $this->getClient();
$res = $client->request('PUT', $fullUrl, $opts);
@ -361,16 +362,16 @@ abstract class Request
try {
$json = json_decode((string) $e->getResponse()->getBody(), true, 512, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
}
$json['ResponseHeaders'] = $responseHeaders;
$json['ResponseStatusCode'] = $statusCode;
return $json;
}
app('log')->error($e->getMessage());
Log::error($e->getMessage());
if (null !== $response) {
app('log')->error((string) $e->getResponse()->getBody());
Log::error((string) $e->getResponse()->getBody());
}
throw new ImporterHttpException(sprintf('Request Exception: %s', $e->getMessage()));
@ -379,7 +380,7 @@ abstract class Request
try {
$body = $res->getBody()->getContents();
} catch (\RuntimeException $e) {
app('log')->error(sprintf('sendUnsignedSpectrePut: Could not get body from SpectreRequest::POST result: %s', $e->getMessage()));
Log::error(sprintf('sendUnsignedSpectrePut: Could not get body from SpectreRequest::POST result: %s', $e->getMessage()));
$body = '{}';
}

13
app/Services/Storage/StorageService.php

@ -26,6 +26,7 @@ declare(strict_types=1);
namespace App\Services\Storage;
use App\Exceptions\ImporterErrorException;
use Illuminate\Support\Facades\Log;
use League\Flysystem\FilesystemException;
/**
@ -45,14 +46,14 @@ class StorageService
$content = $disk->get($name);
$encoding = mb_detect_encoding($content, config('importer.encoding'), true);
if (false === $encoding) {
app('log')->warning('Tried to detect encoding but could not find valid encoding. Assume UTF-8.');
Log::warning('Tried to detect encoding but could not find valid encoding. Assume UTF-8.');
return $content;
}
if ('ASCII' === $encoding || 'UTF-8' === $encoding) {
return $content;
}
app('log')->warning(sprintf('Content is detected as "%s" and will be converted to UTF-8. Your milage may vary.', $encoding));
Log::warning(sprintf('Content is detected as "%s" and will be converted to UTF-8. Your milage may vary.', $encoding));
return mb_convert_encoding($content, 'UTF-8', $encoding);
}
@ -68,11 +69,11 @@ class StorageService
$fileName = hash('sha256', $json);
if ($disk->has($fileName)) {
app('log')->warning(sprintf('Have already stored a file under key "%s", so the content is unchanged from last time.', $fileName));
Log::warning(sprintf('Have already stored a file under key "%s", so the content is unchanged from last time.', $fileName));
}
$disk->put($fileName, $json);
app('log')->debug(sprintf('storeArray: Stored %d bytes in file "%s"', strlen($json), $fileName));
Log::debug(sprintf('storeArray: Stored %d bytes in file "%s"', strlen($json), $fileName));
return $fileName;
}
@ -90,11 +91,11 @@ class StorageService
}
if ($disk->has($fileName)) {
app('log')->warning(sprintf('Have already stored a file under key "%s", so the content is unchanged from last time.', $fileName));
Log::warning(sprintf('Have already stored a file under key "%s", so the content is unchanged from last time.', $fileName));
}
$disk->put($fileName, $content);
app('log')->debug(sprintf('storeContent: Stored %d bytes in file "%s"', strlen($content), $fileName));
Log::debug(sprintf('storeContent: Stored %d bytes in file "%s"', strlen($content), $fileName));
return $fileName;
}

Loading…
Cancel
Save