Add Models\PM\UpdateUsername

This commit is contained in:
Visman 2021-04-02 21:52:25 +07:00
parent 95a44ff2b1
commit 3f340482ac
2 changed files with 51 additions and 0 deletions

View file

@ -0,0 +1,50 @@
<?php
/**
* This file is part of the ForkBB <https://github.com/forkbb>.
*
* @copyright (c) Visman <mio.visman@yandex.ru, https://github.com/MioVisman>
* @license The MIT License (MIT)
*/
declare(strict_types=1);
namespace ForkBB\Models\PM;
use ForkBB\Models\Method;
use ForkBB\Models\User\Model as User;
use RuntimeException;
class UpdateUsername extends Method
{
/**
* Обновляет имя пользователя в таблицах PM
*/
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 ::pm_posts
SET poster=?s:name
WHERE poster_id=?i:id';
$this->c->DB->exec($query, $vars);
$query = 'UPDATE ::pm_topics
SET poster=?s:name
WHERE poster_id=?i:id';
$this->c->DB->exec($query, $vars);
$query = 'UPDATE ::pm_topics
SET target=?s:name
WHERE target_id=?i:id';
$this->c->DB->exec($query, $vars);
}
}

View file

@ -156,6 +156,7 @@ class Save extends Action
$this->c->topics->updateUsername($user);
$this->c->forums->updateUsername($user);
$this->c->Online->updateUsername($user);
$this->c->pms->updateUsername($user);
// ???? и т.д.
}