Skip creation using if statement.

This commit is contained in:
James Cole 2024-05-26 15:36:30 +02:00
parent a20622ac0c
commit 7009b444d9
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
8 changed files with 42 additions and 30 deletions

View File

@ -33,7 +33,7 @@ use Illuminate\Console\Command;
class CorrectAccountBalance extends Command class CorrectAccountBalance extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
public const string CONFIG_NAME = '620_correct_balances'; public const string CONFIG_NAME = '610_correct_balances';
protected $description = 'Recalculate all account balance amounts'; protected $description = 'Recalculate all account balance amounts';
protected $signature = 'firefly-iii:correct-account-balance {--F|force : Force the execution of this command.}'; protected $signature = 'firefly-iii:correct-account-balance {--F|force : Force the execution of this command.}';

View File

@ -49,10 +49,12 @@ class AccountTypeSeeder extends Seeder
AccountType::LIABILITY_CREDIT, AccountType::LIABILITY_CREDIT,
]; ];
foreach ($types as $type) { foreach ($types as $type) {
try { if(null === AccountType::where('type', $type)->first()) {
AccountType::create(['type' => $type]); try {
} catch (\PDOException $e) { AccountType::create(['type' => $type]);
// @ignoreException } catch (\PDOException $e) {
// @ignoreException
}
} }
} }
} }

View File

@ -44,11 +44,10 @@ class ConfigSeeder extends Seeder
'data' => 1, 'data' => 1,
] ]
); );
return;
} }
if (null !== $entry) { $version = (int) config('firefly.db_version');
$version = (int)config('firefly.db_version'); $entry->data = $version;
$entry->data = $version; $entry->save();
$entry->save();
}
} }
} }

View File

@ -60,10 +60,12 @@ class LinkTypeSeeder extends Seeder
], ],
]; ];
foreach ($types as $type) { foreach ($types as $type) {
try { if (null === LinkType::where('name', $type['name'])->first()) {
LinkType::create($type); try {
} catch (\PDOException $e) { LinkType::create($type);
// @ignoreException } catch (\PDOException $e) {
// @ignoreException
}
} }
} }
} }

View File

@ -46,11 +46,14 @@ class PermissionSeeder extends Seeder
], ],
]; ];
foreach ($roles as $role) { foreach ($roles as $role) {
try { if (null === Role::where('name', $role['name'])->first()) {
Role::create($role); try {
} catch (\PDOException $e) { Role::create($role);
// @ignoreException } catch (\PDOException $e) {
// @ignoreException
}
} }
} }
} }
} }

View File

@ -71,10 +71,12 @@ class TransactionCurrencySeeder extends Seeder
$currencies[] = ['code' => 'HRK', 'name' => 'Croatian kuna', 'symbol' => 'kn', 'decimal_places' => 2]; $currencies[] = ['code' => 'HRK', 'name' => 'Croatian kuna', 'symbol' => 'kn', 'decimal_places' => 2];
foreach ($currencies as $currency) { foreach ($currencies as $currency) {
try { if(null === TransactionCurrency::where('code', $currency['code'])->first()) {
TransactionCurrency::create($currency); try {
} catch (\PDOException $e) { TransactionCurrency::create($currency);
// @ignoreException } catch (\PDOException $e) {
// @ignoreException
}
} }
} }
} }

View File

@ -44,10 +44,12 @@ class TransactionTypeSeeder extends Seeder
]; ];
foreach ($types as $type) { foreach ($types as $type) {
try { if(null === TransactionType::where('type', $type)->first()) {
TransactionType::create(['type' => $type]); try {
} catch (\PDOException $e) { TransactionType::create(['type' => $type]);
// @ignoreException } catch (\PDOException $e) {
// @ignoreException
}
} }
} }
} }

View File

@ -45,10 +45,12 @@ class UserRoleSeeder extends Seeder
/** @var string $role */ /** @var string $role */
foreach ($roles as $role) { foreach ($roles as $role) {
try { if(null === UserRole::where('title', $role)->first()) {
UserRole::create(['title' => $role]); try {
} catch (\PDOException $e) { UserRole::create(['title' => $role]);
// @ignoreException } catch (\PDOException $e) {
// @ignoreException
}
} }
} }
} }