Skip to content

Commit

Permalink
Auto commit for release 'develop' on 2024-04-20
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Apr 20, 2024
1 parent 05319b7 commit 8b87b3e
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 126 deletions.
46 changes: 25 additions & 21 deletions app/Console/AutoImports.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private function getFiles(string $directory): array

return [];
}
$array = scandir($directory);
$array = scandir($directory);
if (!is_array($array)) {
$this->error(sprintf('Directory "%s" is empty or invalid.', $directory));

Expand Down Expand Up @@ -196,9 +196,9 @@ private function importFile(string $directory, string $file): void
{
app('log')->debug(sprintf('ImportFile: directory "%s"', $directory));
app('log')->debug(sprintf('ImportFile: file "%s"', $file));
$importableFile = sprintf('%s/%s', $directory, $file);
$jsonFile = sprintf('%s/%s.json', $directory, substr($file, 0, -5));
$fallbackJsonFile = sprintf('%s/%s', $directory, config('importer.fallback_configuration'));
$importableFile = sprintf('%s/%s', $directory, $file);
$jsonFile = sprintf('%s/%s.json', $directory, substr($file, 0, -5));
$fallbackJsonFile = sprintf('%s/%s', $directory, config('importer.fallback_configuration'));

// TODO not yet sure why the distinction is necessary.
// TODO this may also be necessary for camt files.
Expand All @@ -217,20 +217,20 @@ private function importFile(string $directory, string $file): void
$this->error(sprintf('No JSON configuration found. Checked for both "%s" and "%s"', $jsonFile, $fallbackJsonFile));
}

$jsonFile = $jsonFileExists ? $jsonFile : $fallbackJsonFile;
$jsonFile = $jsonFileExists ? $jsonFile : $fallbackJsonFile;

app('log')->debug(sprintf('ImportFile: importable "%s"', $importableFile));
app('log')->debug(sprintf('ImportFile: JSON "%s"', $jsonFile));

// do JSON check
$jsonResult = $this->verifyJSON($jsonFile);
$jsonResult = $this->verifyJSON($jsonFile);
if (false === $jsonResult) {
$message = sprintf('The importer can\'t import %s: could not decode the JSON in config file %s.', $importableFile, $jsonFile);
$this->error($message);

return;
}
$configuration = Configuration::fromArray(json_decode(file_get_contents($jsonFile), true));
$configuration = Configuration::fromArray(json_decode(file_get_contents($jsonFile), true));

// sanity check. If the importableFile is a .json file, and it parses as valid json, don't import it:
if ('file' === $configuration->getFlow() && str_ends_with(strtolower($importableFile), '.json') && $this->verifyJSON($importableFile)) {
Expand Down Expand Up @@ -293,6 +293,7 @@ private function reportBalanceDifferences(Configuration $configuration): void
// check if account exists:
if (!array_key_exists($account->getIdentifier(), $localAccounts)) {
Log::debug(sprintf('Nordigen account "%s" (IBAN "%s") is not being imported, so skipped.', $account->getIdentifier(), $account->getIban()));

continue;
}
// local account ID exists, we can check the balance over at Firefly III.
Expand All @@ -307,10 +308,12 @@ private function reportBalanceDifferences(Configuration $configuration): void
} catch (ApiHttpException $e) {
app('log')->error('Could not get Firefly III account for balance check. Will ignore this issue.');
app('log')->debug($e->getMessage());

continue;
}

/** @var LocalAccount $localAccount */
$localAccount = $result->getAccount();
$localAccount = $result->getAccount();

$this->reportBalanceDifference($account, $localAccount);
}
Expand All @@ -320,15 +323,16 @@ private function reportBalanceDifference(Account $account, LocalAccount $localAc
{
Log::debug(sprintf('Report balance difference between Nordigen account "%s" and Firefly III account #%d.', $account->getIdentifier(), $localAccount->id));
app('log')->debug(sprintf('Nordigen account has %d balance entry (entries)', count($account->getBalances())));

/** @var Balance $balance */
foreach ($account->getBalances() as $index => $balance) {
app('log')->debug(sprintf('Now comparing balance entry #%d of %d', $index + 1, count($account->getBalances())));
$this->reportSingleDifference($account, $localAccount, $balance);
}
}

private function reportSingleDifference(Account $account, LocalAccount $localAccount, Balance $balance): void {

private function reportSingleDifference(Account $account, LocalAccount $localAccount, Balance $balance): void
{
// compare currencies, and warn if necessary.
if ($balance->currency !== $localAccount->currencyCode) {
app('log')->warning(sprintf('Nordigen account "%s" has currency %s, Firefly III account #%d uses %s.', $account->getIdentifier(), $localAccount->id, $balance->currency, $localAccount->currencyCode));
Expand Down Expand Up @@ -371,7 +375,7 @@ private function startConversion(Configuration $configuration, string $importabl
exit(1);
}

$manager = null;
$manager = null;
if ('file' === $flow) {
$contentType = $configuration->getContentType();
if ('unknown' === $contentType) {
Expand Down Expand Up @@ -411,7 +415,7 @@ private function startConversion(Configuration $configuration, string $importabl

// then push stuff into the routine:
$manager->setConfiguration($configuration);
$transactions = [];
$transactions = [];

try {
$transactions = $manager->start();
Expand All @@ -431,7 +435,7 @@ private function startConversion(Configuration $configuration, string $importabl
}

// save transactions in 'jobs' directory under the same key as the conversion thing.
$disk = \Storage::disk('jobs');
$disk = \Storage::disk('jobs');

try {
$disk->put(sprintf('%s.json', $this->identifier), json_encode($transactions, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR));
Expand All @@ -452,7 +456,7 @@ private function startConversion(Configuration $configuration, string $importabl
$this->conversionWarnings = $manager->getAllWarnings();
$this->conversionErrors = $manager->getAllErrors();
}
$this->importerAccounts = $manager->getServiceAccounts();
$this->importerAccounts = $manager->getServiceAccounts();
}

private function reportConversion(): void
Expand Down Expand Up @@ -480,15 +484,15 @@ private function reportConversion(): void
private function startImport(Configuration $configuration): void
{
app('log')->debug(sprintf('Now at %s', __METHOD__));
$routine = new RoutineManager($this->identifier);
$routine = new RoutineManager($this->identifier);
SubmissionStatusManager::startOrFindSubmission($this->identifier);
$disk = \Storage::disk('jobs');
$fileName = sprintf('%s.json', $this->identifier);
$disk = \Storage::disk('jobs');
$fileName = sprintf('%s.json', $this->identifier);

// get files from disk:
if (!$disk->has($fileName)) {
SubmissionStatusManager::setSubmissionStatus(SubmissionStatus::SUBMISSION_ERRORED, $this->identifier);
$message = sprintf('File "%s" not found, cannot continue.', $fileName);
$message = sprintf('File "%s" not found, cannot continue.', $fileName);
$this->error($message);
SubmissionStatusManager::addError($this->identifier, 0, $message);
$this->importMessages = $routine->getAllMessages();
Expand All @@ -502,9 +506,9 @@ private function startImport(Configuration $configuration): void
$json = $disk->get($fileName);
$transactions = json_decode($json, true, 512, JSON_THROW_ON_ERROR);
app('log')->debug(sprintf('Found %d transactions on the drive.', count($transactions)));
} catch (FileNotFoundException | \JsonException $e) {
} catch (FileNotFoundException|\JsonException $e) {
SubmissionStatusManager::setSubmissionStatus(SubmissionStatus::SUBMISSION_ERRORED, $this->identifier);
$message = sprintf('File "%s" could not be decoded, cannot continue..', $fileName);
$message = sprintf('File "%s" could not be decoded, cannot continue..', $fileName);
$this->error($message);
SubmissionStatusManager::addError($this->identifier, 0, $message);
$this->importMessages = $routine->getAllMessages();
Expand Down Expand Up @@ -583,7 +587,7 @@ private function reportImport(): void
private function importUpload(string $jsonFile, string $importableFile): void
{
// do JSON check
$jsonResult = $this->verifyJSON($jsonFile);
$jsonResult = $this->verifyJSON($jsonFile);
if (false === $jsonResult) {
$message = sprintf('The importer can\'t import %s: could not decode the JSON in config file %s.', $importableFile, $jsonFile);
$this->error($message);
Expand Down
2 changes: 0 additions & 2 deletions app/Console/Commands/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ public function handle(): int
$this->line('--------');
$this->line('Running...');



// first do conversion based on the file:
$this->startConversion($configuration, $file);
$this->reportConversion();
Expand Down
4 changes: 3 additions & 1 deletion app/Services/CSV/Conversion/RoutineManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ private function mergeErrors(int $count): void
$count
);
}
#[\Override] public function getServiceAccounts(): array

#[\Override]
public function getServiceAccounts(): array
{
return [];
}
Expand Down
3 changes: 2 additions & 1 deletion app/Services/Camt/Conversion/RoutineManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ private function mergeErrors(int $count): void
);
}

#[\Override] public function getServiceAccounts(): array
#[\Override]
public function getServiceAccounts(): array
{
return [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function download(): array
app('log')->debug(sprintf('Now in %s', __METHOD__));
$this->notBefore = null;
$this->notAfter = null;
$this->accounts = [];
$this->accounts = [];
if ('' !== $this->configuration->getDateNotBefore()) {
$this->notBefore = new Carbon($this->configuration->getDateNotBefore());
}
Expand All @@ -78,7 +78,8 @@ public function download(): array
app('log')->debug('Will also download information on the account for debug purposes.');
$object = new Account();
$object->setIdentifier($account);
$fullInfo = null;
$fullInfo = null;

try {
$fullInfo = AccountInformationCollector::collectInformation($object);
} catch (AgreementExpiredException $e) {
Expand All @@ -97,7 +98,7 @@ public function download(): array
continue;
}
app('log')->debug('Done downloading information for debug purposes.');
if(null !== $fullInfo) {
if (null !== $fullInfo) {
$this->accounts[] = $fullInfo;
}

Expand Down Expand Up @@ -202,6 +203,4 @@ public function getAccounts(): array
{
return $this->accounts;
}


}
3 changes: 2 additions & 1 deletion app/Services/Nordigen/Conversion/RoutineManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ private function mergeErrors(int $count): void
);
}

#[\Override] public function getServiceAccounts(): array
#[\Override]
public function getServiceAccounts(): array
{
return $this->transactionProcessor->getAccounts();
}
Expand Down
4 changes: 3 additions & 1 deletion app/Services/Spectre/Conversion/RoutineManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ private function mergeErrors(int $count): void
$count
);
}
#[\Override] public function getServiceAccounts(): array

#[\Override]
public function getServiceAccounts(): array
{
return [];
}
Expand Down
52 changes: 26 additions & 26 deletions app/Services/Spectre/Request/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ protected function authenticatedGet(): array
if (0 !== count($this->parameters)) {
$fullUrl = sprintf('%s?%s', $fullUrl, http_build_query($this->parameters));
}
$client = $this->getClient();
$res = null;
$body = null;
$json = null;
$client = $this->getClient();
$res = null;
$body = null;
$json = null;

try {
$res = $client->request(
Expand Down Expand Up @@ -210,8 +210,8 @@ protected function sendSignedSpectrePost(array $data): array
if ('' === $this->url) {
throw new ImporterErrorException('No Spectre server defined');
}
$fullUrl = sprintf('%s/%s', $this->getBase(), $this->getUrl());
$headers = $this->getDefaultHeaders();
$fullUrl = sprintf('%s/%s', $this->getBase(), $this->getUrl());
$headers = $this->getDefaultHeaders();

try {
$body = json_encode($data, JSON_THROW_ON_ERROR);
Expand All @@ -224,7 +224,7 @@ protected function sendSignedSpectrePost(array $data): array
try {
$client = $this->getClient();
$res = $client->request('POST', $fullUrl, ['headers' => $headers, 'body' => $body]);
} catch (\Exception | GuzzleException $e) {
} catch (\Exception|GuzzleException $e) {
throw new ImporterHttpException(sprintf('Guzzle Exception: %s', $e->getMessage()));
}

Expand All @@ -235,8 +235,8 @@ protected function sendSignedSpectrePost(array $data): array
$body = '{}';
}

$statusCode = $res->getStatusCode();
$responseHeaders = $res->getHeaders();
$statusCode = $res->getStatusCode();
$responseHeaders = $res->getHeaders();

try {
$json = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
Expand Down Expand Up @@ -274,10 +274,10 @@ protected function sendUnsignedSpectrePost(array $data): array
if ('' === $this->url) {
throw new ImporterErrorException('No Spectre server defined');
}
$fullUrl = sprintf('%s/%s', $this->getBase(), $this->getUrl());
$headers = $this->getDefaultHeaders();
$opts = ['headers' => $headers];
$body = null;
$fullUrl = sprintf('%s/%s', $this->getBase(), $this->getUrl());
$headers = $this->getDefaultHeaders();
$opts = ['headers' => $headers];
$body = null;

try {
$body = json_encode($data, JSON_THROW_ON_ERROR);
Expand All @@ -293,7 +293,7 @@ protected function sendUnsignedSpectrePost(array $data): array
try {
$client = $this->getClient();
$res = $client->request('POST', $fullUrl, $opts);
} catch (\Exception | GuzzleException $e) {
} catch (\Exception|GuzzleException $e) {
app('log')->error($e->getMessage());

throw new ImporterHttpException(sprintf('Guzzle Exception: %s', $e->getMessage()));
Expand All @@ -306,8 +306,8 @@ protected function sendUnsignedSpectrePost(array $data): array
$body = '{}';
}

$statusCode = $res->getStatusCode();
$responseHeaders = $res->getHeaders();
$statusCode = $res->getStatusCode();
$responseHeaders = $res->getHeaders();

try {
$json = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
Expand All @@ -329,10 +329,10 @@ protected function sendUnsignedSpectrePut(array $data): array
if ('' === $this->url) {
throw new ImporterErrorException('No Spectre server defined');
}
$fullUrl = sprintf('%s/%s', $this->getBase(), $this->getUrl());
$headers = $this->getDefaultHeaders();
$opts = ['headers' => $headers];
$body = null;
$fullUrl = sprintf('%s/%s', $this->getBase(), $this->getUrl());
$headers = $this->getDefaultHeaders();
$opts = ['headers' => $headers];
$body = null;

try {
$body = json_encode($data, JSON_THROW_ON_ERROR);
Expand All @@ -347,14 +347,14 @@ protected function sendUnsignedSpectrePut(array $data): array
try {
$client = $this->getClient();
$res = $client->request('PUT', $fullUrl, $opts);
} catch (GuzzleException | RequestException $e) {
} catch (GuzzleException|RequestException $e) {
// get response.
$response = $e->getResponse();
if (null !== $response && 406 === $response->getStatusCode()) {
// ignore it, just log it.
$statusCode = $response->getStatusCode();
$responseHeaders = $response->getHeaders();
$json = [];
$statusCode = $response->getStatusCode();
$responseHeaders = $response->getHeaders();
$json = [];

try {
$json = json_decode((string)$e->getResponse()->getBody(), true, 512, JSON_THROW_ON_ERROR);
Expand All @@ -381,8 +381,8 @@ protected function sendUnsignedSpectrePut(array $data): array
$body = '{}';
}

$statusCode = $res->getStatusCode();
$responseHeaders = $res->getHeaders();
$statusCode = $res->getStatusCode();
$responseHeaders = $res->getHeaders();

try {
$json = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
Expand Down
2 changes: 1 addition & 1 deletion config/importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
declare(strict_types=1);

return [
'version' => 'develop/2024-04-19',
'version' => 'develop/2024-04-20',
'flows' => ['nordigen', 'spectre', 'file'],
'flow_titles' => [
'file' => 'File',
Expand Down
Loading

0 comments on commit 8b87b3e

Please sign in to comment.