phpmyadmin/libraries/classes/Controllers/Database/SearchController.php
Kamil Tekiela 7a22334167
Designer controller globals (#17985)
* Remove globals from DesignerController
* Remove $GLOBALS['params'] in ManageController
* Remove $GLOBALS['params']
* Remove $GLOBALS['total_num_tables']
* Remove $GLOBALS['tooltip_truename']
* Remove $GLOBALS['tooltip_aliasname']
* Remove $GLOBALS['pos']
* Remove $GLOBALS['tables'] (partially)
* Remove $GLOBALS['num_tables'] (partially)
* Remove redundant calls to Util::getDbInfo()
* Move unrelated functionality out of getDbInfo()
* Extract new method getTableListPosition()
* Code style changes
* Update phpstan-baseline.neon

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
2023-01-26 22:58:24 -03:00

83 lines
2.6 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpMyAdmin\Controllers\Database;
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\Database\Search;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Html\MySQLDocumentation;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Message;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Template;
use PhpMyAdmin\Url;
use PhpMyAdmin\Util;
use function __;
class SearchController 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
{
$GLOBALS['errorUrl'] = $GLOBALS['errorUrl'] ?? null;
$GLOBALS['urlParams'] = $GLOBALS['urlParams'] ?? null;
$this->addScriptFiles(['database/search.js', 'sql.js', 'makegrid.js']);
$this->checkParameters(['db']);
$GLOBALS['errorUrl'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database');
$GLOBALS['errorUrl'] .= Url::getCommon(['db' => $GLOBALS['db']], '&');
if (! $this->hasDatabase()) {
return;
}
if (! $GLOBALS['cfg']['UseDbSearch']) {
$errorMessage = __(
'Searching inside the database is disabled by the [code]$cfg[\'UseDbSearch\'][/code] configuration.'
);
$errorMessage .= MySQLDocumentation::showDocumentation('config', 'cfg_UseDbSearch');
$this->response->setRequestStatus(false);
if ($this->response->isAjax()) {
$this->response->addJSON('message', Message::error($errorMessage)->getDisplay());
return;
}
$this->render('error/simple', ['error_message' => $errorMessage, 'back_url' => $GLOBALS['errorUrl']]);
return;
}
$GLOBALS['urlParams']['goto'] = Url::getFromRoute('/database/search');
// Create a database search instance
$databaseSearch = new Search($this->dbi, $GLOBALS['db'], $this->template);
// Main search form has been submitted, get results
if ($request->hasBodyParam('submit_search')) {
$this->response->addHTML($databaseSearch->getSearchResults());
}
// If we are in an Ajax request, we need to exit after displaying all the HTML
if ($this->response->isAjax() && empty($_REQUEST['ajax_page_request'])) {
return;
}
// Display the search form
$this->response->addHTML($databaseSearch->getMainHtml());
}
}