diff --git a/extensions/messages/composer.json b/extensions/messages/composer.json index 506995447..f5c4a9b73 100644 --- a/extensions/messages/composer.json +++ b/extensions/messages/composer.json @@ -25,6 +25,9 @@ "flarum-extension": { "title": "Messages", "category": "feature", + "optional-dependencies": [ + "flarum/tags" + ], "icon": { "name": "fas fa-envelope-open", "color": "#ffffff", diff --git a/extensions/messages/migrations/2024_10_19_000002_create_dialog_message_mentions_tag_table.php b/extensions/messages/migrations/2024_10_19_000002_create_dialog_message_mentions_tag_table.php index d81c19be0..17c3d9b69 100644 --- a/extensions/messages/migrations/2024_10_19_000002_create_dialog_message_mentions_tag_table.php +++ b/extensions/messages/migrations/2024_10_19_000002_create_dialog_message_mentions_tag_table.php @@ -9,16 +9,20 @@ use Flarum\Database\Migration; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; return Migration::createTable( 'dialog_message_mentions_tag', - function (Blueprint $table) { + function (Blueprint $table, Builder $schema) { $table->unsignedInteger('dialog_message_id'); $table->unsignedInteger('mentions_tag_id'); $table->dateTime('created_at')->nullable()->useCurrent(); $table->primary(['dialog_message_id', 'mentions_tag_id']); $table->foreign('dialog_message_id')->references('id')->on('dialog_messages')->cascadeOnDelete(); - $table->foreign('mentions_tag_id')->references('id')->on('tags')->cascadeOnDelete(); + + if ($schema->hasTable('tags')) { + $table->foreign('mentions_tag_id')->references('id')->on('tags')->cascadeOnDelete(); + } } ); diff --git a/framework/core/src/Database/Migration.php b/framework/core/src/Database/Migration.php index a8b7c7055..528039679 100644 --- a/framework/core/src/Database/Migration.php +++ b/framework/core/src/Database/Migration.php @@ -25,8 +25,8 @@ abstract class Migration { return [ 'up' => function (Builder $schema) use ($name, $definition) { - $schema->create($name, function (Blueprint $table) use ($definition) { - $definition($table); + $schema->create($name, function (Blueprint $table) use ($definition, $schema) { + $definition($table, $schema); }); }, 'down' => function (Builder $schema) use ($name) { @@ -40,8 +40,8 @@ abstract class Migration return [ 'up' => function (Builder $schema) use ($name, $definition) { if (! $schema->hasTable($name)) { - $schema->create($name, function (Blueprint $table) use ($definition) { - $definition($table); + $schema->create($name, function (Blueprint $table) use ($definition, $schema) { + $definition($table, $schema); }); } },