Skip to content

Commit

Permalink
Create server, database and table SqlControllers
Browse files Browse the repository at this point in the history
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Mar 24, 2019
1 parent b247fbe commit 4d9da96
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 88 deletions.
46 changes: 13 additions & 33 deletions db_sql.php
Expand Up @@ -7,49 +7,29 @@
*/
declare(strict_types=1);

use PhpMyAdmin\Config\PageSettings;
use PhpMyAdmin\Controllers\Database\SqlController;
use PhpMyAdmin\Response;
use PhpMyAdmin\SqlQueryForm;

if (! defined('ROOT_PATH')) {
define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
}

/**
*
*/
require_once ROOT_PATH . 'libraries/common.inc.php';

PageSettings::showGroup('Sql');

/**
* Runs common work
*/
$response = Response::getInstance();
$header = $response->getHeader();
$scripts = $header->getScripts();

$controller = new SqlController(
$response,
$GLOBALS['dbi'],
$db
);

$header = $response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('makegrid.js');
$scripts->addFile('vendor/jquery/jquery.uitablefilter.js');
$scripts->addFile('sql.js');

require ROOT_PATH . 'libraries/db_common.inc.php';

$sqlQueryForm = new SqlQueryForm();

// After a syntax error, we return to this script
// with the typed query in the textarea.
$goto = 'db_sql.php';
$back = 'db_sql.php';

/**
* Query box, bookmark, insert data from textfile
*/
$response->addHTML(
$sqlQueryForm->getHtml(
true,
false,
isset($_POST['delimiter'])
? htmlspecialchars($_POST['delimiter'])
: ';'
)
);
$response->addHTML($controller->index([
'delimiter' => $_POST['delimiter'] ?? null,
]));
49 changes: 49 additions & 0 deletions libraries/classes/Controllers/Database/SqlController.php
@@ -0,0 +1,49 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Holds the PhpMyAdmin\Controllers\Database\SqlController
* @package PhpMyAdmin\Controllers\Database
*/
declare(strict_types=1);

namespace PhpMyAdmin\Controllers\Database;

use PhpMyAdmin\Config\PageSettings;
use PhpMyAdmin\SqlQueryForm;

/**
* Database SQL executor
* @package PhpMyAdmin\Controllers\Database
*/
class SqlController extends AbstractController
{
/**
* @param array $params Request parameters
* @return string HTML
*/
public function index(array $params): string
{
global $goto, $back;

PageSettings::showGroup('Sql');

require ROOT_PATH . 'libraries/db_common.inc.php';

$sqlQueryForm = new SqlQueryForm();

/**
* After a syntax error, we return to this script
* with the typed query in the textarea.
*/
$goto = 'db_sql.php';
$back = 'db_sql.php';

return $sqlQueryForm->getHtml(
true,
false,
isset($params['delimiter'])
? htmlspecialchars($params['delimiter'])
: ';'
);
}
}
34 changes: 34 additions & 0 deletions libraries/classes/Controllers/Server/SqlController.php
@@ -0,0 +1,34 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Holds the PhpMyAdmin\Controllers\Server\SqlController
* @package PhpMyAdmin\Controllers\Server
*/
declare(strict_types=1);

namespace PhpMyAdmin\Controllers\Server;

use PhpMyAdmin\Config\PageSettings;
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\SqlQueryForm;

/**
* Server SQL executor
* @package PhpMyAdmin\Controllers\Server
*/
class SqlController extends AbstractController
{
/**
* @return string HTML
*/
public function index(): string
{
PageSettings::showGroup('Sql');

require_once ROOT_PATH . 'libraries/server_common.inc.php';

$sqlQueryForm = new SqlQueryForm();

return $sqlQueryForm->getHtml();
}
}
53 changes: 53 additions & 0 deletions libraries/classes/Controllers/Table/SqlController.php
@@ -0,0 +1,53 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Holds the PhpMyAdmin\Controllers\Table\SqlController
*
* @package PhpMyAdmin\Controllers\Table
*/
declare(strict_types=1);

namespace PhpMyAdmin\Controllers\Table;

use PhpMyAdmin\Config\PageSettings;
use PhpMyAdmin\SqlQueryForm;

