Skip to content

Commit

Permalink
Merge pull request #14901 from mauriciofauth/server_databases
Browse files Browse the repository at this point in the history
Refactor ServerDatabasesController

Refactors PhpMyAdmin\Controllers\Server\ServerDatabasesController.

- Renames variables and methods to camelCase format.
- Moves request and response handling back to server_databases.php.
- Groups all HTML into templates/server/databases/index.twig.
- Improves unit tests.
  • Loading branch information
MauricioFauth committed Jan 26, 2019
2 parents 7bc8382 + 32e83d9 commit e972b3e
Show file tree
Hide file tree
Showing 8 changed files with 710 additions and 857 deletions.
572 changes: 221 additions & 351 deletions libraries/classes/Controllers/Server/ServerDatabasesController.php

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions phpstan.neon
Expand Up @@ -24,7 +24,6 @@ parameters:
- '#GisGeomTestCase::\$object#'
- '#Undefined variable: \$array#'
- '#Undefined variable: \$(cfg|db|table|url_query|text_dir|server|pmaThemeImage|action|sql_query|lang|export_type|err_url|collation_connection|filename_template|transform_key|cn|goto|partitionDetails|token_mismatch|auth_plugin|username|hostname|display_query|where_clause)#'#Others
- '#Undefined variable: \$(replication_types|selected)#'#Controllers/Server/ServerDatabasesController.php
- '#Undefined variable: \$(dir|error_header|error_message)#'#error.inc.php
- '#Undefined variable: \$_PMA_RTE#'#rte/rte_main.inc.php
- '#Undefined variable: \$(unsaved_values|is_upload)#'#tbl_change.php
Expand All @@ -40,7 +39,6 @@ parameters:
- '#Variable \$time might not be defined#'#DatabaseInterface.php
- '#Variable \$contentPath in isset\(\) always exists and is not nullable#'#DatabaseInterface.php
- '#Variable \$server_info might not be defined#'#DatabaseInterface.php
# - '#Variable \$single_table always exists and is not nullable#'#Display/ExportTest.php
- '#Function mysqli_get_client_info invoked with 0 parameters, 1 required#'#libraries/classes/Dbi/DbiMysqli.php
- '#Variable \$default_fk_check_value might not be defined#'#libraries/mult_submits.inc.php
- '#Variable \$http_response_header in isset\(\) always exists and is not nullable#'
Expand Down
36 changes: 35 additions & 1 deletion server_databases.php
Expand Up @@ -7,6 +7,7 @@
*/
declare(strict_types=1);

use PhpMyAdmin\CheckUserPrivileges;
use PhpMyAdmin\Controllers\Server\ServerDatabasesController;
use PhpMyAdmin\Di\Container;
use PhpMyAdmin\Response;
Expand All @@ -33,4 +34,37 @@
'ServerDatabasesController',
[]
);
$controller->indexAction();

/** @var Response $response */
$response = $container->get('response');

$checkUserPrivileges = new CheckUserPrivileges($GLOBALS['dbi']);
$checkUserPrivileges->getPrivileges();

if (isset($_POST['drop_selected_dbs'])
&& $response->isAjax()
&& ($GLOBALS['dbi']->isSuperuser() || $GLOBALS['cfg']['AllowUserDropDatabase'])
) {
$response->addJSON($controller->dropDatabasesAction([
'drop_selected_dbs' => $_POST['drop_selected_dbs'],
'selected_dbs' => $_POST['selected_dbs'] ?? null,
]));
} elseif (isset($_POST['new_db'])
&& $response->isAjax()
) {
$response->addJSON($controller->createDatabaseAction([
'new_db' => $_POST['new_db'],
'db_collation' => $_POST['db_collation'] ?? null,
]));
} else {
$header = $response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('server_databases.js');

$response->addHTML($controller->indexAction([
'statistics' => $_REQUEST['statistics'] ?? null,
'pos' => $_REQUEST['pos'] ?? null,
'sort_by' => $_REQUEST['sort_by'] ?? null,
'sort_order' => $_REQUEST['sort_order'] ?? null,
]));
}
71 changes: 0 additions & 71 deletions templates/server/databases/databases_footer.twig

This file was deleted.

0 comments on commit e972b3e

Please sign in to comment.