fix: oauth seeder

This commit is contained in:
Andras Bacsai
2024-12-12 10:04:12 +01:00
parent fba7f6f585
commit 2053fed8a7

View File

@@ -12,19 +12,56 @@ class OauthSettingSeeder extends Seeder
*/
public function run(): void
{
$providers = [
$providers = collect([
'azure',
'bitbucket',
'github',
'gitlab',
'google',
'authentik',
];
]);
$isOauthSeeded = OauthSetting::count() > 0;
$isOauthWithZeroId = OauthSetting::where('id', 0)->exists();
if ($isOauthSeeded) {
if ($isOauthWithZeroId) {
$allProviders = OauthSetting::all();
$notFoundProviders = $providers->diff($allProviders->pluck('provider'));
$allProviders->each(function ($provider) use ($providers) {
$provider->delete();
$providerName = $provider->provider;
$foundProvider = $providers->first(function ($provider) use ($providerName) {
return $provider === $providerName;
});
if ($foundProvider) {
$newProvder = new OauthSetting;
$newProvder = $provider;
unset($newProvder->id);
$newProvder->save();
}
});
foreach ($notFoundProviders as $provider) {
OauthSetting::create([
'provider' => $provider,
]);
}
} else {
foreach ($providers as $provider) {
OauthSetting::updateOrCreate(
['provider' => $provider]
);
OauthSetting::updateOrCreate([
'provider' => $provider,
]);
}
}
} else {
foreach ($providers as $provider) {
OauthSetting::create([
'provider' => $provider,
]);
}
}
}
}