/**
* Table SQL executor
* @package PhpMyAdmin\Controllers\Table
*/
class SqlController extends AbstractController
{
/**
* @param array $params Request parameters
* @return string HTML
*/
public function index(array $params): string
{
global $url_query, $err_url, $goto, $back;

PageSettings::showGroup('Sql');

require ROOT_PATH . 'libraries/tbl_common.inc.php';

$url_query .= '&amp;goto=tbl_sql.php&amp;back=tbl_sql.php';
$err_url = 'tbl_sql.php' . $err_url;

/**
* After a syntax error, we return to this script
* with the typed query in the textarea.
*/
$goto = 'tbl_sql.php';
$back = 'tbl_sql.php';

$sqlQueryForm = new SqlQueryForm();

return $sqlQueryForm->getHtml(
true,
false,
isset($params['delimiter'])
? htmlspecialchars($params['delimiter'])
: ';'
);
}
}
2 changes: 2 additions & 0 deletions libraries/tbl_common.inc.php
Expand Up @@ -13,6 +13,8 @@
exit;
}

global $db, $table;

// Check parameters
PhpMyAdmin\Util::checkParameters(['db', 'table']);

Expand Down
30 changes: 10 additions & 20 deletions server_sql.php
Expand Up @@ -7,36 +7,26 @@
*/
declare(strict_types=1);

use PhpMyAdmin\Config\PageSettings;
use PhpMyAdmin\Controllers\Server\SqlController;
use PhpMyAdmin\Response;
use PhpMyAdmin\SqlQueryForm;

if (! defined('ROOT_PATH')) {
define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
}

/**
*
*/
require_once ROOT_PATH . 'libraries/common.inc.php';

PageSettings::showGroup('Sql');

/**
* Does the common work
*/
$response = Response::getInstance();
$header = $response->getHeader();
$scripts = $header->getScripts();

$controller = new SqlController(
$response,
$GLOBALS['dbi']
);

$header = $response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('makegrid.js');
$scripts->addFile('vendor/jquery/jquery.uitablefilter.js');
$scripts->addFile('sql.js');

require_once ROOT_PATH . 'libraries/server_common.inc.php';

$sqlQueryForm = new SqlQueryForm();

/**
* Query box, bookmark, insert data from textfile
*/
$response->addHTML($sqlQueryForm->getHtml());
$response->addHTML($controller->index());
49 changes: 14 additions & 35 deletions tbl_sql.php
Expand Up @@ -7,51 +7,30 @@
*/
declare(strict_types=1);

use PhpMyAdmin\Config\PageSettings;
use PhpMyAdmin\Controllers\Table\SqlController;
use PhpMyAdmin\Response;
use PhpMyAdmin\SqlQueryForm;

if (! defined('ROOT_PATH')) {
define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
}

/**
*
*/
require_once ROOT_PATH . 'libraries/common.inc.php';

PageSettings::showGroup('Sql');

/**
* Runs common work
*/
$response = Response::getInstance();
$header = $response->getHeader();
$scripts = $header->getScripts();

$controller = new SqlController(
$response,
$GLOBALS['dbi'],
$db,
$table
);

$header = $response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('makegrid.js');
$scripts->addFile('vendor/jquery/jquery.uitablefilter.js');
$scripts->addFile('sql.js');

require ROOT_PATH . 'libraries/tbl_common.inc.php';
$url_query .= '&amp;goto=tbl_sql.php&amp;back=tbl_sql.php';

$err_url = 'tbl_sql.php' . $err_url;
// After a syntax error, we return to this script
// with the typed query in the textarea.
$goto = 'tbl_sql.php';
$back = 'tbl_sql.php';

$sqlQueryForm = new SqlQueryForm();

/**
* Query box, bookmark, insert data from textfile
*/
$response->addHTML(
$sqlQueryForm->getHtml(
true,
false,
isset($_POST['delimiter'])
? htmlspecialchars($_POST['delimiter'])
: ';'
)
);
$response->addHTML($controller->index([
'delimiter' => $_POST['delimiter'] ?? null,
]));

0 comments on commit 4d9da96

Please sign in to comment.