diff --git a/libraries/classes/Controllers/Table/TableStructureController.php b/libraries/classes/Controllers/Table/TableStructureController.php index 850a0ed92b..3db699d808 100644 --- a/libraries/classes/Controllers/Table/TableStructureController.php +++ b/libraries/classes/Controllers/Table/TableStructureController.php @@ -120,7 +120,7 @@ class TableStructureController extends TableController $this->_showtable = $showtable; $this->table_obj = $this->dbi->getTable($this->db, $this->table); - $this->createAddField = new CreateAddField(); + $this->createAddField = new CreateAddField($dbi); } /** diff --git a/libraries/classes/CreateAddField.php b/libraries/classes/CreateAddField.php index e94ece5153..a7b46eee39 100644 --- a/libraries/classes/CreateAddField.php +++ b/libraries/classes/CreateAddField.php @@ -8,6 +8,7 @@ namespace PhpMyAdmin; use PhpMyAdmin\Core; +use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Index; use PhpMyAdmin\Table; use PhpMyAdmin\Util; @@ -19,6 +20,21 @@ use PhpMyAdmin\Util; */ class CreateAddField { + /** + * @var DatabaseInterface + */ + private $dbi; + + /** + * Constructor + * + * @param DatabaseInterface $dbi DatabaseInterface interface + */ + public function __construct(DatabaseInterface $dbi) + { + $this->dbi = $dbi; + } + /** * Transforms the radio button field_key into 4 arrays * @@ -188,7 +204,7 @@ class CreateAddField $keyBlockSizes = $index['Key_block_size']; if (! empty($keyBlockSizes)) { $sqlQuery .= " KEY_BLOCK_SIZE = " - . $GLOBALS['dbi']->escapeString($keyBlockSizes); + . $this->dbi->escapeString($keyBlockSizes); } // specifying index type is allowed only for primary, unique and index only @@ -202,12 +218,12 @@ class CreateAddField $parser = $index['Parser']; if ($index['Index_choice'] == 'FULLTEXT' && ! empty($parser)) { - $sqlQuery .= " WITH PARSER " . $GLOBALS['dbi']->escapeString($parser); + $sqlQuery .= " WITH PARSER " . $this->dbi->escapeString($parser); } $comment = $index['Index_comment']; if (! empty($comment)) { - $sqlQuery .= " COMMENT '" . $GLOBALS['dbi']->escapeString($comment) + $sqlQuery .= " COMMENT '" . $this->dbi->escapeString($comment) . "'"; } @@ -468,11 +484,11 @@ class CreateAddField && $_REQUEST['tbl_storage_engine'] == 'FEDERATED' ) { $sqlQuery .= " CONNECTION = '" - . $GLOBALS['dbi']->escapeString($_REQUEST['connection']) . "'"; + . $this->dbi->escapeString($_REQUEST['connection']) . "'"; } if (!empty($_REQUEST['comment'])) { $sqlQuery .= ' COMMENT = \'' - . $GLOBALS['dbi']->escapeString($_REQUEST['comment']) . '\''; + . $this->dbi->escapeString($_REQUEST['comment']) . '\''; } $sqlQuery .= $this->getPartitionsDefinition(); $sqlQuery .= ';'; @@ -521,9 +537,9 @@ class CreateAddField // To allow replication, we first select the db to use and then run queries // on this db. - if (!($GLOBALS['dbi']->selectDb($db))) { + if (!($this->dbi->selectDb($db))) { Util::mysqlDie( - $GLOBALS['dbi']->getError(), + $this->dbi->getError(), 'USE ' . Util::backquote($db), false, $errorUrl @@ -535,6 +551,6 @@ class CreateAddField if (isset($_REQUEST['preview_sql'])) { Core::previewSQL($sqlQuery); } - return [$GLOBALS['dbi']->tryQuery($sqlQuery), $sqlQuery]; + return [$this->dbi->tryQuery($sqlQuery), $sqlQuery]; } } diff --git a/tbl_addfield.php b/tbl_addfield.php index c364595667..a0f9a46d58 100644 --- a/tbl_addfield.php +++ b/tbl_addfield.php @@ -64,7 +64,7 @@ if (isset($_REQUEST['do_save_data'])) { //tbl_structure.php below unset($_REQUEST['do_save_data']); - $createAddField = new CreateAddField(); + $createAddField = new CreateAddField($GLOBALS['dbi']); list($result, $sql_query) = $createAddField->tryColumnCreationQuery($db, $table, $err_url); diff --git a/tbl_create.php b/tbl_create.php index 0afe8d8d56..f17707ef55 100644 --- a/tbl_create.php +++ b/tbl_create.php @@ -50,7 +50,7 @@ if ($GLOBALS['dbi']->getColumns($db, $table)) { ); } -$createAddField = new CreateAddField(); +$createAddField = new CreateAddField($GLOBALS['dbi']); // for libraries/tbl_columns_definition_form.inc.php // check number of fields to be created diff --git a/test/classes/CreateAddFieldTest.php b/test/classes/CreateAddFieldTest.php index 53bb0fa4d5..a2916debd2 100644 --- a/test/classes/CreateAddFieldTest.php +++ b/test/classes/CreateAddFieldTest.php @@ -17,6 +17,9 @@ use PHPUnit\Framework\TestCase; */ class CreateAddFieldTest extends TestCase { + /** + * @var CreateAddField + */ private $createAddField; /** @@ -26,7 +29,7 @@ class CreateAddFieldTest extends TestCase */ protected function setUp() { - $this->createAddField = new CreateAddField(); + $this->createAddField = new CreateAddField($GLOBALS['dbi']); } /**