-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Expand file tree
/
Copy pathImportController.php
More file actions
141 lines (117 loc) · 5.14 KB
/
ImportController.php
File metadata and controls
141 lines (117 loc) · 5.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
declare(strict_types=1);
namespace PhpMyAdmin\Controllers\Server;
use PhpMyAdmin\Charsets;
use PhpMyAdmin\Config;
use PhpMyAdmin\Config\PageSettings;
use PhpMyAdmin\Controllers\InvocableController;
use PhpMyAdmin\Current;
use PhpMyAdmin\Dbal\DatabaseInterface;
use PhpMyAdmin\Encoding;
use PhpMyAdmin\Http\Response;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Import\Ajax;
use PhpMyAdmin\Import\Import;
use PhpMyAdmin\Import\ImportSettings;
use PhpMyAdmin\Message;
use PhpMyAdmin\Plugins;
use PhpMyAdmin\Plugins\PluginType;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Routing\Route;
use PhpMyAdmin\Util;
use PhpMyAdmin\Utils\ForeignKey;
use function __;
use function is_numeric;
use function is_string;
#[Route('/server/import', ['GET', 'POST'])]
final readonly class ImportController implements InvocableController
{
public function __construct(
private ResponseRenderer $response,
private DatabaseInterface $dbi,
private PageSettings $pageSettings,
private Config $config,
) {
}
public function __invoke(ServerRequest $request): Response
{
$this->pageSettings->init('Import');
$pageSettingsErrorHtml = $this->pageSettings->getErrorHTML();
$pageSettingsHtml = $this->pageSettings->getHTML();
$this->response->addScriptFiles(['import.js']);
if ($this->dbi->isSuperUser()) {
$this->dbi->selectDb('mysql');
}
[$uploadId] = Ajax::uploadProgressSetup();
ImportSettings::$importType = 'server';
$importList = Plugins::getImport();
if ($importList === []) {
$this->response->addHTML(Message::error(__(
'Could not load import plugins, please check your installation!',
))->getDisplay());
return $this->response->response();
}
$offset = null;
if (isset($_REQUEST['offset']) && is_numeric($_REQUEST['offset'])) {
$offset = (int) $_REQUEST['offset'];
}
$timeoutPassed = $_REQUEST['timeout_passed'] ?? null;
$localImportFile = $_REQUEST['local_import_file'] ?? null;
$compressions = Import::getCompressions($this->config);
$charsets = Charsets::getCharsets($this->dbi, $this->config->selectedServer['DisableIS']);
$idKey = $_SESSION[Ajax::SESSION_KEY]['handler']::getIdKey();
$hiddenInputs = [$idKey => $uploadId, 'import_type' => 'server'];
$pluginName = $this->getFormat($request->getParam('format'));
$pluginName = Plugins::validatePluginNameOrUseDefault($importList, $pluginName);
$choice = Plugins::getChoice($importList, $pluginName);
$options = Plugins::getOptions(PluginType::Import, $importList);
$skipQueriesDefault = $this->getSkipQueries($request->getParam('skip_queries'));
$isAllowInterruptChecked = Plugins::checkboxCheck(PluginType::Import, 'allow_interrupt');
$maxUploadSize = Util::getUploadSizeInBytes();
$this->response->render('server/import/index', [
'page_settings_error_html' => $pageSettingsErrorHtml,
'page_settings_html' => $pageSettingsHtml,
'upload_id' => $uploadId,
'handler' => $_SESSION[Ajax::SESSION_KEY]['handler'],
'hidden_inputs' => $hiddenInputs,
'db' => Current::$database,
'table' => Current::$table,
'max_upload_size' => $maxUploadSize,
'formatted_maximum_upload_size' => Util::getFormattedMaximumUploadSize($maxUploadSize),
'plugins_choice' => $choice,
'options' => $options,
'skip_queries_default' => $skipQueriesDefault,
'is_allow_interrupt_checked' => $isAllowInterruptChecked,
'local_import_file' => $localImportFile,
'is_upload' => $this->config->isUploadEnabled(),
'upload_dir' => $this->config->config->UploadDir ,
'timeout_passed_global' => ImportSettings::$timeoutPassed,
'compressions' => $compressions,
'is_encoding_supported' => Encoding::isSupported(),
'encodings' => Encoding::listEncodings(),
'import_charset' => $this->config->config->Import->charset,
'timeout_passed' => $timeoutPassed,
'offset' => $offset,
'can_convert_kanji' => Encoding::canConvertKanji(),
'charsets' => $charsets,
'is_foreign_key_check' => ForeignKey::isCheckEnabled(),
'user_upload_dir' => Util::userDir($this->config->selectedServer['user'], $this->config->config->UploadDir),
'local_files' => Import::getLocalFiles($this->config, $importList),
]);
return $this->response->response();
}
private function getFormat(mixed $formatParam): string
{
if (is_string($formatParam) && $formatParam !== '') {
return $formatParam;
}
return $this->config->settings['Import']['format'];
}
private function getSkipQueries(mixed $skipQueriesParam): int
{
if (is_numeric($skipQueriesParam) && $skipQueriesParam >= 0) {
return (int) $skipQueriesParam;
}
return $this->config->settings['Import']['skip_queries'];
}
}