Add Topics\UpdateUsername()
This commit is contained in:
parent
d2cc0f187b
commit
c2f4964842
3 changed files with 45 additions and 0 deletions
|
@ -1050,6 +1050,12 @@ class Update extends Admin
|
|||
'PostManagerFeed'
|
||||
);
|
||||
|
||||
$coreConfig->add(
|
||||
'multiple=>TopicManagerUpdateUsername',
|
||||
'\\ForkBB\\Models\\Topic\\UpdateUsername::class',
|
||||
'TopicManagerMove'
|
||||
);
|
||||
|
||||
$coreConfig->save();
|
||||
|
||||
return null;
|
||||
|
|
38
app/Models/Topic/UpdateUsername.php
Normal file
38
app/Models/Topic/UpdateUsername.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ForkBB\Models\Topic;
|
||||
|
||||
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 ::topics
|
||||
SET poster=?s:name
|
||||
WHERE poster_id=?i:id';
|
||||
|
||||
$this->c->DB->exec($query, $vars);
|
||||
|
||||
$query = 'UPDATE ::topics
|
||||
SET last_poster=?s:name
|
||||
WHERE last_poster_id=?i:id';
|
||||
|
||||
$this->c->DB->exec($query, $vars);
|
||||
}
|
||||
}
|
|
@ -278,6 +278,7 @@ return [
|
|||
'TopicManagerAccess' => \ForkBB\Models\Topic\Access::class,
|
||||
'TopicManagerMerge' => \ForkBB\Models\Topic\Merge::class,
|
||||
'TopicManagerMove' => \ForkBB\Models\Topic\Move::class,
|
||||
'TopicManagerUpdateUsername' => \ForkBB\Models\Topic\UpdateUsername::class,
|
||||
|
||||
'PostModel' => \ForkBB\Models\Post\Model::class,
|
||||
'PostManagerLoad' => \ForkBB\Models\Post\Load::class,
|
||||
|
|
Loading…
Add table
Reference in a new issue