cleanup: Commands are a lot less verbal and report better on success / failue

This commit is contained in:
James Cole
2023-06-02 07:36:17 +02:00
parent 1e1497ff4e
commit dcf71c6fdf
60 changed files with 1108 additions and 1698 deletions

View File

@@ -39,22 +39,10 @@ use Illuminate\Console\Command;
*/
class CorrectAmounts extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'This command makes sure positive and negative amounts are recorded correctly.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:fix-amount-pos-neg';
protected $signature = 'firefly-iii:fix-amount-pos-neg';
/**
* Execute the console command.
*
* @return int
*/
public function handle(): int

View File

@@ -34,25 +34,14 @@ use Schema;
*/
class CorrectDatabase extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Will correct the integrity of your database, if necessary.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:correct-database';
protected $signature = 'firefly-iii:correct-database';
/**
* Execute the console command.
*/
public function handle(): int
{
$this->line('Handle Firefly III database correction commands.');
// if table does not exist, return false
if (!Schema::hasTable('users')) {
$this->error('No "users"-table, will not continue.');

View File

@@ -24,7 +24,6 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Transaction;
@@ -33,26 +32,15 @@ use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use JsonException;
use Illuminate\Support\Collection;
/**
* Class CorrectOpeningBalanceCurrencies
*/
class CorrectOpeningBalanceCurrencies extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Will make sure that opening balance transaction currencies match the account they\'re for.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:fix-ob-currencies';
protected $signature = 'firefly-iii:fix-ob-currencies';
/**
* Execute the console command.
@@ -61,32 +49,22 @@ class CorrectOpeningBalanceCurrencies extends Command
*/
public function handle(): int
{
Log::debug(sprintf('Now in %s', __METHOD__));
// get all OB journals:
$set = TransactionJournal::leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
->whereNull('transaction_journals.deleted_at')
->where('transaction_types.type', TransactionType::OPENING_BALANCE)->get(['transaction_journals.*']);
$this->line(sprintf('Going to verify %d opening balance transactions.', $set->count()));
$count = 0;
$journals = $this->getJournals();
$count = 0;
/** @var TransactionJournal $journal */
foreach ($set as $journal) {
foreach ($journals as $journal) {
$count += $this->correctJournal($journal);
}
if ($count > 0) {
$message = sprintf('Corrected %d opening balance transaction(s).', $count);
Log::debug($message);
$this->line($message);
}
if (0 === $count) {
$message = 'There was nothing to fix in the opening balance transactions.';
Log::debug($message);
$message = 'Correct: There was nothing to fix in the opening balance transactions.';
$this->info($message);
}
Log::debug(sprintf('Done with %s', __METHOD__));
return 0;
}
@@ -94,24 +72,21 @@ class CorrectOpeningBalanceCurrencies extends Command
* @param TransactionJournal $journal
*
* @return int
* @throws FireflyException
* @throws JsonException
*/
private function correctJournal(TransactionJournal $journal): int
{
// get the asset account for this opening balance:
$account = $this->getAccount($journal);
if (null === $account) {
$message = sprintf('Transaction journal #%d has no valid account. Cant fix this line.', $journal->id);
$message = sprintf('Transaction journal #%d has no valid account. Can\'t fix this line.', $journal->id);
app('log')->warning($message);
$this->warn($message);
return 0;
}
$currency = $this->getCurrency($account);
// update journal and all transactions:
return $this->setCurrency($journal, $currency);
return $this->setCorrectCurrency($account, $journal);
}
/**
@@ -138,8 +113,6 @@ class CorrectOpeningBalanceCurrencies extends Command
* @param Account $account
*
* @return TransactionCurrency
* @throws JsonException
* @throws FireflyException
*/
private function getCurrency(Account $account): TransactionCurrency
{
@@ -151,14 +124,25 @@ class CorrectOpeningBalanceCurrencies extends Command
}
/**
* @return Collection
*/
private function getJournals(): Collection
{
/** @var Collection */
return TransactionJournal::leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
->whereNull('transaction_journals.deleted_at')
->where('transaction_types.type', TransactionType::OPENING_BALANCE)->get(['transaction_journals.*']);
}
/**
* @param Account $account
* @param TransactionJournal $journal
* @param TransactionCurrency $currency
*
* @return int
*/
private function setCurrency(TransactionJournal $journal, TransactionCurrency $currency): int
private function setCorrectCurrency(Account $account, TransactionJournal $journal): int
{
$count = 0;
$currency = $this->getCurrency($account);
$count = 0;
if ((int)$journal->transaction_currency_id !== (int)$currency->id) {
$journal->transaction_currency_id = $currency->id;
$journal->save();

View File

@@ -58,7 +58,6 @@ class CreateAccessTokens extends Command
/** @var UserRepositoryInterface $repository */
$repository = app(UserRepositoryInterface::class);
$start = microtime(true);
$count = 0;
$users = $repository->all();
/** @var User $user */
@@ -72,10 +71,8 @@ class CreateAccessTokens extends Command
}
}
if (0 === $count) {
$this->info('All access tokens OK!');
$this->info('Correct: Verified access tokens.');
}
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verify access tokens in %s seconds.', $end));
return 0;
}

View File

@@ -51,7 +51,6 @@ class CreateLinkTypes extends Command
*/
public function handle(): int
{
$start = microtime(true);
$count = 0;
$set = [
'Related' => ['relates to', 'relates to'],
@@ -74,11 +73,8 @@ class CreateLinkTypes extends Command
$link->save();
}
if (0 === $count) {
$this->info('All link types OK!');
$this->info('Correct: all link types are OK');
}
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified link types in %s seconds', $end));
return 0;
}
}

View File

@@ -26,25 +26,14 @@ namespace FireflyIII\Console\Commands\Correction;
use Exception;
use FireflyIII\Models\TransactionGroup;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
/**
* Class DeleteEmptyGroups
*/
class DeleteEmptyGroups extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Delete empty transaction groups.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:delete-empty-groups';
protected $signature = 'firefly-iii:delete-empty-groups';
/**
* Execute the console command.
@@ -55,14 +44,11 @@ class DeleteEmptyGroups extends Command
*/
public function handle(): int
{
Log::debug(sprintf('Now in %s', __METHOD__));
$start = microtime(true);
$groupIds
= TransactionGroup::leftJoin('transaction_journals', 'transaction_groups.id', '=', 'transaction_journals.transaction_group_id')
->whereNull('transaction_journals.id')->get(['transaction_groups.id'])->pluck('id')->toArray();
= TransactionGroup::leftJoin('transaction_journals', 'transaction_groups.id', '=', 'transaction_journals.transaction_group_id')
->whereNull('transaction_journals.id')->get(['transaction_groups.id'])->pluck('id')->toArray();
$total = count($groupIds);
Log::debug(sprintf('Count is %d', $total));
if ($total > 0) {
$this->info(sprintf('Deleted %d empty transaction group(s).', $total));
@@ -72,8 +58,9 @@ class DeleteEmptyGroups extends Command
TransactionGroup::whereNull('deleted_at')->whereIn('id', $chunk)->delete();
}
}
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified empty groups in %s seconds', $end));
if (0 === $total) {
$this->info('Correct: verified empty groups.');
}
return 0;
}

