Update configuration and fix some files.

This commit is contained in:
James Cole
2025-05-27 17:02:18 +02:00
parent c074fec0a7
commit d8f512ca3a
31 changed files with 154 additions and 111 deletions

View File

@@ -76,7 +76,7 @@ class CorrectsOpeningBalanceCurrencies extends Command
{
// get the asset account for this opening balance:
$account = $this->getAccount($journal);
if (null === $account) {
if (!$account instanceof Account) {
$message = sprintf('Transaction journal #%d has no valid account. Can\'t fix this line.', $journal->id);
app('log')->warning($message);
$this->friendlyError($message);

View File

@@ -387,7 +387,7 @@ class CorrectsUnevenAmount extends Command
continue;
}
if (0 === bccomp($source->amount, $source->foreign_amount) && 0 === bccomp($source->foreign_amount, $source->amount)) {
if (0 === bccomp((string) $source->amount, (string) $source->foreign_amount) && 0 === bccomp((string) $source->foreign_amount, (string) $source->amount)) {
Log::debug('Already fixed, continue.');
continue;

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Export;
use FireflyIII\Models\TransactionJournal;
use Carbon\Carbon;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Console\Commands\VerifiesAccessToken;
@@ -38,6 +39,8 @@ use Illuminate\Support\Collection;
use Exception;
use InvalidArgumentException;
use function Safe\file_put_contents;
class ExportsData extends Command
{
use ShowsFriendlyMessages;
@@ -203,7 +206,7 @@ class ExportsData extends Command
if (true === $error && 'start' === $field) {
$journal = $this->journalRepository->firstNull();
$date = null === $journal ? today(config('app.timezone'))->subYear() : $journal->date;
$date = $journal instanceof TransactionJournal ? $journal->date : today(config('app.timezone'))->subYear();
$date->startOfDay();
return $date;
@@ -275,7 +278,7 @@ class ExportsData extends Command
*/
private function exportData(array $options, array $data): void
{
$date = date('Y_m_d');
$date = Carbon::now()->format('Y_m_d');
foreach ($data as $key => $content) {
$file = sprintf('%s%s_%s.csv', $options['directory'], $date, $key);
if (false === $options['force'] && file_exists($file)) {
@@ -285,7 +288,7 @@ class ExportsData extends Command
$this->friendlyWarning(sprintf('File "%s" exists already but will be replaced.', $file));
}
// continue to write to file.
\Safe\file_put_contents($file, $content);
file_put_contents($file, $content);
$this->friendlyPositive(sprintf('Wrote %s-export to file "%s".', $key, $file));
}
}

View File

@@ -43,6 +43,9 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use function Safe\mb_regex_encoding;
use function Safe\json_encode;
/**
* This command was inspired by https://github.com/elliot-gh. It will check all amount fields
* and their values and correct them to the correct number of decimal places. This fixes issues where
@@ -130,7 +133,7 @@ class ForcesDecimalSize extends Command
// if sqlite, add function?
if ('sqlite' === (string) config('database.default')) {
DB::connection()->getPdo()->sqliteCreateFunction('REGEXP', static function ($pattern, $value) {
\Safe\mb_regex_encoding('UTF-8');
mb_regex_encoding('UTF-8');
$pattern = trim($pattern, '"');
return (false !== mb_ereg($pattern, (string) $value)) ? 1 : 0;
@@ -234,7 +237,7 @@ class ForcesDecimalSize extends Command
/** @var Builder $query */
$query = Account::leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id')
->where('account_meta.name', 'currency_id')
->where('account_meta.data', \Safe\json_encode((string) $currency->id))
->where('account_meta.data', json_encode((string) $currency->id))
;
$query->where(static function (Builder $q) use ($fields, $currency, $operator, $cast, $regularExpression): void {
foreach ($fields as $field) {
@@ -338,7 +341,7 @@ class ForcesDecimalSize extends Command
->leftJoin('accounts', 'piggy_banks.account_id', '=', 'accounts.id')
->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id')
->where('account_meta.name', 'currency_id')
->where('account_meta.data', \Safe\json_encode((string) $currency->id))
->where('account_meta.data', json_encode((string) $currency->id))
->where(static function (Builder $q) use ($fields, $currency, $cast, $operator, $regularExpression): void {
foreach ($fields as $field) {
$q->orWhere(
@@ -394,7 +397,7 @@ class ForcesDecimalSize extends Command
->leftJoin('accounts', 'piggy_banks.account_id', '=', 'accounts.id')
->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id')
->where('account_meta.name', 'currency_id')
->where('account_meta.data', \Safe\json_encode((string) $currency->id))
->where('account_meta.data', json_encode((string) $currency->id))
->where(static function (Builder $q) use ($fields, $currency, $operator, $cast, $regularExpression): void {
foreach ($fields as $field) {
$q->orWhere(
@@ -448,7 +451,7 @@ class ForcesDecimalSize extends Command
$query = PiggyBank::leftJoin('accounts', 'piggy_banks.account_id', '=', 'accounts.id')
->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id')
->where('account_meta.name', 'currency_id')
->where('account_meta.data', \Safe\json_encode((string) $currency->id))
->where('account_meta.data', json_encode((string) $currency->id))
->where(static function (Builder $q) use ($fields, $currency, $operator, $cast, $regularExpression): void {
foreach ($fields as $field) {
$q->orWhere(

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\System;
use Carbon\Carbon;
use FireflyIII\Support\System\GeneratesInstallationId;
use Illuminate\Console\Command;
@@ -111,8 +112,8 @@ class OutputsInstructions extends Command
*/
private function showLogo(): void
{
$today = date('m-d');
$month = date('m');
$today = Carbon::now()->format('m-d');
$month = Carbon::now()->format('m');
// variation in colors and effects just because I can!
// default is Ukraine flag:
$colors = ['blue', 'blue', 'blue', 'yellow', 'yellow', 'yellow', 'default', 'default'];

View File

@@ -31,6 +31,11 @@ use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Storage;
use function Safe\tempnam;
use function Safe\file_put_contents;
use function Safe\md5_file;
use function Safe\mime_content_type;
class ScansAttachments extends Command
{
use ShowsFriendlyMessages;
@@ -63,15 +68,15 @@ class ScansAttachments extends Command
app('log')->error(sprintf('Could not decrypt data of attachment #%d: %s', $attachment->id, $e->getMessage()));
$decryptedContent = $encryptedContent;
}
$tempFileName = \Safe\tempnam(sys_get_temp_dir(), 'FireflyIII');
$tempFileName = tempnam(sys_get_temp_dir(), 'FireflyIII');
if (false === $tempFileName) {
app('log')->error(sprintf('Could not create temporary file for attachment #%d', $attachment->id));
exit(1);
}
\Safe\file_put_contents($tempFileName, $decryptedContent);
$attachment->md5 = (string) \Safe\md5_file($tempFileName);
$attachment->mime = (string) \Safe\mime_content_type($tempFileName);
file_put_contents($tempFileName, $decryptedContent);
$attachment->md5 = (string) md5_file($tempFileName);
$attachment->mime = (string) mime_content_type($tempFileName);
$attachment->save();
$this->friendlyInfo(sprintf('Fixed attachment #%d', $attachment->id));
}

View File

@@ -30,6 +30,8 @@ use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Storage;
use League\Flysystem\FilesystemException;
use function Safe\json_decode;
class VerifySecurityAlerts extends Command
{
use ShowsFriendlyMessages;
@@ -57,7 +59,7 @@ class VerifySecurityAlerts extends Command
return 0;
}
$content = $disk->get('alerts.json');
$json = \Safe\json_decode($content, true, 10);
$json = json_decode((string) $content, true, 10);
/** @var array $array */
foreach ($json as $array) {

View File

@@ -248,7 +248,7 @@ class ApplyRules extends Command
foreach ($ruleList as $ruleId) {
$rule = $this->ruleRepository->find((int) $ruleId);
if (null !== $rule && true === $rule->active) {
if ($rule instanceof Rule && true === $rule->active) {
$this->ruleSelection[] = $rule->id;
}
}

View File

@@ -134,7 +134,7 @@ class Cron extends Command
$exchangeRates = new ExchangeRatesCronjob();
$exchangeRates->setForce($force);
// set date in cron job:
if (null !== $date) {
if ($date instanceof Carbon) {
$exchangeRates->setDate($date);
}
@@ -177,7 +177,7 @@ class Cron extends Command
$recurring->setForce($force);
// set date in cron job:
if (null !== $date) {
if ($date instanceof Carbon) {
$recurring->setDate($date);
}
@@ -198,7 +198,7 @@ class Cron extends Command
$autoBudget = new AutoBudgetCronjob();
$autoBudget->setForce($force);
// set date in cron job:
if (null !== $date) {
if ($date instanceof Carbon) {
$autoBudget->setDate($date);
}
@@ -223,7 +223,7 @@ class Cron extends Command
$autoBudget = new BillWarningCronjob();
$autoBudget->setForce($force);
// set date in cron job:
if (null !== $date) {
if ($date instanceof Carbon) {
$autoBudget->setDate($date);
}

View File

@@ -120,7 +120,7 @@ class AddsTransactionIdentifiers extends Command
/** @var Transaction $transaction */
foreach ($transactions as $transaction) {
$opposing = $this->findOpposing($transaction, $exclude);
if (null !== $opposing) {
if ($opposing instanceof Transaction) {
// give both a new identifier:
$transaction->identifier = $identifier;
$opposing->identifier = $identifier;

View File

@@ -34,6 +34,8 @@ use Illuminate\Support\Facades\DB;
use JsonException;
use stdClass;
use function Safe\json_decode;
class RemovesDatabaseDecryption extends Command
{
use ShowsFriendlyMessages;
@@ -169,7 +171,7 @@ class RemovesDatabaseDecryption extends Command
{
// try to json_decrypt the value.
try {
$newValue = \Safe\json_decode($value, true, 512, JSON_THROW_ON_ERROR) ?? $value;
$newValue = json_decode($value, true, 512, JSON_THROW_ON_ERROR) ?? $value;
} catch (JsonException $e) {
$message = sprintf('Could not JSON decode preference row #%d: %s. This does not have to be a problem.', $id, $e->getMessage());
$this->friendlyError($message);

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Exceptions\FireflyException;
@@ -141,7 +142,7 @@ class UpgradesAccountCurrencies extends Command
return;
}
// do not match and opening balance id is not null.
if ($accountCurrency !== $obCurrency && null !== $openingBalance) {
if ($accountCurrency !== $obCurrency && $openingBalance instanceof TransactionJournal) {
// update opening balance:
$openingBalance->transaction_currency_id = $accountCurrency;
$openingBalance->save();

View File

@@ -123,7 +123,7 @@ class UpgradesBillsToRules extends Command
$groupTitle = (string) trans('firefly.rulegroup_for_bills_title', [], $language);
$ruleGroup = $this->ruleGroupRepository->findByTitle($groupTitle);
if (null === $ruleGroup) {
if (!$ruleGroup instanceof RuleGroup) {
$ruleGroup = $this->ruleGroupRepository->store(
[
'title' => (string) trans('firefly.rulegroup_for_bills_title', [], $language),

View File

@@ -27,8 +27,10 @@ namespace FireflyIII\Console\Commands\Upgrade;
use Illuminate\Support\Facades\Log;
use Safe\Exceptions\InfoException;
use function Safe\set_time_limit;
try {
\Safe\set_time_limit(0);
set_time_limit(0);
} catch (InfoException) {
Log::warning('set_time_limit returned false. This could be an issue, unless you also run XDebug.');
}

View File

@@ -122,7 +122,7 @@ class UpgradesLiabilities extends Command
{
$source = $this->getSourceTransaction($openingBalance);
$destination = $this->getDestinationTransaction($openingBalance);
if (null === $source || null === $destination) {
if (!$source instanceof Transaction || !$destination instanceof Transaction) {
return;
}
// source MUST be the liability.

View File

@@ -30,6 +30,8 @@ use FireflyIII\Models\RecurrenceMeta;
use FireflyIII\Models\RecurrenceTransactionMeta;
use Illuminate\Console\Command;
use function Safe\json_encode;
class UpgradesRecurrenceMetaData extends Command
{
use ShowsFriendlyMessages;
@@ -100,7 +102,7 @@ class UpgradesRecurrenceMetaData extends Command
if ('tags' === $meta->name) {
$array = explode(',', $meta->value);
$value = \Safe\json_encode($array, JSON_THROW_ON_ERROR);
$value = json_encode($array, JSON_THROW_ON_ERROR);
}
RecurrenceTransactionMeta::create(

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade;
use Carbon\Carbon;
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Factory\TransactionGroupFactory;
use FireflyIII\Models\Budget;
@@ -192,7 +193,7 @@ class UpgradesToGroups extends Command
app('log')->debug(sprintf('Now going to add transaction #%d to the array.', $transaction->id));
$opposingTr = $this->findOpposingTransaction($journal, $transaction);
if (null === $opposingTr) {
if (!$opposingTr instanceof Transaction) {
$this->friendlyError(
sprintf(
'Journal #%d has no opposing transaction for transaction #%d. Cannot upgrade this entry.',
@@ -367,8 +368,8 @@ class UpgradesToGroups extends Command
{
$groupId = DB::table('transaction_groups')->insertGetId(
[
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
'updated_at' => Carbon::now()->format('Y-m-d H:i:s'),
'title' => null,
'user_id' => $array['user_id'],
]

View File

@@ -202,7 +202,7 @@ class UpgradesTransferCurrencies extends Command
{
$this->sourceTransaction = $this->getSourceTransaction($journal);
$this->sourceAccount = $this->sourceTransaction?->account;
$this->sourceCurrency = null === $this->sourceAccount ? null : $this->getCurrency($this->sourceAccount);
$this->sourceCurrency = $this->sourceAccount instanceof Account ? $this->getCurrency($this->sourceAccount) : null;
}
private function getSourceTransaction(TransactionJournal $transfer): ?Transaction
@@ -221,7 +221,7 @@ class UpgradesTransferCurrencies extends Command
return $this->accountCurrencies[$accountId];
}
$currency = $this->accountRepos->getAccountCurrency($account);
if (null === $currency) {
if (!$currency instanceof TransactionCurrency) {
$this->accountCurrencies[$accountId] = 0;
return null;
@@ -238,7 +238,7 @@ class UpgradesTransferCurrencies extends Command
{
$this->destinationTransaction = $this->getDestinationTransaction($journal);
$this->destinationAccount = $this->destinationTransaction?->account;
$this->destinationCurrency = null === $this->destinationAccount ? null : $this->getCurrency($this->destinationAccount);
$this->destinationCurrency = $this->destinationAccount instanceof Account ? $this->getCurrency($this->destinationAccount) : null;
}
private function getDestinationTransaction(TransactionJournal $transfer): ?Transaction
@@ -252,15 +252,15 @@ class UpgradesTransferCurrencies extends Command
*/
private function isEmptyTransactions(): bool
{
return null === $this->sourceTransaction || null === $this->destinationTransaction
|| null === $this->sourceAccount
|| null === $this->destinationAccount;
return !$this->sourceTransaction instanceof Transaction || !$this->destinationTransaction instanceof Transaction
|| !$this->sourceAccount instanceof Account
|| !$this->destinationAccount instanceof Account;
}
private function isNoCurrencyPresent(): bool
{
// source account must have a currency preference.
if (null === $this->sourceCurrency) {
if (!$this->sourceCurrency instanceof TransactionCurrency) {
$message = sprintf('Account #%d ("%s") must have currency preference but has none.', $this->sourceAccount->id, $this->sourceAccount->name);
app('log')->error($message);
$this->friendlyError($message);
@@ -269,7 +269,7 @@ class UpgradesTransferCurrencies extends Command
}
// destination account must have a currency preference.
if (null === $this->destinationCurrency) {
if (!$this->destinationCurrency instanceof TransactionCurrency) {
$message = sprintf(
'Account #%d ("%s") must have currency preference but has none.',
$this->destinationAccount->id,
@@ -290,7 +290,7 @@ class UpgradesTransferCurrencies extends Command
*/
private function fixSourceNoCurrency(): void
{
if (null === $this->sourceTransaction->transaction_currency_id && null !== $this->sourceCurrency) {
if (null === $this->sourceTransaction->transaction_currency_id && $this->sourceCurrency instanceof TransactionCurrency) {
$this->sourceTransaction
->transaction_currency_id
= $this->sourceCurrency->id
@@ -312,7 +312,7 @@ class UpgradesTransferCurrencies extends Command
*/
private function fixSourceUnmatchedCurrency(): void
{
if (null !== $this->sourceCurrency
if ($this->sourceCurrency instanceof TransactionCurrency
&& null === $this->sourceTransaction->foreign_amount
&& (int) $this->sourceTransaction->transaction_currency_id !== $this->sourceCurrency->id
) {
@@ -336,7 +336,7 @@ class UpgradesTransferCurrencies extends Command
*/
private function fixDestNoCurrency(): void
{
if (null === $this->destinationTransaction->transaction_currency_id && null !== $this->destinationCurrency) {
if (null === $this->destinationTransaction->transaction_currency_id && $this->destinationCurrency instanceof TransactionCurrency) {
$this->destinationTransaction
->transaction_currency_id
= $this->destinationCurrency->id
@@ -358,7 +358,7 @@ class UpgradesTransferCurrencies extends Command
*/
private function fixDestinationUnmatchedCurrency(): void
{
if (null !== $this->destinationCurrency
if ($this->destinationCurrency instanceof TransactionCurrency
&& null === $this->destinationTransaction->foreign_amount
&& (int) $this->destinationTransaction->transaction_currency_id !== $this->destinationCurrency->id
) {

View File

@@ -120,7 +120,7 @@ class UpgradesVariousCurrencyInformation extends Command
$leadTransaction = $this->getLeadTransaction($journal);
if (null === $leadTransaction) {
if (!$leadTransaction instanceof Transaction) {
$this->friendlyError(sprintf('Could not reliably determine which transaction is in the lead for transaction journal #%d.', $journal->id));
return;
@@ -129,7 +129,7 @@ class UpgradesVariousCurrencyInformation extends Command
$account = $leadTransaction->account;
$currency = $this->getCurrency($account);
$isMultiCurrency = $this->isMultiCurrency($account);
if (null === $currency) {
if (!$currency instanceof TransactionCurrency) {
$this->friendlyError(
sprintf(
'Account #%d ("%s") has no currency preference, so transaction journal #%d can\'t be corrected',
@@ -227,7 +227,7 @@ class UpgradesVariousCurrencyInformation extends Command
return $this->accountCurrencies[$accountId];
}
$currency = $this->accountRepos->getAccountCurrency($account);
if (null === $currency) {
if (!$currency instanceof TransactionCurrency) {
$this->accountCurrencies[$accountId] = 0;
return null;