Update.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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\BBCodeList;
  10. use ForkBB\Models\Method;
  11. use ForkBB\Models\BBCodeList\BBCodeList;
  12. use ForkBB\Models\BBCodeList\Structure;
  13. use RuntimeException;
  14. use function \ForkBB\__;
  15. class Update extends Method
  16. {
  17. /**
  18. * Обновляет структуру bb-кода
  19. */
  20. public function update(int $id, Structure $structure): BBCodeList
  21. {
  22. if (null !== ($error = $structure->getError())) {
  23. throw new RuntimeException('BBCode structure has error (' . __($error) . ')');
  24. }
  25. $vars = [
  26. ':id' => $id,
  27. ':tag' => $structure->tag,
  28. ':structure' => $structure->toString(),
  29. ];
  30. $query = 'UPDATE ::bbcode
  31. SET bb_structure=?s:structure
  32. WHERE id=?i:id AND bb_tag=?s:tag AND bb_edit=1';
  33. $this->c->DB->exec($query, $vars);
  34. return $this->model->reset();
  35. }
  36. }