View File

@@ -63,7 +63,6 @@ class DeleteEmptyJournals extends Command
private function deleteEmptyJournals(): void
{
$start = microtime(true);
$count = 0;
$set = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->groupBy('transaction_journals.id')
@@ -82,10 +81,8 @@ class DeleteEmptyJournals extends Command
++$count;
}
if (0 === $count) {
$this->info('No empty transaction journals.');
$this->info('Correct: no empty transaction journals.');
}
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified empty journals in %s seconds', $end));
}
/**
@@ -115,7 +112,7 @@ class DeleteEmptyJournals extends Command
}
}
if (0 === $total) {
$this->info('No uneven transaction journals.');
$this->info('Correct: no uneven transaction journals.');
}
}
}

View File

@@ -55,12 +55,9 @@ class DeleteOrphanedTransactions extends Command
*/
public function handle(): int
{
$start = microtime(true);
$this->deleteOrphanedJournals();
$this->deleteOrphanedTransactions();
$this->deleteFromOrphanedAccounts();
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified orphans in %s seconds', $end));
return 0;
}
@@ -93,7 +90,7 @@ class DeleteOrphanedTransactions extends Command
$count++;
}
if (0 === $count) {
$this->info('No orphaned accounts.');
$this->info('Correct: no orphaned accounts.');
}
}
@@ -105,7 +102,7 @@ class DeleteOrphanedTransactions extends Command
->get(['transaction_journals.id', 'transaction_journals.transaction_group_id']);
$count = $set->count();
if (0 === $count) {
$this->info('No orphaned journals.');
$this->info('Correct: no orphaned journals.');
}
if ($count > 0) {
$this->info(sprintf('Found %d orphaned journal(s).', $count));
@@ -157,7 +154,7 @@ class DeleteOrphanedTransactions extends Command
}
}
if (0 === $count) {
$this->info('No orphaned transactions.');
$this->info('Correct: no orphaned transactions.');
}
}
}

