diff --git a/extensions/tags/migrations/2026_04_07_000000_drop_legacy_background_columns_from_tags.php b/extensions/tags/migrations/2026_04_07_000000_drop_legacy_background_columns_from_tags.php new file mode 100644 index 0000000000..9da8c8b847 --- /dev/null +++ b/extensions/tags/migrations/2026_04_07_000000_drop_legacy_background_columns_from_tags.php @@ -0,0 +1,50 @@ + function (Builder $schema) { + if (! $schema->hasTable('tags')) { + return; + } + + if ($schema->hasColumn('tags', 'background_path')) { + $schema->table('tags', function (Blueprint $table) { + $table->dropColumn('background_path'); + }); + } + + if ($schema->hasColumn('tags', 'background_mode')) { + $schema->table('tags', function (Blueprint $table) { + $table->dropColumn('background_mode'); + }); + } + }, + 'down' => function (Builder $schema) { + if (! $schema->hasTable('tags')) { + return; + } + + if (! $schema->hasColumn('tags', 'background_path')) { + $schema->table('tags', function (Blueprint $table) { + $table->string('background_path', 100)->nullable()->after('color'); + }); + } + + if (! $schema->hasColumn('tags', 'background_mode')) { + $afterColumn = $schema->hasColumn('tags', 'background_path') ? 'background_path' : 'color'; + + $schema->table('tags', function (Blueprint $table) use ($afterColumn) { + $table->string('background_mode', 100)->nullable()->after($afterColumn); + }); + } + } +]; diff --git a/extensions/tags/src/Api/Resource/TagResource.php b/extensions/tags/src/Api/Resource/TagResource.php index 75ccbbb8c6..8f237bd449 100644 --- a/extensions/tags/src/Api/Resource/TagResource.php +++ b/extensions/tags/src/Api/Resource/TagResource.php @@ -113,8 +113,9 @@ public function fields(): array ->writableOnUpdate() ->visible(fn (Tag $tag, FlarumContext $context) => $context->getActor()->isAdmin()), Schema\Str::make('backgroundUrl') - ->get(fn (Tag $tag) => $tag->background_path), - Schema\Str::make('backgroundMode'), + ->get(fn (Tag $tag) => $tag->getAttribute('background_path')), + Schema\Str::make('backgroundMode') + ->get(fn (Tag $tag) => $tag->getAttribute('background_mode')), Schema\Integer::make('discussionCount'), Schema\Integer::make('position') ->nullable(), diff --git a/extensions/tags/src/Tag.php b/extensions/tags/src/Tag.php index 469e9e729c..ae51dacdff 100644 --- a/extensions/tags/src/Tag.php +++ b/extensions/tags/src/Tag.php @@ -28,8 +28,6 @@ * @property string $slug * @property string $description * @property string $color - * @property string $background_path - * @property string $background_mode * @property bool $is_primary * @property int $position * @property int $parent_id diff --git a/extensions/tags/src/TagFactory.php b/extensions/tags/src/TagFactory.php index 629fb4bb9c..a88e8d39d5 100644 --- a/extensions/tags/src/TagFactory.php +++ b/extensions/tags/src/TagFactory.php @@ -21,8 +21,6 @@ public function definition(): array 'slug' => $this->faker->slug, 'description' => $this->faker->sentence, 'color' => $this->faker->hexColor, - 'background_path' => null, - 'background_mode' => null, 'position' => 0, 'parent_id' => null, 'default_sort' => null, diff --git a/extensions/tags/tests/integration/api/tags/SchemaTest.php b/extensions/tags/tests/integration/api/tags/SchemaTest.php new file mode 100644 index 0000000000..8c7a7c366c --- /dev/null +++ b/extensions/tags/tests/integration/api/tags/SchemaTest.php @@ -0,0 +1,36 @@ +extension('flarum-tags'); + } + + #[Test] + public function legacy_background_columns_are_not_present_on_tags_table() + { + $schema = $this->app()->getContainer()->make(Builder::class); + + $this->assertFalse($schema->hasColumn('tags', 'background_path')); + $this->assertFalse($schema->hasColumn('tags', 'background_mode')); + } +}