Skip to content

Commit

Permalink
Use DI for $dbi global in Export class
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 Apr 18, 2019
1 parent 13323c7 commit 7f793cd
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 13 deletions.
2 changes: 1 addition & 1 deletion db_export.php
Expand Up @@ -30,7 +30,7 @@
$scripts = $header->getScripts();
$scripts->addFile('export.js');

$export = new Export();
$export = new Export($GLOBALS['dbi']);

// $sub_part is used in Util::getDbInfo() to see if we are coming from
// db_export.php, in which case we don't obey $cfg['MaxTableList']
Expand Down
2 changes: 1 addition & 1 deletion export.php
Expand Up @@ -32,7 +32,7 @@
$scripts = $header->getScripts();
$scripts->addFile('export_output.js');

$export = new Export();
$export = new Export($GLOBALS['dbi']);

//check if it's the GET request to check export time out
if (isset($_GET['check_time_out'])) {
Expand Down
30 changes: 22 additions & 8 deletions libraries/classes/Export.php
Expand Up @@ -18,6 +18,20 @@
*/
class Export
{
/**
* @var DatabaseInterface
*/
private $dbi;

/**
* Export constructor.
* @param DatabaseInterface $dbi DatabaseInterface instance
*/
public function __construct($dbi)
{
$this->dbi = $dbi;
}

/**
* Sets a session variable upon a possible fatal error during export
*
Expand Down Expand Up @@ -582,7 +596,7 @@ public function exportServer(
if (isset($tmp_select)
&& mb_strpos(' ' . $tmp_select, '|' . $current_db . '|')
) {
$tables = $GLOBALS['dbi']->getTables($current_db);
$tables = $this->dbi->getTables($current_db);
$this->exportDatabase(
$current_db,
$tables,
Expand Down Expand Up @@ -712,10 +726,10 @@ public function exportDatabase(
// This obtains the current table's size
$query = 'SELECT data_length + index_length
from information_schema.TABLES
WHERE table_schema = "' . $GLOBALS['dbi']->escapeString($db) . '"
AND table_name = "' . $GLOBALS['dbi']->escapeString($table) . '"';
WHERE table_schema = "' . $this->dbi->escapeString($db) . '"
AND table_name = "' . $this->dbi->escapeString($table) . '"';

$size = $GLOBALS['dbi']->fetchValue($query);
$size = $this->dbi->fetchValue($query);
//Converting the size to MB
$size = ($size / 1024) / 1024;
if ($size > $table_size) {
Expand Down Expand Up @@ -969,7 +983,7 @@ public function exportTable(
$sql_query = preg_replace('%;\s*$%', '', $sql_query);
}
$local_query = $sql_query . $add_query;
$GLOBALS['dbi']->selectDb($db);
$this->dbi->selectDb($db);
} else {
// Data is exported only for Non-generated columns
$tableObj = new Table($table, $db);
Expand Down Expand Up @@ -1120,7 +1134,7 @@ public function lockTables(string $db, array $tables, string $lockType = "WRITE"
}

$sql = "LOCK TABLES " . implode(", ", $locks);
return $GLOBALS['dbi']->tryQuery($sql);
return $this->dbi->tryQuery($sql);
}

/**
Expand All @@ -1130,7 +1144,7 @@ public function lockTables(string $db, array $tables, string $lockType = "WRITE"
*/
public function unlockTables()
{
return $GLOBALS['dbi']->tryQuery("UNLOCK TABLES");
return $this->dbi->tryQuery("UNLOCK TABLES");
}

/**
Expand Down Expand Up @@ -1204,7 +1218,7 @@ public function processExportSchema(?string $export_type): void
Core::fatalError(__('Bad type!'));
}

$GLOBALS['dbi']->selectDb($GLOBALS['db']);
$this->dbi->selectDb($GLOBALS['db']);
$export_plugin->exportSchema($GLOBALS['db']);
}
}
2 changes: 1 addition & 1 deletion libraries/classes/Plugins/ExportPlugin.php
Expand Up @@ -53,7 +53,7 @@ abstract class ExportPlugin
public function __construct()
{
$this->relation = new Relation($GLOBALS['dbi']);
$this->export = new Export();
$this->export = new Export($GLOBALS['dbi']);
$this->transformations = new Transformations();
}

Expand Down
2 changes: 1 addition & 1 deletion schema_export.php
Expand Up @@ -35,5 +35,5 @@
* Include the appropriate Schema Class depending on $export_type
* default is PDF
*/
$export = new Export();
$export = new Export($GLOBALS['dbi']);
$export->processExportSchema($_REQUEST['export_type']);
2 changes: 1 addition & 1 deletion test/classes/ExportTest.php
Expand Up @@ -34,7 +34,7 @@ class ExportTest extends TestCase
*/
protected function setUp(): void
{
$this->export = new Export();
$this->export = new Export($GLOBALS['dbi']);
}

/**
Expand Down

0 comments on commit 7f793cd

Please sign in to comment.