1
0
mirror of https://github.com/flarum/core.git synced 2025-08-08 09:26:34 +02:00

feat(pm): messages anchor link (#4175)

This commit is contained in:
Sami Mazouz
2025-02-08 18:30:35 +01:00
committed by GitHub
parent 333bbb11e2
commit db1e36d545
19 changed files with 324 additions and 69 deletions

View File

@@ -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) {
$schema->table('dialog_messages', function (Blueprint $table) {
$table->unsignedBigInteger('number')->nullable()->after('content');
});
$numbers = [];
$schema->getConnection()
->table('dialogs')
->orderBy('id')
->each(function (object $dialog) use ($schema, &$numbers) {
$numbers[$dialog->id] = 0;
$schema->getConnection()
->table('dialog_messages')
->where('dialog_id', $dialog->id)
->orderBy('id')
->each(function (object $message) use ($schema, &$numbers) {
$schema->getConnection()
->table('dialog_messages')
->where('id', $message->id)
->update(['number' => ++$numbers[$message->dialog_id]]);
});
unset($numbers[$dialog->id]);
});
$schema->table('dialog_messages', function (Blueprint $table) {
$table->unsignedBigInteger('number')->nullable(false)->change();
});
},
'down' => function (Builder $schema) {
$schema->table('dialog_messages', function (Blueprint $table) {
$table->dropColumn('number');
});
}
];