SetValuesController.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. declare(strict_types=1);
  3. namespace PhpMyAdmin\Controllers\Sql;
  4. use PhpMyAdmin\CheckUserPrivileges;
  5. use PhpMyAdmin\Controllers\AbstractController;
  6. use PhpMyAdmin\ResponseRenderer;
  7. use PhpMyAdmin\Sql;
  8. use PhpMyAdmin\Template;
  9. use function __;
  10. use function explode;
  11. final class SetValuesController extends AbstractController
  12. {
  13. /** @var Sql */
  14. private $sql;
  15. /** @var CheckUserPrivileges */
  16. private $checkUserPrivileges;
  17. public function __construct(
  18. ResponseRenderer $response,
  19. Template $template,
  20. Sql $sql,
  21. CheckUserPrivileges $checkUserPrivileges
  22. ) {
  23. parent::__construct($response, $template);
  24. $this->sql = $sql;
  25. $this->checkUserPrivileges = $checkUserPrivileges;
  26. }
  27. /**
  28. * Get possible values for SET fields during grid edit.
  29. */
  30. public function __invoke(): void
  31. {
  32. global $db, $table;
  33. $this->checkUserPrivileges->getPrivileges();
  34. $column = $_POST['column'];
  35. $currentValue = $_POST['curr_value'];
  36. $fullValues = $_POST['get_full_values'] ?? false;
  37. $whereClause = $_POST['where_clause'] ?? null;
  38. $values = $this->sql->getValuesForColumn($db, $table, $column);
  39. if ($values === null) {
  40. $this->response->addJSON('message', __('Error in processing request'));
  41. $this->response->setRequestStatus(false);
  42. return;
  43. }
  44. // If the $currentValue was truncated, we should fetch the correct full values from the table.
  45. if ($fullValues && ! empty($whereClause)) {
  46. $currentValue = $this->sql->getFullValuesForSetColumn($db, $table, $column, $whereClause);
  47. }
  48. $select = $this->template->render('sql/set_column', [
  49. 'values' => $values,
  50. 'current_values' => explode(',', $currentValue),
  51. ]);
  52. $this->response->addJSON('select', $select);
  53. }
  54. }