mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
cleanup: Commands are a lot less verbal and report better on success / failue
This commit is contained in:
@@ -45,18 +45,8 @@ use Psr\Container\NotFoundExceptionInterface;
|
||||
class UpgradeLiabilitiesEight extends Command
|
||||
{
|
||||
public const CONFIG_NAME = '600_upgrade_liabilities';
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Upgrade liabilities to new 6.0.0 structure.';
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'firefly-iii:liabilities-600 {--F|force : Force the execution of this command.}';
|
||||
protected $signature = 'firefly-iii:liabilities-600 {--F|force : Force the execution of this command.}';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
@@ -68,7 +58,6 @@ class UpgradeLiabilitiesEight extends Command
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$start = microtime(true);
|
||||
if ($this->isExecuted() && true !== $this->option('force')) {
|
||||
$this->warn('This command has already been executed.');
|
||||
|
||||
@@ -77,9 +66,6 @@ class UpgradeLiabilitiesEight extends Command
|
||||
$this->upgradeLiabilities();
|
||||
$this->markAsExecuted();
|
||||
|
||||
$end = round(microtime(true) - $start, 2);
|
||||
$this->info(sprintf('Upgraded liabilities for 6.0.0 in %s seconds.', $end));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -90,7 +76,6 @@ class UpgradeLiabilitiesEight extends Command
|
||||
*/
|
||||
private function deleteCreditTransaction(Account $account): void
|
||||
{
|
||||
Log::debug('Will delete credit transaction.');
|
||||
$liabilityType = TransactionType::whereType(TransactionType::LIABILITY_CREDIT)->first();
|
||||
$liabilityJournal = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('transactions.account_id', $account->id)
|
||||
@@ -100,11 +85,9 @@ class UpgradeLiabilitiesEight extends Command
|
||||
$group = $liabilityJournal->transactionGroup;
|
||||
$service = new TransactionGroupDestroyService();
|
||||
$service->destroy($group);
|
||||
Log::debug(sprintf('Deleted liability credit group #%d', $group->id));
|
||||
|
||||
return;
|
||||
}
|
||||
Log::debug('No liability credit journal found.');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,7 +100,6 @@ class UpgradeLiabilitiesEight extends Command
|
||||
$count = 0;
|
||||
$journals = TransactionJournal::leftJoin('transactions', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->where('transactions.account_id', $account->id)->get(['transaction_journals.*']);
|
||||
Log::debug(sprintf('Found %d journals to analyse.', $journals->count()));
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$delete = false;
|
||||
@@ -140,16 +122,6 @@ class UpgradeLiabilitiesEight extends Command
|
||||
$delete = false;
|
||||
|
||||
if ($delete) {
|
||||
Log::debug(
|
||||
sprintf(
|
||||
'Deleted %s journal #%d ("%s") (%s %s).',
|
||||
$journal->transactionType->type,
|
||||
$journal->id,
|
||||
$journal->description,
|
||||
$journal->transactionCurrency->code,
|
||||
$dest->amount
|
||||
)
|
||||
);
|
||||
$service = app(TransactionGroupDestroyService::class);
|
||||
$service->destroy($journal->transactionGroup);
|
||||
$count++;
|
||||
@@ -173,8 +145,6 @@ class UpgradeLiabilitiesEight extends Command
|
||||
->where('transaction_journals.transaction_type_id', $openingBalanceType->id)
|
||||
->first(['transaction_journals.*']);
|
||||
if (null === $openingJournal) {
|
||||
Log::debug('Account has no opening balance and can be skipped.');
|
||||
|
||||
return false;
|
||||
}
|
||||
$liabilityJournal = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
@@ -182,16 +152,11 @@ class UpgradeLiabilitiesEight extends Command
|
||||
->where('transaction_journals.transaction_type_id', $liabilityType->id)
|
||||
->first(['transaction_journals.*']);
|
||||
if (null === $liabilityJournal) {
|
||||
Log::debug('Account has no liability credit and can be skipped.');
|
||||
|
||||
return false;
|
||||
}
|
||||
if (!$openingJournal->date->isSameDay($liabilityJournal->date)) {
|
||||
Log::debug('Account has opening/credit not on the same day.');
|
||||
|
||||
return false;
|
||||
}
|
||||
Log::debug('Account has bad opening balance data.');
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -243,7 +208,6 @@ class UpgradeLiabilitiesEight extends Command
|
||||
$source->account_id = $destId;
|
||||
$source->save();
|
||||
$dest->save();
|
||||
Log::debug(sprintf('Opening balance transaction journal #%d reversed.', $openingJournal->id));
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -255,7 +219,6 @@ class UpgradeLiabilitiesEight extends Command
|
||||
*/
|
||||
private function upgradeForUser(User $user): void
|
||||
{
|
||||
Log::debug(sprintf('Upgrading liabilities for user #%d', $user->id));
|
||||
$accounts = $user->accounts()
|
||||
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||
->whereIn('account_types.type', config('firefly.valid_liabilities'))
|
||||
@@ -274,7 +237,6 @@ class UpgradeLiabilitiesEight extends Command
|
||||
*/
|
||||
private function upgradeLiabilities(): void
|
||||
{
|
||||
Log::debug('Upgrading liabilities.');
|
||||
$users = User::get();
|
||||
/** @var User $user */
|
||||
foreach ($users as $user) {
|
||||
@@ -287,16 +249,11 @@ class UpgradeLiabilitiesEight extends Command
|
||||
*/
|
||||
private function upgradeLiability(Account $account): void
|
||||
{
|
||||
Log::debug(sprintf('Upgrade liability #%d ("%s")', $account->id, $account->name));
|
||||
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$repository->setUser($account->user);
|
||||
|
||||
$direction = $repository->getMetaValue($account, 'liability_direction');
|
||||
if ('debit' === $direction) {
|
||||
Log::debug('Direction is debit ("I owe this amount"), so no need to upgrade.');
|
||||
}
|
||||
if ('credit' === $direction && $this->hasBadOpening($account)) {
|
||||
$this->deleteCreditTransaction($account);
|
||||
$this->reverseOpeningBalance($account);
|
||||
@@ -308,6 +265,5 @@ class UpgradeLiabilitiesEight extends Command
|
||||
$this->line(sprintf('Removed %d old format transaction(s) for liability #%d ("%s")', $count, $account->id, $account->name));
|
||||
}
|
||||
}
|
||||
Log::debug(sprintf('Done upgrading liability #%d ("%s")', $account->id, $account->name));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user