-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Expand file tree
/
Copy pathSetValuesController.php
More file actions
66 lines (53 loc) · 1.98 KB
/
SetValuesController.php
File metadata and controls
66 lines (53 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Controllers\Sql;
use PhpMyAdmin\Controllers\InvocableController;
use PhpMyAdmin\Current;
use PhpMyAdmin\Http\Response;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Routing\Route;
use PhpMyAdmin\Sql;
use PhpMyAdmin\Template;
use function __;
use function explode;
#[Route('/sql/get-set-values', ['POST'])]
final readonly class SetValuesController implements InvocableController
{
public function __construct(
private ResponseRenderer $response,
private Template $template,
private Sql $sql,
) {
}
/**
* Get possible values for SET fields during grid edit.
*/
public function __invoke(ServerRequest $request): Response
{
$column = $request->getParsedBodyParamAsString('column');
$currentValue = $request->getParsedBodyParamAsString('curr_value');
$whereClause = $request->getParsedBodyParamAsStringOrNull('where_clause');
$values = $this->sql->getValuesForColumn(Current::$database, Current::$table, $column);
if ($values === null) {
$this->response->addJSON('message', __('Error in processing request'));
$this->response->setRequestStatus(false);
return $this->response->response();
}
// If the $currentValue was truncated, we should fetch the correct full values from the table.
if ($request->hasBodyParam('get_full_values') && $whereClause !== null && $whereClause !== '') {
$currentValue = $this->sql->getFullValuesForSetColumn(
Current::$database,
Current::$table,
$column,
$whereClause,
);
}
$select = $this->template->render('sql/set_column', [
'values' => $values,
'current_values' => explode(',', $currentValue),
]);
$this->response->addJSON('select', $select);
return $this->response->response();
}
}