View File

@@ -52,7 +52,6 @@ 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);
$journals = TransactionJournal::whereIn('id', $set)->get();
@@ -64,12 +63,9 @@ class DeleteZeroAmount extends Command
Transaction::where('transaction_journal_id', $journal->id)->delete();
}
if (0 === $journals->count()) {
$this->info('No zero-amount transaction journals.');
$this->info('Correct: no zero-amount transaction journals.');
}
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified zero-amount integrity in %s seconds', $end));
return 0;
}
}

View File

@@ -37,18 +37,8 @@ use Illuminate\Support\Facades\Log;
*/
class EnableCurrencies extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Enables all currencies in use.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:enable-currencies';
protected $signature = 'firefly-iii:enable-currencies';
/**
* Execute the console command.
@@ -57,7 +47,6 @@ class EnableCurrencies extends Command
*/
public function handle(): int
{
$start = microtime(true);
$found = [];
// get all meta entries
/** @var Collection $meta */
@@ -85,8 +74,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) {
@@ -94,22 +83,15 @@ class EnableCurrencies extends Command
}
)
);
$message = sprintf('%d different currencies are currently in use.', count($found));
$this->info($message);
Log::debug($message, $found);
$disabled = TransactionCurrency::whereIn('id', $found)->where('enabled', false)->count();
if ($disabled > 0) {
$this->info(sprintf('%d were (was) still disabled. This has been corrected.', $disabled));
}
if (0 === $disabled) {
$this->info('All currencies are correctly enabled or disabled.');
$this->info('Correct: All currencies are correctly enabled or disabled.');
}
TransactionCurrency::whereIn('id', $found)->update(['enabled' => true]);
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified currencies in %s seconds.', $end));
return 0;
}
}

View File

@@ -32,18 +32,8 @@ use Illuminate\Console\Command;
*/
class FixAccountOrder extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Make sure account order is correct.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:fix-account-order';
protected $signature = 'firefly-iii:fix-account-order';
private AccountRepositoryInterface $repository;
@@ -55,7 +45,6 @@ class FixAccountOrder extends Command
public function handle(): int
{
$this->stupidLaravel();
$start = microtime(true);
$users = User::get();
foreach ($users as $user) {
@@ -63,8 +52,7 @@ class FixAccountOrder extends Command
$this->repository->resetAccountOrder();
}
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verifying account order took %s seconds', $end));
$this->info('Correct: All accounts are ordered correctly');
return 0;
}

View File

