Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:firefly-iii/data-importer into d…
Browse files Browse the repository at this point in the history
…evelop
  • Loading branch information
JC5 committed Nov 17, 2024
2 parents 7b84978 + 234f6b4 commit b1ac051
Show file tree
Hide file tree
Showing 9 changed files with 397 additions and 296 deletions.
52 changes: 26 additions & 26 deletions .ci/php-cs-fixer/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 38 additions & 36 deletions app/Console/AutoImports.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@
*/
trait AutoImports
{
protected array $conversionErrors = [];
protected array $conversionMessages = [];
protected array $conversionWarnings = [];
protected array $conversionErrors = [];
protected array $conversionMessages = [];
protected array $conversionWarnings = [];
protected array $conversionRateLimits = []; // only conversion can have rate limits.
protected string $identifier;
protected array $importErrors = [];
protected array $importMessages = [];
protected array $importWarnings = [];
protected array $importerAccounts = [];
protected array $importErrors = [];
protected array $importMessages = [];
protected array $importWarnings = [];
protected array $importerAccounts = [];

private function getFiles(string $directory): array
{
Expand Down Expand Up @@ -171,7 +171,7 @@ private function importFiles(string $directory, array $files): array

/** @var string $file */
foreach ($files as $file) {
$key = sprintf('%s/%s', $directory, $file);
$key = sprintf('%s/%s', $directory, $file);

try {
$exitCodes[$key] = $this->importFile($directory, $file);
Expand All @@ -181,13 +181,13 @@ private function importFiles(string $directory, array $files): array
$exitCodes[$key] = 1;
}
// report has already been sent. Reset errors and continue.
$this->conversionErrors = [];
$this->conversionMessages = [];
$this->conversionWarnings = [];
$this->conversionErrors = [];
$this->conversionMessages = [];
$this->conversionWarnings = [];
$this->conversionRateLimits = [];
$this->importErrors = [];
$this->importMessages = [];
$this->importWarnings = [];
$this->importErrors = [];
$this->importMessages = [];
$this->importWarnings = [];
}

return $exitCodes;
Expand Down Expand Up @@ -298,11 +298,11 @@ private function importFile(string $directory, string $file): int
*/
private function startConversion(Configuration $configuration, string $importableFile): void
{
$this->conversionMessages = [];
$this->conversionWarnings = [];
$this->conversionErrors = [];
$this->conversionMessages = [];
$this->conversionWarnings = [];
$this->conversionErrors = [];
$this->conversionRateLimits = [];
$flow = $configuration->getFlow();
$flow = $configuration->getFlow();

app('log')->debug(sprintf('Now in %s', __METHOD__));

Expand All @@ -312,7 +312,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 @@ -352,52 +352,52 @@ private function startConversion(Configuration $configuration, string $importabl

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

try {
$transactions = $manager->start();
} catch (ImporterErrorException $e) {
app('log')->error($e->getMessage());
RoutineStatusManager::setConversionStatus(ConversionStatus::CONVERSION_ERRORED, $this->identifier);
$this->conversionMessages = $manager->getAllMessages();
$this->conversionWarnings = $manager->getAllWarnings();
$this->conversionErrors = $manager->getAllErrors();
$this->conversionMessages = $manager->getAllMessages();
$this->conversionWarnings = $manager->getAllWarnings();
$this->conversionErrors = $manager->getAllErrors();
$this->conversionRateLimits = $manager->getAllRateLimits();
}
if (0 === count($transactions)) {
app('log')->error('[a] Zero transactions!');
RoutineStatusManager::setConversionStatus(ConversionStatus::CONVERSION_DONE, $this->identifier);
$this->conversionMessages = $manager->getAllMessages();
$this->conversionWarnings = $manager->getAllWarnings();
$this->conversionErrors = $manager->getAllErrors();
$this->conversionMessages = $manager->getAllMessages();
$this->conversionWarnings = $manager->getAllWarnings();
$this->conversionErrors = $manager->getAllErrors();
$this->conversionRateLimits = $manager->getAllRateLimits();
}

// 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));
} catch (\JsonException $e) {
app('log')->error(sprintf('JSON exception: %s', $e->getMessage()));
RoutineStatusManager::setConversionStatus(ConversionStatus::CONVERSION_ERRORED, $this->identifier);
$this->conversionMessages = $manager->getAllMessages();
$this->conversionWarnings = $manager->getAllWarnings();
$this->conversionErrors = $manager->getAllErrors();
$this->conversionMessages = $manager->getAllMessages();
$this->conversionWarnings = $manager->getAllWarnings();
$this->conversionErrors = $manager->getAllErrors();
$this->conversionRateLimits = $manager->getAllRateLimits();
$transactions = [];
$transactions = [];
}

if (count($transactions) > 0) {
// set done:
RoutineStatusManager::setConversionStatus(ConversionStatus::CONVERSION_DONE, $this->identifier);

$this->conversionMessages = $manager->getAllMessages();
$this->conversionWarnings = $manager->getAllWarnings();
$this->conversionErrors = $manager->getAllErrors();
$this->conversionMessages = $manager->getAllMessages();
$this->conversionWarnings = $manager->getAllWarnings();
$this->conversionErrors = $manager->getAllErrors();
$this->conversionRateLimits = $manager->getAllRateLimits();
}
$this->importerAccounts = $manager->getServiceAccounts();
$this->importerAccounts = $manager->getServiceAccounts();
}

private function reportConversion(): void
Expand All @@ -411,8 +411,10 @@ private function reportConversion(): void
foreach ($list as $set) {
/** @var string $func */
$func = $set[1];

/** @var array $all */
$all = $set[0];
$all = $set[0];

/**
* @var int $index
* @var array $messages
Expand Down
6 changes: 3 additions & 3 deletions app/Handlers/Events/ImportedTransactionsEventHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public function sendReportOverMail(ImportedTransactions $event): void
}

$log = [
'messages' => $event->messages,
'warnings' => $event->warnings,
'errors' => $event->errors,
'messages' => $event->messages,
'warnings' => $event->warnings,
'errors' => $event->errors,
'rate_limits' => $event->rateLimits,
];
if (count($event->messages) > 0 || count($event->warnings) > 0 || count($event->errors) > 0) {
Expand Down
12 changes: 6 additions & 6 deletions app/Mail/ImportReportMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ class ImportReportMail extends Mailable
*/
public function __construct(array $log)
{
$this->time = date('Y-m-d \@ H:i:s');
$this->url = (string) config('importer.url');
$this->version = config('importer.version');
$this->time = date('Y-m-d \@ H:i:s');
$this->url = (string) config('importer.url');
$this->version = config('importer.version');
if ('' !== (string) config('importer.vanity_url')) {
$this->url = (string) config('importer.vanity_url');
}
$this->errors = $log['errors'] ?? [];
$this->warnings = $log['warnings'] ?? [];
$this->messages = $log['messages'] ?? [];
$this->errors = $log['errors'] ?? [];
$this->warnings = $log['warnings'] ?? [];
$this->messages = $log['messages'] ?? [];
$this->rateLimits = $log['rate_limits'] ?? [];
}

Expand Down
Loading

0 comments on commit b1ac051

Please sign in to comment.