Skip to content

Commit

Permalink
Extract exit from Display\Import 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 Aug 19, 2020
1 parent 65b79af commit 2843639
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 58 deletions.
37 changes: 26 additions & 11 deletions libraries/classes/Controllers/Database/ImportController.php
Expand Up @@ -7,24 +7,24 @@
use PhpMyAdmin\Common;
use PhpMyAdmin\Config\PageSettings;
use PhpMyAdmin\Display\Import;
use PhpMyAdmin\Display\ImportAjax;
use PhpMyAdmin\Message;
use PhpMyAdmin\Plugins;
use PhpMyAdmin\Util;

final class ImportController extends AbstractController
{
public function index(): void
{
global $db, $max_upload_size, $table, $tables, $num_tables, $total_num_tables, $is_show_stats;
global $db_is_system_schema, $tooltip_truename, $tooltip_aliasname, $pos, $sub_part;
global $db_is_system_schema, $tooltip_truename, $tooltip_aliasname, $pos, $sub_part, $SESSION_KEY;

$pageSettings = new PageSettings('Import');
$this->response->addHTML($pageSettings->getErrorHTML());
$this->response->addHTML($pageSettings->getHTML());

$this->addScriptFiles(['import.js']);

/**
* Gets tables information and displays top links
*/
Common::database();

[
Expand All @@ -39,13 +39,28 @@ public function index(): void
$pos,
] = Util::getDbInfo($db, $sub_part ?? '');

$this->response->addHTML(
Import::get(
'database',
$db,
$table,
$max_upload_size
)
[$SESSION_KEY, $uploadId] = ImportAjax::uploadProgressSetup();

$importList = Plugins::getImport('database');

if (empty($importList)) {
$this->response->addHTML(Message::error(__(
'Could not load import plugins, please check your installation!'
))->getDisplay());

return;
}

$import = Import::get(
'database',
$db,
$table,
$max_upload_size,
$SESSION_KEY,
$uploadId,
$importList
);

$this->render('display/import/import', $import);
}
}
28 changes: 24 additions & 4 deletions libraries/classes/Controllers/Server/ImportController.php
Expand Up @@ -8,12 +8,15 @@
use PhpMyAdmin\Config\PageSettings;
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\Display\Import;
use PhpMyAdmin\Display\ImportAjax;
use PhpMyAdmin\Message;
use PhpMyAdmin\Plugins;

final class ImportController extends AbstractController
{
public function index(): void
{
global $db, $max_upload_size, $table;
global $db, $max_upload_size, $table, $SESSION_KEY;

$pageSettings = new PageSettings('Import');
$this->response->addHTML($pageSettings->getErrorHTML());
Expand All @@ -23,11 +26,28 @@ public function index(): void

Common::server();

$this->response->addHTML(Import::get(
[$SESSION_KEY, $uploadId] = ImportAjax::uploadProgressSetup();

$importList = Plugins::getImport('server');

if (empty($importList)) {
$this->response->addHTML(Message::error(__(
'Could not load import plugins, please check your installation!'
))->getDisplay());

return;
}

$import = Import::get(
'server',
$db,
$table,
$max_upload_size
));
$max_upload_size,
$SESSION_KEY,
$uploadId,
$importList
);

$this->render('display/import/import', $import);
}
}
31 changes: 24 additions & 7 deletions libraries/classes/Controllers/Table/ImportController.php
Expand Up @@ -7,34 +7,51 @@
use PhpMyAdmin\Common;
use PhpMyAdmin\Config\PageSettings;
use PhpMyAdmin\Display\Import;
use PhpMyAdmin\Display\ImportAjax;
use PhpMyAdmin\Message;
use PhpMyAdmin\Plugins;
use PhpMyAdmin\Url;

final class ImportController extends AbstractController
{
public function index(): void
{
global $db, $max_upload_size, $table, $url_query, $url_params;
global $db, $max_upload_size, $table, $url_query, $url_params, $SESSION_KEY;

$pageSettings = new PageSettings('Import');
$this->response->addHTML($pageSettings->getErrorHTML());
$this->response->addHTML($pageSettings->getHTML());

$this->addScriptFiles(['import.js']);

/**
* Gets tables information and displays top links
*/
Common::table();

$url_params['goto'] = Url::getFromRoute('/table/import');
$url_params['back'] = Url::getFromRoute('/table/import');
$url_query .= Url::getCommon($url_params, '&');

$this->response->addHTML(Import::get(
[$SESSION_KEY, $uploadId] = ImportAjax::uploadProgressSetup();

$importList = Plugins::getImport('table');

if (empty($importList)) {
$this->response->addHTML(Message::error(__(
'Could not load import plugins, please check your installation!'
))->getDisplay());

return;
}

$import = Import::get(
'table',
$db,
$table,
$max_upload_size
));
$max_upload_size,
$SESSION_KEY,
$uploadId,
$importList
);

$this->render('display/import/import', $import);
}
}
51 changes: 15 additions & 36 deletions libraries/classes/Display/Import.php
@@ -1,7 +1,4 @@
<?php
/**
* functions for displaying import for: server, database and table
*/

declare(strict_types=1);

Expand All @@ -12,51 +9,33 @@
use PhpMyAdmin\Core;
use PhpMyAdmin\Encoding;
use PhpMyAdmin\FileListing;
use PhpMyAdmin\Message;
use PhpMyAdmin\Plugins;
use PhpMyAdmin\Template;
use PhpMyAdmin\Util;
use function function_exists;
use function intval;

/**
* PhpMyAdmin\Display\Import class
* Functions for displaying import for: server, database and table
*/
class Import
{
/**
* Gets HTML to display import dialogs
*
* @param string $importType Import type: server|database|table
* @param string $db Selected DB
* @param string $table Selected Table
* @param int $maxUploadSize Max upload size
*
* @return string HTML
* @return array
*/
public static function get($importType, $db, $table, $maxUploadSize)
{
public static function get(
$importType,
$db,
$table,
$maxUploadSize,
string $sessionKey,
string $uploadId,
array $importList
): array {
global $cfg;
global $SESSION_KEY;

$template = new Template();

[
$SESSION_KEY,
$uploadId,
] = ImportAjax::uploadProgressSetup();

$importList = Plugins::getImport($importType);

/* Fail if we didn't find any plugin */
if (empty($importList)) {
echo Message::error(
__(
'Could not load import plugins, please check your installation!'
)
)->getDisplay();
exit;
}

if (Core::isValid($_REQUEST['offset'], 'numeric')) {
$offset = intval($_REQUEST['offset']);
Expand Down Expand Up @@ -92,10 +71,10 @@ public static function get($importType, $db, $table, $maxUploadSize)
];
}

return $template->render('display/import/import', [
return [
'upload_id' => $uploadId,
'handler' => $_SESSION[$SESSION_KEY]['handler'],
'id_key' => $_SESSION[$SESSION_KEY]['handler']::getIdKey(),
'handler' => $_SESSION[$sessionKey]['handler'],
'id_key' => $_SESSION[$sessionKey]['handler']::getIdKey(),
'pma_theme_image' => $GLOBALS['pmaThemeImage'],
'import_type' => $importType,
'db' => $db,
Expand All @@ -117,7 +96,7 @@ public static function get($importType, $db, $table, $maxUploadSize)
'is_foreign_key_check' => Util::isForeignKeyCheck(),
'user_upload_dir' => Util::userDir($cfg['UploadDir'] ?? ''),
'local_files' => self::getLocalFiles($importList),
]);
];
}

/**
Expand Down

0 comments on commit 2843639

Please sign in to comment.