@@ -38,18 +38,8 @@ use Illuminate\Support\Facades\Log;
*/
class FixAccountTypes extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Make sure all journals have the correct from/to account types.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:fix-account-types';
protected $signature = 'firefly-iii:fix-account-types';
private int $count;
private array $expected;
private AccountFactory $factory;
@@ -63,103 +53,23 @@ class FixAccountTypes extends Command
public function handle(): int
{
$this->stupidLaravel();
Log::debug('Now in fix-account-types');
$start = microtime(true);
$this->factory = app(AccountFactory::class);
$this->expected = config('firefly.source_dests');
$journals = TransactionJournal::with(['TransactionType', 'transactions', 'transactions.account', 'transactions.account.accounttype'])->get();
Log::debug(sprintf('Found %d journals to inspect.', $journals->count()));
foreach ($journals as $journal) {
$this->inspectJournal($journal);
}
if (0 === $this->count) {
Log::debug('No journals had to be fixed.');
$this->info('All account types are OK!');
$this->info('Correct: all account types are OK');
}
if (0 !== $this->count) {
Log::debug(sprintf('%d journals had to be fixed.', $this->count));
$this->info(sprintf('Acted on %d transaction(s)!', $this->count));
}
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verifying account types took %s seconds', $end));
return 0;
}
/**
* Laravel will execute ALL __construct() methods for ALL commands whenever a SINGLE command is
* executed. This leads to noticeable slow-downs and class calls. To prevent this, this method should
* be called from the handle method instead of using the constructor to initialize the command.
*
*/
private function stupidLaravel(): void
{
$this->count = 0;
}
/**
* @param TransactionJournal $journal
*
* @throws FireflyException
*/
private function inspectJournal(TransactionJournal $journal): void
{
$transactions = $journal->transactions()->count();
if (2 !== $transactions) {
Log::debug(sprintf('Journal has %d transactions, so can\'t fix.', $transactions));
$this->info(sprintf('Cannot inspect transaction journal #%d because it has %d transaction(s) instead of 2.', $journal->id, $transactions));
return;
}
$type = $journal->transactionType->type;
$sourceTransaction = $this->getSourceTransaction($journal);
$destTransaction = $this->getDestinationTransaction($journal);
$sourceAccount = $sourceTransaction->account;
$sourceAccountType = $sourceAccount->accountType->type;
$destAccount = $destTransaction->account;
$destAccountType = $destAccount->accountType->type;
if (!array_key_exists($type, $this->expected)) {
Log::info(sprintf('No source/destination info for transaction type %s.', $type));
$this->info(sprintf('No source/destination info for transaction type %s.', $type));
return;
}
if (!array_key_exists($sourceAccountType, $this->expected[$type])) {
Log::debug(sprintf('Going to fix journal #%d', $journal->id));
$this->fixJournal($journal, $type, $sourceTransaction, $destTransaction);
return;
}
$expectedTypes = $this->expected[$type][$sourceAccountType];
if (!in_array($destAccountType, $expectedTypes, true)) {
Log::debug(sprintf('Going to fix journal #%d', $journal->id));
$this->fixJournal($journal, $type, $sourceTransaction, $destTransaction);
}
}
/**
* @param TransactionJournal $journal
*
* @return Transaction
*/
private function getSourceTransaction(TransactionJournal $journal): Transaction
{
return $journal->transactions->firstWhere('amount', '<', 0);
}
/**
* @param TransactionJournal $journal
*
* @return Transaction
*/
private function getDestinationTransaction(TransactionJournal $journal): Transaction
{
return $journal->transactions->firstWhere('amount', '>', 0);
}
/**
* @param TransactionJournal $journal
* @param string $type
@@ -254,4 +164,77 @@ class FixAccountTypes extends Command
break;
}
}
/**
* @param TransactionJournal $journal
*
* @return Transaction
*/
private function getDestinationTransaction(TransactionJournal $journal): Transaction
{
return $journal->transactions->firstWhere('amount', '>', 0);
}
/**
* @param TransactionJournal $journal
*
* @return Transaction
*/
private function getSourceTransaction(TransactionJournal $journal): Transaction
{
return $journal->transactions->firstWhere('amount', '<', 0);
}
/**
* @param TransactionJournal $journal
*
* @throws FireflyException
*/
private function inspectJournal(TransactionJournal $journal): void
{
$transactions = $journal->transactions()->count();
if (2 !== $transactions) {
Log::debug(sprintf('Journal has %d transactions, so can\'t fix.', $transactions));
$this->info(sprintf('Cannot inspect transaction journal #%d because it has %d transaction(s) instead of 2.', $journal->id, $transactions));
return;
}
$type = $journal->transactionType->type;
$sourceTransaction = $this->getSourceTransaction($journal);
$destTransaction = $this->getDestinationTransaction($journal);
$sourceAccount = $sourceTransaction->account;
$sourceAccountType = $sourceAccount->accountType->type;
$destAccount = $destTransaction->account;
$destAccountType = $destAccount->accountType->type;
if (!array_key_exists($type, $this->expected)) {
Log::info(sprintf('No source/destination info for transaction type %s.', $type));
$this->info(sprintf('No source/destination info for transaction type %s.', $type));
return;
}
if (!array_key_exists($sourceAccountType, $this->expected[$type])) {
Log::debug(sprintf('Going to fix journal #%d', $journal->id));
$this->fixJournal($journal, $type, $sourceTransaction, $destTransaction);
return;
}
$expectedTypes = $this->expected[$type][$sourceAccountType];
if (!in_array($destAccountType, $expectedTypes, true)) {
Log::debug(sprintf('Going to fix journal #%d', $journal->id));
$this->fixJournal($journal, $type, $sourceTransaction, $destTransaction);
}
}
/**
* Laravel will execute ALL __construct() methods for ALL commands whenever a SINGLE command is
* executed. This leads to noticeable slow-downs and class calls. To prevent this, this method should
* be called from the handle method instead of using the constructor to initialize the command.
*
*/
private function stupidLaravel(): void
{
$this->count = 0;
}
}

