diff --git a/app/Events/Wiki/Group/GroupDeleting.php b/app/Events/Wiki/Group/GroupDeleting.php index 161fb2475..89c334f49 100644 --- a/app/Events/Wiki/Group/GroupDeleting.php +++ b/app/Events/Wiki/Group/GroupDeleting.php @@ -50,7 +50,7 @@ class GroupDeleting extends BaseEvent implements UpdateRelatedIndicesEvent if ($group->isForceDeleting()) { $group->animethemes->each(function (AnimeTheme $theme) { AnimeTheme::withoutEvents(function () use ($theme) { - $theme->theme_group()->dissociate(); + $theme->group()->dissociate(); $theme->save(); }); $theme->searchable(); diff --git a/app/Http/Api/Field/Wiki/Anime/Theme/ThemeGroupField.php b/app/Http/Api/Field/Wiki/Anime/Theme/ThemeGroupField.php deleted file mode 100644 index 614322ba0..000000000 --- a/app/Http/Api/Field/Wiki/Anime/Theme/ThemeGroupField.php +++ /dev/null @@ -1,60 +0,0 @@ - $animethemeentries - * @property string|null $group - * @property Group|null $theme_group + * @property Group|null $group * @property int|null $group_id * @property int|null $sequence * @property string $slug @@ -49,19 +48,18 @@ class AnimeTheme extends BaseModel final public const TABLE = 'anime_themes'; final public const ATTRIBUTE_ANIME = 'anime_id'; - final public const ATTRIBUTE_GROUP = 'group'; final public const ATTRIBUTE_ID = 'theme_id'; + final public const ATTRIBUTE_GROUP = 'group_id'; final public const ATTRIBUTE_SEQUENCE = 'sequence'; final public const ATTRIBUTE_SLUG = 'slug'; final public const ATTRIBUTE_SONG = 'song_id'; - final public const ATTRIBUTE_THEME_GROUP = 'group_id'; final public const ATTRIBUTE_TYPE = 'type'; final public const RELATION_ANIME = 'anime'; final public const RELATION_ARTISTS = 'song.artists'; final public const RELATION_AUDIO = 'animethemeentries.videos.audio'; final public const RELATION_ENTRIES = 'animethemeentries'; - final public const RELATION_GROUP = 'theme_group'; + final public const RELATION_GROUP = 'group'; final public const RELATION_IMAGES = 'anime.images'; final public const RELATION_SONG = 'song'; final public const RELATION_SYNONYMS = 'anime.animesynonyms'; @@ -75,7 +73,6 @@ class AnimeTheme extends BaseModel protected $fillable = [ AnimeTheme::ATTRIBUTE_ANIME, AnimeTheme::ATTRIBUTE_GROUP, - AnimeTheme::ATTRIBUTE_THEME_GROUP, AnimeTheme::ATTRIBUTE_SEQUENCE, AnimeTheme::ATTRIBUTE_SLUG, AnimeTheme::ATTRIBUTE_SONG, @@ -176,9 +173,9 @@ class AnimeTheme extends BaseModel * * @return BelongsTo */ - public function theme_group(): BelongsTo + public function group(): BelongsTo { - return $this->belongsTo(Group::class, AnimeTheme::ATTRIBUTE_THEME_GROUP); + return $this->belongsTo(Group::class, AnimeTheme::ATTRIBUTE_GROUP); } /** diff --git a/app/Models/Wiki/Artist.php b/app/Models/Wiki/Artist.php index 730f4bcd9..e75e83df1 100644 --- a/app/Models/Wiki/Artist.php +++ b/app/Models/Wiki/Artist.php @@ -56,7 +56,7 @@ class Artist extends BaseModel final public const RELATION_MEMBERS = 'members'; final public const RELATION_RESOURCES = 'resources'; final public const RELATION_SONGS = 'songs'; - final public const RELATION_THEME_GROUPS = 'songs.animethemes.theme_group'; + final public const RELATION_THEME_GROUPS = 'songs.animethemes.group'; /** * The attributes that are mass assignable. diff --git a/app/Models/Wiki/Group.php b/app/Models/Wiki/Group.php index 61dbf9e79..5b6e6514c 100644 --- a/app/Models/Wiki/Group.php +++ b/app/Models/Wiki/Group.php @@ -101,6 +101,6 @@ class Group extends BaseModel */ public function animethemes(): HasMany { - return $this->hasMany(AnimeTheme::class, AnimeTheme::ATTRIBUTE_THEME_GROUP); + return $this->hasMany(AnimeTheme::class, AnimeTheme::ATTRIBUTE_GROUP); } } diff --git a/app/Models/Wiki/Song.php b/app/Models/Wiki/Song.php index f443da8a4..3bb24a943 100644 --- a/app/Models/Wiki/Song.php +++ b/app/Models/Wiki/Song.php @@ -47,6 +47,7 @@ class Song extends BaseModel final public const RELATION_ANIMETHEMES = 'animethemes'; final public const RELATION_ARTISTS = 'artists'; final public const RELATION_RESOURCES = 'resources'; + final public const RELATION_THEME_GROUPS = 'animethemes.group'; final public const RELATION_VIDEOS = 'animethemes.animethemeentries.videos'; /** diff --git a/app/Models/Wiki/Video.php b/app/Models/Wiki/Video.php index 18780e5db..9aea34547 100644 --- a/app/Models/Wiki/Video.php +++ b/app/Models/Wiki/Video.php @@ -84,6 +84,7 @@ class Video extends BaseModel implements Streamable, Viewable final public const RELATION_ANIMESYNONYMS = 'animethemeentries.animetheme.anime.animesynonyms'; final public const RELATION_ANIMETHEME = 'animethemeentries.animetheme'; final public const RELATION_ANIMETHEMEENTRIES = 'animethemeentries'; + final public const RELATION_GROUP = 'animethemeentries.animetheme.group'; final public const RELATION_AUDIO = 'audio'; final public const RELATION_SCRIPT = 'videoscript'; final public const RELATION_SONG = 'animethemeentries.animetheme.song'; diff --git a/app/Nova/Resources/Wiki/Anime/Theme.php b/app/Nova/Resources/Wiki/Anime/Theme.php index 5e5504be7..51121faea 100644 --- a/app/Nova/Resources/Wiki/Anime/Theme.php +++ b/app/Nova/Resources/Wiki/Anime/Theme.php @@ -198,17 +198,6 @@ class Theme extends BaseResource ->filterable() ->showWhenPeeking(), - Text::make(__('nova.fields.anime_theme.group.name'), AnimeTheme::ATTRIBUTE_GROUP) - ->sortable() - ->nullable() - ->rules(['nullable', 'max:192']) - ->help(__('nova.fields.anime_theme.group.help')) - ->showOnPreview() - ->filterable() - ->maxlength(192) - ->enforceMaxlength() - ->showWhenPeeking(), - Text::make(__('nova.fields.anime_theme.slug.name'), AnimeTheme::ATTRIBUTE_SLUG) ->sortable() ->rules(['required', 'max:192', 'alpha_dash']) diff --git a/app/Scout/Elasticsearch/Api/Field/Wiki/Anime/Theme/ThemeGroupField.php b/app/Scout/Elasticsearch/Api/Field/Wiki/Anime/Theme/ThemeGroupField.php deleted file mode 100644 index fe31bef35..000000000 --- a/app/Scout/Elasticsearch/Api/Field/Wiki/Anime/Theme/ThemeGroupField.php +++ /dev/null @@ -1,25 +0,0 @@ -id(AnimeTheme::ATTRIBUTE_ID); $table->timestamps(6); $table->softDeletes(BaseModel::ATTRIBUTE_DELETED_AT, 6); - $table->string(AnimeTheme::ATTRIBUTE_GROUP)->nullable(); $table->integer(AnimeTheme::ATTRIBUTE_TYPE)->nullable(); $table->integer(AnimeTheme::ATTRIBUTE_SEQUENCE)->nullable(); $table->string(AnimeTheme::ATTRIBUTE_SLUG); diff --git a/database/migrations/2024_04_26_140035_add_theme_group_attribute_to_anime_theme.php b/database/migrations/2024_04_26_140035_add_theme_group_attribute_to_anime_theme.php index 9170551fb..17d6117c1 100644 --- a/database/migrations/2024_04_26_140035_add_theme_group_attribute_to_anime_theme.php +++ b/database/migrations/2024_04_26_140035_add_theme_group_attribute_to_anime_theme.php @@ -15,10 +15,10 @@ return new class extends Migration */ public function up(): void { - if (! Schema::hasColumn(AnimeTheme::TABLE, AnimeTheme::ATTRIBUTE_THEME_GROUP)) { + if (! Schema::hasColumn(AnimeTheme::TABLE, AnimeTheme::ATTRIBUTE_GROUP)) { Schema::table(AnimeTheme::TABLE, function (Blueprint $table) { - $table->unsignedBigInteger(AnimeTheme::ATTRIBUTE_THEME_GROUP)->nullable(); - $table->foreign(AnimeTheme::ATTRIBUTE_THEME_GROUP)->references(Group::ATTRIBUTE_ID)->on(Group::TABLE)->nullOnDelete(); + $table->unsignedBigInteger(AnimeTheme::ATTRIBUTE_GROUP)->nullable(); + $table->foreign(AnimeTheme::ATTRIBUTE_GROUP)->references(Group::ATTRIBUTE_ID)->on(Group::TABLE)->nullOnDelete(); }); } } @@ -28,9 +28,9 @@ return new class extends Migration */ public function down(): void { - if (Schema::hasColumn(AnimeTheme::TABLE, AnimeTheme::ATTRIBUTE_THEME_GROUP)) { + if (Schema::hasColumn(AnimeTheme::TABLE, AnimeTheme::ATTRIBUTE_GROUP)) { Schema::table(AnimeTheme::TABLE, function (Blueprint $table) { - $table->dropConstrainedForeignId(AnimeTheme::ATTRIBUTE_THEME_GROUP); + $table->dropConstrainedForeignId(AnimeTheme::ATTRIBUTE_GROUP); }); } } diff --git a/elastic/migrations/2020_12_22_034505_create_entry_index.php b/elastic/migrations/2020_12_22_034505_create_entry_index.php index 7fbc59599..c6ab5482d 100644 --- a/elastic/migrations/2020_12_22_034505_create_entry_index.php +++ b/elastic/migrations/2020_12_22_034505_create_entry_index.php @@ -100,7 +100,30 @@ final class CreateEntryIndex implements MigrationInterface 'type' => 'date', ], 'group' => [ - 'type' => 'text', + 'type' => 'nested', + 'properties' => [ + 'created_at' => [ + 'type' => 'date', + ], + 'group_id' => [ + 'type' => 'long', + ], + 'name' => [ + 'type' => 'text', + ], + 'slug' => [ + 'type' => 'text', + ], + 'video_filename' => [ + 'type' => 'text', + ], + 'updated_at' => [ + 'type' => 'date', + ], + ], + ], + 'group_id' => [ + 'type' => 'long', ], 'sequence' => [ 'type' => 'long', diff --git a/elastic/migrations/2020_12_22_034557_create_theme_index.php b/elastic/migrations/2020_12_22_034557_create_theme_index.php index fbcb1d5ac..a2c1f3acf 100644 --- a/elastic/migrations/2020_12_22_034557_create_theme_index.php +++ b/elastic/migrations/2020_12_22_034557_create_theme_index.php @@ -73,13 +73,29 @@ final class CreateThemeIndex implements MigrationInterface $mapping->long('anime_id'); $mapping->text('anime_slug'); $mapping->date('created_at'); - $mapping->text('group', [ - 'fields' => [ - 'keyword' => [ - 'type' => 'keyword', + $mapping->nested('group', [ + 'properties' => [ + 'created_at' => [ + 'type' => 'date', + ], + 'group_id' => [ + 'type' => 'long', + ], + 'name' => [ + 'type' => 'text', + ], + 'slug' => [ + 'type' => 'text', + ], + 'video_filename' => [ + 'type' => 'text', + ], + 'updated_at' => [ + 'type' => 'date', ], ], ]); + $mapping->long('group_id'); $mapping->long('sequence'); $mapping->text('slug', [ 'copy_to' => [ diff --git a/elastic/migrations/2020_12_22_034601_create_video_index.php b/elastic/migrations/2020_12_22_034601_create_video_index.php index 75cb4a533..b23f4f181 100644 --- a/elastic/migrations/2020_12_22_034601_create_video_index.php +++ b/elastic/migrations/2020_12_22_034601_create_video_index.php @@ -110,7 +110,30 @@ final class CreateVideoIndex implements MigrationInterface 'type' => 'date', ], 'group' => [ - 'type' => 'text', + 'type' => 'nested', + 'properties' => [ + 'created_at' => [ + 'type' => 'date', + ], + 'group_id' => [ + 'type' => 'long', + ], + 'name' => [ + 'type' => 'text', + ], + 'slug' => [ + 'type' => 'text', + ], + 'video_filename' => [ + 'type' => 'text', + ], + 'updated_at' => [ + 'type' => 'date', + ], + ], + ], + 'group_id' => [ + 'type' => 'long', ], 'sequence' => [ 'type' => 'long', diff --git a/lang/en/nova.php b/lang/en/nova.php index 0011b9297..ed38fe36c 100644 --- a/lang/en/nova.php +++ b/lang/en/nova.php @@ -423,10 +423,6 @@ return [ ], ], 'anime_theme' => [ - 'group' => [ - 'help' => 'For separating sequences belonging to dubs, rebroadcasts, remasters, etc. By default, leave blank.', - 'name' => 'Group', - ], 'sequence' => [ 'help' => 'Numeric ordering of theme. If only one theme of this type exists for the show, this can be left blank.', 'name' => 'Sequence', diff --git a/tests/Unit/Models/Wiki/Anime/AnimeThemeTest.php b/tests/Unit/Models/Wiki/Anime/AnimeThemeTest.php index 87e7b5102..7c18802ef 100644 --- a/tests/Unit/Models/Wiki/Anime/AnimeThemeTest.php +++ b/tests/Unit/Models/Wiki/Anime/AnimeThemeTest.php @@ -107,8 +107,8 @@ class AnimeThemeTest extends TestCase ->for(Group::factory()) ->createOne(); - static::assertInstanceOf(BelongsTo::class, $theme->theme_group()); - static::assertInstanceOf(Group::class, $theme->theme_group()->first()); + static::assertInstanceOf(BelongsTo::class, $theme->group()); + static::assertInstanceOf(Group::class, $theme->group()->first()); } /**