UpdateUsername.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * This file is part of the ForkBB <https://github.com/forkbb>.
  4. *
  5. * @copyright (c) Visman <mio.visman@yandex.ru, https://github.com/MioVisman>
  6. * @license The MIT License (MIT)
  7. */
  8. declare(strict_types=1);
  9. namespace ForkBB\Models\PM;
  10. use ForkBB\Models\Method;
  11. use ForkBB\Models\User\User;
  12. use RuntimeException;
  13. class UpdateUsername extends Method
  14. {
  15. /**
  16. * Обновляет имя пользователя в таблицах PM
  17. */
  18. public function updateUsername(User $user): void
  19. {
  20. if ($user->isGuest) {
  21. throw new RuntimeException('User expected, not guest');
  22. }
  23. $vars = [
  24. ':id' => $user->id,
  25. ':name' => $user->username,
  26. ];
  27. $query = 'UPDATE ::pm_posts
  28. SET poster=?s:name
  29. WHERE poster_id=?i:id';
  30. $this->c->DB->exec($query, $vars);
  31. $query = 'UPDATE ::pm_topics
  32. SET poster=?s:name
  33. WHERE poster_id=?i:id';
  34. $this->c->DB->exec($query, $vars);
  35. $query = 'UPDATE ::pm_topics
  36. SET target=?s:name
  37. WHERE target_id=?i:id';
  38. $this->c->DB->exec($query, $vars);
  39. }
  40. }