mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Code reordering and reformatting. I should really start employing style CI.
This commit is contained in:
@@ -76,7 +76,7 @@ class CorrectDatabase extends Command
|
||||
'firefly-iii:fix-recurring-transactions',
|
||||
'firefly-iii:restore-oauth-keys',
|
||||
'firefly-iii:fix-transaction-types',
|
||||
'firefly-iii:fix-frontpage-accounts'
|
||||
'firefly-iii:fix-frontpage-accounts',
|
||||
];
|
||||
foreach ($commands as $command) {
|
||||
$this->line(sprintf('Now executing %s', $command));
|
||||
|
@@ -106,7 +106,7 @@ class DeleteOrphanedTransactions extends Command
|
||||
private function deleteFromOrphanedAccounts(): void
|
||||
{
|
||||
$set
|
||||
= Transaction
|
||||
= Transaction
|
||||
::leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')
|
||||
->whereNotNull('accounts.deleted_at')
|
||||
->get(['transactions.*']);
|
||||
|
@@ -53,9 +53,9 @@ class DeleteZeroAmount extends Command
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$start = microtime(true);
|
||||
$set = Transaction::where('amount', 0)->get(['transaction_journal_id'])->pluck('transaction_journal_id')->toArray();
|
||||
$set = array_unique($set);
|
||||
$start = microtime(true);
|
||||
$set = Transaction::where('amount', 0)->get(['transaction_journal_id'])->pluck('transaction_journal_id')->toArray();
|
||||
$set = array_unique($set);
|
||||
$journals = TransactionJournal::whereIn('id', $set)->get();
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($journals as $journal) {
|
||||
|
@@ -85,8 +85,8 @@ class EnableCurrencies extends Command
|
||||
$found[] = (int)$entry->transaction_currency_id;
|
||||
}
|
||||
|
||||
$found = array_values(array_unique($found));
|
||||
$found = array_values(
|
||||
$found = array_values(array_unique($found));
|
||||
$found = array_values(
|
||||
array_filter(
|
||||
$found, function (int $currencyId) {
|
||||
return $currencyId !== 0;
|
||||
|
@@ -57,7 +57,7 @@ class FixPiggies extends Command
|
||||
{
|
||||
$count = 0;
|
||||
$start = microtime(true);
|
||||
$set = PiggyBankEvent::with(['PiggyBank', 'TransactionJournal', 'TransactionJournal.TransactionType'])->get();
|
||||
$set = PiggyBankEvent::with(['PiggyBank', 'TransactionJournal', 'TransactionJournal.TransactionType'])->get();
|
||||
|
||||
/** @var PiggyBankEvent $event */
|
||||
foreach ($set as $event) {
|
||||
|
@@ -125,7 +125,7 @@ class FixPostgresSequences extends Command
|
||||
|
||||
$highestId = DB::table($tableToCheck)->select(DB::raw('MAX(id)'))->first();
|
||||
$nextId = DB::table($tableToCheck)->select(DB::raw(sprintf('nextval(\'%s_id_seq\')', $tableToCheck)))->first();
|
||||
if(null === $nextId) {
|
||||
if (null === $nextId) {
|
||||
$this->line(sprintf('nextval is NULL for table "%s", go to next table.', $tableToCheck));
|
||||
continue;
|
||||
}
|
||||
|
@@ -91,7 +91,7 @@ class FixUnevenAmount extends Command
|
||||
// one of the transactions is bad.
|
||||
$journal = TransactionJournal::find($param);
|
||||
if (!$journal) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
/** @var Transaction $source */
|
||||
$source = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
|
@@ -36,7 +36,6 @@ use FireflyIII\Support\Export\ExportDataGenerator;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Collection;
|
||||
use InvalidArgumentException;
|
||||
use League\Csv\CannotInsertRecord;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
|
@@ -26,6 +26,7 @@ namespace FireflyIII\Console\Commands\Upgrade;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\BudgetLimit;
|
||||
use Illuminate\Console\Command;
|
||||
use JsonException;
|
||||
|
||||
/**
|
||||
* Class BudgetLimitCurrency
|
||||
@@ -51,7 +52,7 @@ class BudgetLimitCurrency extends Command
|
||||
*
|
||||
* @return int
|
||||
* @throws FireflyException
|
||||
* @throws \JsonException
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
@@ -106,7 +107,7 @@ class BudgetLimitCurrency extends Command
|
||||
return (bool)$configVar->data;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -104,7 +104,7 @@ class CCLiabilities extends Command
|
||||
return (bool)$configVar->data;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -116,7 +116,7 @@ class MigrateAttachments extends Command
|
||||
return (bool)$configVar->data;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -66,7 +66,7 @@ class MigrateJournalNotes extends Command
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
$set = TransactionJournalMeta::whereName('notes')->get();
|
||||
$set = TransactionJournalMeta::whereName('notes')->get();
|
||||
/** @var TransactionJournalMeta $meta */
|
||||
foreach ($set as $meta) {
|
||||
$journal = $meta->transactionJournal;
|
||||
@@ -114,7 +114,7 @@ class MigrateJournalNotes extends Command
|
||||
return (bool)$configVar->data;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -92,7 +92,7 @@ class MigrateRecurrenceMeta extends Command
|
||||
return (bool)$configVar->data;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -85,7 +85,7 @@ class MigrateRecurrenceType extends Command
|
||||
return (bool)$configVar->data;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -83,7 +83,7 @@ class MigrateTagLocations extends Command
|
||||
return (bool)$configVar->data;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
private function migrateTagLocations(): void
|
||||
|
@@ -137,7 +137,7 @@ class MigrateToGroups extends Command
|
||||
return (bool)$configVar->data;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -128,7 +128,7 @@ class MigrateToRules extends Command
|
||||
return (bool)$configVar->data;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -123,7 +123,7 @@ class OtherCurrenciesCorrections extends Command
|
||||
return (bool)$configVar->data;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -248,10 +248,10 @@ class OtherCurrenciesCorrections extends Command
|
||||
{
|
||||
$accountId = $account->id;
|
||||
if (array_key_exists($accountId, $this->accountCurrencies) && 0 === $this->accountCurrencies[$accountId]) {
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
if (array_key_exists($accountId, $this->accountCurrencies) && $this->accountCurrencies[$accountId] instanceof TransactionCurrency) {
|
||||
return $this->accountCurrencies[$accountId];
|
||||
return $this->accountCurrencies[$accountId];
|
||||
}
|
||||
$currency = $this->accountRepos->getAccountCurrency($account);
|
||||
if (null === $currency) {
|
||||
|
@@ -107,7 +107,7 @@ class RenameAccountMeta extends Command
|
||||
return (bool)$configVar->data;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -191,6 +191,7 @@ class TransactionIdentifier extends Command
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return $opposing;
|
||||
}
|
||||
|
||||
|
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Console\Commands\Upgrade;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
@@ -132,7 +133,7 @@ class TransferCurrenciesCorrections extends Command
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function isExecuted(): bool
|
||||
{
|
||||
@@ -141,7 +142,7 @@ class TransferCurrenciesCorrections extends Command
|
||||
return (bool)$configVar->data;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -271,10 +272,10 @@ class TransferCurrenciesCorrections extends Command
|
||||
{
|
||||
$accountId = $account->id;
|
||||
if (array_key_exists($accountId, $this->accountCurrencies) && 0 === $this->accountCurrencies[$accountId]) {
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
if (array_key_exists($accountId, $this->accountCurrencies) && $this->accountCurrencies[$accountId] instanceof TransactionCurrency) {
|
||||
return $this->accountCurrencies[$accountId];
|
||||
return $this->accountCurrencies[$accountId];
|
||||
}
|
||||
$currency = $this->accountRepos->getAccountCurrency($account);
|
||||
if (null === $currency) {
|
||||
|
@@ -106,7 +106,7 @@ class UpgradeDatabase extends Command
|
||||
|
||||
// instructions
|
||||
'firefly:instructions update',
|
||||
'firefly-iii:verify-security-alerts'
|
||||
'firefly-iii:verify-security-alerts',
|
||||
];
|
||||
$args = [];
|
||||
if ($this->option('force')) {
|
||||
|
@@ -92,59 +92,6 @@ class UpgradeLiabilities extends Command
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param TransactionJournal $openingBalance
|
||||
*/
|
||||
private function correctOpeningBalance(Account $account, TransactionJournal $openingBalance): void
|
||||
{
|
||||
$source = $this->getSourceTransaction($openingBalance);
|
||||
$destination = $this->getDestinationTransaction($openingBalance);
|
||||
if (null === $source || null === $destination) {
|
||||
return;
|
||||
}
|
||||
// source MUST be the liability.
|
||||
if ((int)$destination->account_id === (int)$account->id) {
|
||||
Log::debug(sprintf('Must switch around, because account #%d is the destination.', $destination->account_id));
|
||||
// so if not, switch things around:
|
||||
$sourceAccountId = (int)$source->account_id;
|
||||
$source->account_id = $destination->account_id;
|
||||
$destination->account_id = $sourceAccountId;
|
||||
$source->save();
|
||||
$destination->save();
|
||||
Log::debug(sprintf('Source transaction #%d now has account #%d', $source->id, $source->account_id));
|
||||
Log::debug(sprintf('Dest transaction #%d now has account #%d', $destination->id, $destination->account_id));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return Transaction|null
|
||||
*/
|
||||
private function getSourceTransaction(TransactionJournal $journal): ?Transaction
|
||||
{
|
||||
return $journal->transactions()->where('amount', '<', 0)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return Transaction|null
|
||||
*/
|
||||
private function getDestinationTransaction(TransactionJournal $journal): ?Transaction
|
||||
{
|
||||
return $journal->transactions()->where('amount', '>', 0)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function markAsExecuted(): void
|
||||
{
|
||||
app('fireflyconfig')->set(self::CONFIG_NAME, true);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -200,4 +147,57 @@ class UpgradeLiabilities extends Command
|
||||
$factory->crud($account, 'liability_direction', 'debit');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param TransactionJournal $openingBalance
|
||||
*/
|
||||
private function correctOpeningBalance(Account $account, TransactionJournal $openingBalance): void
|
||||
{
|
||||
$source = $this->getSourceTransaction($openingBalance);
|
||||
$destination = $this->getDestinationTransaction($openingBalance);
|
||||
if (null === $source || null === $destination) {
|
||||
return;
|
||||
}
|
||||
// source MUST be the liability.
|
||||
if ((int)$destination->account_id === (int)$account->id) {
|
||||
Log::debug(sprintf('Must switch around, because account #%d is the destination.', $destination->account_id));
|
||||
// so if not, switch things around:
|
||||
$sourceAccountId = (int)$source->account_id;
|
||||
$source->account_id = $destination->account_id;
|
||||
$destination->account_id = $sourceAccountId;
|
||||
$source->save();
|
||||
$destination->save();
|
||||
Log::debug(sprintf('Source transaction #%d now has account #%d', $source->id, $source->account_id));
|
||||
Log::debug(sprintf('Dest transaction #%d now has account #%d', $destination->id, $destination->account_id));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return Transaction|null
|
||||
*/
|
||||
private function getSourceTransaction(TransactionJournal $journal): ?Transaction
|
||||
{
|
||||
return $journal->transactions()->where('amount', '<', 0)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return Transaction|null
|
||||
*/
|
||||
private function getDestinationTransaction(TransactionJournal $journal): ?Transaction
|
||||
{
|
||||
return $journal->transactions()->where('amount', '>', 0)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function markAsExecuted(): void
|
||||
{
|
||||
app('fireflyconfig')->set(self::CONFIG_NAME, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -25,14 +25,21 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Storage;
|
||||
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
||||
use Log;
|
||||
use Storage;
|
||||
|
||||
/**
|
||||
* Class VerifySecurityAlerts
|
||||
*/
|
||||
class VerifySecurityAlerts extends Command
|
||||
{
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Verify security alerts';
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
@@ -40,18 +47,11 @@ class VerifySecurityAlerts extends Command
|
||||
*/
|
||||
protected $signature = 'firefly-iii:verify-security-alerts';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Verify security alerts';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
@@ -64,6 +64,7 @@ class VerifySecurityAlerts extends Command
|
||||
$disk = Storage::disk('resources');
|
||||
if (!$disk->has('alerts.json')) {
|
||||
Log::debug('No alerts.json file present.');
|
||||
|
||||
return 0;
|
||||
}
|
||||
$content = $disk->get('alerts.json');
|
||||
@@ -81,6 +82,7 @@ class VerifySecurityAlerts extends Command
|
||||
if ('info' === $array['level']) {
|
||||
Log::debug('INFO level alert');
|
||||
$this->info($array['message']);
|
||||
|
||||
return 0;
|
||||
}
|
||||
if ('warning' === $array['level']) {
|
||||
@@ -88,6 +90,7 @@ class VerifySecurityAlerts extends Command
|
||||
$this->warn('------------------------ :o');
|
||||
$this->warn($array['message']);
|
||||
$this->warn('------------------------ :o');
|
||||
|
||||
return 0;
|
||||
}
|
||||
if ('danger' === $array['level']) {
|
||||
@@ -95,6 +98,7 @@ class VerifySecurityAlerts extends Command
|
||||
$this->error('------------------------ :-(');
|
||||
$this->error($array['message']);
|
||||
$this->error('------------------------ :-(');
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user