feat: add legacy setting support to ease migration

This commit is contained in:
idevakk
2025-11-16 10:59:42 -08:00
parent e3da8cf950
commit cb05040c96
4 changed files with 205 additions and 4 deletions

View File

@@ -69,4 +69,38 @@ class Username extends Model
return $query->pluck('username')->toArray();
}
/**
* Retrieve all active usernames grouped by type and provider.
*
* @return array Array with gmailUsernames, premium_gmailUsernames, outlookUsernames, premium_outlookUsernames keys
*/
public static function getActiveUsernames(): array
{
$usernames = static::query()
->where('is_active', true)
->where(function ($query) {
$query->whereNull('starts_at')
->orWhere('starts_at', '<=', now());
})
->where(function ($query) {
$query->whereNull('ends_at')
->orWhere('ends_at', '>=', now());
})
->select('username', 'username_type', 'provider_type')
->get()
->groupBy(['provider_type', 'username_type']);
$gmailPublic = $usernames->get(ProviderType::GMAIL->value, collect())->get(UsernameType::PUBLIC->value, collect())->pluck('username')->toArray();
$gmailPremium = $usernames->get(ProviderType::GMAIL->value, collect())->get(UsernameType::PREMIUM->value, collect())->pluck('username')->toArray();
$outlookPublic = $usernames->get(ProviderType::OUTLOOK->value, collect())->get(UsernameType::PUBLIC->value, collect())->pluck('username')->toArray();
$outlookPremium = $usernames->get(ProviderType::OUTLOOK->value, collect())->get(UsernameType::PREMIUM->value, collect())->pluck('username')->toArray();
return [
'gmailUsernames' => $gmailPublic,
'premium_gmailUsernames' => $gmailPremium,
'outlookUsernames' => $outlookPublic,
'premium_outlookUsernames' => $outlookPremium,
];
}
}