remove unnecessary code and change sync-behavior to suppress sync error based on wrong from_date

This commit is contained in:
paulwer 2023-12-16 14:33:09 +01:00
parent c3ff64a0e6
commit a4e8351199

View File

@ -34,10 +34,6 @@ class ProcessBankTransactionsNordigen implements ShouldQueue
private ?string $from_date;
private bool $stop_loop = true;
private int $skip = 0;
public Company $company;
public Nordigen $nordigen;
public $nordigen_account;
@ -48,7 +44,7 @@ class ProcessBankTransactionsNordigen implements ShouldQueue
public function __construct(BankIntegration $bank_integration)
{
$this->bank_integration = $bank_integration;
$this->from_date = $bank_integration->from_date;
$this->from_date = $bank_integration->from_date ?: now()->subDays(90);
$this->company = $this->bank_integration->company;
}
@ -71,9 +67,6 @@ class ProcessBankTransactionsNordigen implements ShouldQueue
set_time_limit(0);
//Loop through everything until we are up to date
$this->from_date = $this->from_date ?: '2021-01-01';
// UPDATE ACCOUNT
try {
$this->updateAccount();
@ -94,11 +87,13 @@ class ProcessBankTransactionsNordigen implements ShouldQueue
return;
// UPDATE TRANSACTIONS
do {
try {
$this->processTransactions();
} catch (\Exception $e) {
// reset from_date in case this was the error (self-heal) and perform a max sync of data we can fetch (next-time) @todo we should analyze the error for this
$this->bank_integration->from_date = now()->subDays(90);
$this->bank_integration->save();
nlog("{$this->bank_integration->account->key} - exited abnormally => " . $e->getMessage());
$content = [
@ -112,9 +107,7 @@ class ProcessBankTransactionsNordigen implements ShouldQueue
throw $e;
}
}
while ($this->stop_loop);
// Perform Matching
BankMatchingService::dispatch($this->company->id, $this->company->db);
}
@ -148,18 +141,13 @@ class ProcessBankTransactionsNordigen implements ShouldQueue
//Get transaction count object
$transactions = $this->nordigen->getTransactions($this->bank_integration->nordigen_account_id, $this->from_date);
Log::Info($transactions);
//Get int count
$count = sizeof($transactions);
//if no transactions, update the from_date and move on
if (count($transactions) == 0) {
$this->bank_integration->from_date = now()->subDays(5);
$this->bank_integration->disabled_upstream = false;
$this->bank_integration->save();
$this->stop_loop = false;
return;
}
@ -175,7 +163,6 @@ class ProcessBankTransactionsNordigen implements ShouldQueue
$now = now();
foreach ($transactions as $transaction) {
if (BankTransaction::where('transaction_id', $transaction['transaction_id'])->where('company_id', $this->company->id)->where('bank_integration_id', $this->bank_integration->id)->withTrashed()->exists())
@ -194,17 +181,6 @@ class ProcessBankTransactionsNordigen implements ShouldQueue
}
// $this->skip = $this->skip + 500;
// if ($count < 500) {
// $this->stop_loop = false;
// $this->bank_integration->from_date = now()->subDays(5);
// $this->bank_integration->save();
// }
$this->stop_loop = false;
$this->bank_integration->from_date = now()->subDays(5);
$this->bank_integration->save();