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
{
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 $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,
];
foreach ($types as $type) {
try {
AccountType::create(['type' => $type]);
} catch (\PDOException $e) {
// @ignoreException
if(null === AccountType::where('type', $type)->first()) {
try {
AccountType::create(['type' => $type]);
} catch (\PDOException $e) {
// @ignoreException
}
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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