Add Posts\UpdateUsername()
This commit is contained in:
parent
244321516c
commit
d2cc0f187b
3 changed files with 45 additions and 0 deletions
|
@ -1044,6 +1044,12 @@ class Update extends Admin
|
|||
'ForumManagerMarkread'
|
||||
);
|
||||
|
||||
$coreConfig->add(
|
||||
'multiple=>PostManagerUpdateUsername',
|
||||
'\\ForkBB\\Models\\Post\\UpdateUsername::class',
|
||||
'PostManagerFeed'
|
||||
);
|
||||
|
||||
$coreConfig->save();
|
||||
|
||||
return null;
|
||||
|
|
38
app/Models/Post/UpdateUsername.php
Normal file
38
app/Models/Post/UpdateUsername.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ForkBB\Models\Post;
|
||||
|
||||
use ForkBB\Models\Action;
|
||||
use ForkBB\Models\User\Model as User;
|
||||
use RuntimeException;
|
||||
|
||||
class UpdateUsername extends Action
|
||||
{
|
||||
/**
|
||||
* Обновляет имя пользователя в сообщениях
|
||||
*/
|
||||
public function updateUsername(User $user): void
|
||||
{
|
||||
if ($user->isGuest) {
|
||||
throw new RuntimeException('User expected, not guest');
|
||||
}
|
||||
|
||||
$vars = [
|
||||
':id' => $user->id,
|
||||
':name' => $user->username,
|
||||
];
|
||||
$query = 'UPDATE ::posts
|
||||
SET poster=?s:name
|
||||
WHERE poster_id=?i:id';
|
||||
|
||||
$this->c->DB->exec($query, $vars);
|
||||
|
||||
$query = 'UPDATE ::posts
|
||||
SET editor=?s:name
|
||||
WHERE editor_id=?i:id';
|
||||
|
||||
$this->c->DB->exec($query, $vars);
|
||||
}
|
||||
}
|
|
@ -290,6 +290,7 @@ return [
|
|||
'PostManagerUserStat' => \ForkBB\Models\Post\UserStat::class,
|
||||
'PostManagerMove' => \ForkBB\Models\Post\Move::class,
|
||||
'PostManagerFeed' => \ForkBB\Models\Post\Feed::class,
|
||||
'PostManagerUpdateUsername' => \ForkBB\Models\Post\UpdateUsername::class,
|
||||
|
||||
'ReportModel' => \ForkBB\Models\Report\Model::class,
|
||||
'ReportManagerSave' => \ForkBB\Models\Report\Save::class,
|
||||
|
|
Loading…
Add table
Reference in a new issue