Add Online\UpdateUsername()
This commit is contained in:
parent
c2f4964842
commit
cb8b7f4440
3 changed files with 39 additions and 0 deletions
32
app/Models/Online/UpdateUsername.php
Normal file
32
app/Models/Online/UpdateUsername.php
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ForkBB\Models\Online;
|
||||
|
||||
use ForkBB\Models\Method;
|
||||
use ForkBB\Models\User\Model as User;
|
||||
use RuntimeException;
|
||||
|
||||
class UpdateUsername extends Method
|
||||
{
|
||||
/**
|
||||
* Обновляет имя пользователя в таблице online
|
||||
*/
|
||||
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 ::online
|
||||
SET ident=?s:name
|
||||
WHERE user_id=?i:id';
|
||||
|
||||
$this->c->DB->exec($query, $vars);
|
||||
}
|
||||
}
|
|
@ -1056,6 +1056,12 @@ class Update extends Admin
|
|||
'TopicManagerMove'
|
||||
);
|
||||
|
||||
$coreConfig->add(
|
||||
'multiple=>OnlineModelUpdateUsername',
|
||||
'\\ForkBB\\Models\\Online\\UpdateUsername::class',
|
||||
'OnlineModelInfo'
|
||||
);
|
||||
|
||||
$coreConfig->save();
|
||||
|
||||
return null;
|
||||
|
|
|
@ -217,6 +217,7 @@ return [
|
|||
'ConfigModelSave' => \ForkBB\Models\Config\Save::class,
|
||||
|
||||
'OnlineModelInfo' => \ForkBB\Models\Online\Info::class,
|
||||
'OnlineModelUpdateUsername' => \ForkBB\Models\Online\UpdateUsername::class,
|
||||
|
||||
'BanListModel' => \ForkBB\Models\BanList\Model::class,
|
||||
'BanListModelLoad' => \ForkBB\Models\BanList\Load::class,
|
||||
|
|
Loading…
Add table
Reference in a new issue