Skip to content

Commit 0d24325

Browse files
Merge pull request #18359 from kamil-tekiela/InsertEdit-refactoring
InsertEdit refactoring - part 1
2 parents fe2d9d4 + 5cd6c16 commit 0d24325

13 files changed

Lines changed: 307 additions & 628 deletions

File tree

js/src/drag_drop_import.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,6 @@ var DragDropImport = {
329329
fd.append('token', CommonParams.get('token'));
330330
fd.append('import_type', 'database');
331331
// todo: method to find the value below
332-
fd.append('MAX_FILE_SIZE', '4194304');
333-
// todo: method to find the value below
334332
fd.append('charset_of_file', 'utf-8');
335333
// todo: method to find the value below
336334
fd.append('allow_interrupt', 'yes');

libraries/classes/Controllers/Import/ImportController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ public function __invoke(ServerRequest $request): void
101101
$GLOBALS['format'] = $request->getParsedBodyParam('format', '');
102102
$GLOBALS['import_type'] = $request->getParsedBodyParam('import_type');
103103
$GLOBALS['is_js_confirmed'] = $request->getParsedBodyParam('is_js_confirmed');
104-
$GLOBALS['MAX_FILE_SIZE'] = $request->getParsedBodyParam('MAX_FILE_SIZE');
105104
$GLOBALS['message_to_show'] = $request->getParsedBodyParam('message_to_show');
106105
$GLOBALS['noplugin'] = $request->getParsedBodyParam('noplugin');
107106
$GLOBALS['skip_queries'] = $request->getParsedBodyParam('skip_queries');

libraries/classes/Controllers/Table/ChangeController.php

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use function str_contains;
2525
use function strlen;
2626
use function strpos;
27+
use function trim;
2728

2829
/**
2930
* Displays form for editing and inserting new table rows.
@@ -61,7 +62,6 @@ public function __invoke(ServerRequest $request): void
6162
$GLOBALS['tabindex'] ??= null;
6263
$GLOBALS['tabindex_for_value'] ??= null;
6364
$GLOBALS['o_rows'] ??= null;
64-
$GLOBALS['biggest_max_file_size'] ??= null;
6565
$GLOBALS['has_blob_field'] ??= null;
6666
$GLOBALS['jsvkey'] ??= null;
6767
$GLOBALS['vkey'] ??= null;
@@ -182,14 +182,10 @@ public function __invoke(ServerRequest $request): void
182182
$GLOBALS['tabindex'] = 0;
183183
$GLOBALS['tabindex_for_value'] = 0;
184184
$GLOBALS['o_rows'] = 0;
185-
$GLOBALS['biggest_max_file_size'] = 0;
186185

187186
$GLOBALS['urlParams']['db'] = $GLOBALS['db'];
188187
$GLOBALS['urlParams']['table'] = $GLOBALS['table'];
189-
$GLOBALS['urlParams'] = $this->insertEdit->urlParamsInEditMode(
190-
$GLOBALS['urlParams'],
191-
$GLOBALS['where_clause_array'],
192-
);
188+
$GLOBALS['urlParams'] = $this->urlParamsInEditMode($GLOBALS['urlParams'], $GLOBALS['where_clause_array']);
193189

194190
$GLOBALS['has_blob_field'] = false;
195191
foreach ($GLOBALS['table_columns'] as $column) {
@@ -263,7 +259,6 @@ public function __invoke(ServerRequest $request): void
263259
$GLOBALS['table'],
264260
$GLOBALS['db'],
265261
$rowId,
266-
$GLOBALS['biggest_max_file_size'],
267262
$GLOBALS['text_dir'],
268263
$GLOBALS['repopulate'],
269264
$GLOBALS['where_clause_array'],
@@ -286,11 +281,6 @@ public function __invoke(ServerRequest $request): void
286281
'is_numeric' => $isNumeric,
287282
]);
288283

289-
if ($GLOBALS['biggest_max_file_size'] > 0) {
290-
$htmlOutput .= '<input type="hidden" name="MAX_FILE_SIZE" value="'
291-
. $GLOBALS['biggest_max_file_size'] . '">' . "\n";
292-
}
293-
294284
$htmlOutput .= '</form>';
295285

296286
$htmlOutput .= $this->insertEdit->getHtmlForGisEditor();
@@ -308,4 +298,27 @@ public function __invoke(ServerRequest $request): void
308298

309299
$this->response->addHTML($htmlOutput);
310300
}
301+
302+
/**
303+
* Add some url parameters
304+
*
305+
* @param mixed[] $urlParams containing $db and $table as url parameters
306+
* @param mixed[] $whereClauseArray where clauses array
307+
*
308+
* @return mixed[] Add some url parameters to $url_params array and return it
309+
*/
310+
public function urlParamsInEditMode(
311+
array $urlParams,
312+
array $whereClauseArray,
313+
): array {
314+
foreach ($whereClauseArray as $whereClause) {
315+
$urlParams['where_clause'] = trim($whereClause);
316+
}
317+
318+
if (! empty($_POST['sql_query'])) {
319+
$urlParams['sql_query'] = $_POST['sql_query'];
320+
}
321+
322+
return $urlParams;
323+
}
311324
}

