Skip to content

Commit

Permalink
Use DI for Sql class constructor
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 Sep 5, 2020
1 parent 992af33 commit c57dda7
Show file tree
Hide file tree
Showing 12 changed files with 182 additions and 61 deletions.
Expand Up @@ -7,11 +7,14 @@
use PhpMyAdmin\Common;
use PhpMyAdmin\Database\Qbe;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Operations;
use PhpMyAdmin\Relation;
use PhpMyAdmin\RelationCleanup;
use PhpMyAdmin\Response;
use PhpMyAdmin\SavedSearches;
use PhpMyAdmin\Sql;
use PhpMyAdmin\Template;
use PhpMyAdmin\Transformations;
use PhpMyAdmin\Url;
use PhpMyAdmin\Util;
use function stripos;
Expand Down Expand Up @@ -102,7 +105,16 @@ public function index(): void
$hasMessageToDisplay = true;
} else {
$goto = Url::getFromRoute('/database/sql');
$sql = new Sql();

$sql = new Sql(
$this->dbi,
$this->relation,
new RelationCleanup($this->dbi, $this->relation),
new Operations($this->dbi, $this->relation),
new Transformations(),
$this->template
);

$this->response->addHTML($sql->executeQueryAndSendQueryResponse(
null, // analyzed_sql_results
false, // is_gotofile
Expand Down
11 changes: 10 additions & 1 deletion libraries/classes/Controllers/Database/StructureController.php
Expand Up @@ -25,6 +25,7 @@
use PhpMyAdmin\Table;
use PhpMyAdmin\Template;
use PhpMyAdmin\Tracker;
use PhpMyAdmin\Transformations;
use PhpMyAdmin\Url;
use PhpMyAdmin\Util;
use function array_search;
Expand Down Expand Up @@ -1562,7 +1563,15 @@ public function emptyTable(): void
}

if (! empty($_REQUEST['pos'])) {
$sql = new Sql();
$sql = new Sql(
$this->dbi,
$this->relation,
$this->relationCleanup,
$this->operations,
new Transformations(),
$this->template
);

$_REQUEST['pos'] = $sql->calculatePosForLastPage($db, $table, $_REQUEST['pos']);
}

Expand Down
1 change: 0 additions & 1 deletion libraries/classes/Controllers/SqlController.php
Expand Up @@ -287,7 +287,6 @@ public function getSetValues(): void
// If the $currentValue was truncated, we should fetch the correct full values from the table.
if ($fullValues && ! empty($whereClause)) {
$currentValue = $this->sql->getFullValuesForSetColumn(
$this->dbi,
$db,
$table,
$column,
Expand Down
14 changes: 13 additions & 1 deletion libraries/classes/Controllers/Table/DeleteController.php
Expand Up @@ -5,7 +5,11 @@
namespace PhpMyAdmin\Controllers\Table;

use PhpMyAdmin\Common;
use PhpMyAdmin\Operations;
use PhpMyAdmin\Relation;
use PhpMyAdmin\RelationCleanup;
use PhpMyAdmin\Sql;
use PhpMyAdmin\Transformations;
use PhpMyAdmin\Url;
use PhpMyAdmin\Util;
use function is_array;
Expand All @@ -22,7 +26,15 @@ public function rows(): void
$original_sql_query = $_POST['original_sql_query'] ?? '';
$selected = $_POST['selected'] ?? [];

$sql = new Sql();
$relation = new Relation($this->dbi);
$sql = new Sql(
$this->dbi,
$relation,
new RelationCleanup($this->dbi, $relation),
new Operations($this->dbi, $relation),
new Transformations(),
$this->template
);

if ($mult_btn === __('Yes')) {
$default_fk_check_value = Util::handleDisableFKCheckInit();
Expand Down
13 changes: 12 additions & 1 deletion libraries/classes/Controllers/Table/SearchController.php
Expand Up @@ -7,11 +7,14 @@
use PhpMyAdmin\Common;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\Operations;
use PhpMyAdmin\Relation;
use PhpMyAdmin\RelationCleanup;
use PhpMyAdmin\Response;
use PhpMyAdmin\Sql;
use PhpMyAdmin\Table\Search;
use PhpMyAdmin\Template;
use PhpMyAdmin\Transformations;
use PhpMyAdmin\Util;
use function in_array;
use function intval;
Expand Down Expand Up @@ -260,7 +263,15 @@ public function doSelectionAction()
/**
* Add this to ensure following procedures included running correctly.
*/
$sql = new Sql();
$sql = new Sql(
$this->dbi,
$this->relation,
new RelationCleanup($this->dbi, $this->relation),
new Operations($this->dbi, $this->relation),
new Transformations(),
$this->template
);

$this->response->addHTML($sql->executeQueryAndSendQueryResponse(
null, // analyzed_sql_results
false, // is_gotofile
Expand Down
11 changes: 10 additions & 1 deletion libraries/classes/Controllers/Table/StructureController.php
Expand Up @@ -17,6 +17,7 @@
use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\Index;
use PhpMyAdmin\Message;
use PhpMyAdmin\Operations;
use PhpMyAdmin\ParseAnalyze;
use PhpMyAdmin\Partition;
use PhpMyAdmin\Relation;
Expand Down Expand Up @@ -1059,7 +1060,15 @@ protected function displayTableBrowseForSelectedColumns($goto, $themeImagePath)
$db,
] = ParseAnalyze::sqlQuery($sql_query, $db);

$sql = new Sql();
$sql = new Sql(
$this->dbi,
$this->relation,
$this->relationCleanup,
new Operations($this->dbi, $this->relation),
$this->transformations,
$this->template
);

$this->response->addHTML(
$sql->executeQueryAndGetQueryResponse(
$analyzed_sql_results ?? '',
Expand Down
15 changes: 14 additions & 1 deletion libraries/classes/Database/MultiTableQuery.php
Expand Up @@ -8,9 +8,13 @@
namespace PhpMyAdmin\Database;

use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Operations;
use PhpMyAdmin\ParseAnalyze;
use PhpMyAdmin\Relation;
use PhpMyAdmin\RelationCleanup;
use PhpMyAdmin\Sql;
use PhpMyAdmin\Template;
use PhpMyAdmin\Transformations;
use PhpMyAdmin\Url;
use function array_keys;
use function md5;
Expand Down Expand Up @@ -110,7 +114,16 @@ public static function displayResults($sqlQuery, $db, $themeImagePath): string
[,$db] = ParseAnalyze::sqlQuery($sqlQuery, $db);

$goto = Url::getFromRoute('/database/multi-table-query');
$sql = new Sql();

$relation = new Relation($GLOBALS['dbi']);
$sql = new Sql(
$GLOBALS['dbi'],
$relation,
new RelationCleanup($GLOBALS['dbi'], $relation),
new Operations($GLOBALS['dbi'], $relation),
new Transformations(),
new Template()
);

return $sql->executeQueryAndSendQueryResponse(
null, // analyzed_sql_results
Expand Down

0 comments on commit c57dda7

Please sign in to comment.