fix: UTF-8 BOM in update SQL files causing MariaDB syntax error

PowerShell 5.1 Out-File -Encoding UTF8 adds BOM (EF BB BF) which
breaks SQL execution on production. Also fix manifest JSON serializing
full PS objects instead of plain strings.

- build-update.ps1: use UTF8Encoding($false) for all file writes
- build-update.ps1: force .ToString() on Get-Content results
- UpdateRepository.php: strip BOM and normalize line endings in executeSql
- Rebuild ver_0.304 package files (clean SQL + manifest)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-22 16:49:23 +01:00
parent 62255541ab
commit 5c1842181a
4 changed files with 38 additions and 300 deletions

View File

@@ -416,7 +416,12 @@ class UpdateRepository
return $log; return $log;
} }
$queries = explode( PHP_EOL, $response ); // Usunięcie UTF-8 BOM i normalizacja końców linii
$response = ltrim( $response, "\xEF\xBB\xBF" );
$response = str_replace( "\r\n", "\n", $response );
$response = str_replace( "\r", "\n", $response );
$queries = explode( "\n", $response );
$log[] = '[OK] Pobrano ' . count( $queries ) . ' zapytań SQL'; $log[] = '[OK] Pobrano ' . count( $queries ) . ' zapytań SQL';
$success = 0; $success = 0;
$errors = 0; $errors = 0;

View File

@@ -32,6 +32,7 @@ param(
) )
$ErrorActionPreference = "Stop" $ErrorActionPreference = "Stop"
$Utf8NoBom = New-Object System.Text.UTF8Encoding $false
# --- Helpers --- # --- Helpers ---
@@ -214,7 +215,7 @@ $sqlQueries = @()
$migrationFile = "migrations/$versionNumber.sql" $migrationFile = "migrations/$versionNumber.sql"
if (Test-Path $migrationFile) { if (Test-Path $migrationFile) {
$sqlQueries = Get-Content $migrationFile | Where-Object { $_.Trim() -ne '' } $sqlQueries = @(Get-Content $migrationFile | Where-Object { $_.Trim() -ne '' } | ForEach-Object { $_.ToString() })
Write-Step "Znaleziono migracje SQL: $migrationFile ($($sqlQueries.Count) zapytan)" Write-Step "Znaleziono migracje SQL: $migrationFile ($($sqlQueries.Count) zapytan)"
} else { } else {
Write-Step "Brak migracji SQL ($migrationFile nie istnieje)" Write-Step "Brak migracji SQL ($migrationFile nie istnieje)"
@@ -322,7 +323,7 @@ $manifest = @{
$manifestJson = $manifest | ConvertTo-Json -Depth 4 $manifestJson = $manifest | ConvertTo-Json -Depth 4
$manifestPath = "$updatesDir/ver_${versionNumber}_manifest.json" $manifestPath = "$updatesDir/ver_${versionNumber}_manifest.json"
$manifestJson | Out-File $manifestPath -Encoding UTF8 [System.IO.File]::WriteAllText($manifestPath, $manifestJson, $Utf8NoBom)
Write-Ok "Utworzono manifest: $manifestPath" Write-Ok "Utworzono manifest: $manifestPath"
@@ -330,7 +331,7 @@ Write-Ok "Utworzono manifest: $manifestPath"
if ($sqlQueries.Count -gt 0) { if ($sqlQueries.Count -gt 0) {
$sqlPath = "$updatesDir/ver_${versionNumber}_sql.txt" $sqlPath = "$updatesDir/ver_${versionNumber}_sql.txt"
($sqlQueries -join "`n") | Out-File $sqlPath -Encoding UTF8 -NoNewline [System.IO.File]::WriteAllText($sqlPath, ($sqlQueries -join "`n"), $Utf8NoBom)
Write-Ok "Utworzono legacy SQL: $sqlPath" Write-Ok "Utworzono legacy SQL: $sqlPath"
} }
@@ -340,7 +341,7 @@ if ($deletedFilesOnly.Count -gt 0 -or $deletedDirs.Count -gt 0) {
foreach ($d in $deletedDirs) { $filesContent += "D: ../$d" } foreach ($d in $deletedDirs) { $filesContent += "D: ../$d" }
$filesPath = "$updatesDir/ver_${versionNumber}_files.txt" $filesPath = "$updatesDir/ver_${versionNumber}_files.txt"
($filesContent -join "`n") | Out-File $filesPath -Encoding UTF8 -NoNewline [System.IO.File]::WriteAllText($filesPath, ($filesContent -join "`n"), $Utf8NoBom)
Write-Ok "Utworzono legacy files: $filesPath" Write-Ok "Utworzono legacy files: $filesPath"
} }
@@ -350,7 +351,7 @@ $versionsFile = "updates/versions.php"
if (Test-Path $versionsFile) { if (Test-Path $versionsFile) {
$content = Get-Content $versionsFile -Raw $content = Get-Content $versionsFile -Raw
$content = $content -replace '\$current_ver\s*=\s*\d+;', "`$current_ver = $versionInt;" $content = $content -replace '\$current_ver\s*=\s*\d+;', "`$current_ver = $versionInt;"
$content | Out-File $versionsFile -Encoding UTF8 -NoNewline [System.IO.File]::WriteAllText($versionsFile, $content, $Utf8NoBom)
Write-Ok "Zaktualizowano versions.php: `$current_ver = $versionInt" Write-Ok "Zaktualizowano versions.php: `$current_ver = $versionInt"
} }
@@ -363,7 +364,7 @@ if (Test-Path $changelogFile) {
$changelogContent = Get-Content $changelogFile -Raw $changelogContent = Get-Content $changelogFile -Raw
$changelogContent = $newEntry + $changelogContent $changelogContent = $newEntry + $changelogContent
$changelogContent | Out-File $changelogFile -Encoding UTF8 -NoNewline [System.IO.File]::WriteAllText($changelogFile, $changelogContent, $Utf8NoBom)
Write-Ok "Zaktualizowano changelog.php" Write-Ok "Zaktualizowano changelog.php"
} }

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
ALTER TABLE pp_shop_payment_methods ADD COLUMN min_order_amount DECIMAL(10,2) DEFAULT NULL;
ALTER TABLE pp_shop_payment_methods ADD COLUMN max_order_amount DECIMAL(10,2) DEFAULT NULL;