diff options
author | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2022-09-21 06:06:14 +0300 |
---|---|---|
committer | Maurício Meneghini Fauth <mauricio@fauth.dev> | 2022-09-21 06:06:14 +0300 |
commit | a56b425a2a5c3cc16d170d3c3f503bd899949326 (patch) | |
tree | 7f36a5e66c51d9b9e38ed49914c8cb68d5ea6e2c /libraries/classes | |
parent | c2018c4c2195fc26f188e15ae56a0a30e385174f (diff) |
Extract /console/bookmark/add action from ImportController
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
Diffstat (limited to 'libraries/classes')
-rw-r--r-- | libraries/classes/Controllers/Console/Bookmark/AddController.php | 58 | ||||
-rw-r--r-- | libraries/classes/Controllers/Import/ImportController.php | 27 |
2 files changed, 58 insertions, 27 deletions
diff --git a/libraries/classes/Controllers/Console/Bookmark/AddController.php b/libraries/classes/Controllers/Console/Bookmark/AddController.php new file mode 100644 index 0000000000..42b7ee6c09 --- /dev/null +++ b/libraries/classes/Controllers/Console/Bookmark/AddController.php @@ -0,0 +1,58 @@ +<?php + +declare(strict_types=1); + +namespace PhpMyAdmin\Controllers\Console\Bookmark; + +use PhpMyAdmin\Bookmark; +use PhpMyAdmin\Controllers\AbstractController; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Http\ServerRequest; +use PhpMyAdmin\ResponseRenderer; +use PhpMyAdmin\Template; + +use function __; +use function is_string; + +final class AddController extends AbstractController +{ + /** @var DatabaseInterface */ + private $dbi; + + public function __construct(ResponseRenderer $response, Template $template, DatabaseInterface $dbi) + { + parent::__construct($response, $template); + $this->dbi = $dbi; + } + + public function __invoke(ServerRequest $request): void + { + $db = $request->getParsedBodyParam('db'); + $label = $request->getParsedBodyParam('label'); + $bookmarkQuery = $request->getParsedBodyParam('bookmark_query'); + $shared = $request->getParsedBodyParam('shared'); + + if (! is_string($label) || ! is_string($db) || ! is_string($bookmarkQuery) || ! is_string($shared)) { + $this->response->addJSON('message', __('Incomplete params')); + + return; + } + + $bookmarkFields = [ + 'bkm_database' => $db, + 'bkm_user' => $GLOBALS['cfg']['Server']['user'], + 'bkm_sql_query' => $bookmarkQuery, + 'bkm_label' => $label, + ]; + $bookmark = Bookmark::createBookmark($this->dbi, $bookmarkFields, $shared === 'true'); + if ($bookmark === false || ! $bookmark->save()) { + $this->response->addJSON('message', __('Failed')); + + return; + } + + $this->response->addJSON('message', __('Succeeded')); + $this->response->addJSON('data', $bookmarkFields); + $this->response->addJSON('isShared', $shared === 'true'); + } +} diff --git a/libraries/classes/Controllers/Import/ImportController.php b/libraries/classes/Controllers/Import/ImportController.php index f4b1deaf03..a317f15e55 100644 --- a/libraries/classes/Controllers/Import/ImportController.php +++ b/libraries/classes/Controllers/Import/ImportController.php @@ -118,33 +118,6 @@ final class ImportController extends AbstractController $GLOBALS['local_import_file'] = $_POST['local_import_file'] ?? null; $GLOBALS['show_as_php'] = $_POST['show_as_php'] ?? null; - // If it's a console bookmark add request - if (isset($_POST['console_bookmark_add'])) { - if (! isset($_POST['label'], $_POST['db'], $_POST['bookmark_query'], $_POST['shared'])) { - $this->response->addJSON('message', __('Incomplete params')); - - return; - } - - $bookmarkFields = [ - 'bkm_database' => $_POST['db'], - 'bkm_user' => $GLOBALS['cfg']['Server']['user'], - 'bkm_sql_query' => $_POST['bookmark_query'], - 'bkm_label' => $_POST['label'], - ]; - $isShared = ($_POST['shared'] === 'true'); - $bookmark = Bookmark::createBookmark($this->dbi, $bookmarkFields, $isShared); - if ($bookmark !== false && $bookmark->save()) { - $this->response->addJSON('message', __('Succeeded')); - $this->response->addJSON('data', $bookmarkFields); - $this->response->addJSON('isShared', $isShared); - } else { - $this->response->addJSON('message', __('Failed')); - } - - return; - } - // reset import messages for ajax request $_SESSION['Import_message']['message'] = null; $_SESSION['Import_message']['go_back_url'] = null; |