Skip to content

Commit

Permalink
Remove Import::stop method
Browse files Browse the repository at this point in the history
Related to #16258.

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Aug 18, 2020
1 parent d9e6ef6 commit 9cab697
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 50 deletions.
56 changes: 41 additions & 15 deletions libraries/classes/Controllers/ImportController.php
Expand Up @@ -528,30 +528,51 @@ public function index(): void
$import_handle = new File($import_file);
$import_handle->checkUploadedFile();
if ($import_handle->isError()) {
$this->import->stop($import_handle->getError());
/** @var Message $errorMessage */
$errorMessage = $import_handle->getError();

$import_handle->close();

$_SESSION['Import_message']['message'] = $errorMessage->getDisplay();

$this->response->setRequestStatus(false);
$this->response->addJSON('message', $errorMessage->getDisplay());
$this->response->addHTML($errorMessage->getDisplay());

return;
}
$import_handle->setDecompressContent(true);
$import_handle->open();
if ($import_handle->isError()) {
$this->import->stop($import_handle->getError());
/** @var Message $errorMessage */
$errorMessage = $import_handle->getError();

return;
}
} elseif (! $error) {
if (! isset($import_text) || empty($import_text)) {
$message = Message::error(
__(
'No data was received to import. Either no file name was ' .
'submitted, or the file size exceeded the maximum size permitted ' .
'by your PHP configuration. See [doc@faq1-16]FAQ 1.16[/doc].'
)
);
$this->import->stop($message);
$import_handle->close();

$_SESSION['Import_message']['message'] = $errorMessage->getDisplay();

$this->response->setRequestStatus(false);
$this->response->addJSON('message', $errorMessage->getDisplay());
$this->response->addHTML($errorMessage->getDisplay());

return;
}
} elseif (! $error && (! isset($import_text) || empty($import_text))) {
$message = Message::error(
__(
'No data was received to import. Either no file name was ' .
'submitted, or the file size exceeded the maximum size permitted ' .
'by your PHP configuration. See [doc@faq1-16]FAQ 1.16[/doc].'
)
);

$_SESSION['Import_message']['message'] = $message->getDisplay();

$this->response->setRequestStatus(false);
$this->response->addJSON('message', $message->getDisplay());
$this->response->addHTML($message->getDisplay());

return;
}

// so we can obtain the message
Expand Down Expand Up @@ -602,7 +623,12 @@ public function index(): void
$message = Message::error(
__('Could not load import plugins, please check your installation!')
);
$this->import->stop($message);

$_SESSION['Import_message']['message'] = $message->getDisplay();

$this->response->setRequestStatus(false);
$this->response->addJSON('message', $message->getDisplay());
$this->response->addHTML($message->getDisplay());

return;
}
Expand Down
30 changes: 0 additions & 30 deletions libraries/classes/Import.php
Expand Up @@ -41,7 +41,6 @@
use function substr;
use function time;
use function trim;
use function unlink;

/**
* Library that provides common import functions that are used by import plugins
Expand Down Expand Up @@ -1427,35 +1426,6 @@ public function buildSql(
$import_notice = $message;
}

/**
* Stops the import on (mostly upload/file related) error
*
* @param Message $error_message The error message
*
* @access public
*/
public function stop(Message $error_message): void
{
global $import_handle, $file_to_unlink;

// Close open handles
if ($import_handle !== false && $import_handle !== null) {
$import_handle->close();
}

// Delete temporary file
if ($file_to_unlink != '') {
unlink($file_to_unlink);
}
$msg = $error_message->getDisplay();
$_SESSION['Import_message']['message'] = $msg;

$response = Response::getInstance();
$response->setRequestStatus(false);
$response->addJSON('message', $msg);
$response->addHTML($msg);
}

/**
* Handles request for Simulation of UPDATE/DELETE queries.
*/
Expand Down
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Expand Up @@ -260,11 +260,6 @@ parameters:
count: 1
path: libraries/classes/Controllers/ExportController.php

-
message: "#^Parameter \\#1 \\$error_message of method PhpMyAdmin\\\\Import\\:\\:stop\\(\\) expects PhpMyAdmin\\\\Message, PhpMyAdmin\\\\Message\\|null given\\.$#"
count: 2
path: libraries/classes/Controllers/ImportController.php

-
message: "#^Negated boolean expression is always true\\.$#"
count: 1
Expand Down

0 comments on commit 9cab697

Please sign in to comment.