mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Clean up some code.
This commit is contained in:
@@ -46,14 +46,10 @@ class FixAccountTypes extends Command
|
||||
* The name and signature of the console command.
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'firefly-iii:fix-account-types';
|
||||
/** @var int */
|
||||
private $count;
|
||||
private array $expected;
|
||||
/** @var AccountFactory */
|
||||
private $factory;
|
||||
/** @var array */
|
||||
private $fixable;
|
||||
protected $signature = 'firefly-iii:fix-account-types';
|
||||
private int $count;
|
||||
private array $expected;
|
||||
private AccountFactory $factory;
|
||||
|
||||
|
||||
/**
|
||||
@@ -65,19 +61,8 @@ class FixAccountTypes extends Command
|
||||
{
|
||||
$this->stupidLaravel();
|
||||
Log::debug('Now in fix-account-types');
|
||||
$start = microtime(true);
|
||||
$this->factory = app(AccountFactory::class);
|
||||
// some combinations can be fixed by this script:
|
||||
$this->fixable = [// transfers from asset to liability and vice versa
|
||||
sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::ASSET, AccountType::LOAN), sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::ASSET, AccountType::DEBT), sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::ASSET, AccountType::MORTGAGE), sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::LOAN, AccountType::ASSET), sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::DEBT, AccountType::ASSET), sprintf('%s%s%s', TransactionType::TRANSFER, AccountType::MORTGAGE, AccountType::ASSET),
|
||||
|
||||
// withdrawals with a revenue account as destination instead of an expense account.
|
||||
sprintf('%s%s%s', TransactionType::WITHDRAWAL, AccountType::ASSET, AccountType::REVENUE),
|
||||
|
||||
// deposits with an expense account as source instead of a revenue account.
|
||||
sprintf('%s%s%s', TransactionType::DEPOSIT, AccountType::EXPENSE, AccountType::ASSET),];
|
||||
|
||||
|
||||
$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()));
|
||||
@@ -203,10 +188,10 @@ class FixAccountTypes extends Command
|
||||
*/
|
||||
private function inspectJournal(TransactionJournal $journal): void
|
||||
{
|
||||
$count = $journal->transactions()->count();
|
||||
if (2 !== $count) {
|
||||
Log::debug(sprintf('Journal has %d transactions, so cant fix.', $count));
|
||||
$this->info(sprintf('Cannot inspect transaction journal #%d because it has %d transaction(s) instead of 2.', $journal->id, $count));
|
||||
$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;
|
||||
}
|
||||
|
@@ -44,8 +44,7 @@ class RenameMetaFields extends Command
|
||||
*/
|
||||
protected $signature = 'firefly-iii:rename-meta-fields';
|
||||
|
||||
/** @var int */
|
||||
private $count;
|
||||
private int $count;
|
||||
|
||||
|
||||
/**
|
||||
@@ -93,9 +92,9 @@ class RenameMetaFields extends Command
|
||||
*/
|
||||
private function rename(string $original, string $update): void
|
||||
{
|
||||
$count = DB::table('journal_meta')
|
||||
$total = DB::table('journal_meta')
|
||||
->where('name', '=', $original)
|
||||
->update(['name' => $update]);
|
||||
$this->count += $count;
|
||||
$this->count += $total;
|
||||
}
|
||||
}
|
||||
|
@@ -98,8 +98,6 @@ class DecryptDatabase extends Command
|
||||
} catch(JsonException $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
//Log::debug(sprintf('Decrypted field "%s" "%s" to "%s" in table "%s" (row #%d)', $field, $original, print_r($value, true), $table, $id));
|
||||
|
||||
/** @var Preference $object */
|
||||
$object = Preference::find((int) $id);
|
||||
if (null !== $object) {
|
||||
@@ -110,7 +108,6 @@ class DecryptDatabase extends Command
|
||||
}
|
||||
|
||||
if ($value !== $original) {
|
||||
//Log::debug(sprintf('Decrypted field "%s" "%s" to "%s" in table "%s" (row #%d)', $field, $original, $value, $table, $id));
|
||||
DB::table($table)->where('id', $id)->update([$field => $value]);
|
||||
}
|
||||
}
|
||||
|
@@ -131,11 +131,11 @@ class ApplyRules extends Command
|
||||
$ruleEngine->setUser($this->getUser());
|
||||
|
||||
// add the accounts as filter:
|
||||
$accounts = [];
|
||||
$filterAccountList = [];
|
||||
foreach($this->accounts as $account) {
|
||||
$accounts[] = $account->id;
|
||||
$filterAccountList[] = $account->id;
|
||||
}
|
||||
$list = implode(',', $accounts);
|
||||
$list = implode(',', $filterAccountList);
|
||||
$ruleEngine->addOperator(['type' => 'account_id', 'value' => $list]);
|
||||
|
||||
// add the date as a filter:
|
||||
@@ -295,7 +295,7 @@ class ApplyRules extends Command
|
||||
private function verifyInputDates(): void
|
||||
{
|
||||
// parse start date.
|
||||
$startDate = Carbon::now()->startOfMonth();
|
||||
$inputStart = Carbon::now()->startOfMonth();
|
||||
$startString = $this->option('start_date');
|
||||
if (null === $startString) {
|
||||
/** @var JournalRepositoryInterface $repository */
|
||||
@@ -303,26 +303,26 @@ class ApplyRules extends Command
|
||||
$repository->setUser($this->getUser());
|
||||
$first = $repository->firstNull();
|
||||
if (null !== $first) {
|
||||
$startDate = $first->date;
|
||||
$inputStart = $first->date;
|
||||
}
|
||||
}
|
||||
if (null !== $startString && '' !== $startString) {
|
||||
$startDate = Carbon::createFromFormat('Y-m-d', $startString);
|
||||
$inputStart = Carbon::createFromFormat('Y-m-d', $startString);
|
||||
}
|
||||
|
||||
// parse end date
|
||||
$endDate = Carbon::now();
|
||||
$inputEnd = Carbon::now();
|
||||
$endString = $this->option('end_date');
|
||||
if (null !== $endString && '' !== $endString) {
|
||||
$endDate = Carbon::createFromFormat('Y-m-d', $endString);
|
||||
$inputEnd = Carbon::createFromFormat('Y-m-d', $endString);
|
||||
}
|
||||
|
||||
if ($startDate > $endDate) {
|
||||
[$endDate, $startDate] = [$startDate, $endDate];
|
||||
if ($inputStart > $inputEnd) {
|
||||
[$inputEnd, $inputStart] = [$inputStart, $inputEnd];
|
||||
}
|
||||
|
||||
$this->startDate = $startDate;
|
||||
$this->endDate = $endDate;
|
||||
$this->startDate = $inputStart;
|
||||
$this->endDate = $inputEnd;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -72,8 +72,8 @@ class MigrateAttachments extends Command
|
||||
foreach ($attachments as $att) {
|
||||
|
||||
// move description:
|
||||
$description = (string) $att->description;
|
||||
if ('' !== $description) {
|
||||
$attDescription = (string) $att->description;
|
||||
if ('' !== $attDescription) {
|
||||
|
||||
// find or create note:
|
||||
$note = $att->notes()->first();
|
||||
@@ -81,7 +81,7 @@ class MigrateAttachments extends Command
|
||||
$note = new Note;
|
||||
$note->noteable()->associate($att);
|
||||
}
|
||||
$note->text = $description;
|
||||
$note->text = $attDescription;
|
||||
$note->save();
|
||||
|
||||
// clear description:
|
||||
|
@@ -58,23 +58,18 @@ class MigrateToGroups extends Command
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'firefly-iii:migrate-to-groups {--F|force : Force the migration, even if it fired before.}';
|
||||
/** @var JournalCLIRepositoryInterface */
|
||||
private $cliRepository;
|
||||
private $count;
|
||||
/** @var TransactionGroupFactory */
|
||||
private $groupFactory;
|
||||
/** @var JournalRepositoryInterface */
|
||||
private $journalRepository;
|
||||
/** @var JournalDestroyService */
|
||||
private $service;
|
||||
|
||||
protected $signature = 'firefly-iii:migrate-to-groups {--F|force : Force the migration, even if it fired before.}';
|
||||
private JournalCLIRepositoryInterface $cliRepository;
|
||||
private int $count;
|
||||
private TransactionGroupFactory $groupFactory;
|
||||
private JournalRepositoryInterface $journalRepository;
|
||||
private JournalDestroyService $service;
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @throws Exception
|
||||
* @return int
|
||||
* @throws Exception
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
@@ -254,16 +249,16 @@ class MigrateToGroups extends Command
|
||||
private function makeGroupsFromAll(): void
|
||||
{
|
||||
$orphanedJournals = $this->cliRepository->getJournalsWithoutGroup();
|
||||
$count = count($orphanedJournals);
|
||||
if ($count > 0) {
|
||||
Log::debug(sprintf('Going to convert %d transaction journals. Please hold..', $count));
|
||||
$this->line(sprintf('Going to convert %d transaction journals. Please hold..', $count));
|
||||
$total = count($orphanedJournals);
|
||||
if ($total > 0) {
|
||||
Log::debug(sprintf('Going to convert %d transaction journals. Please hold..', $total));
|
||||
$this->line(sprintf('Going to convert %d transaction journals. Please hold..', $total));
|
||||
/** @var array $journal */
|
||||
foreach ($orphanedJournals as $array) {
|
||||
$this->giveGroup($array);
|
||||
}
|
||||
}
|
||||
if (0 === $count) {
|
||||
if (0 === $total) {
|
||||
$this->info('No need to convert transaction journals.');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user