mirror of
https://github.com/flarum/core.git
synced 2025-08-06 16:36:47 +02:00
Moved deprecated user notification preferences logic into a dedicated trait,
did the same for user preferences to one that we can retain; those for user columns re-added migrations, fixed most of the fallback methods
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<?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->create('notification_preferences', function (Blueprint $table) {
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->string('type');
|
||||
$table->string('channel');
|
||||
$table->boolean('enabled')->default(false);
|
||||
|
||||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
|
||||
});
|
||||
},
|
||||
|
||||
'down' => function (Builder $schema) {
|
||||
$schema->drop('notification_preferences');
|
||||
}
|
||||
];
|
@@ -0,0 +1,27 @@
|
||||
<?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('users', function (Blueprint $table) {
|
||||
$table->boolean('disclose_online')->default(false);
|
||||
$table->string('locale')->nullable();
|
||||
});
|
||||
},
|
||||
|
||||
'down' => function (Builder $schema) {
|
||||
$schema->table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('disclose_online');
|
||||
$table->dropColumn('locale');
|
||||
});
|
||||
}
|
||||
];
|
@@ -0,0 +1,52 @@
|
||||
<?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\Builder;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
return [
|
||||
'up' => function (Builder $builder) {
|
||||
$db = $builder->getConnection();
|
||||
|
||||
$db->table('users')
|
||||
->select(['id', 'preferences'])
|
||||
->whereNotNull('preferences')
|
||||
->orderBy('id')
|
||||
->each(function ($user) use ($db) {
|
||||
collect(json_decode($user->preferences ?? '{}'))
|
||||
->each(function ($value, $key) use ($user, $db) {
|
||||
if (in_array($key, ['discloseOnline', 'followAfterReply'])) {
|
||||
$db->table('users')
|
||||
->where('id', $user->id)
|
||||
->update([Str::snake($key) => (bool) $value]);
|
||||
}
|
||||
if ($key === 'locale') {
|
||||
$db->table('users')
|
||||
->where('id', $user->id)
|
||||
->update(['locale' => $value]);
|
||||
}
|
||||
if (preg_match('/^notify_(?<type>[^_]+)_(?<channel>.*)$/', $key, $matches)) {
|
||||
$db->table('notification_preferences')
|
||||
->insert([
|
||||
'user_id' => $user->id,
|
||||
'type' => $matches['type'],
|
||||
'channel' => $matches['channel'],
|
||||
'enabled' => (bool) $value
|
||||
]);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
'down' => function (Builder $builder) {
|
||||
$db = $builder->getConnection();
|
||||
|
||||
$db->table('notification_preferences')->truncate();
|
||||
}
|
||||
];
|
@@ -0,0 +1,25 @@
|
||||
<?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('users', function (Blueprint $table) {
|
||||
$table->dropColumn('preferences');
|
||||
});
|
||||
},
|
||||
|
||||
'down' => function (Builder $schema) {
|
||||
$schema->table('users', function (Blueprint $table) {
|
||||
$table->binary('preferences')->nullable();
|
||||
});
|
||||
}
|
||||
];
|
Reference in New Issue
Block a user