Update.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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\BanList;
  10. use ForkBB\Models\Method;
  11. use ForkBB\Models\BanList\BanList;
  12. use InvalidArgumentException;
  13. class Update extends Method
  14. {
  15. /**
  16. * Обновляет бан
  17. */
  18. public function update(array $ban): BanList
  19. {
  20. if (
  21. empty($ban['id'])
  22. || ! \is_int($ban['id'])
  23. || ! isset($ban['username'], $ban['ip'], $ban['email'], $ban['message'], $ban['expire'])
  24. ) {
  25. throw new InvalidArgumentException('Expected an array with a ban description');
  26. }
  27. if (
  28. '' == $ban['username']
  29. && '' == $ban['ip']
  30. && '' == $ban['email']
  31. ) {
  32. throw new InvalidArgumentException('Empty ban');
  33. }
  34. $query = 'UPDATE ::bans
  35. SET username=?s:username, ip=?s:ip, email=?s:email, message=?s:message, expire=?i:expire
  36. WHERE id=?i:id';
  37. $this->c->DB->exec($query, $ban);
  38. return $this->model;
  39. }
  40. }