1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-08 07:47:00 +02:00
This commit is contained in:
Ryan Cramer
2024-02-20 09:31:26 -05:00
parent 3e90cb74fa
commit f3e614640b

View File

@@ -49,7 +49,7 @@
* ~~~~~ * ~~~~~
* #pw-body * #pw-body
* *
* ProcessWire 3.x, Copyright 2023 by Ryan Cramer * ProcessWire 3.x, Copyright 2024 by Ryan Cramer
* https://processwire.com * https://processwire.com
* *
* *
@@ -834,10 +834,14 @@ class WireDatabaseBackup {
if(in_array($table, $options['excludeExportTables'])) continue; if(in_array($table, $options['excludeExportTables'])) continue;
$numTables++; $numTables++;
$columns = array(); $columns = array();
$columnTypes = array();
$query = $database->prepare("SHOW COLUMNS FROM `$table`"); $query = $database->prepare("SHOW COLUMNS FROM `$table`");
$query->execute(); $query->execute();
/** @noinspection PhpAssignmentInConditionInspection */ /** @noinspection PhpAssignmentInConditionInspection */
while($row = $query->fetch(\PDO::FETCH_NUM)) $columns[] = $row[0]; while($row = $query->fetch(\PDO::FETCH_NUM)) {
$columns[] = $row[0];
$columnTypes[] = $row[1];
}
$query->closeCursor(); $query->closeCursor();
$columnsStr = '`' . implode('`, `', $columns) . '`'; $columnsStr = '`' . implode('`, `', $columns) . '`';
@@ -862,9 +866,12 @@ class WireDatabaseBackup {
while($row = $query->fetch(\PDO::FETCH_NUM)) { while($row = $query->fetch(\PDO::FETCH_NUM)) {
$numInserts++; $numInserts++;
$out = "\nINSERT INTO `$table` ($columnsStr) VALUES("; $out = "\nINSERT INTO `$table` ($columnsStr) VALUES(";
foreach($row as $value) { foreach($row as $key => $value) {
$columnType = $columnTypes[$key];
if(is_null($value)) { if(is_null($value)) {
$value = 'NULL'; $value = 'NULL';
} else if(stripos($columnType, 'bit') === 0 && ctype_digit("$value")) {
// leave bit column value unquoted
} else { } else {
if($hasReplace) foreach($options['findReplace'] as $find => $replace) { if($hasReplace) foreach($options['findReplace'] as $find => $replace) {
if(strpos($value, $find)) $value = str_replace($find, $replace, $value); if(strpos($value, $find)) $value = str_replace($find, $replace, $value);