[CmdletBinding()] param( [string]$ComposeFile = (Join-Path $PSScriptRoot '..\docker-compose.yml'), [string]$OutputPath = (Join-Path $PSScriptRoot '..\database\contao-baseline.sql'), [switch]$Force ) $ErrorActionPreference = 'Stop' $tables = @('tl_theme', 'tl_layout', 'tl_module', 'tl_page', 'tl_article', 'tl_content', 'tl_form', 'tl_form_field') if ((Test-Path -LiteralPath $OutputPath) -and -not $Force) { $confirmation = Read-Host "Die Datei '$OutputPath' existiert bereits. Überschreiben? [j/N]" if ($confirmation.Trim().ToLowerInvariant() -notin @('j', 'ja', 'y', 'yes')) { Write-Host 'Export nicht überschrieben.' return } } $composeFile = (Resolve-Path -LiteralPath $ComposeFile).Path $outputDirectory = Split-Path -Parent $OutputPath New-Item -ItemType Directory -Path $outputDirectory -Force | Out-Null # Credentials bleiben im Compose-Service und werden nicht in den Export geschrieben. $command = 'exec mariadb-dump -u"$MARIADB_USER" -p"$MARIADB_PASSWORD" --no-tablespaces --no-create-info --skip-comments --skip-triggers --skip-add-locks --skip-disable-keys --complete-insert --skip-extended-insert --order-by-primary --hex-blob "$MARIADB_DATABASE" tl_theme tl_layout tl_module tl_page tl_article tl_content tl_form tl_form_field' $dump = & docker compose -f $composeFile exec -T db sh -lc $command if ($LASTEXITCODE -ne 0) { throw 'Der Contao-Baseline-Export ist fehlgeschlagen.' } $header = @( '-- Contao website baseline for local development.', '--', '-- Contains only versionable website data. It deliberately excludes users,', '-- credentials, sessions, logs, cache entries and file metadata.', '-- Generated with scripts/Export-ContaoBaseline.ps1.', '' ) $utf8WithoutBom = New-Object System.Text.UTF8Encoding($false) [System.IO.File]::WriteAllText( (Resolve-Path -LiteralPath $outputDirectory).Path + [System.IO.Path]::DirectorySeparatorChar + (Split-Path -Leaf $OutputPath), (($header + $dump) -join [Environment]::NewLine) + [Environment]::NewLine, $utf8WithoutBom ) Write-Host "Contao-Baseline exportiert nach $OutputPath"