View File

@@ -36,18 +36,8 @@ use Illuminate\Console\Command;
*/
class FixFrontpageAccounts extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Fixes a preference that may include deleted accounts or accounts of another type.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:fix-frontpage-accounts';
protected $signature = 'firefly-iii:fix-frontpage-accounts';
/**
* Execute the console command.
@@ -56,8 +46,6 @@ class FixFrontpageAccounts extends Command
*/
public function handle(): int
{
$start = microtime(true);
$users = User::get();
/** @var User $user */
foreach ($users as $user) {
@@ -66,8 +54,7 @@ class FixFrontpageAccounts extends Command
$this->fixPreference($preference);
}
}
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verifying account preferences took %s seconds', $end));
$this->info('Correct: account preferences are OK');
return 0;
}

View File

@@ -36,18 +36,8 @@ use Illuminate\Console\Command;
*/
class FixGroupAccounts extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Unify the source / destination accounts of split groups.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:unify-group-accounts';
protected $signature = 'firefly-iii:unify-group-accounts';
/**
* Execute the console command.
@@ -72,7 +62,7 @@ class FixGroupAccounts extends Command
$handler->unifyAccounts($event);
}
$this->line('Updated inconsistent transaction groups.');
$this->info('Correct: updated possible inconsistent transaction groups.');
return 0;
}

View File

@@ -34,18 +34,9 @@ use Illuminate\Support\Collection;
*/
class FixIbans extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Removes spaces from IBANs';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:fix-ibans';
protected $signature = 'firefly-iii:fix-ibans';
private int $count = 0;
/**
* Execute the console command.
@@ -57,6 +48,9 @@ class FixIbans extends Command
$accounts = Account::whereNotNull('iban')->get();
$this->filterIbans($accounts);
$this->countAndCorrectIbans($accounts);
if (0 === $this->count) {
$this->info('Correct: All IBANs are valid.');
}
return 0;
}
@@ -99,6 +93,7 @@ class FixIbans extends Command
);
$account->iban = null;
$account->save();
$this->count++;
}
}
@@ -124,6 +119,7 @@ class FixIbans extends Command
$account->iban = $iban;
$account->save();
$this->line(sprintf('Removed spaces from IBAN of account #%d', $account->id));
$this->count++;
}
}
}

View File

@@ -34,18 +34,8 @@ use Illuminate\Console\Command;
class FixLongDescriptions extends Command
{
private const MAX_LENGTH = 1000;
/**
* The console command description.
*
* @var string
*/
protected $description = 'Fixes long descriptions in journals and groups.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:fix-long-descriptions';
protected $signature = 'firefly-iii:fix-long-descriptions';
/**
* Execute the console command.
@@ -54,14 +44,15 @@ class FixLongDescriptions extends Command
*/
public function handle(): int
{
$start = microtime(true);
$journals = TransactionJournal::get(['id', 'description']);
$count = 0;
/** @var TransactionJournal $journal */
foreach ($journals as $journal) {
if (strlen($journal->description) > self::MAX_LENGTH) {
$journal->description = substr($journal->description, 0, self::MAX_LENGTH);
$journal->save();
$this->line(sprintf('Truncated description of transaction journal #%d', $journal->id));
$count++;
}
}
@@ -72,11 +63,12 @@ class FixLongDescriptions extends Command
$group->title = substr($group->title, 0, self::MAX_LENGTH);
$group->save();
$this->line(sprintf('Truncated description of transaction group #%d', $group->id));
$count++;
}
}
$end = round(microtime(true) - $start, 2);
$this->info('Verified all transaction group and journal title lengths.');
$this->info(sprintf('Took %s seconds.', $end));
if (0 === $count) {
$this->info('Correct: all transaction group and journal title lengths are within bounds.');
}
return 0;
}

