Skip to content

Commit 62ec1bc

Browse files
Merge pull request #18445 from kamil-tekiela/InsertEdit-pt4
InsertEdit refactoring - part 4
2 parents b100c05 + 7838a42 commit 62ec1bc

20 files changed

Lines changed: 615 additions & 665 deletions

libraries/classes/Controllers/Table/ReplaceController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use PhpMyAdmin\InsertEdit;
1919
use PhpMyAdmin\Message;
2020
use PhpMyAdmin\Plugins\IOTransformationsPlugin;
21+
use PhpMyAdmin\Query\Generator as QueryGenerator;
2122
use PhpMyAdmin\ResponseRenderer;
2223
use PhpMyAdmin\Table;
2324
use PhpMyAdmin\Template;
@@ -286,7 +287,7 @@ public function __invoke(ServerRequest $request): void
286287

287288
// Builds the sql query
288289
if ($isInsert && $valueSets !== []) {
289-
$GLOBALS['query'] = (array) $this->insertEdit->buildInsertSqlQuery(
290+
$GLOBALS['query'] = (array) QueryGenerator::buildInsertSqlQuery(
290291
$GLOBALS['table'],
291292
$isInsertignore,
292293
$queryFields,

libraries/classes/Database/Routines.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,17 +1357,17 @@ public function getExecuteForm(array $routine): string
13571357
) {
13581358
$params[$i]['generator'] = null;
13591359
} else {
1360-
$field = [
1361-
'True_Type' => mb_strtolower($routine['item_param_type'][$i]),
1362-
'Type' => '',
1363-
'Key' => '',
1364-
'Field' => '',
1365-
'Default' => '',
1366-
'first_timestamp' => false,
1367-
];
1368-
1369-
$generator = Generator::getFunctionsForField($field, false, []);
1370-
$params[$i]['generator'] = $generator;
1360+
$defaultFunction = Generator::getDefaultFunctionForField(
1361+
mb_strtolower($routine['item_param_type'][$i]),
1362+
false,
1363+
'',
1364+
'',
1365+
false,
1366+
'',
1367+
'',
1368+
false,
1369+
);
1370+
$params[$i]['generator'] = Generator::getFunctionsForField($defaultFunction, []);
13711371
}
13721372
}
13731373

libraries/classes/Html/Generator.php

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -258,23 +258,28 @@ public static function getServerSSL(): string
258258
/**
259259
* Returns default function for a particular column.
260260
*
261-
* @param mixed[] $field Data about the column for which
262-
* to generate the dropdown
263-
* @param bool $insertMode Whether the operation is 'insert'
264-
*
265261
* @return string An HTML snippet of a dropdown list with function
266262
* names appropriate for the requested column.
267-
*
268-
* @global mixed $data data of currently edited row
269-
* (used to detect whether to choose defaults)
270-
* @global array $cfg PMA configuration
271263
*/
272-
public static function getDefaultFunctionForField(array $field, bool $insertMode): string
273-
{
264+
public static function getDefaultFunctionForField(
265+
string $trueType,
266+
bool $firstTimestamp,
267+
string|null $defaultValue,
268+
string $extra,
269+
bool $isNull,
270+
string $key,
271+
string $type,
272+
bool $insertMode,
273+
): string {
274+
// For uuid field, no default function
275+
if ($trueType === 'uuid') {
276+
return '';
277+
}
278+
274279
$defaultFunction = '';
275280

276281
// Can we get field class based values?
277-
$currentClass = $GLOBALS['dbi']->types->getTypeClass($field['True_Type']);
282+
$currentClass = $GLOBALS['dbi']->types->getTypeClass($trueType);
278283
if (! empty($currentClass) && isset($GLOBALS['cfg']['DefaultFunctions']['FUNC_' . $currentClass])) {
279284
$defaultFunction = $GLOBALS['cfg']['DefaultFunctions']['FUNC_' . $currentClass];
280285
// Change the configured default function to include the ST_ prefix with MySQL 5.6 and later.
@@ -295,27 +300,22 @@ public static function getDefaultFunctionForField(array $field, bool $insertMode
295300
// and the column does not have the
296301
// ON UPDATE DEFAULT TIMESTAMP attribute.
297302
if (
298-
($field['True_Type'] === 'timestamp')
299-
&& $field['first_timestamp']
300-
&& empty($field['Default'])
301-
&& $field['Extra'] !== 'on update CURRENT_TIMESTAMP'
302-
&& $field['Null'] === 'NO'
303+
($trueType === 'timestamp')
304+
&& $firstTimestamp
305+
&& ($defaultValue === null || $defaultValue === '')
306+
&& $extra !== 'on update CURRENT_TIMESTAMP'
307+
&& ! $isNull
303308
) {
304309
$defaultFunction = $GLOBALS['cfg']['DefaultFunctions']['first_timestamp'];
305310
}
306311

307-
// For uuid field, no default function
308-
if ($field['True_Type'] === 'uuid') {
309-
return '';
310-
}
311-
312312
// For primary keys of type char(36) or varchar(36) UUID if the default
313313
// function
314314
// Only applies to insert mode, as it would silently trash data on updates.
315315
if (
316316
$insertMode
317-
&& $field['Key'] === 'PRI'
318-
&& ($field['Type'] === 'char(36)' || $field['Type'] === 'varchar(36)')
317+
&& $key === 'PRI'
318+
&& ($type === 'char(36)' || $type === 'varchar(36)')
319319
) {
320320
return $GLOBALS['cfg']['DefaultFunctions']['FUNC_UUID'];
321321
}
@@ -326,16 +326,12 @@ public static function getDefaultFunctionForField(array $field, bool $insertMode
326326
/**
327327
* Creates a dropdown box with MySQL functions for a particular column.
328328
*
329-
* @param mixed[] $field Data about the column for which to generate the dropdown
330-
* @param bool $insertMode Whether the operation is 'insert'
331329
* @param mixed[] $foreignData Foreign data
332330
*
333331
* @return string An HTML snippet of a dropdown list with function names appropriate for the requested column.
334332
*/
335-
public static function getFunctionsForField(array $field, bool $insertMode, array $foreignData): string
333+
public static function getFunctionsForField(string $defaultFunction, array $foreignData): string
336334
{
337-
$defaultFunction = self::getDefaultFunctionForField($field, $insertMode);
338-
339335
// Create the output
340336
$retval = '<option></option>' . "\n";
341337
// loop on the dropdown array and print all available options for that

0 commit comments

Comments
 (0)