Fix various code.

This commit is contained in:
James Cole
2025-05-27 17:06:15 +02:00
parent d8f512ca3a
commit 2cb14f6b72
123 changed files with 581 additions and 500 deletions

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Jobs;
use Carbon\Carbon;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Message;
use Illuminate\Queue\InteractsWithQueue;
@@ -32,6 +33,11 @@ use Illuminate\Support\Facades\Mail;
use Symfony\Component\Mailer\Exception\TransportException;
use Exception;
use function Safe\json_encode;
use function Safe\file_put_contents;
use function Safe\json_decode;
use function Safe\file_get_contents;
/**
* Class MailError.
*/
@@ -48,7 +54,7 @@ class MailError extends Job implements ShouldQueue
$debug = $this->exception;
unset($debug['stackTrace'], $debug['headers']);
app('log')->error(sprintf('Exception is: %s', \Safe\json_encode($debug)));
app('log')->error(sprintf('Exception is: %s', json_encode($debug)));
}
/**
@@ -119,11 +125,11 @@ class MailError extends Job implements ShouldQueue
if (!file_exists($file)) {
Log::debug(sprintf('Wrote new file in "%s"', $file));
\Safe\file_put_contents($file, \Safe\json_encode($limits, JSON_PRETTY_PRINT));
file_put_contents($file, json_encode($limits, JSON_PRETTY_PRINT));
}
if (file_exists($file)) {
Log::debug(sprintf('Read file in "%s"', $file));
$limits = \Safe\json_decode((string) \Safe\file_get_contents($file), true);
$limits = json_decode((string) file_get_contents($file), true);
}
// limit reached?
foreach ($types as $type => $info) {
@@ -131,15 +137,15 @@ class MailError extends Job implements ShouldQueue
if (!array_key_exists($type, $limits)) {
Log::debug(sprintf('Limit "%s" reset to zero, did not exist yet.', $type));
$limits[$type] = [
'time' => time(),
'time' => Carbon::now()->getTimestamp(),
'sent' => 0,
];
}
if (time() - $limits[$type]['time'] > $info['reset']) {
Log::debug(sprintf('Time past for this limit is %d seconds, exceeding %d seconds. Reset to zero.', time() - $limits[$type]['time'], $info['reset']));
if (Carbon::now()->getTimestamp() - $limits[$type]['time'] > $info['reset']) {
Log::debug(sprintf('Time past for this limit is %d seconds, exceeding %d seconds. Reset to zero.', Carbon::now()->getTimestamp() - $limits[$type]['time'], $info['reset']));
$limits[$type] = [
'time' => time(),
'time' => Carbon::now()->getTimestamp(),
'sent' => 0,
];
}
@@ -151,7 +157,7 @@ class MailError extends Job implements ShouldQueue
}
++$limits[$type]['sent'];
}
\Safe\file_put_contents($file, \Safe\json_encode($limits, JSON_PRETTY_PRINT));
file_put_contents($file, json_encode($limits, JSON_PRETTY_PRINT));
Log::debug('No limits reached, return FALSE.');
return false;