View File

@@ -34,18 +34,8 @@ use Illuminate\Console\Command;
*/
class FixPiggies extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Fixes common issues with piggy banks.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:fix-piggies';
protected $signature = 'firefly-iii:fix-piggies';
/**
* Execute the console command.
@@ -55,7 +45,6 @@ class FixPiggies extends Command
public function handle(): int
{
$count = 0;
$start = microtime(true);
$set = PiggyBankEvent::with(['PiggyBank', 'TransactionJournal'])->get();
/** @var PiggyBankEvent $event */
@@ -74,15 +63,12 @@ class FixPiggies extends Command
}
}
if (0 === $count) {
$this->line('All piggy bank events are correct.');
$this->info('Correct: all piggy bank events are OK.');
}
if (0 !== $count) {
$this->line(sprintf('Fixed %d piggy bank event(s).', $count));
}
$end = round(microtime(true) - $start, 2);
$this->line(sprintf('Verified the content of %d piggy bank events in %s seconds.', $set->count(), $end));
return 0;
}
}

View File

@@ -37,22 +37,11 @@ use Illuminate\Console\Command;
*/
class FixRecurringTransactions extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Fixes recurring transactions with the wrong transaction type.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:fix-recurring-transactions';
/** @var RecurringRepositoryInterface */
private $recurringRepos;
/** @var UserRepositoryInterface */
private $userRepos;
protected $description = 'Fixes recurring transactions with the wrong transaction type.';
protected $signature = 'firefly-iii:fix-recurring-transactions';
private int $count = 0;
private RecurringRepositoryInterface $recurringRepos;
private UserRepositoryInterface $userRepos;
/**
* Execute the console command.
@@ -61,11 +50,11 @@ class FixRecurringTransactions extends Command
*/
public function handle(): int
{
$start = microtime(true);
$this->stupidLaravel();
$this->correctTransactions();
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Corrected recurring transactions in %s seconds.', $end));
if (0 === $this->count) {
$this->info('Correct: all recurring transactions are OK.');
}
return 0;
}
@@ -111,6 +100,7 @@ class FixRecurringTransactions extends Command
if (null !== $transactionType) {
$recurrence->transaction_type_id = $transactionType->id;
$recurrence->save();
$this->count++;
}
}
}

View File

@@ -37,18 +37,8 @@ use Illuminate\Support\Collection;
*/
class FixTransactionTypes extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Make sure all transactions are of the correct type, based on source + dest.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:fix-transaction-types';
protected $signature = 'firefly-iii:fix-transaction-types';
/**
* Execute the console command.
@@ -57,7 +47,6 @@ class FixTransactionTypes extends Command
*/
public function handle(): int
{
$start = microtime(true);
$count = 0;
$journals = $this->collectJournals();
/** @var TransactionJournal $journal */
@@ -67,13 +56,12 @@ class FixTransactionTypes extends Command
$count++;
}
}
$end = round(microtime(true) - $start, 2);
if ($count > 0) {
$this->info(sprintf('Corrected transaction type of %d transaction journals in %s seconds.', $count, $end));
$this->info('Corrected transaction type of %d transaction journals.', $count);
return 0;
}
$this->line(sprintf('All transaction journals are of the correct transaction type (in %s seconds).', $end));
$this->info('Correct: all transaction journals are of the correct transaction type');
return 0;
}

View File

@@ -27,7 +27,6 @@ use DB;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use stdClass;
/**
@@ -35,18 +34,8 @@ use stdClass;
*/
class FixUnevenAmount extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Fix journals with uneven amounts.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:fix-uneven-amount';
protected $signature = 'firefly-iii:fix-uneven-amount';
/**
* Execute the console command.
@@ -55,10 +44,7 @@ class FixUnevenAmount extends Command
*/
public function handle(): int
{
Log::debug(sprintf('Now in %s', __METHOD__));
$start = microtime(true);
$count = 0;
// get invalid journals
$count = 0;
$journals = DB::table('transactions')
->groupBy('transaction_journal_id')
->whereNull('deleted_at')
@@ -74,12 +60,9 @@ class FixUnevenAmount extends Command
}
}
if (0 === $count) {
$this->info('Amount integrity OK!');
$this->info('Correct: Database amount integrity is OK');
}
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified amount integrity in %s seconds', $end));
return 0;
}

