UpdateLastVisit.php 1019 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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\User;
  10. use ForkBB\Models\Action;
  11. use ForkBB\Models\User\User;
  12. use RuntimeException;
  13. class UpdateLastVisit extends Action
  14. {
  15. /**
  16. * Обновляет время последнего визита пользователя
  17. */
  18. public function updateLastVisit(User $user): void
  19. {
  20. if ($user->isGuest) {
  21. throw new RuntimeException('Expected user');
  22. }
  23. if ($user->logged > 0) {
  24. $vars = [
  25. ':loggid' => $user->logged,
  26. ':id' => $user->id,
  27. ];
  28. $query = 'UPDATE ::users
  29. SET last_visit=?i:loggid
  30. WHERE id=?i:id';
  31. $this->c->DB->exec($query, $vars);
  32. $user->__last_visit = $user->logged;
  33. }
  34. }
  35. }