-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a dedicated controller to update Console config
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
- Loading branch information
1 parent
775a9a4
commit 65c6f18
Showing
6 changed files
with
108 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpMyAdmin\Controllers\Console; | ||
|
||
use PhpMyAdmin\Config; | ||
use PhpMyAdmin\Controllers\AbstractController; | ||
use PhpMyAdmin\Http\ServerRequest; | ||
use PhpMyAdmin\Message; | ||
use PhpMyAdmin\ResponseRenderer; | ||
use PhpMyAdmin\Template; | ||
|
||
use function in_array; | ||
use function is_string; | ||
use function json_decode; | ||
|
||
final class UpdateConfigController extends AbstractController | ||
{ | ||
public function __construct(ResponseRenderer $response, Template $template, private Config $config) | ||
{ | ||
parent::__construct($response, $template); | ||
} | ||
|
||
public function __invoke(ServerRequest $request): void | ||
{ | ||
$validKeys = [ | ||
'StartHistory', | ||
'AlwaysExpand', | ||
'CurrentQuery', | ||
'EnterExecutes', | ||
'DarkTheme', | ||
'Mode', | ||
'Height', | ||
'GroupQueries', | ||
'OrderBy', | ||
'Order', | ||
]; | ||
$key = $request->getParsedBodyParam('key'); | ||
$value = $request->getParsedBodyParam('value'); | ||
if (! in_array($key, $validKeys, true) || ! is_string($value)) { | ||
$this->response->setRequestStatus(false); | ||
$this->response->addJSON(['message' => Message::error()]); | ||
|
||
return; | ||
} | ||
|
||
$result = $this->config->setUserValue(null, 'Console/' . $key, json_decode($value)); | ||
if ($result === true) { | ||
return; | ||
} | ||
|
||
$this->response->setRequestStatus(false); | ||
$this->response->addJSON(['message' => $result]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters