From 92f414f72be76343af5427c14c9b370858889807 Mon Sep 17 00:00:00 2001 From: abdalrhman <89781398+Abdooo2235@users.noreply.github.com> Date: Tue, 7 Apr 2026 23:05:00 +0000 Subject: [PATCH 1/2] tags: drop legacy background columns from tags table --- ...op_legacy_background_columns_from_tags.php | 50 +++++++++++++++++++ .../tags/src/Api/Resource/TagResource.php | 5 +- extensions/tags/src/Tag.php | 2 - extensions/tags/src/TagFactory.php | 2 - .../tests/integration/api/tags/SchemaTest.php | 36 +++++++++++++ 5 files changed, 89 insertions(+), 6 deletions(-) create mode 100644 extensions/tags/migrations/2026_04_07_000000_drop_legacy_background_columns_from_tags.php create mode 100644 extensions/tags/tests/integration/api/tags/SchemaTest.php 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')); + } +} From 099ac1aad1f35504e31ee57e1adfd87bfc6a080c Mon Sep 17 00:00:00 2001 From: abdalrhman <89781398+Abdooo2235@users.noreply.github.com> Date: Fri, 17 Apr 2026 21:16:56 +0000 Subject: [PATCH 2/2] tags: remove legacy background attributes --- extensions/tags/js/src/common/models/Tag.ts | 6 --- ...op_legacy_background_columns_from_tags.php | 45 +++---------------- .../tags/src/Api/Resource/TagResource.php | 4 -- 3 files changed, 5 insertions(+), 50 deletions(-) diff --git a/extensions/tags/js/src/common/models/Tag.ts b/extensions/tags/js/src/common/models/Tag.ts index 46a023becb..c7eea44311 100644 --- a/extensions/tags/js/src/common/models/Tag.ts +++ b/extensions/tags/js/src/common/models/Tag.ts @@ -16,12 +16,6 @@ export default class Tag extends Model { color() { return Model.attribute('color').call(this); } - backgroundUrl() { - return Model.attribute('backgroundUrl').call(this); - } - backgroundMode() { - return Model.attribute('backgroundMode').call(this); - } icon() { return Model.attribute('icon').call(this); } 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 index 9da8c8b847..7b12644ae0 100644 --- 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 @@ -7,44 +7,9 @@ * LICENSE file that was distributed with this source code. */ -use Illuminate\Database\Schema\Blueprint; -use Illuminate\Database\Schema\Builder; +use Flarum\Database\Migration; -return [ - 'up' => 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); - }); - } - } -]; +return Migration::dropColumns('tags', [ + 'background_path' => ['string', 'length' => 100, 'nullable' => true], + 'background_mode' => ['string', 'length' => 100, 'nullable' => true], +]); diff --git a/extensions/tags/src/Api/Resource/TagResource.php b/extensions/tags/src/Api/Resource/TagResource.php index 8f237bd449..5972881de6 100644 --- a/extensions/tags/src/Api/Resource/TagResource.php +++ b/extensions/tags/src/Api/Resource/TagResource.php @@ -112,10 +112,6 @@ public function fields(): array Schema\Boolean::make('isRestricted') ->writableOnUpdate() ->visible(fn (Tag $tag, FlarumContext $context) => $context->getActor()->isAdmin()), - Schema\Str::make('backgroundUrl') - ->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(),