Skip to content

Commit

Permalink
Store config in global variable instead
Browse files Browse the repository at this point in the history
  • Loading branch information
nanaya committed Nov 6, 2023
1 parent 32485bc commit 85d570e
Show file tree
Hide file tree
Showing 211 changed files with 469 additions and 462 deletions.
2 changes: 1 addition & 1 deletion app/Console/Commands/BuildsUpdatePropagationHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function handle()
$date = Carbon::now();

$builds = Build::propagationHistory()
->whereIn('stream_id', config('osu.changelog.update_streams'))
->whereIn('stream_id', $GLOBALS['cfg']['osu']['changelog']['update_streams'])
->get();

foreach ($builds as $build) {
Expand Down
4 changes: 2 additions & 2 deletions app/Console/Commands/DbCreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ class DbCreate extends Command

public function handle()
{
$defaultConnection = config('database.connections.mysql');
$defaultConnection = $GLOBALS['cfg']['database']['connections']['mysql'];

$dsn = isset($defaultConnection['unix_socket'])
? "mysql:unix_socket={$defaultConnection['unix_socket']}"
: "mysql:host={$defaultConnection['host']};port={$defaultConnection['port']}";

$pdo = new PDO($dsn, $defaultConnection['username'], $defaultConnection['password']);

foreach (config('database.connections') as $connection) {
foreach ($GLOBALS['cfg']['database']['connections'] as $connection) {
$db = $connection['database'];

$this->info("Creating database '{$db}'");
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/EsCreateSearchBlacklist.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class EsCreateSearchBlacklist extends Command
*/
public function handle()
{
$alias = config('osu.elasticsearch.prefix').'blacklist';
$alias = $GLOBALS['cfg']['osu']['elasticsearch']['prefix'].'blacklist';
$client = Es::getClient();

/** @var array $response The type-hint in the doc is wrong. */
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/MigrateFreshAllCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function handle()
return 1;
}

$connections = config('database.connections');
$connections = $GLOBALS['cfg']['database']['connections'];

$this->warn('This will drop tables in the following databases:');

Expand Down
6 changes: 3 additions & 3 deletions app/Console/Commands/ModdingRankCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,20 @@ private function rankAll($modeInt)
->where('approved_date', '>=', now()->subDays())
->count();

$rankableQuota = config('osu.beatmapset.rank_per_day') - $rankedTodayCount;
$rankableQuota = $GLOBALS['cfg']['osu']['beatmapset']['rank_per_day'] - $rankedTodayCount;

$this->info("{$rankedTodayCount} beatmapsets ranked last 24 hours. Can rank {$rankableQuota} more");

if ($rankableQuota <= 0) {
return;
}

$toRankLimit = min(config('osu.beatmapset.rank_per_run'), $rankableQuota);
$toRankLimit = min($GLOBALS['cfg']['osu']['beatmapset']['rank_per_run'], $rankableQuota);

$toBeRankedQuery = Beatmapset::qualified()
->withoutTrashed()
->withModesForRanking($modeInt)
->where('queued_at', '<', now()->subDays(config('osu.beatmapset.minimum_days_for_rank')));
->where('queued_at', '<', now()->subDays($GLOBALS['cfg']['osu']['beatmapset']['minimum_days_for_rank']));

$rankingQueue = $toBeRankedQuery->count();

Expand Down
4 changes: 2 additions & 2 deletions app/Console/Commands/NotificationsCleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class NotificationsCleanup extends Command

public function handle()
{
$total = config('osu.notification.cleanup.max_delete_per_run');
$total = $GLOBALS['cfg']['osu']['notification']['cleanup']['max_delete_per_run'];

if ($total === 0) {
return;
Expand All @@ -46,7 +46,7 @@ public function handle()

for ($i = 0; $i < $loops; $i++) {
$deleted = Notification::where('id', '<', $maxNotificationId)->limit($perLoop)->delete();
Datadog::increment(config('datadog-helper.prefix_web').'.notifications_cleanup.notifications', 1, null, $deleted);
Datadog::increment($GLOBALS['cfg']['datadog-helper']['prefix_web'].'.notifications_cleanup.notifications', 1, null, $deleted);

$deletedTotal += $deleted;
}
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/OAuthDeleteExpiredTokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class OAuthDeleteExpiredTokens extends Command

public function handle()
{
$this->expiredBefore = now()->subDays(config('osu.oauth.retain_expired_tokens_days'));
$this->expiredBefore = now()->subDays($GLOBALS['cfg']['osu']['oauth']['retain_expired_tokens_days']);
$this->line("Deleting before {$this->expiredBefore}");

$this->deleteAuthCodes();
Expand Down
6 changes: 3 additions & 3 deletions app/Console/Commands/UserNotificationsCleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class UserNotificationsCleanup extends Command

public function handle()
{
$total = config('osu.notification.cleanup.max_delete_per_run');
$total = $GLOBALS['cfg']['osu']['notification']['cleanup']['max_delete_per_run'];

if ($total === 0) {
return;
Expand All @@ -27,7 +27,7 @@ public function handle()
$perLoop = min($total, 10000);
$loops = $total / $perLoop;

$createdBefore = now()->subDays(config('osu.notification.cleanup.keep_days'));
$createdBefore = now()->subDays($GLOBALS['cfg']['osu']['notification']['cleanup']['keep_days']);
$this->line("Deleting user notifications before {$createdBefore}");

$progress = $this->output->createProgressBar($total);
Expand Down Expand Up @@ -59,7 +59,7 @@ public function handle()
);
$deleted = count($notificationIds);
$deletedTotal += $deleted;
Datadog::increment(config('datadog-helper.prefix_web').'.notifications_cleanup.user_notifications', 1, null, $deleted);
Datadog::increment($GLOBALS['cfg']['datadog-helper']['prefix_web'].'.notifications_cleanup.user_notifications', 1, null, $deleted);
$progress->advance($deleted);
}

Expand Down
2 changes: 1 addition & 1 deletion app/Events/NotificationEventBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ public static function generateChannelName($notifiable, $subtype)

public function __construct()
{
$this->broadcastQueue = config('osu.notification.queue_name');
$this->broadcastQueue = $GLOBALS['cfg']['osu']['notification']['queue_name'];
}
}
5 changes: 3 additions & 2 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ public function report(Throwable $e)
return;
}

if (config('sentry.dsn')) {
// Fallback in case error happening before config is initialised
if ($GLOBALS['cfg']['sentry']['dsn'] ?? false) {
$this->reportWithSentry($e);
}

Expand Down Expand Up @@ -134,7 +135,7 @@ public function render($request, Throwable $e)

$isJsonRequest = is_json_request();

if (config('app.debug') || ($isJsonRequest && static::isOAuthServerException($e))) {
if ($GLOBALS['cfg']['app']['debug'] || ($isJsonRequest && static::isOAuthServerException($e))) {
$response = parent::render($request, $e);
} else {
$message = static::exceptionMessage($e);
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Account/GithubUsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ public function destroy()
private function makeGithubOAuthProvider(): GithubProvider
{
return new GithubProvider([
'clientId' => config('osu.github.client_id'),
'clientSecret' => config('osu.github.client_secret'),
'clientId' => $GLOBALS['cfg']['osu']['github']['client_id'],
'clientSecret' => $GLOBALS['cfg']['osu']['github']['client_secret'],
]);
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/BeatmapsetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ private function getSearchResponse(?array $params = null)

$records = datadog_timing(function () use ($search) {
return $search->records();
}, config('datadog-helper.prefix_web').'.search', ['type' => 'beatmapset']);
}, $GLOBALS['cfg']['datadog-helper']['prefix_web'].'.search', ['type' => 'beatmapset']);

$error = $search->getError();

Expand Down
12 changes: 6 additions & 6 deletions app/Http/Controllers/ChangelogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function index()
} else {
$chartConfig = Cache::remember(
'chart_config_global',
config('osu.changelog.build_history_interval'),
$GLOBALS['cfg']['osu']['changelog']['build_history_interval'],
function () {
return $this->chartConfig(null);
}
Expand All @@ -203,7 +203,7 @@ function () {

public function github()
{
$token = config('osu.changelog.github_token');
$token = $GLOBALS['cfg']['osu']['changelog']['github_token'];

$signatureHeader = explode('=', request()->header('X-Hub-Signature') ?? '');

Expand Down Expand Up @@ -371,7 +371,7 @@ public function build($streamName, $version)

$chartConfig = Cache::remember(
"chart_config:v2:{$build->updateStream->getKey()}",
config('osu.changelog.build_history_interval'),
$GLOBALS['cfg']['osu']['changelog']['build_history_interval'],
function () use ($build) {
return $this->chartConfig($build->updateStream);
}
Expand Down Expand Up @@ -400,8 +400,8 @@ private function getUpdateStreams()
{
return $this->updateStreams ??= json_collection(
UpdateStream::whereHasBuilds()
->orderByField('stream_id', config('osu.changelog.update_streams'))
->find(config('osu.changelog.update_streams'))
->orderByField('stream_id', $GLOBALS['cfg']['osu']['changelog']['update_streams'])
->find($GLOBALS['cfg']['osu']['changelog']['update_streams'])
->sortBy(function ($i) {
return $i->isFeatured() ? 0 : 1;
}),
Expand All @@ -412,7 +412,7 @@ private function getUpdateStreams()

private function chartConfig($stream)
{
$history = BuildPropagationHistory::changelog(optional($stream)->getKey(), config('osu.changelog.chart_days'))->get();
$history = BuildPropagationHistory::changelog(optional($stream)->getKey(), $GLOBALS['cfg']['osu']['changelog']['chart_days'])->get();

if ($stream === null) {
$chartOrder = array_map(function ($b) {
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ChatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct()

// TODO: notification server and chat client needs some updating
// to handle verification_requirement_change properly.
if (config('osu.user.post_action_verification')) {
if ($GLOBALS['cfg']['osu']['user']['post_action_verification']) {
$this->middleware('verify-user');
}

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function login($user, $remember = false)
$session->regenerateToken();
$session->put('requires_verification', VerifyUserAlways::isRequired($user));
Auth::login($user, $remember);
if (config('osu.user.bypass_verification')) {
if ($GLOBALS['cfg']['osu']['user']['bypass_verification']) {
UserVerificationState::fromCurrentRequest()->markVerified();
}
$session->migrate(true, $user->getKey());
Expand Down
24 changes: 12 additions & 12 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function getDownload()
};

return ext_view('home.download', [
'lazerUrl' => config("osu.urls.lazer_dl.{$platform}"),
'lazerUrl' => $GLOBALS['cfg']['osu']['urls']['lazer_dl'][$platform],
'lazerPlatformName' => $lazerPlatformNames[$platform],
]);
}
Expand Down Expand Up @@ -197,7 +197,7 @@ public function search()

public function setLocale()
{
$newLocale = get_valid_locale(Request::input('locale')) ?? config('app.fallback_locale');
$newLocale = get_valid_locale(Request::input('locale')) ?? $GLOBALS['cfg']['app']['fallback_locale'];
App::setLocale($newLocale);

if (Auth::check()) {
Expand Down Expand Up @@ -327,12 +327,12 @@ public function supportTheGame()
'more_beatmaps' => [
'icons' => ['fas fa-file-upload'],
'translation_options' => [
'base' => config('osu.beatmapset.upload_allowed'),
'bonus' => config('osu.beatmapset.upload_bonus_per_ranked'),
'bonus_max' => config('osu.beatmapset.upload_bonus_per_ranked_max'),
'supporter_base' => config('osu.beatmapset.upload_allowed_supporter'),
'supporter_bonus' => config('osu.beatmapset.upload_bonus_per_ranked_supporter'),
'supporter_bonus_max' => config('osu.beatmapset.upload_bonus_per_ranked_max_supporter'),
'base' => $GLOBALS['cfg']['osu']['beatmapset']['upload_allowed'],
'bonus' => $GLOBALS['cfg']['osu']['beatmapset']['upload_bonus_per_ranked'],
'bonus_max' => $GLOBALS['cfg']['osu']['beatmapset']['upload_bonus_per_ranked_max'],
'supporter_base' => $GLOBALS['cfg']['osu']['beatmapset']['upload_allowed_supporter'],
'supporter_bonus' => $GLOBALS['cfg']['osu']['beatmapset']['upload_bonus_per_ranked_supporter'],
'supporter_bonus_max' => $GLOBALS['cfg']['osu']['beatmapset']['upload_bonus_per_ranked_max_supporter'],
],
],
'early_access' => [
Expand All @@ -351,15 +351,15 @@ public function supportTheGame()
'more_favourites' => [
'icons' => ['fas fa-star'],
'translation_options' => [
'normally' => config('osu.beatmapset.favourite_limit'),
'supporter' => config('osu.beatmapset.favourite_limit_supporter'),
'normally' => $GLOBALS['cfg']['osu']['beatmapset']['favourite_limit'],
'supporter' => $GLOBALS['cfg']['osu']['beatmapset']['favourite_limit_supporter'],
],
],
'more_friends' => [
'icons' => ['fas fa-user-friends'],
'translation_options' => [
'normally' => config('osu.user.max_friends'),
'supporter' => config('osu.user.max_friends_supporter'),
'normally' => $GLOBALS['cfg']['osu']['user']['max_friends'],
'supporter' => $GLOBALS['cfg']['osu']['user']['max_friends_supporter'],
],
],
'friend_filtering' => [
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/InterOp/BeatmapsetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function broadcastRevive($id)
public function destroy($id)
{
$beatmapset = Beatmapset::findOrFail($id);
$user = User::findOrFail(config('osu.legacy.bancho_bot_user_id'));
$user = User::findOrFail($GLOBALS['cfg']['osu']['legacy']['bancho_bot_user_id']);

(new BeatmapsetDelete($beatmapset, $user))->handle();

Expand All @@ -47,7 +47,7 @@ public function destroy($id)
public function disqualify($id)
{
$beatmapset = Beatmapset::findOrFail($id);
$user = User::findOrFail(config('osu.legacy.bancho_bot_user_id'));
$user = User::findOrFail($GLOBALS['cfg']['osu']['legacy']['bancho_bot_user_id']);

$message = request('message') ?? null;

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/LegacyInterOpController.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public function userBatchSendMessage()
];
}

Datadog::increment(config('datadog-helper.prefix_web').'.chat.batch', 1, [
Datadog::increment($GLOBALS['cfg']['datadog-helper']['prefix_web'].'.chat.batch', 1, [
'status' => $result['status'],
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function store($roomId, $playlistId)
$params = request()->all();

$buildId = ClientCheck::findBuild($user, $params)?->getKey()
?? config('osu.client.default_build_id');
?? $GLOBALS['cfg']['osu']['client']['default_build_id'];

$scoreToken = $room->startPlay($user, $playlistItem, $buildId);

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/NotificationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function markRead()

private function endpointUrl()
{
$url = config('osu.notification.endpoint');
$url = $GLOBALS['cfg']['osu']['notification']['endpoint'];

if (($url[0] ?? null) === '/') {
$host = request()->getHttpHost();
Expand Down
10 changes: 5 additions & 5 deletions app/Http/Controllers/Payments/XsollaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct()

public function token()
{
$projectId = config('payments.xsolla.project_id');
$projectId = $GLOBALS['cfg']['payments']['xsolla']['project_id'];
$user = Auth::user();
$order = Order::whereOrderNumber(request('orderNumber'))
->whereCanCheckout()
Expand All @@ -45,7 +45,7 @@ public function token()

$tokenRequest = new TokenRequest($projectId, (string) $user->user_id);
$tokenRequest
->setSandboxMode(config('payments.sandbox'))
->setSandboxMode($GLOBALS['cfg']['payments']['sandbox'])
->setExternalPaymentId($order->getOrderNumber())
->setUserEmail($user->user_email)
->setUserName($user->username)
Expand All @@ -57,14 +57,14 @@ public function token()
]);

$xsollaClient = XsollaClient::factory([
'merchant_id' => config('payments.xsolla.merchant_id'),
'api_key' => config('payments.xsolla.api_key'),
'merchant_id' => $GLOBALS['cfg']['payments']['xsolla']['merchant_id'],
'api_key' => $GLOBALS['cfg']['payments']['xsolla']['api_key'],
]);

// This will be used for XPayStationWidget options.
return [
'access_token' => $xsollaClient->createPaymentUITokenFromRequest($tokenRequest),
'sandbox' => config('payments.sandbox'),
'sandbox' => $GLOBALS['cfg']['payments']['sandbox'],
];
}

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/RankingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function index($mode, $type)
});

if ($type === 'performance') {
$isExperimentalRank = config('osu.scores.experimental_rank_as_default');
$isExperimentalRank = $GLOBALS['cfg']['osu']['scores']['experimental_rank_as_default'];
if ($this->country !== null) {
$stats->where('country_acronym', $this->country['acronym']);
// preferrable to rank_score when filtering by country.
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ScoreTokensController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function store($beatmapId)
try {
$scoreToken = ScoreToken::create([
'beatmap_id' => $beatmap->getKey(),
'build_id' => $build?->getKey() ?? config('osu.client.default_build_id'),
'build_id' => $build?->getKey() ?? $GLOBALS['cfg']['osu']['client']['default_build_id'],
'ruleset_id' => $params['ruleset_id'],
'user_id' => $user->getKey(),
]);
Expand Down
Loading

0 comments on commit 85d570e

Please sign in to comment.