Skip to content

Commit

Permalink
Merge branch 'master' into forum-show-variable
Browse files Browse the repository at this point in the history
  • Loading branch information
notbakaneko authored Nov 7, 2023
2 parents c4cf8f0 + 6f5188e commit 051b0d8
Show file tree
Hide file tree
Showing 17 changed files with 78 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/Libraries/Ip.php → app/Enums/Ip.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

declare(strict_types=1);

namespace App\Libraries;
namespace App\Enums;

enum Ip: string
{
Expand Down
2 changes: 1 addition & 1 deletion app/Libraries/Ruleset.php → app/Enums/Ruleset.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

declare(strict_types=1);

namespace App\Libraries;
namespace App\Enums;

enum Ruleset: int
{
Expand Down
25 changes: 25 additions & 0 deletions app/Libraries/Countries.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

namespace App\Libraries;

use App\Models\Country;
use App\Traits\Memoizes;
use Illuminate\Database\Eloquent\Collection;

class Countries
{
use Memoizes;

private function allByCode(): Collection
{
return $this->memoize(__FUNCTION__, fn () => Country::get(['acronym', 'name'])->keyBy('acronym'));
}

public function byCode(string $code): ?Country
{
return $this->allByCode()->get($code);
}
}
1 change: 1 addition & 0 deletions app/Libraries/Ip2Asn.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace App\Libraries;

use App\Enums\Ip;
use Exception;
use WeakMap;

Expand Down
1 change: 1 addition & 0 deletions app/Libraries/Ip2AsnUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace App\Libraries;

use App\Enums\Ip;
use Log;

class Ip2AsnUpdater
Expand Down
5 changes: 5 additions & 0 deletions app/Libraries/Markdown/CustomContainerInline/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public function render(Node $node, ChildNodeRendererInterface $childRenderer)
$attrs->remove('flag');
$attrs->set('class', 'flag-country flag-country--flat flag-country--wiki');
$attrs->set('style', "background-image: url('".flag_url($code)."')");

$country = app('countries')->byCode($code);
if ($country !== null) {
$attrs->set('title', $country->name);
}
}

return new HtmlElement(
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Multiplayer/PlaylistItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

namespace App\Models\Multiplayer;

use App\Enums\Ruleset;
use App\Exceptions\InvariantException;
use App\Libraries\Ruleset;
use App\Models\Beatmap;
use App\Models\Model;
use App\Models\ScoreToken;
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Multiplayer/ScoreLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static function complete(ScoreToken $token, array $params): static
public $timestamps = false;

protected $primaryKey = 'score_id';
protected $table = 'multiplayer_score_links';
protected $table = 'multiplayer_playlist_item_scores';

public function playlistItem(): BelongsTo
{
Expand Down
2 changes: 0 additions & 2 deletions app/Models/ScoreToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
*/
class ScoreToken extends Model
{
protected $table = 'solo_score_tokens';

public function beatmap()
{
return $this->belongsTo(Beatmap::class, 'beatmap_id');
Expand Down
1 change: 0 additions & 1 deletion app/Models/Solo/Score.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class Score extends Model implements Traits\ReportableInterface

const PROCESSING_QUEUE = 'osu-queue:score-statistics';

protected $table = 'solo_scores';
protected $casts = [
'data' => ScoreData::class,
'has_replay' => 'boolean',
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Solo/ScorePerformance.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ class ScorePerformance extends Model
public $timestamps = false;

protected $primaryKey = 'score_id';
protected $table = 'solo_scores_performance';
protected $table = 'score_performance';
}
2 changes: 2 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Libraries\AssetsManifest;
use App\Libraries\ChatFilters;
use App\Libraries\CleanHTML;
use App\Libraries\Countries;
use App\Libraries\Groups;
use App\Libraries\Ip2Asn;
use App\Libraries\LayoutCache;
Expand Down Expand Up @@ -38,6 +39,7 @@ class AppServiceProvider extends ServiceProvider
{
const LOCAL_CACHE_SINGLETONS = [
'chat-filters' => ChatFilters::class,
'countries' => Countries::class,
'groups' => Groups::class,
'layout-cache' => LayoutCache::class,
'medals' => Medals::class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;

return new class extends Migration
{
private const ALIASES = [
'multiplayer_score_links' => 'multiplayer_playlist_item_scores',
'solo_score_tokens' => 'score_tokens',
'solo_scores' => 'scores',
'solo_scores_legacy_id_map' => 'score_legacy_id_map',
'solo_scores_performance' => 'score_performance',
'solo_scores_process_history' => 'score_process_history',
];

public function up(): void
{
foreach (static::ALIASES as $current => $alias) {
DB::statement("CREATE VIEW {$alias} AS SELECT * FROM {$current}");
}
}

public function down(): void
{
foreach (static::ALIASES as $alias) {
DB::statement("DROP VIEW {$alias}");
}
}
};
2 changes: 1 addition & 1 deletion tests/Controllers/BeatmapsControllerSoloScoresTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public static function tearDownAfterClass(): void
Genre::truncate();
Group::truncate();
Language::truncate();
SoloScore::truncate();
SoloScore::select()->delete(); // TODO: revert to truncate after the table is actually renamed
User::truncate();
UserGroup::truncate();
UserGroupEvent::truncate();
Expand Down
4 changes: 2 additions & 2 deletions tests/Jobs/RemoveBeatmapsetSoloScoresTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public function testHandle()
Genre::truncate();
Group::truncate();
Language::truncate();
Score::truncate();
ScorePerformance::truncate();
Score::select()->delete(); // TODO: revert to truncate after the table is actually renamed
ScorePerformance::select()->delete(); // TODO: revert to truncate after the table is actually renamed
User::truncate();
UserGroup::truncate();
UserGroupEvent::truncate();
Expand Down
2 changes: 1 addition & 1 deletion tests/Libraries/ModsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

namespace Tests\Libraries;

use App\Enums\Ruleset;
use App\Exceptions\InvariantException;
use App\Libraries\Ruleset;
use Tests\TestCase;

class ModsTest extends TestCase
Expand Down
2 changes: 1 addition & 1 deletion tests/Models/Solo/ScoreEsIndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static function tearDownAfterClass(): void
Genre::truncate();
Group::truncate();
Language::truncate();
Score::truncate();
Score::select()->delete(); // TODO: revert to truncate after the table is actually renamed
User::truncate();
UserGroup::truncate();
UserGroupEvent::truncate();
Expand Down

0 comments on commit 051b0d8

Please sign in to comment.