libraries/classes/Controllers/Table/ReplaceController.php

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use PhpMyAdmin\Util;
2626

2727
use function __;
28+
use function array_keys;
2829
use function array_values;
2930
use function class_exists;
3031
use function implode;
@@ -104,7 +105,9 @@ public function __invoke(ServerRequest $request): void
104105
/**
105106
* Prepares the update/insert of a row
106107
*/
107-
[$loopArray, $usingKey, $isInsert, $isInsertignore] = $this->insertEdit->getParamsForUpdateOrInsert();
108+
[$loopArray, $usingKey, $isInsert] = $this->getParamsForUpdateOrInsert();
109+
110+
$isInsertignore = isset($_POST['submit_type']) && $_POST['submit_type'] === 'insertignore';
108111

109112
$GLOBALS['query'] = [];
110113
$valueSets = [];
@@ -283,7 +286,12 @@ public function __invoke(ServerRequest $request): void
283286

284287
// Builds the sql query
285288
if ($isInsert && $valueSets !== []) {
286-
$GLOBALS['query'] = $this->insertEdit->buildSqlQuery($isInsertignore, $queryFields, $valueSets);
289+
$GLOBALS['query'] = (array) $this->insertEdit->buildInsertSqlQuery(
290+
$GLOBALS['table'],
291+
$isInsertignore,
292+
$queryFields,
293+
$valueSets,
294+
);
287295
} elseif (empty($GLOBALS['query']) && ! isset($_POST['preview_sql']) && ! $rowSkipped) {
288296
// No change -> move back to the calling script
289297
//
@@ -504,4 +512,36 @@ private function moveBackToCallingScript(string $gotoInclude, ServerRequest $req
504512
/** @psalm-suppress UnresolvableInclude */
505513
require ROOT_PATH . Core::securePath($gotoInclude);
506514
}
515+
516+
/**
517+
* Prepares the update/insert of a row
518+
*
519+
* @return mixed[] $loop_array, $using_key, $is_insert
520+
* @psalm-return array{array, bool, bool}
521+
*/
522+
private function getParamsForUpdateOrInsert(): array
523+
{
524+
if (isset($_POST['where_clause'])) {
525+
// we were editing something => use the WHERE clause
526+
$loopArray = is_array($_POST['where_clause'])
527+
? $_POST['where_clause']
528+
: [$_POST['where_clause']];
529+
$usingKey = true;
530+
$isInsert = isset($_POST['submit_type'])
531+
&& ($_POST['submit_type'] === 'insert'
532+
|| $_POST['submit_type'] === 'showinsert'
533+
|| $_POST['submit_type'] === 'insertignore');
534+
} else {
535+
// new row => use indexes
536+
$loopArray = [];
537+
if (! empty($_POST['fields'])) {
538+
$loopArray = array_keys($_POST['fields']['multi_edit']);
539+
}
540+
541+
$usingKey = false;
542+
$isInsert = true;
543+
}
544+
545+
return [$loopArray, $usingKey, $isInsert];
546+
}
507547
}

0 commit comments

Comments
 (0)