Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;

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);
});
}
}
];
5 changes: 3 additions & 2 deletions extensions/tags/src/Api/Resource/TagResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 0 additions & 2 deletions extensions/tags/src/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions extensions/tags/src/TagFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
36 changes: 36 additions & 0 deletions extensions/tags/tests/integration/api/tags/SchemaTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/

namespace Flarum\Tags\Tests\integration\api\tags;

use Flarum\Testing\integration\TestCase;
use Illuminate\Database\Schema\Builder;
use PHPUnit\Framework\Attributes\Test;

class SchemaTest extends TestCase
{
/**
* @inheritDoc
*/
protected function setUp(): void
{
parent::setUp();

$this->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'));
}
}