UpdateUsername.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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\Post;
  10. use ForkBB\Models\Action;
  11. use ForkBB\Models\User\User;
  12. use RuntimeException;
  13. class UpdateUsername extends Action
  14. {
  15. /**
  16. * Обновляет имя пользователя в таблице сообщений
  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 ::posts
  28. SET poster=?s:name
  29. WHERE poster_id=?i:id';
  30. $this->c->DB->exec($query, $vars);
  31. $query = 'UPDATE ::posts
  32. SET editor=?s:name
  33. WHERE editor_id=?i:id';
  34. $this->c->DB->exec($query, $vars);
  35. }
  36. }