View File

@@ -32,18 +32,8 @@ use Illuminate\Console\Command;
*/
class RemoveBills extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Remove bills from transactions that shouldn\'t have one.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:remove-bills';
protected $signature = 'firefly-iii:remove-bills';
/**
* Execute the console command.
@@ -52,7 +42,6 @@ class RemoveBills extends Command
*/
public function handle(): int
{
$start = microtime(true);
/** @var TransactionType|null $withdrawal */
$withdrawal = TransactionType::where('type', TransactionType::WITHDRAWAL)->first();
if (null === $withdrawal) {
@@ -65,14 +54,10 @@ class RemoveBills extends Command
$journal->bill_id = null;
$journal->save();
}
if (0 === $journals->count()) {
$this->info('All transaction journals have correct bill information.');
}
if ($journals->count() > 0) {
$this->info('Fixed all transaction journals so they have correct bill information.');
}
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified bills / journals in %s seconds', $end));
$this->info('Correct: verified bills / journals in %s seconds');
return 0;
}

View File

@@ -31,18 +31,8 @@ use Illuminate\Console\Command;
*/
class RenameMetaFields extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Rename changed meta fields.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:rename-meta-fields';
protected $signature = 'firefly-iii:rename-meta-fields';
private int $count;
@@ -54,7 +44,6 @@ class RenameMetaFields extends Command
public function handle(): int
{
$this->count = 0;
$start = microtime(true);
$changes = [
'original-source' => 'original_source',
@@ -74,15 +63,11 @@ class RenameMetaFields extends Command
$this->rename($original, $update);
}
if (0 === $this->count) {
$this->line('All meta fields are correct.');
$this->info('Correct: all meta fields are correct.');
}
if (0 !== $this->count) {
$this->line(sprintf('Renamed %d meta field(s).', $this->count));
$this->info(sprintf('Renamed %d meta field(s).', $this->count));
}
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Renamed meta fields in %s seconds', $end));
return 0;
}

View File

@@ -33,18 +33,8 @@ use Illuminate\Support\Facades\Log;
*/
class TransferBudgets extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Removes budgets from transfers.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:fix-transfer-budgets';
protected $signature = 'firefly-iii:fix-transfer-budgets';
/**
* Execute the console command.
@@ -53,7 +43,6 @@ class TransferBudgets extends Command
*/
public function handle(): int
{
$start = microtime(true);
$set = TransactionJournal::distinct()
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
->leftJoin('budget_transaction_journal', 'transaction_journals.id', '=', 'budget_transaction_journal.transaction_journal_id')
@@ -69,8 +58,7 @@ class TransferBudgets extends Command
$count++;
}
if (0 === $count) {
$message = 'No invalid budget/journal entries.';
Log::debug($message);
$message = 'Correct: no invalid budget/journal entries.';
$this->info($message);
}
if (0 !== $count) {
@@ -78,9 +66,6 @@ class TransferBudgets extends Command
Log::debug($message);
$this->line($message);
}
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified budget/journals in %s seconds.', $end));
return 0;
}
}

View File

@@ -15,18 +15,8 @@ use Illuminate\Support\Facades\Log;
*/
class TriggerCreditCalculation extends Command
{
/**
* The console command description.
*
* @var string
*/
protected $description = 'Triggers the credit recalculation service for liabilities.';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'firefly-iii:trigger-credit-recalculation';
protected $signature = 'firefly-iii:trigger-credit-recalculation';
/**
* Execute the console command.
@@ -59,7 +49,6 @@ class TriggerCreditCalculation extends Command
->whereIn('account_types.type', config('firefly.valid_liabilities'))
->get(['accounts.*']);
foreach ($accounts as $account) {
Log::debug(sprintf('Processing account #%d ("%s")', $account->id, $account->name));
$this->processAccount($account);
}
}