Skip to content
Closed
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
Expand Up @@ -11,14 +11,14 @@
use Illuminate\Database\Schema\Blueprint;

return Migration::createTable(
'dialog_message_mentions_user',
'message_mentions_user',
function (Blueprint $table) {
$table->unsignedInteger('dialog_message_id');
$table->unsignedInteger('mentions_user_id');
$table->unsignedInteger('message_id');
$table->unsignedInteger('user_id');
$table->dateTime('created_at')->nullable()->useCurrent();

$table->primary(['dialog_message_id', 'mentions_user_id']);
$table->foreign('dialog_message_id')->references('id')->on('dialog_messages')->cascadeOnDelete();
$table->foreign('mentions_user_id')->references('id')->on('users')->cascadeOnDelete();
$table->primary(['message_id', 'user_id']);
$table->foreign('message_id')->references('id')->on('dialog_messages')->cascadeOnDelete();
$table->foreign('user_id')->references('id')->on('users')->cascadeOnDelete();
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
use Illuminate\Database\Schema\Blueprint;

return Migration::createTable(
'dialog_message_mentions_post',
'message_mentions_post',
function (Blueprint $table) {
$table->unsignedInteger('dialog_message_id');
$table->unsignedInteger('mentions_post_id');
$table->unsignedInteger('message_id');
$table->unsignedInteger('post_id');
$table->dateTime('created_at')->nullable()->useCurrent();

$table->primary(['dialog_message_id', 'mentions_post_id']);
$table->foreign('dialog_message_id')->references('id')->on('dialog_messages')->cascadeOnDelete();
$table->foreign('mentions_post_id')->references('id')->on('posts')->cascadeOnDelete();
$table->primary(['message_id', 'post_id']);
$table->foreign('message_id')->references('id')->on('dialog_messages')->cascadeOnDelete();
$table->foreign('post_id')->references('id')->on('posts')->cascadeOnDelete();
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
use Illuminate\Database\Schema\Blueprint;

return Migration::createTable(
'dialog_message_mentions_group',
'message_mentions_group',
function (Blueprint $table) {
$table->unsignedInteger('dialog_message_id');
$table->unsignedInteger('mentions_group_id');
$table->unsignedInteger('message_id');
$table->unsignedInteger('group_id');
$table->dateTime('created_at')->nullable()->useCurrent();

$table->primary(['dialog_message_id', 'mentions_group_id']);
$table->foreign('dialog_message_id')->references('id')->on('dialog_messages')->cascadeOnDelete();
$table->foreign('mentions_group_id')->references('id')->on('groups')->cascadeOnDelete();
$table->primary(['message_id', 'group_id']);
$table->foreign('message_id')->references('id')->on('dialog_messages')->cascadeOnDelete();
$table->foreign('group_id')->references('id')->on('groups')->cascadeOnDelete();
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
use Illuminate\Database\Schema\Builder;

return Migration::createTable(
'dialog_message_mentions_tag',
'message_mentions_tag',
function (Blueprint $table, Builder $schema) {
$table->unsignedInteger('dialog_message_id');
$table->unsignedInteger('mentions_tag_id');
$table->unsignedInteger('message_id');
$table->unsignedInteger('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->primary(['message_id', 'tag_id']);
$table->foreign('message_id')->references('id')->on('dialog_messages')->cascadeOnDelete();

if ($schema->hasTable('tags')) {
$table->foreign('mentions_tag_id')->references('id')->on('tags')->cascadeOnDelete();
$table->foreign('tag_id')->references('id')->on('tags')->cascadeOnDelete();
}
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?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;

$tables = [
'dialog_message_mentions_user' => ['message_mentions_user', ['dialog_message_id' => 'message_id', 'mentions_user_id' => 'user_id']],
'dialog_message_mentions_post' => ['message_mentions_post', ['dialog_message_id' => 'message_id', 'mentions_post_id' => 'post_id']],
'dialog_message_mentions_group' => ['message_mentions_group', ['dialog_message_id' => 'message_id', 'mentions_group_id' => 'group_id']],
'dialog_message_mentions_tag' => ['message_mentions_tag', ['dialog_message_id' => 'message_id', 'mentions_tag_id' => 'tag_id']],
];

return [
'up' => function (Builder $schema) use ($tables) {
foreach ($tables as $from => [$to, $columns]) {
if (! $schema->hasTable($from) || $schema->hasTable($to)) {
continue;
}

$schema->rename($from, $to);

$schema->table($to, function (Blueprint $table) use ($columns) {
foreach ($columns as $old => $new) {
$table->renameColumn($old, $new);
}
});
}
},
// Deliberately one-way. The migrations that created these tables drop them by their
// current name, and they roll back after this one, so restoring the old names here
// would leave that drop with nothing to remove.
'down' => function (Builder $schema) {
},
];
8 changes: 4 additions & 4 deletions extensions/messages/src/DialogMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,21 @@ public function user(): BelongsTo

public function mentionsUsers(): BelongsToMany
{
return $this->belongsToMany(User::class, 'dialog_message_mentions_user', 'dialog_message_id', 'mentions_user_id');
return $this->belongsToMany(User::class, 'message_mentions_user', 'message_id', 'user_id');
}

public function mentionsPosts(): BelongsToMany
{
return $this->belongsToMany(Post::class, 'dialog_message_mentions_post', 'dialog_message_id', 'mentions_post_id');
return $this->belongsToMany(Post::class, 'message_mentions_post', 'message_id', 'post_id');
}

public function mentionsGroups(): BelongsToMany
{
return $this->belongsToMany(Group::class, 'dialog_message_mentions_group', 'dialog_message_id', 'mentions_group_id');
return $this->belongsToMany(Group::class, 'message_mentions_group', 'message_id', 'group_id');
}

public function mentionsTags(): BelongsToMany
{
return $this->belongsToMany(Tag::class, 'dialog_message_mentions_tag', 'dialog_message_id', 'mentions_tag_id');
return $this->belongsToMany(Tag::class, 'message_mentions_tag', 'message_id', 'tag_id');
}
}
Loading