From 28436399dd835f2cfd857b552344435aa732ab63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Wed, 19 Aug 2020 02:25:48 -0300 Subject: [PATCH] Extract exit from Display\Import class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- .../Controllers/Database/ImportController.php | 37 ++++++++++---- .../Controllers/Server/ImportController.php | 28 ++++++++-- .../Controllers/Table/ImportController.php | 31 ++++++++--- libraries/classes/Display/Import.php | 51 ++++++------------- 4 files changed, 89 insertions(+), 58 deletions(-) diff --git a/libraries/classes/Controllers/Database/ImportController.php b/libraries/classes/Controllers/Database/ImportController.php index 53ce7535a956..c6d16ebda521 100644 --- a/libraries/classes/Controllers/Database/ImportController.php +++ b/libraries/classes/Controllers/Database/ImportController.php @@ -7,6 +7,9 @@ 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 @@ -14,7 +17,7 @@ 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()); @@ -22,9 +25,6 @@ public function index(): void $this->addScriptFiles(['import.js']); - /** - * Gets tables information and displays top links - */ Common::database(); [ @@ -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); } } diff --git a/libraries/classes/Controllers/Server/ImportController.php b/libraries/classes/Controllers/Server/ImportController.php index 3eaeb9d10872..7843c6798abe 100644 --- a/libraries/classes/Controllers/Server/ImportController.php +++ b/libraries/classes/Controllers/Server/ImportController.php @@ -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()); @@ -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); } } diff --git a/libraries/classes/Controllers/Table/ImportController.php b/libraries/classes/Controllers/Table/ImportController.php index 329274b5a671..15f3128be11b 100644 --- a/libraries/classes/Controllers/Table/ImportController.php +++ b/libraries/classes/Controllers/Table/ImportController.php @@ -7,13 +7,16 @@ 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()); @@ -21,20 +24,34 @@ public function index(): void $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); } } diff --git a/libraries/classes/Display/Import.php b/libraries/classes/Display/Import.php index a0fdf2aa13a7..175e7cfac997 100644 --- a/libraries/classes/Display/Import.php +++ b/libraries/classes/Display/Import.php @@ -1,7 +1,4 @@ getDisplay(); - exit; - } if (Core::isValid($_REQUEST['offset'], 'numeric')) { $offset = intval($_REQUEST['offset']); @@ -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, @@ -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), - ]); + ]; } /**