mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 08:35:00 +00:00
Code cleanup.
This commit is contained in:
@@ -55,8 +55,6 @@ class AccountCurrencies extends Command
|
||||
/**
|
||||
* Each (asset) account must have a reference to a preferred currency. If the account does not have one, it's
|
||||
* forced upon the account.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
@@ -84,7 +82,6 @@ class AccountCurrencies extends Command
|
||||
* 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
|
||||
{
|
||||
@@ -94,19 +91,16 @@ class AccountCurrencies extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
private function isExecuted(): bool
|
||||
{
|
||||
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
|
||||
|
||||
return (bool)$configVar?->data;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function updateAccountCurrencies(): void
|
||||
{
|
||||
$users = $this->userRepos->all();
|
||||
@@ -116,8 +110,6 @@ class AccountCurrencies extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function updateCurrenciesForUser(User $user): void
|
||||
@@ -134,10 +126,6 @@ class AccountCurrencies extends Command
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param TransactionCurrency $currency
|
||||
*/
|
||||
private function updateAccount(Account $account, TransactionCurrency $currency): void
|
||||
{
|
||||
$this->accountRepos->setUser($account->user);
|
||||
@@ -150,7 +138,7 @@ class AccountCurrencies extends Command
|
||||
AccountMeta::where('account_id', $account->id)->where('name', 'currency_id')->forceDelete();
|
||||
AccountMeta::create(['account_id' => $account->id, 'name' => 'currency_id', 'data' => $currency->id]);
|
||||
$this->friendlyInfo(sprintf('Account #%d ("%s") now has a currency setting (%s).', $account->id, $account->name, $currency->code));
|
||||
$this->count++;
|
||||
++$this->count;
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -159,7 +147,7 @@ class AccountCurrencies extends Command
|
||||
if (0 === $accountCurrency && $obCurrency > 0) {
|
||||
AccountMeta::create(['account_id' => $account->id, 'name' => 'currency_id', 'data' => $obCurrency]);
|
||||
$this->friendlyInfo(sprintf('Account #%d ("%s") now has a currency setting (#%d).', $account->id, $account->name, $obCurrency));
|
||||
$this->count++;
|
||||
++$this->count;
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -175,13 +163,10 @@ class AccountCurrencies extends Command
|
||||
}
|
||||
);
|
||||
$this->friendlyInfo(sprintf('Account #%d ("%s") now has a correct currency for opening balance.', $account->id, $account->name));
|
||||
$this->count++;
|
||||
++$this->count;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function markAsExecuted(): void
|
||||
{
|
||||
app('fireflyconfig')->set(self::CONFIG_NAME, true);
|
||||
|
@@ -45,7 +45,6 @@ class AppendBudgetLimitPeriods extends Command
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
@@ -64,7 +63,6 @@ class AppendBudgetLimitPeriods extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
@@ -75,21 +73,16 @@ class AppendBudgetLimitPeriods extends Command
|
||||
return (bool)$configVar->data;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function theresNoLimit(): void
|
||||
{
|
||||
$limits = BudgetLimit::whereNull('period')->get();
|
||||
|
||||
/** @var BudgetLimit $limit */
|
||||
foreach ($limits as $limit) {
|
||||
$this->fixLimit($limit);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BudgetLimit $limit
|
||||
*/
|
||||
private function fixLimit(BudgetLimit $limit): void
|
||||
{
|
||||
$period = $this->getLimitPeriod($limit);
|
||||
@@ -119,11 +112,6 @@ class AppendBudgetLimitPeriods extends Command
|
||||
app('log')->debug($msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BudgetLimit $limit
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
private function getLimitPeriod(BudgetLimit $limit): ?string
|
||||
{
|
||||
// is daily
|
||||
@@ -172,9 +160,6 @@ class AppendBudgetLimitPeriods extends Command
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function markAsExecuted(): void
|
||||
{
|
||||
app('fireflyconfig')->set(self::CONFIG_NAME, true);
|
||||
|
@@ -23,7 +23,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Console\Commands\Upgrade;
|
||||
|
||||
use DB;
|
||||
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\Category;
|
||||
@@ -50,7 +49,6 @@ class BackToJournals extends Command
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
@@ -68,7 +66,6 @@ class BackToJournals extends Command
|
||||
$this->friendlyWarning('Forcing the command.');
|
||||
}
|
||||
|
||||
|
||||
$this->migrateAll();
|
||||
$this->friendlyInfo('Updated category and budget info for all transaction journals');
|
||||
$this->markAsExecuted();
|
||||
@@ -77,7 +74,6 @@ class BackToJournals extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
@@ -89,7 +85,6 @@ class BackToJournals extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
@@ -100,22 +95,16 @@ class BackToJournals extends Command
|
||||
return (bool)$configVar->data;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function migrateAll(): void
|
||||
{
|
||||
$this->migrateBudgets();
|
||||
$this->migrateCategories();
|
||||
|
||||
// empty tables
|
||||
DB::table('budget_transaction')->delete();
|
||||
DB::table('category_transaction')->delete();
|
||||
\DB::table('budget_transaction')->delete();
|
||||
\DB::table('category_transaction')->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function migrateBudgets(): void
|
||||
{
|
||||
$journals = new Collection();
|
||||
@@ -125,45 +114,42 @@ class BackToJournals extends Command
|
||||
$collected = TransactionJournal::whereIn('id', $journalIds)->with(['transactions', 'budgets', 'transactions.budgets'])->get();
|
||||
$journals = $journals->merge($collected);
|
||||
}
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$this->migrateBudgetsForJournal($journal);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getIdsForBudgets(): array
|
||||
{
|
||||
$transactions = DB::table('budget_transaction')->distinct()->pluck('transaction_id')->toArray();
|
||||
$transactions = \DB::table('budget_transaction')->distinct()->pluck('transaction_id')->toArray();
|
||||
$array = [];
|
||||
$chunks = array_chunk($transactions, 500);
|
||||
|
||||
foreach ($chunks as $chunk) {
|
||||
$set = DB::table('transactions')->whereIn('transactions.id', $chunk)->pluck('transaction_journal_id')->toArray();
|
||||
$set = \DB::table('transactions')->whereIn('transactions.id', $chunk)->pluck('transaction_journal_id')->toArray();
|
||||
$array = array_merge($array, $set);
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*/
|
||||
private function migrateBudgetsForJournal(TransactionJournal $journal): void
|
||||
{
|
||||
// grab category from first transaction
|
||||
/** @var Transaction|null $transaction */
|
||||
/** @var null|Transaction $transaction */
|
||||
$transaction = $journal->transactions->first();
|
||||
if (null === $transaction) {
|
||||
$this->friendlyInfo(sprintf('Transaction journal #%d has no transactions. Will be fixed later.', $journal->id));
|
||||
|
||||
return;
|
||||
}
|
||||
/** @var Budget|null $budget */
|
||||
|
||||
/** @var null|Budget $budget */
|
||||
$budget = $transaction->budgets->first();
|
||||
/** @var Budget|null $journalBudget */
|
||||
|
||||
/** @var null|Budget $journalBudget */
|
||||
$journalBudget = $journal->budgets->first();
|
||||
|
||||
// both have a budget, but they don't match.
|
||||
@@ -181,61 +167,55 @@ class BackToJournals extends Command
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function migrateCategories(): void
|
||||
{
|
||||
$journals = new Collection();
|
||||
$allIds = $this->getIdsForCategories();
|
||||
|
||||
|
||||
$chunks = array_chunk($allIds, 500);
|
||||
foreach ($chunks as $chunk) {
|
||||
$collected = TransactionJournal::whereIn('id', $chunk)->with(['transactions', 'categories', 'transactions.categories'])->get();
|
||||
$journals = $journals->merge($collected);
|
||||
}
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$this->migrateCategoriesForJournal($journal);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getIdsForCategories(): array
|
||||
{
|
||||
$transactions = DB::table('category_transaction')->distinct()->pluck('transaction_id')->toArray();
|
||||
$transactions = \DB::table('category_transaction')->distinct()->pluck('transaction_id')->toArray();
|
||||
$array = [];
|
||||
$chunks = array_chunk($transactions, 500);
|
||||
|
||||
foreach ($chunks as $chunk) {
|
||||
$set = DB::table('transactions')
|
||||
->whereIn('transactions.id', $chunk)
|
||||
->pluck('transaction_journal_id')->toArray();
|
||||
$set = \DB::table('transactions')
|
||||
->whereIn('transactions.id', $chunk)
|
||||
->pluck('transaction_journal_id')->toArray()
|
||||
;
|
||||
$array = array_merge($array, $set);
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*/
|
||||
private function migrateCategoriesForJournal(TransactionJournal $journal): void
|
||||
{
|
||||
// grab category from first transaction
|
||||
/** @var Transaction|null $transaction */
|
||||
/** @var null|Transaction $transaction */
|
||||
$transaction = $journal->transactions->first();
|
||||
if (null === $transaction) {
|
||||
$this->friendlyInfo(sprintf('Transaction journal #%d has no transactions. Will be fixed later.', $journal->id));
|
||||
|
||||
return;
|
||||
}
|
||||
/** @var Category|null $category */
|
||||
|
||||
/** @var null|Category $category */
|
||||
$category = $transaction->categories->first();
|
||||
/** @var Category|null $journalCategory */
|
||||
|
||||
/** @var null|Category $journalCategory */
|
||||
$journalCategory = $journal->categories->first();
|
||||
|
||||
// both have a category, but they don't match.
|
||||
@@ -250,9 +230,6 @@ class BackToJournals extends Command
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function markAsExecuted(): void
|
||||
{
|
||||
app('fireflyconfig')->set(self::CONFIG_NAME, true);
|
||||
|
@@ -48,7 +48,6 @@ class BudgetLimitCurrency extends Command
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws FireflyException
|
||||
* @throws NotFoundExceptionInterface
|
||||
@@ -61,16 +60,16 @@ class BudgetLimitCurrency extends Command
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
$count = 0;
|
||||
$budgetLimits = BudgetLimit::get();
|
||||
|
||||
/** @var BudgetLimit $budgetLimit */
|
||||
foreach ($budgetLimits as $budgetLimit) {
|
||||
if (null === $budgetLimit->transaction_currency_id) {
|
||||
/** @var Budget|null $budget */
|
||||
/** @var null|Budget $budget */
|
||||
$budget = $budgetLimit->budget;
|
||||
if (null !== $budget) {
|
||||
/** @var User|null $user */
|
||||
/** @var null|User $user */
|
||||
$user = $budget->user;
|
||||
if (null !== $user) {
|
||||
$currency = app('amount')->getDefaultCurrencyByUserGroup($user->userGroup);
|
||||
@@ -79,7 +78,7 @@ class BudgetLimitCurrency extends Command
|
||||
$this->friendlyInfo(
|
||||
sprintf('Budget limit #%d (part of budget "%s") now has a currency setting (%s).', $budgetLimit->id, $budget->name, $currency->name)
|
||||
);
|
||||
$count++;
|
||||
++$count;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,7 +92,6 @@ class BudgetLimitCurrency extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
@@ -107,9 +105,6 @@ class BudgetLimitCurrency extends Command
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function markAsExecuted(): void
|
||||
{
|
||||
app('fireflyconfig')->set(self::CONFIG_NAME, true);
|
||||
|
@@ -46,7 +46,6 @@ class CCLiabilities extends Command
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws FireflyException
|
||||
* @throws NotFoundExceptionInterface
|
||||
@@ -59,7 +58,6 @@ class CCLiabilities extends Command
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
$ccType = AccountType::where('type', AccountType::CREDITCARD)->first();
|
||||
$debtType = AccountType::where('type', AccountType::DEBT)->first();
|
||||
if (null === $ccType || null === $debtType) {
|
||||
@@ -68,6 +66,7 @@ class CCLiabilities extends Command
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** @var Collection $accounts */
|
||||
$accounts = Account::where('account_type_id', $ccType->id)->get();
|
||||
foreach ($accounts as $account) {
|
||||
@@ -89,19 +88,16 @@ class CCLiabilities extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
private function isExecuted(): bool
|
||||
{
|
||||
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
|
||||
|
||||
return (bool)$configVar?->data;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function markAsExecuted(): void
|
||||
{
|
||||
app('fireflyconfig')->set(self::CONFIG_NAME, true);
|
||||
|
@@ -24,17 +24,13 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Console\Commands\Upgrade;
|
||||
|
||||
use Crypt;
|
||||
use DB;
|
||||
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Preference;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Contracts\Encryption\DecryptException;
|
||||
use JsonException;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Class DecryptDatabase
|
||||
@@ -49,7 +45,6 @@ class DecryptDatabase extends Command
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
@@ -68,6 +63,7 @@ class DecryptDatabase extends Command
|
||||
'transactions' => ['description'],
|
||||
'journal_links' => ['comment'],
|
||||
];
|
||||
|
||||
/**
|
||||
* @var string $table
|
||||
* @var array $fields
|
||||
@@ -75,13 +71,11 @@ class DecryptDatabase extends Command
|
||||
foreach ($tables as $table => $fields) {
|
||||
$this->decryptTable($table, $fields);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $table
|
||||
* @param array $fields
|
||||
*
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
@@ -102,9 +96,6 @@ class DecryptDatabase extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $table
|
||||
*
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
@@ -112,6 +103,7 @@ class DecryptDatabase extends Command
|
||||
{
|
||||
$configName = sprintf('is_decrypted_%s', $table);
|
||||
$configVar = null;
|
||||
|
||||
try {
|
||||
$configVar = app('fireflyconfig')->get($configName, false);
|
||||
} catch (FireflyException $e) {
|
||||
@@ -124,27 +116,19 @@ class DecryptDatabase extends Command
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $table
|
||||
* @param string $field
|
||||
*/
|
||||
private function decryptField(string $table, string $field): void
|
||||
{
|
||||
$rows = DB::table($table)->get(['id', $field]);
|
||||
/** @var stdClass $row */
|
||||
$rows = \DB::table($table)->get(['id', $field]);
|
||||
|
||||
/** @var \stdClass $row */
|
||||
foreach ($rows as $row) {
|
||||
$this->decryptRow($table, $field, $row);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $table
|
||||
* @param string $field
|
||||
* @param stdClass $row
|
||||
*/
|
||||
private function decryptRow(string $table, string $field, stdClass $row): void
|
||||
private function decryptRow(string $table, string $field, \stdClass $row): void
|
||||
{
|
||||
$original = $row->$field;
|
||||
$original = $row->{$field};
|
||||
if (null === $original) {
|
||||
return;
|
||||
}
|
||||
@@ -168,7 +152,7 @@ class DecryptDatabase extends Command
|
||||
}
|
||||
|
||||
if ($value !== $original) {
|
||||
DB::table($table)->where('id', $id)->update([$field => $value]);
|
||||
\DB::table($table)->where('id', $id)->update([$field => $value]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,12 +162,13 @@ class DecryptDatabase extends Command
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function tryDecrypt($value)
|
||||
{
|
||||
try {
|
||||
$value = Crypt::decrypt($value);
|
||||
$value = \Crypt::decrypt($value);
|
||||
} catch (DecryptException $e) {
|
||||
if ('The MAC is invalid.' === $e->getMessage()) {
|
||||
throw new FireflyException($e->getMessage(), 0, $e);
|
||||
@@ -193,16 +178,12 @@ class DecryptDatabase extends Command
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param string $value
|
||||
*/
|
||||
private function decryptPreferencesRow(int $id, string $value): void
|
||||
{
|
||||
// try to json_decrypt the value.
|
||||
try {
|
||||
$newValue = json_decode($value, true, 512, JSON_THROW_ON_ERROR) ?? $value;
|
||||
} catch (JsonException $e) {
|
||||
} 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);
|
||||
app('log')->warning($message);
|
||||
@@ -212,7 +193,7 @@ class DecryptDatabase extends Command
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var Preference|null $object */
|
||||
/** @var null|Preference $object */
|
||||
$object = Preference::find($id);
|
||||
if (null !== $object) {
|
||||
$object->data = $newValue;
|
||||
|
@@ -24,7 +24,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Console\Commands\Upgrade;
|
||||
|
||||
use DB;
|
||||
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
@@ -35,19 +34,16 @@ class FixPostgresSequences extends Command
|
||||
{
|
||||
use ShowsFriendlyMessages;
|
||||
|
||||
|
||||
protected $description = 'Fixes issues with PostgreSQL sequences.';
|
||||
|
||||
protected $signature = 'firefly-iii:fix-pgsql-sequences';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
if (DB::connection()->getName() !== 'pgsql') {
|
||||
if ('pgsql' !== \DB::connection()->getName()) {
|
||||
return 0;
|
||||
}
|
||||
$this->friendlyLine('Going to verify PostgreSQL table sequences.');
|
||||
@@ -113,17 +109,18 @@ class FixPostgresSequences extends Command
|
||||
foreach ($tablesToCheck as $tableToCheck) {
|
||||
$this->friendlyLine(sprintf('Checking the next id sequence for table "%s".', $tableToCheck));
|
||||
|
||||
$highestId = DB::table($tableToCheck)->select(DB::raw('MAX(id)'))->first();
|
||||
$nextId = DB::table($tableToCheck)->select(DB::raw(sprintf('nextval(\'%s_id_seq\')', $tableToCheck)))->first();
|
||||
$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) {
|
||||
$this->friendlyInfo(sprintf('nextval is NULL for table "%s", go to next table.', $tableToCheck));
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($nextId->nextval < $highestId->max) { // @phpstan-ignore-line
|
||||
DB::select(sprintf('SELECT setval(\'%s_id_seq\', %d)', $tableToCheck, $highestId->max));
|
||||
$highestId = DB::table($tableToCheck)->select(DB::raw('MAX(id)'))->first();
|
||||
$nextId = DB::table($tableToCheck)->select(DB::raw(sprintf('nextval(\'%s_id_seq\')', $tableToCheck)))->first();
|
||||
\DB::select(sprintf('SELECT setval(\'%s_id_seq\', %d)', $tableToCheck, $highestId->max));
|
||||
$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 ($nextId->nextval > $highestId->max) { // @phpstan-ignore-line
|
||||
$this->friendlyInfo(sprintf('Table "%s" autoincrement corrected.', $tableToCheck));
|
||||
}
|
||||
@@ -136,7 +133,6 @@ class FixPostgresSequences extends Command
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@@ -47,7 +47,6 @@ class MigrateAttachments extends Command
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws FireflyException
|
||||
* @throws NotFoundExceptionInterface
|
||||
@@ -61,7 +60,6 @@ class MigrateAttachments extends Command
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
$attachments = Attachment::get();
|
||||
$count = 0;
|
||||
|
||||
@@ -84,7 +82,7 @@ class MigrateAttachments extends Command
|
||||
$att->save();
|
||||
|
||||
app('log')->debug(sprintf('Migrated attachment #%s description to note #%d.', $att->id, $note->id));
|
||||
$count++;
|
||||
++$count;
|
||||
}
|
||||
}
|
||||
if (0 === $count) {
|
||||
@@ -101,7 +99,6 @@ class MigrateAttachments extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
@@ -115,9 +112,6 @@ class MigrateAttachments extends Command
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function markAsExecuted(): void
|
||||
{
|
||||
app('fireflyconfig')->set(self::CONFIG_NAME, true);
|
||||
|
@@ -46,7 +46,6 @@ class MigrateJournalNotes extends Command
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
@@ -62,6 +61,7 @@ class MigrateJournalNotes extends Command
|
||||
|
||||
$count = 0;
|
||||
$set = TransactionJournalMeta::whereName('notes')->get();
|
||||
|
||||
/** @var TransactionJournalMeta $meta */
|
||||
foreach ($set as $meta) {
|
||||
$journal = $meta->transactionJournal;
|
||||
@@ -76,7 +76,7 @@ class MigrateJournalNotes extends Command
|
||||
app('log')->debug(sprintf('Migrated meta note #%d to Note #%d', $meta->id, $note->id));
|
||||
$meta->delete();
|
||||
|
||||
$count++;
|
||||
++$count;
|
||||
}
|
||||
|
||||
if (0 === $count) {
|
||||
@@ -94,7 +94,6 @@ class MigrateJournalNotes extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
@@ -108,9 +107,6 @@ class MigrateJournalNotes extends Command
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function markAsExecuted(): void
|
||||
{
|
||||
app('fireflyconfig')->set(self::CONFIG_NAME, true);
|
||||
|
@@ -29,7 +29,6 @@ use FireflyIII\Models\Recurrence;
|
||||
use FireflyIII\Models\RecurrenceMeta;
|
||||
use FireflyIII\Models\RecurrenceTransactionMeta;
|
||||
use Illuminate\Console\Command;
|
||||
use JsonException;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
@@ -49,9 +48,8 @@ class MigrateRecurrenceMeta extends Command
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws JsonException
|
||||
* @throws \JsonException
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function handle(): int
|
||||
@@ -76,7 +74,6 @@ class MigrateRecurrenceMeta extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
@@ -91,14 +88,14 @@ class MigrateRecurrenceMeta extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
* @throws JsonException
|
||||
* @throws \JsonException
|
||||
*/
|
||||
private function migrateMetaData(): int
|
||||
{
|
||||
$count = 0;
|
||||
// get all recurrence meta data:
|
||||
$collection = RecurrenceMeta::with('recurrence')->get();
|
||||
|
||||
/** @var RecurrenceMeta $meta */
|
||||
foreach ($collection as $meta) {
|
||||
$count += $this->migrateEntry($meta);
|
||||
@@ -108,14 +105,11 @@ class MigrateRecurrenceMeta extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RecurrenceMeta $meta
|
||||
*
|
||||
* @return int
|
||||
* @throws JsonException
|
||||
* @throws \JsonException
|
||||
*/
|
||||
private function migrateEntry(RecurrenceMeta $meta): int
|
||||
{
|
||||
/** @var Recurrence|null $recurrence */
|
||||
/** @var null|Recurrence $recurrence */
|
||||
$recurrence = $meta->recurrence;
|
||||
if (null === $recurrence) {
|
||||
return 0;
|
||||
@@ -143,9 +137,6 @@ class MigrateRecurrenceMeta extends Command
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function markAsExecuted(): void
|
||||
{
|
||||
app('fireflyconfig')->set(self::CONFIG_NAME, true);
|
||||
|
@@ -48,7 +48,6 @@ class MigrateRecurrenceType extends Command
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
@@ -63,46 +62,39 @@ class MigrateRecurrenceType extends Command
|
||||
$this->migrateTypes();
|
||||
$this->markAsExecuted();
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
private function isExecuted(): bool
|
||||
{
|
||||
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
|
||||
|
||||
return (bool)$configVar?->data;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function migrateTypes(): void
|
||||
{
|
||||
$set = Recurrence::get();
|
||||
|
||||
/** @var Recurrence $recurrence */
|
||||
foreach ($set as $recurrence) {
|
||||
if ($recurrence->transactionType->type !== TransactionType::INVALID) {
|
||||
if (TransactionType::INVALID !== $recurrence->transactionType->type) {
|
||||
$this->migrateRecurrence($recurrence);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Recurrence $recurrence
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function migrateRecurrence(Recurrence $recurrence): void
|
||||
{
|
||||
$originalType = $recurrence->transaction_type_id;
|
||||
$newType = $this->getInvalidType();
|
||||
$recurrence->transaction_type_id = $newType->id;
|
||||
$recurrence->save();
|
||||
|
||||
/** @var RecurrenceTransaction $transaction */
|
||||
foreach ($recurrence->recurrenceTransactions as $transaction) {
|
||||
$transaction->transaction_type_id = $originalType;
|
||||
@@ -111,17 +103,11 @@ class MigrateRecurrenceType extends Command
|
||||
$this->friendlyInfo(sprintf('Updated recurrence #%d to new transaction type model.', $recurrence->id));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function getInvalidType(): TransactionType
|
||||
{
|
||||
return TransactionType::whereType(TransactionType::INVALID)->firstOrCreate(['type' => TransactionType::INVALID]);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function markAsExecuted(): void
|
||||
{
|
||||
app('fireflyconfig')->set(self::CONFIG_NAME, true);
|
||||
|
@@ -47,7 +47,6 @@ class MigrateTagLocations extends Command
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
@@ -65,7 +64,6 @@ class MigrateTagLocations extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
@@ -79,12 +77,10 @@ class MigrateTagLocations extends Command
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function migrateTagLocations(): void
|
||||
{
|
||||
$tags = Tag::get();
|
||||
|
||||
/** @var Tag $tag */
|
||||
foreach ($tags as $tag) {
|
||||
if ($this->hasLocationDetails($tag)) {
|
||||
@@ -93,19 +89,11 @@ class MigrateTagLocations extends Command
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function hasLocationDetails(Tag $tag): bool
|
||||
{
|
||||
return null !== $tag->latitude && null !== $tag->longitude && null !== $tag->zoomLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
*/
|
||||
private function migrateLocationDetails(Tag $tag): void
|
||||
{
|
||||
$location = new Location();
|
||||
@@ -121,9 +109,6 @@ class MigrateTagLocations extends Command
|
||||
$tag->save();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function markAsExecuted(): void
|
||||
{
|
||||
app('fireflyconfig')->set(self::CONFIG_NAME, true);
|
||||
|
@@ -23,8 +23,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Console\Commands\Upgrade;
|
||||
|
||||
use DB;
|
||||
use Exception;
|
||||
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
|
||||
use FireflyIII\Factory\TransactionGroupFactory;
|
||||
use FireflyIII\Models\Budget;
|
||||
@@ -62,7 +60,6 @@ class MigrateToGroups extends Command
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
@@ -80,7 +77,6 @@ class MigrateToGroups extends Command
|
||||
$this->friendlyWarning('Forcing the migration.');
|
||||
}
|
||||
|
||||
|
||||
$this->makeGroupsFromSplitJournals();
|
||||
$this->makeGroupsFromAll();
|
||||
|
||||
@@ -99,8 +95,6 @@ class MigrateToGroups extends Command
|
||||
* 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
|
||||
{
|
||||
@@ -112,7 +106,6 @@ class MigrateToGroups extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
@@ -127,13 +120,14 @@ class MigrateToGroups extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function makeGroupsFromSplitJournals(): void
|
||||
{
|
||||
$splitJournals = $this->cliRepository->getSplitJournals();
|
||||
if ($splitJournals->count() > 0) {
|
||||
$this->friendlyLine(sprintf('Going to convert %d split transaction(s). Please hold..', $splitJournals->count()));
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($splitJournals as $journal) {
|
||||
$this->makeMultiGroup($journal);
|
||||
@@ -142,9 +136,7 @@ class MigrateToGroups extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function makeMultiGroup(TransactionJournal $journal): void
|
||||
{
|
||||
@@ -207,6 +199,7 @@ class MigrateToGroups extends Command
|
||||
$transaction->id
|
||||
)
|
||||
);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -262,7 +255,7 @@ class MigrateToGroups extends Command
|
||||
// delete the old transaction journal.
|
||||
$this->service->destroy($journal);
|
||||
|
||||
$this->count++;
|
||||
++$this->count;
|
||||
|
||||
// report on result:
|
||||
app('log')->debug(
|
||||
@@ -283,11 +276,6 @@ class MigrateToGroups extends Command
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
private function getDestinationTransactions(TransactionJournal $journal): Collection
|
||||
{
|
||||
return $journal->transactions->filter(
|
||||
@@ -297,12 +285,6 @@ class MigrateToGroups extends Command
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
* @param Transaction $transaction
|
||||
*
|
||||
* @return Transaction|null
|
||||
*/
|
||||
private function findOpposingTransaction(TransactionJournal $journal, Transaction $transaction): ?Transaction
|
||||
{
|
||||
$set = $journal->transactions->filter(
|
||||
@@ -319,18 +301,12 @@ class MigrateToGroups extends Command
|
||||
return $set->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Transaction $left
|
||||
* @param Transaction $right
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
private function getTransactionBudget(Transaction $left, Transaction $right): ?int
|
||||
{
|
||||
app('log')->debug('Now in getTransactionBudget()');
|
||||
|
||||
// try to get a budget ID from the left transaction:
|
||||
/** @var Budget|null $budget */
|
||||
/** @var null|Budget $budget */
|
||||
$budget = $left->budgets()->first();
|
||||
if (null !== $budget) {
|
||||
app('log')->debug(sprintf('Return budget #%d, from transaction #%d', $budget->id, $left->id));
|
||||
@@ -339,7 +315,7 @@ class MigrateToGroups extends Command
|
||||
}
|
||||
|
||||
// try to get a budget ID from the right transaction:
|
||||
/** @var Budget|null $budget */
|
||||
/** @var null|Budget $budget */
|
||||
$budget = $right->budgets()->first();
|
||||
if (null !== $budget) {
|
||||
app('log')->debug(sprintf('Return budget #%d, from transaction #%d', $budget->id, $right->id));
|
||||
@@ -352,18 +328,12 @@ class MigrateToGroups extends Command
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Transaction $left
|
||||
* @param Transaction $right
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
private function getTransactionCategory(Transaction $left, Transaction $right): ?int
|
||||
{
|
||||
app('log')->debug('Now in getTransactionCategory()');
|
||||
|
||||
// try to get a category ID from the left transaction:
|
||||
/** @var Category|null $category */
|
||||
/** @var null|Category $category */
|
||||
$category = $left->categories()->first();
|
||||
if (null !== $category) {
|
||||
app('log')->debug(sprintf('Return category #%d, from transaction #%d', $category->id, $left->id));
|
||||
@@ -372,7 +342,7 @@ class MigrateToGroups extends Command
|
||||
}
|
||||
|
||||
// try to get a category ID from the left transaction:
|
||||
/** @var Category|null $category */
|
||||
/** @var null|Category $category */
|
||||
$category = $right->categories()->first();
|
||||
if (null !== $category) {
|
||||
app('log')->debug(sprintf('Return category #%d, from transaction #%d', $category->id, $category->id));
|
||||
@@ -395,6 +365,7 @@ class MigrateToGroups extends Command
|
||||
if ($total > 0) {
|
||||
app('log')->debug(sprintf('Going to convert %d transaction journals. Please hold..', $total));
|
||||
$this->friendlyInfo(sprintf('Going to convert %d transaction journals. Please hold..', $total));
|
||||
|
||||
/** @var array $array */
|
||||
foreach ($orphanedJournals as $array) {
|
||||
$this->giveGroup($array);
|
||||
@@ -405,12 +376,9 @@ class MigrateToGroups extends Command
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
*/
|
||||
private function giveGroup(array $array): void
|
||||
{
|
||||
$groupId = DB::table('transaction_groups')->insertGetId(
|
||||
$groupId = \DB::table('transaction_groups')->insertGetId(
|
||||
[
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
@@ -418,13 +386,10 @@ class MigrateToGroups extends Command
|
||||
'user_id' => $array['user_id'],
|
||||
]
|
||||
);
|
||||
DB::table('transaction_journals')->where('id', $array['id'])->update(['transaction_group_id' => $groupId]);
|
||||
$this->count++;
|
||||
\DB::table('transaction_journals')->where('id', $array['id'])->update(['transaction_group_id' => $groupId]);
|
||||
++$this->count;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function markAsMigrated(): void
|
||||
{
|
||||
app('fireflyconfig')->set(self::CONFIG_NAME, true);
|
||||
|
@@ -58,7 +58,6 @@ class MigrateToRules extends Command
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws FireflyException
|
||||
* @throws NotFoundExceptionInterface
|
||||
@@ -73,8 +72,8 @@ class MigrateToRules extends Command
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
$users = $this->userRepository->all();
|
||||
|
||||
/** @var User $user */
|
||||
foreach ($users as $user) {
|
||||
$this->migrateUser($user);
|
||||
@@ -96,8 +95,6 @@ class MigrateToRules extends Command
|
||||
* 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
|
||||
{
|
||||
@@ -109,7 +106,6 @@ class MigrateToRules extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
@@ -126,8 +122,6 @@ class MigrateToRules extends Command
|
||||
/**
|
||||
* Migrate bills to new rule structure for a specific user.
|
||||
*
|
||||
* @param User $user
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function migrateUser(User $user): void
|
||||
@@ -159,11 +153,6 @@ class MigrateToRules extends Command
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RuleGroup $ruleGroup
|
||||
* @param Bill $bill
|
||||
* @param Preference $language
|
||||
*/
|
||||
private function migrateBill(RuleGroup $ruleGroup, Bill $bill, Preference $language): void
|
||||
{
|
||||
if ('MIGRATED_TO_RULES' === $bill->match) {
|
||||
@@ -228,12 +217,9 @@ class MigrateToRules extends Command
|
||||
'active' => $bill->active,
|
||||
];
|
||||
$this->billRepository->update($bill, $newBillData);
|
||||
$this->count++;
|
||||
++$this->count;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function markAsExecuted(): void
|
||||
{
|
||||
app('fireflyconfig')->set(self::CONFIG_NAME, true);
|
||||
|
@@ -56,7 +56,6 @@ class OtherCurrenciesCorrections extends Command
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
@@ -70,7 +69,6 @@ class OtherCurrenciesCorrections extends Command
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
$this->updateOtherJournalsCurrencies();
|
||||
$this->markAsExecuted();
|
||||
|
||||
@@ -83,8 +81,6 @@ class OtherCurrenciesCorrections extends Command
|
||||
* 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
|
||||
{
|
||||
@@ -96,7 +92,6 @@ class OtherCurrenciesCorrections extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
@@ -119,7 +114,7 @@ class OtherCurrenciesCorrections extends Command
|
||||
private function updateOtherJournalsCurrencies(): void
|
||||
{
|
||||
$set = $this->cliRepos->getAllJournals(
|
||||
[TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION,]
|
||||
[TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::OPENING_BALANCE, TransactionType::RECONCILIATION]
|
||||
);
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
@@ -128,9 +123,6 @@ class OtherCurrenciesCorrections extends Command
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
*/
|
||||
private function updateJournalCurrency(TransactionJournal $journal): void
|
||||
{
|
||||
$this->accountRepos->setUser($journal->user);
|
||||
@@ -156,7 +148,7 @@ class OtherCurrenciesCorrections extends Command
|
||||
$journal->id
|
||||
)
|
||||
);
|
||||
$this->count++;
|
||||
++$this->count;
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -179,31 +171,33 @@ class OtherCurrenciesCorrections extends Command
|
||||
);
|
||||
// also update the journal, of course:
|
||||
$journal->transaction_currency_id = $currency->id;
|
||||
$this->count++;
|
||||
++$this->count;
|
||||
$journal->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the transaction that determines the transaction that "leads" and will determine
|
||||
* the currency to be used by all transactions, and the journal itself.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return Transaction|null
|
||||
*/
|
||||
private function getLeadTransaction(TransactionJournal $journal): ?Transaction
|
||||
{
|
||||
/** @var Transaction $lead */
|
||||
$lead = null;
|
||||
|
||||
switch ($journal->transactionType->type) {
|
||||
default:
|
||||
break;
|
||||
|
||||
case TransactionType::WITHDRAWAL:
|
||||
$lead = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
|
||||
break;
|
||||
|
||||
case TransactionType::DEPOSIT:
|
||||
$lead = $journal->transactions()->where('amount', '>', 0)->first();
|
||||
|
||||
break;
|
||||
|
||||
case TransactionType::OPENING_BALANCE:
|
||||
// whichever isn't an initial balance account:
|
||||
$lead = $journal->transactions()->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')->leftJoin(
|
||||
@@ -212,7 +206,9 @@ class OtherCurrenciesCorrections extends Command
|
||||
'=',
|
||||
'account_types.id'
|
||||
)->where('account_types.type', '!=', AccountType::INITIAL_BALANCE)->first(['transactions.*']);
|
||||
|
||||
break;
|
||||
|
||||
case TransactionType::RECONCILIATION:
|
||||
// whichever isn't the reconciliation account:
|
||||
$lead = $journal->transactions()->leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')->leftJoin(
|
||||
@@ -221,17 +217,13 @@ class OtherCurrenciesCorrections extends Command
|
||||
'=',
|
||||
'account_types.id'
|
||||
)->where('account_types.type', '!=', AccountType::RECONCILIATION)->first(['transactions.*']);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return $lead;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return TransactionCurrency|null
|
||||
*/
|
||||
private function getCurrency(Account $account): ?TransactionCurrency
|
||||
{
|
||||
$accountId = $account->id;
|
||||
@@ -252,9 +244,6 @@ class OtherCurrenciesCorrections extends Command
|
||||
return $currency;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function markAsExecuted(): void
|
||||
{
|
||||
app('fireflyconfig')->set(self::CONFIG_NAME, true);
|
||||
|
@@ -46,7 +46,6 @@ class RenameAccountMeta extends Command
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws FireflyException
|
||||
* @throws NotFoundExceptionInterface
|
||||
@@ -91,7 +90,6 @@ class RenameAccountMeta extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
@@ -105,9 +103,6 @@ class RenameAccountMeta extends Command
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function markAsExecuted(): void
|
||||
{
|
||||
app('fireflyconfig')->set(self::CONFIG_NAME, true);
|
||||
|
@@ -32,7 +32,6 @@ use Illuminate\Console\Command;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Schema;
|
||||
|
||||
/**
|
||||
* Class TransactionIdentifier
|
||||
@@ -57,7 +56,6 @@ class TransactionIdentifier extends Command
|
||||
* When either of these are the same amount, FF3 can't keep them apart: +3/-3, +3/-3, +3/-3. This happens more
|
||||
* often than you would think. So each set gets a number (1,2,3) to keep them apart.
|
||||
*
|
||||
* @return int
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws FireflyException
|
||||
* @throws NotFoundExceptionInterface
|
||||
@@ -73,11 +71,12 @@ class TransactionIdentifier extends Command
|
||||
}
|
||||
|
||||
// if table does not exist, return false
|
||||
if (!Schema::hasTable('transaction_journals')) {
|
||||
if (!\Schema::hasTable('transaction_journals')) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$journals = $this->cliRepository->getSplitJournals();
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$this->updateJournalIdentifiers($journal);
|
||||
@@ -99,8 +98,6 @@ class TransactionIdentifier extends Command
|
||||
* 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
|
||||
{
|
||||
@@ -109,7 +106,6 @@ class TransactionIdentifier extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
@@ -126,8 +122,6 @@ class TransactionIdentifier extends Command
|
||||
/**
|
||||
* Grab all positive transactions from this journal that are not deleted. for each one, grab the negative opposing
|
||||
* one which has 0 as an identifier and give it the same identifier.
|
||||
*
|
||||
* @param TransactionJournal $transactionJournal
|
||||
*/
|
||||
private function updateJournalIdentifiers(TransactionJournal $transactionJournal): void
|
||||
{
|
||||
@@ -146,18 +140,12 @@ class TransactionIdentifier extends Command
|
||||
$opposing->save();
|
||||
$exclude[] = $transaction->id;
|
||||
$exclude[] = $opposing->id;
|
||||
$this->count++;
|
||||
++$this->count;
|
||||
}
|
||||
++$identifier;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Transaction $transaction
|
||||
* @param array $exclude
|
||||
*
|
||||
* @return Transaction|null
|
||||
*/
|
||||
private function findOpposing(Transaction $transaction, array $exclude): ?Transaction
|
||||
{
|
||||
// find opposing:
|
||||
@@ -166,9 +154,10 @@ class TransactionIdentifier extends Command
|
||||
try {
|
||||
/** @var Transaction $opposing */
|
||||
$opposing = Transaction::where('transaction_journal_id', $transaction->transaction_journal_id)
|
||||
->where('amount', $amount)->where('identifier', '=', 0)
|
||||
->whereNotIn('id', $exclude)
|
||||
->first();
|
||||
->where('amount', $amount)->where('identifier', '=', 0)
|
||||
->whereNotIn('id', $exclude)
|
||||
->first()
|
||||
;
|
||||
} catch (QueryException $e) {
|
||||
app('log')->error($e->getMessage());
|
||||
$this->friendlyError('Firefly III could not find the "identifier" field in the "transactions" table.');
|
||||
@@ -182,9 +171,6 @@ class TransactionIdentifier extends Command
|
||||
return $opposing;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function markAsExecuted(): void
|
||||
{
|
||||
app('fireflyconfig')->set(self::CONFIG_NAME, true);
|
||||
|
@@ -60,7 +60,6 @@ class TransferCurrenciesCorrections extends Command
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
@@ -74,16 +73,17 @@ class TransferCurrenciesCorrections extends Command
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
$this->startUpdateRoutine();
|
||||
$this->markAsExecuted();
|
||||
|
||||
if (0 === $this->count) {
|
||||
$this->friendlyPositive('All transfers have correct currency information.');
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
$this->friendlyInfo(sprintf('Verified currency information of %d transfer(s).', $this->count));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -91,8 +91,6 @@ class TransferCurrenciesCorrections extends Command
|
||||
* 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
|
||||
{
|
||||
@@ -105,8 +103,6 @@ class TransferCurrenciesCorrections extends Command
|
||||
|
||||
/**
|
||||
* Reset all the class fields for the current transfer.
|
||||
*
|
||||
|
||||
*/
|
||||
private function resetInformation(): void
|
||||
{
|
||||
@@ -119,7 +115,6 @@ class TransferCurrenciesCorrections extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
@@ -144,27 +139,23 @@ class TransferCurrenciesCorrections extends Command
|
||||
private function startUpdateRoutine(): void
|
||||
{
|
||||
$set = $this->cliRepos->getAllJournals([TransactionType::TRANSFER]);
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($set as $journal) {
|
||||
$this->updateTransferCurrency($journal);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $transfer
|
||||
*/
|
||||
private function updateTransferCurrency(TransactionJournal $transfer): void
|
||||
{
|
||||
$this->resetInformation();
|
||||
|
||||
|
||||
if ($this->isSplitJournal($transfer)) {
|
||||
$this->friendlyWarning(sprintf('Transaction journal #%d is a split journal. Cannot continue.', $transfer->id));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$this->getSourceInformation($transfer);
|
||||
$this->getDestinationInformation($transfer);
|
||||
|
||||
@@ -186,7 +177,6 @@ class TransferCurrenciesCorrections extends Command
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// fix source transaction having no currency.
|
||||
$this->fixSourceNoCurrency();
|
||||
|
||||
@@ -215,10 +205,6 @@ class TransferCurrenciesCorrections extends Command
|
||||
|
||||
/**
|
||||
* Is this a split transaction journal?
|
||||
*
|
||||
* @param TransactionJournal $transfer
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isSplitJournal(TransactionJournal $transfer): bool
|
||||
{
|
||||
@@ -227,10 +213,6 @@ class TransferCurrenciesCorrections extends Command
|
||||
|
||||
/**
|
||||
* Extract source transaction, source account + source account currency from the journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
|
||||
*/
|
||||
private function getSourceInformation(TransactionJournal $journal): void
|
||||
{
|
||||
@@ -239,21 +221,11 @@ class TransferCurrenciesCorrections extends Command
|
||||
$this->sourceCurrency = null === $this->sourceAccount ? null : $this->getCurrency($this->sourceAccount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $transfer
|
||||
*
|
||||
* @return Transaction|null
|
||||
*/
|
||||
private function getSourceTransaction(TransactionJournal $transfer): ?Transaction
|
||||
{
|
||||
return $transfer->transactions()->where('amount', '<', 0)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return TransactionCurrency|null
|
||||
*/
|
||||
private function getCurrency(Account $account): ?TransactionCurrency
|
||||
{
|
||||
$accountId = $account->id;
|
||||
@@ -276,10 +248,6 @@ class TransferCurrenciesCorrections extends Command
|
||||
|
||||
/**
|
||||
* Extract destination transaction, destination account + destination account currency from the journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
|
||||
*/
|
||||
private function getDestinationInformation(TransactionJournal $journal): void
|
||||
{
|
||||
@@ -288,11 +256,6 @@ class TransferCurrenciesCorrections extends Command
|
||||
$this->destinationCurrency = null === $this->destinationAccount ? null : $this->getCurrency($this->destinationAccount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $transfer
|
||||
*
|
||||
* @return Transaction|null
|
||||
*/
|
||||
private function getDestinationTransaction(TransactionJournal $transfer): ?Transaction
|
||||
{
|
||||
return $transfer->transactions()->where('amount', '>', 0)->first();
|
||||
@@ -300,8 +263,6 @@ class TransferCurrenciesCorrections extends Command
|
||||
|
||||
/**
|
||||
* Is either the source or destination transaction NULL?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isEmptyTransactions(): bool
|
||||
{
|
||||
@@ -310,9 +271,6 @@ class TransferCurrenciesCorrections extends Command
|
||||
|| null === $this->destinationAccount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
private function isNoCurrencyPresent(): bool
|
||||
{
|
||||
// source account must have a currency preference.
|
||||
@@ -349,14 +307,15 @@ class TransferCurrenciesCorrections extends Command
|
||||
if (null === $this->sourceTransaction->transaction_currency_id && null !== $this->sourceCurrency) {
|
||||
$this->sourceTransaction
|
||||
->transaction_currency_id
|
||||
= $this->sourceCurrency->id;
|
||||
= $this->sourceCurrency->id
|
||||
;
|
||||
$message = sprintf(
|
||||
'Transaction #%d has no currency setting, now set to %s.',
|
||||
$this->sourceTransaction->id,
|
||||
$this->sourceCurrency->code
|
||||
);
|
||||
$this->friendlyInfo($message);
|
||||
$this->count++;
|
||||
++$this->count;
|
||||
$this->sourceTransaction->save();
|
||||
}
|
||||
}
|
||||
@@ -379,7 +338,7 @@ class TransferCurrenciesCorrections extends Command
|
||||
$this->sourceTransaction->amount
|
||||
);
|
||||
$this->friendlyWarning($message);
|
||||
$this->count++;
|
||||
++$this->count;
|
||||
$this->sourceTransaction->transaction_currency_id = $this->sourceCurrency->id;
|
||||
$this->sourceTransaction->save();
|
||||
}
|
||||
@@ -394,14 +353,15 @@ class TransferCurrenciesCorrections extends Command
|
||||
if (null === $this->destinationTransaction->transaction_currency_id && null !== $this->destinationCurrency) {
|
||||
$this->destinationTransaction
|
||||
->transaction_currency_id
|
||||
= $this->destinationCurrency->id;
|
||||
= $this->destinationCurrency->id
|
||||
;
|
||||
$message = sprintf(
|
||||
'Transaction #%d has no currency setting, now set to %s.',
|
||||
$this->destinationTransaction->id,
|
||||
$this->destinationCurrency->code
|
||||
);
|
||||
$this->friendlyInfo($message);
|
||||
$this->count++;
|
||||
++$this->count;
|
||||
$this->destinationTransaction->save();
|
||||
}
|
||||
}
|
||||
@@ -424,7 +384,7 @@ class TransferCurrenciesCorrections extends Command
|
||||
$this->destinationTransaction->amount
|
||||
);
|
||||
$this->friendlyWarning($message);
|
||||
$this->count++;
|
||||
++$this->count;
|
||||
$this->destinationTransaction->transaction_currency_id = $this->destinationCurrency->id;
|
||||
$this->destinationTransaction->save();
|
||||
}
|
||||
@@ -465,7 +425,7 @@ class TransferCurrenciesCorrections extends Command
|
||||
|
||||
$this->sourceTransaction->save();
|
||||
$this->destinationTransaction->save();
|
||||
$this->count++;
|
||||
++$this->count;
|
||||
$this->friendlyInfo(
|
||||
sprintf('Verified foreign currency ID of transaction #%d and #%d', $this->sourceTransaction->id, $this->destinationTransaction->id)
|
||||
);
|
||||
@@ -481,7 +441,7 @@ class TransferCurrenciesCorrections extends Command
|
||||
if (null === $this->sourceTransaction->foreign_amount && null !== $this->destinationTransaction->foreign_amount) {
|
||||
$this->sourceTransaction->foreign_amount = bcmul($this->destinationTransaction->foreign_amount, '-1');
|
||||
$this->sourceTransaction->save();
|
||||
$this->count++;
|
||||
++$this->count;
|
||||
$this->friendlyInfo(
|
||||
sprintf(
|
||||
'Restored foreign amount of source transaction #%d to %s',
|
||||
@@ -501,7 +461,7 @@ class TransferCurrenciesCorrections extends Command
|
||||
if (null === $this->destinationTransaction->foreign_amount && null !== $this->sourceTransaction->foreign_amount) {
|
||||
$this->destinationTransaction->foreign_amount = bcmul($this->sourceTransaction->foreign_amount, '-1');
|
||||
$this->destinationTransaction->save();
|
||||
$this->count++;
|
||||
++$this->count;
|
||||
$this->friendlyInfo(
|
||||
sprintf(
|
||||
'Restored foreign amount of destination transaction #%d to %s',
|
||||
@@ -514,8 +474,6 @@ class TransferCurrenciesCorrections extends Command
|
||||
|
||||
/**
|
||||
* This method makes sure that the transaction journal uses the currency given in the source transaction.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
*/
|
||||
private function fixTransactionJournalCurrency(TransactionJournal $journal): void
|
||||
{
|
||||
@@ -529,15 +487,12 @@ class TransferCurrenciesCorrections extends Command
|
||||
$this->sourceCurrency->code,
|
||||
$oldCurrencyCode
|
||||
);
|
||||
$this->count++;
|
||||
++$this->count;
|
||||
$this->friendlyInfo($message);
|
||||
$journal->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function markAsExecuted(): void
|
||||
{
|
||||
app('fireflyconfig')->set(self::CONFIG_NAME, true);
|
||||
|
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
|
||||
|
||||
/*
|
||||
* UpgradeCurrencyPreferences.php
|
||||
* Copyright (c) 2023 james@firefly-iii.org
|
||||
@@ -48,8 +47,6 @@ class UpgradeCurrencyPreferences extends Command
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
@@ -67,9 +64,6 @@ class UpgradeCurrencyPreferences extends Command
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
private function isExecuted(): bool
|
||||
{
|
||||
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
|
||||
@@ -83,27 +77,25 @@ class UpgradeCurrencyPreferences extends Command
|
||||
private function runUpgrade(): void
|
||||
{
|
||||
$groups = UserGroup::get();
|
||||
|
||||
/** @var UserGroup $group */
|
||||
foreach ($groups as $group) {
|
||||
$this->upgradeGroupPreferences($group);
|
||||
}
|
||||
|
||||
$users = User::get();
|
||||
|
||||
/** @var User $user */
|
||||
foreach ($users as $user) {
|
||||
$this->upgradeUserPreferences($user);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UserGroup $group
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function upgradeGroupPreferences(UserGroup $group)
|
||||
{
|
||||
$currencies = TransactionCurrency::get();
|
||||
$enabled = new Collection();
|
||||
|
||||
/** @var TransactionCurrency $currency */
|
||||
foreach ($currencies as $currency) {
|
||||
if ($currency->enabled) {
|
||||
@@ -113,15 +105,11 @@ class UpgradeCurrencyPreferences extends Command
|
||||
$group->currencies()->sync($enabled->pluck('id')->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function upgradeUserPreferences(User $user): void
|
||||
{
|
||||
$currencies = TransactionCurrency::get();
|
||||
$enabled = new Collection();
|
||||
|
||||
/** @var TransactionCurrency $currency */
|
||||
foreach ($currencies as $currency) {
|
||||
if ($currency->enabled) {
|
||||
@@ -141,11 +129,6 @@ class UpgradeCurrencyPreferences extends Command
|
||||
$user->userGroup->currencies()->updateExistingPivot($defaultCurrency->id, ['group_default' => true]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getPreference(User $user): string
|
||||
{
|
||||
$preference = Preference::where('user_id', $user->id)->where('name', 'currencyPreference')->first(['id', 'user_id', 'name', 'data', 'updated_at', 'created_at']);
|
||||
@@ -157,12 +140,10 @@ class UpgradeCurrencyPreferences extends Command
|
||||
if (null !== $preference->data && !is_array($preference->data)) {
|
||||
return (string)$preference->data;
|
||||
}
|
||||
|
||||
return 'EUR';
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function markAsExecuted(): void
|
||||
{
|
||||
app('fireflyconfig')->set(self::CONFIG_NAME, true);
|
||||
|
@@ -30,8 +30,6 @@ use Illuminate\Console\Command;
|
||||
|
||||
/**
|
||||
* Class UpgradeDatabase
|
||||
*
|
||||
|
||||
*/
|
||||
class UpgradeDatabase extends Command
|
||||
{
|
||||
@@ -42,8 +40,6 @@ class UpgradeDatabase extends Command
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
@@ -89,9 +85,6 @@ class UpgradeDatabase extends Command
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function callInitialCommands(): void
|
||||
{
|
||||
$this->call('migrate', ['--seed' => true, '--force' => true, '--no-interaction' => true]);
|
||||
|
@@ -50,7 +50,6 @@ class UpgradeLiabilities extends Command
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
@@ -64,11 +63,11 @@ class UpgradeLiabilities extends Command
|
||||
$this->upgradeLiabilities();
|
||||
|
||||
$this->markAsExecuted();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
@@ -82,27 +81,24 @@ class UpgradeLiabilities extends Command
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function upgradeLiabilities(): void
|
||||
{
|
||||
$users = User::get();
|
||||
|
||||
/** @var User $user */
|
||||
foreach ($users as $user) {
|
||||
$this->upgradeForUser($user);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
private function upgradeForUser(User $user): void
|
||||
{
|
||||
$accounts = $user->accounts()
|
||||
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||
->whereIn('account_types.type', config('firefly.valid_liabilities'))
|
||||
->get(['accounts.*']);
|
||||
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||
->whereIn('account_types.type', config('firefly.valid_liabilities'))
|
||||
->get(['accounts.*'])
|
||||
;
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
$this->upgradeLiability($account);
|
||||
@@ -112,9 +108,6 @@ class UpgradeLiabilities extends Command
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*/
|
||||
private function upgradeLiability(Account $account): void
|
||||
{
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
@@ -137,10 +130,6 @@ class UpgradeLiabilities extends Command
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param TransactionJournal $openingBalance
|
||||
*/
|
||||
private function correctOpeningBalance(Account $account, TransactionJournal $openingBalance): void
|
||||
{
|
||||
$source = $this->getSourceTransaction($openingBalance);
|
||||
@@ -159,29 +148,16 @@ class UpgradeLiabilities extends Command
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
|
@@ -51,7 +51,6 @@ class UpgradeLiabilitiesEight extends Command
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
@@ -69,7 +68,6 @@ class UpgradeLiabilitiesEight extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
@@ -83,27 +81,24 @@ class UpgradeLiabilitiesEight extends Command
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function upgradeLiabilities(): void
|
||||
{
|
||||
$users = User::get();
|
||||
|
||||
/** @var User $user */
|
||||
foreach ($users as $user) {
|
||||
$this->upgradeForUser($user);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
private function upgradeForUser(User $user): void
|
||||
{
|
||||
$accounts = $user->accounts()
|
||||
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||
->whereIn('account_types.type', config('firefly.valid_liabilities'))
|
||||
->get(['accounts.*']);
|
||||
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||
->whereIn('account_types.type', config('firefly.valid_liabilities'))
|
||||
->get(['accounts.*'])
|
||||
;
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
$this->upgradeLiability($account);
|
||||
@@ -113,9 +108,6 @@ class UpgradeLiabilitiesEight extends Command
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*/
|
||||
private function upgradeLiability(Account $account): void
|
||||
{
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
@@ -136,26 +128,23 @@ class UpgradeLiabilitiesEight extends Command
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function hasBadOpening(Account $account): bool
|
||||
{
|
||||
$openingBalanceType = TransactionType::whereType(TransactionType::OPENING_BALANCE)->first();
|
||||
$liabilityType = TransactionType::whereType(TransactionType::LIABILITY_CREDIT)->first();
|
||||
$openingJournal = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('transactions.account_id', $account->id)
|
||||
->where('transaction_journals.transaction_type_id', $openingBalanceType->id)
|
||||
->first(['transaction_journals.*']);
|
||||
->where('transactions.account_id', $account->id)
|
||||
->where('transaction_journals.transaction_type_id', $openingBalanceType->id)
|
||||
->first(['transaction_journals.*'])
|
||||
;
|
||||
if (null === $openingJournal) {
|
||||
return false;
|
||||
}
|
||||
$liabilityJournal = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('transactions.account_id', $account->id)
|
||||
->where('transaction_journals.transaction_type_id', $liabilityType->id)
|
||||
->first(['transaction_journals.*']);
|
||||
->where('transactions.account_id', $account->id)
|
||||
->where('transaction_journals.transaction_type_id', $liabilityType->id)
|
||||
->first(['transaction_journals.*'])
|
||||
;
|
||||
if (null === $liabilityJournal) {
|
||||
return false;
|
||||
}
|
||||
@@ -166,18 +155,14 @@ class UpgradeLiabilitiesEight extends Command
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function deleteCreditTransaction(Account $account): void
|
||||
{
|
||||
$liabilityType = TransactionType::whereType(TransactionType::LIABILITY_CREDIT)->first();
|
||||
$liabilityJournal = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('transactions.account_id', $account->id)
|
||||
->where('transaction_journals.transaction_type_id', $liabilityType->id)
|
||||
->first(['transaction_journals.*']);
|
||||
->where('transactions.account_id', $account->id)
|
||||
->where('transaction_journals.transaction_type_id', $liabilityType->id)
|
||||
->first(['transaction_journals.*'])
|
||||
;
|
||||
if (null !== $liabilityJournal) {
|
||||
$group = $liabilityJournal->transactionGroup;
|
||||
$service = new TransactionGroupDestroyService();
|
||||
@@ -187,22 +172,21 @@ class UpgradeLiabilitiesEight extends Command
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function reverseOpeningBalance(Account $account): void
|
||||
{
|
||||
$openingBalanceType = TransactionType::whereType(TransactionType::OPENING_BALANCE)->first();
|
||||
|
||||
/** @var TransactionJournal $openingJournal */
|
||||
$openingJournal = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('transactions.account_id', $account->id)
|
||||
->where('transaction_journals.transaction_type_id', $openingBalanceType->id)
|
||||
->first(['transaction_journals.*']);
|
||||
/** @var Transaction|null $source */
|
||||
->where('transactions.account_id', $account->id)
|
||||
->where('transaction_journals.transaction_type_id', $openingBalanceType->id)
|
||||
->first(['transaction_journals.*'])
|
||||
;
|
||||
|
||||
/** @var null|Transaction $source */
|
||||
$source = $openingJournal->transactions()->where('amount', '<', 0)->first();
|
||||
/** @var Transaction|null $dest */
|
||||
|
||||
/** @var null|Transaction $dest */
|
||||
$dest = $openingJournal->transactions()->where('amount', '>', 0)->first();
|
||||
if (null !== $source && null !== $dest) {
|
||||
$sourceId = $source->account_id;
|
||||
@@ -217,23 +201,20 @@ class UpgradeLiabilitiesEight extends Command
|
||||
app('log')->warning('Did not find opening balance.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function deleteTransactions(Account $account): int
|
||||
{
|
||||
$count = 0;
|
||||
$journals = TransactionJournal::leftJoin('transactions', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->where('transactions.account_id', $account->id)->get(['transaction_journals.*']);
|
||||
->where('transactions.account_id', $account->id)->get(['transaction_journals.*'])
|
||||
;
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($journals as $journal) {
|
||||
// $delete = false;
|
||||
// /** @var Transaction $source */
|
||||
// $source = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
// /** @var Transaction $dest */
|
||||
// $dest = $journal->transactions()->where('amount', '>', 0)->first();
|
||||
// $delete = false;
|
||||
// /** @var Transaction $source */
|
||||
// $source = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
// /** @var Transaction $dest */
|
||||
// $dest = $journal->transactions()->where('amount', '>', 0)->first();
|
||||
|
||||
/**
|
||||
* // if source is this liability and destination is expense, remove transaction.
|
||||
@@ -253,16 +234,13 @@ class UpgradeLiabilitiesEight extends Command
|
||||
// if ($delete) {
|
||||
$service = app(TransactionGroupDestroyService::class);
|
||||
$service->destroy($journal->transactionGroup);
|
||||
$count++;
|
||||
++$count;
|
||||
// }
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function markAsExecuted(): void
|
||||
{
|
||||
app('fireflyconfig')->set(self::CONFIG_NAME, true);
|
||||
|
Reference in New Issue
Block a user