From b331c16ea45e5a0a0f2b261603951274a774ceec Mon Sep 17 00:00:00 2001 From: Jonny Date: Sat, 8 Aug 2026 17:41:12 +0200 Subject: [PATCH] docs: add implementation plan for content migration (phase 4/5) --- .../plans/2026-08-08-content-migration.md | 614 ++++++++++++++++++ 1 file changed, 614 insertions(+) create mode 100644 docs/superpowers/plans/2026-08-08-content-migration.md diff --git a/docs/superpowers/plans/2026-08-08-content-migration.md b/docs/superpowers/plans/2026-08-08-content-migration.md new file mode 100644 index 0000000..837e6be --- /dev/null +++ b/docs/superpowers/plans/2026-08-08-content-migration.md @@ -0,0 +1,614 @@ +# Content-Migration (Phase 4/5) Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Alle 163 News-Artikel und 12 relevante Standardseiten aus +`scrape/freunde-des-spessart-alt/` sind mit Autor, Datum, Tags und Bildern im Theme +"friends-spessart" sichtbar. + +**Architecture:** Ein PHP-Migrationsskript (`import.php`) liest die wp-json-REST-Dumps +und Medien, die zuvor per SFTP nach `/root/migration-data/` auf die VM übertragen +wurden, und legt Posts/Pages/Autoren/Bilder direkt über WordPress-Kernfunktionen an. +Ausführung über `wp eval-file`. Kein Docker, keine externen Abhängigkeiten. + +**Tech Stack:** PHP (WordPress-Funktionen: `wp_insert_post`, `wp_insert_attachment`, +`wp_insert_user`, `wp_kses`), WP-CLI (`wp eval-file`), Python + paramiko (SFTP-Transfer, +gleiches Muster wie in Phase 1-3 dieser Session). + +## Global Constraints + +- Quelle: `scrape/freunde-des-spessart-alt/www.freunde-des-spessarts.de/wp-json/wp/v2/` + (News, Pages, Tags, Users) und `.../wp-content/uploads/` (Bilder/PDFs) +- Staging-Verzeichnis auf der VM: `/root/migration-data/` (news/, pages/, tags/, users/, + uploads/) — wird nach erfolgreicher Migration gelöscht (Task 6) +- Ausgeschlossene Seiten-IDs: `2` (alte Homepage, Elementor, ersetzt durch + `front-page.php`) und `134` (alte Aktuelles-Listing-Seite, ersetzt durch + `archive-news.php`) +- Zu importierende Seiten-IDs (12): `1049, 1068, 1073, 1105, 1173, 1302, 1539, 179, 186, + 21, 904, 972` +- Jede JSON-Datei beginnt mit PHP-Debug-Text vor dem eigentlichen JSON — immer ab dem + ersten `{` parsen +- Bild-/PDF-URLs im Content zeigen auf `https://www.freunde-des-spessarts.de/wp-content/ + uploads/...` — Pfad nach `/wp-content/uploads/` entspricht 1:1 der lokalen Datei unter + `/root/migration-data/uploads/...` +- Elementor-Content wird erkannt an `data-elementor-type` im HTML und mit `wp_kses()` + bereinigt (siehe Task 5) +- Alle SSH/SFTP-Aufrufe nutzen die etablierten Skripte dieser Session + (`ssh_exec.py`, `sftp_put.py`) mit `MSYS_NO_PATHCONV=1`. In allen Befehlen unten steht + `scratchpad/` als Kurzform für das tatsächliche Scratchpad-Verzeichnis dieser Session: + `C:\Users\Jonny\AppData\Local\Temp\claude\C--Users-Jonny-Projekte-Claude-Freunde-des-Spessart\29772c32-a659-4acf-bc34-8d783886e514\scratchpad`. + Falls dieser Plan in einer neuen Session/von einem frischen Subagenten ausgeführt wird, + der kein eigenes Scratchpad-Verzeichnis mit diesen Hilfsskripten hat: `ssh_exec.py` und + `sftp_put.py` sind einfache paramiko-Skripte (siehe deren Verwendung unten für die + erwartete Signatur `python ssh_exec.py ""` bzw. + `python sftp_put.py `) und müssen dann zuerst neu angelegt + werden, bevor Task 1 beginnt + +--- + +### Task 1: Staging-Daten auf die VM übertragen + +**Files (lokal, Quelle):** +- `scrape/freunde-des-spessart-alt/www.freunde-des-spessarts.de/wp-json/wp/v2/news/*.html` +- `scrape/freunde-des-spessart-alt/www.freunde-des-spessarts.de/wp-json/wp/v2/pages/{1049,1068,1073,1105,1173,1302,1539,179,186,21,904,972}.html` +- `scrape/freunde-des-spessart-alt/www.freunde-des-spessarts.de/wp-json/wp/v2/tags/*.html` +- `scrape/freunde-des-spessart-alt/www.freunde-des-spessarts.de/wp-json/wp/v2/users/*.html` +- `scrape/freunde-des-spessart-alt/www.freunde-des-spessarts.de/wp-content/uploads/**` + +**Interfaces:** +- Produziert: `/root/migration-data/{news,pages,tags,users,uploads}/` auf der VM, das + Task 2-5 lesen + +- [ ] **Step 1: Zielverzeichnisse auf der VM anlegen** + +```bash +python scratchpad/ssh_exec.py "mkdir -p /root/migration-data/news /root/migration-data/pages /root/migration-data/tags /root/migration-data/users /root/migration-data/uploads" +``` + +- [ ] **Step 2: Ein rekursives SFTP-Upload-Skript für ganze Verzeichnisse schreiben** + +Erweiterung des bestehenden Musters (`scratchpad/sftp_put.py` kopiert nur Einzeldateien). +Neues Skript `scratchpad/sftp_put_dir.py`: + +```python +import paramiko, socket, sys, os + +host = "10.19.1.37" +user = "root" +password = "FreundeSpessart" + +local_dir = sys.argv[1] +remote_dir = sys.argv[2] + +sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +sock.settimeout(15) +sock.connect((host, 22)) +t = paramiko.Transport(sock) +t.start_client(timeout=15) +t.auth_password(user, password) +sftp = t.open_sftp_client() + +def ensure_remote_dir(path): + parts = path.split("/") + cur = "" + for p in parts: + if not p: + continue + cur += "/" + p + try: + sftp.stat(cur) + except FileNotFoundError: + sftp.mkdir(cur) + +count = 0 +for root, dirs, files in os.walk(local_dir): + rel = os.path.relpath(root, local_dir) + target_dir = remote_dir if rel == "." else remote_dir + "/" + rel.replace("\\", "/") + ensure_remote_dir(target_dir) + for f in files: + local_path = os.path.join(root, f) + remote_path = target_dir + "/" + f + sftp.put(local_path, remote_path) + count += 1 + if count % 100 == 0: + print(f"... {count} Dateien uebertragen", flush=True) + +print(f"FERTIG: {count} Dateien uebertragen") +sftp.close() +t.close() +``` + +- [ ] **Step 3: News-, Tags-, Users-JSONs übertragen (ganze Verzeichnisse)** + +```bash +MSYS_NO_PATHCONV=1 python scratchpad/sftp_put_dir.py "scrape/freunde-des-spessart-alt/www.freunde-des-spessarts.de/wp-json/wp/v2/news" "/root/migration-data/news" +MSYS_NO_PATHCONV=1 python scratchpad/sftp_put_dir.py "scrape/freunde-des-spessart-alt/www.freunde-des-spessarts.de/wp-json/wp/v2/tags" "/root/migration-data/tags" +MSYS_NO_PATHCONV=1 python scratchpad/sftp_put_dir.py "scrape/freunde-des-spessart-alt/www.freunde-des-spessarts.de/wp-json/wp/v2/users" "/root/migration-data/users" +``` + +- [ ] **Step 4: Die 12 relevanten Pages-JSONs einzeln übertragen** + +```bash +MSYS_NO_PATHCONV=1 python -c " +import subprocess +ids = [1049,1068,1073,1105,1173,1302,1539,179,186,21,904,972] +for i in ids: + subprocess.run(['python', 'scratchpad/sftp_put.py', + f'scrape/freunde-des-spessart-alt/www.freunde-des-spessarts.de/wp-json/wp/v2/pages/{i}.html', + f'/root/migration-data/pages/{i}.html'], check=True) +" +``` + +- [ ] **Step 5: Uploads-Verzeichnis übertragen (größter Batch, ca. 260 MB)** + +```bash +MSYS_NO_PATHCONV=1 python scratchpad/sftp_put_dir.py "scrape/freunde-des-spessart-alt/www.freunde-des-spessarts.de/wp-content/uploads" "/root/migration-data/uploads" +``` + +- [ ] **Step 6: Übertragung verifizieren** + +```bash +python scratchpad/ssh_exec.py "find /root/migration-data/news -name '*.html' | wc -l; find /root/migration-data/pages -name '*.html' | wc -l; find /root/migration-data/tags -name '*.html' | wc -l; find /root/migration-data/users -name '*.html' | wc -l; find /root/migration-data/uploads -type f | wc -l" +``` + +Erwartet: 164 News, 12 Pages, Tags-Anzahl > 0, 4 Users, ~521 Uploads-Dateien (siehe +`docs/struktur-alt.md`). + +--- + +### Task 2: Migrationsskript-Grundgerüst und Autoren-Import + +**Files (lokal, dann per SFTP auf die VM nach `/root/migration-data/import.php`):** +- Create: `scratchpad/migration/import.php` + +**Interfaces:** +- Produziert: Funktionen `fds_migrate_load_json()`, `fds_migrate_create_authors()`, die + Task 4 und 5 nutzen + +- [ ] **Step 1: Skript-Grundgerüst mit JSON-Loader und Autoren-Funktion schreiben** + +```php + friends-spessart Theme +// Ausfuehrung: wp eval-file /root/migration-data/import.php --allow-root + +define( 'FDS_MIGRATE_DATA', '/root/migration-data' ); + +function fds_migrate_load_json( $path ) { + $raw = file_get_contents( $path ); + if ( $raw === false ) return null; + $pos = strpos( $raw, '{' ); + if ( $pos === false ) return null; + $data = json_decode( substr( $raw, $pos ), true ); + return json_last_error() === JSON_ERROR_NONE ? $data : null; +} + +function fds_migrate_create_authors() { + $map = array(); + foreach ( glob( FDS_MIGRATE_DATA . '/users/*.html' ) as $file ) { + $data = fds_migrate_load_json( $file ); + if ( ! $data || empty( $data['slug'] ) ) continue; + $old_id = $data['id']; + $existing = get_user_by( 'slug', $data['slug'] ); + if ( $existing ) { + $map[ $old_id ] = $existing->ID; + continue; + } + $new_id = wp_insert_user( array( + 'user_login' => $data['slug'], + 'user_pass' => wp_generate_password( 24, true ), + 'user_email' => $data['slug'] . '@freunde-des-spessarts.de', + 'display_name' => $data['name'], + 'nickname' => $data['name'], + 'role' => 'author', + ) ); + if ( is_wp_error( $new_id ) ) { + WP_CLI::warning( "Autor {$data['slug']} konnte nicht angelegt werden: " . $new_id->get_error_message() ); + continue; + } + $map[ $old_id ] = $new_id; + } + return $map; +} + +$fds_author_map = fds_migrate_create_authors(); +WP_CLI::log( 'Autoren-Mapping: ' . print_r( $fds_author_map, true ) ); +``` + +- [ ] **Step 2: Skript auf die VM übertragen** + +```bash +MSYS_NO_PATHCONV=1 python scratchpad/sftp_put.py "scratchpad/migration/import.php" "/root/migration-data/import.php" +``` + +- [ ] **Step 3: Testlauf und Verifikation** + +```bash +python scratchpad/ssh_exec.py "cd /var/www/freunde-des-spessart && wp eval-file /root/migration-data/import.php --allow-root && wp user list --role=author --fields=user_login,display_name --allow-root" +``` + +Erwartet: 4 Zeilen mit `s-fiederling`, `d-simon`, `s-scharrer`, `c-kunkel` und den +jeweiligen Anzeigenamen. + +--- + +### Task 3: Bild-Migrations-Funktion schreiben und testen + +**Files:** +- Modify: `scratchpad/migration/import.php` + +**Interfaces:** +- Konsumiert: `/root/migration-data/uploads/` aus Task 1 +- Produziert: `fds_migrate_image_by_url()`, `fds_migrate_content_images()`, die Task 4 + und 5 nutzen + +- [ ] **Step 1: Funktionen an `import.php` anhängen** + +```php +function fds_migrate_image_by_url( $old_url, &$cache ) { + if ( isset( $cache[ $old_url ] ) ) return $cache[ $old_url ]; + + $marker = '/wp-content/uploads/'; + $pos = strpos( $old_url, $marker ); + if ( $pos === false ) return null; + + $rel = substr( $old_url, $pos + strlen( $marker ) ); + $local_path = FDS_MIGRATE_DATA . '/uploads/' . $rel; + if ( ! file_exists( $local_path ) ) { + $cache[ $old_url ] = null; + return null; + } + + $filename = basename( $local_path ); + $filetype = wp_check_filetype( $filename ); + $upload = wp_upload_bits( $filename, null, file_get_contents( $local_path ) ); + if ( ! empty( $upload['error'] ) ) { + $cache[ $old_url ] = null; + return null; + } + + $attachment = array( + 'post_mime_type' => $filetype['type'], + 'post_title' => sanitize_file_name( $filename ), + 'post_content' => '', + 'post_status' => 'inherit', + ); + $attach_id = wp_insert_attachment( $attachment, $upload['file'] ); + require_once ABSPATH . 'wp-admin/includes/image.php'; + $attach_data = wp_generate_attachment_metadata( $attach_id, $upload['file'] ); + wp_update_attachment_metadata( $attach_id, $attach_data ); + + $cache[ $old_url ] = $attach_id; + return $attach_id; +} + +function fds_migrate_content_images( $content, &$cache ) { + $first_id = null; + $content = preg_replace_callback( + '#https://www\.freunde-des-spessarts\.de/wp-content/uploads/[^\s"\'<>)]+#', + function ( $m ) use ( &$cache, &$first_id ) { + $attach_id = fds_migrate_image_by_url( $m[0], $cache ); + if ( $attach_id ) { + if ( $first_id === null ) $first_id = $attach_id; + return wp_get_attachment_url( $attach_id ); + } + return $m[0]; + }, + $content + ); + return array( $content, $first_id ); +} +``` + +- [ ] **Step 2: Skript aktualisieren und mit Testaufruf verifizieren** + +```bash +MSYS_NO_PATHCONV=1 python scratchpad/sftp_put.py "scratchpad/migration/import.php" "/root/migration-data/import.php" +``` + +An das Ende der lokalen `import.php` (nur für diesen Testlauf, wird in Task 4 wieder +entfernt) temporär anhängen und mit hochladen: + +```php +$fds_test_cache = array(); +$fds_test_id = fds_migrate_image_by_url( + 'https://www.freunde-des-spessarts.de/wp-content/uploads/2021/03/image001-300x224.png', + $fds_test_cache +); +WP_CLI::log( 'Test-Bild-Attachment-ID: ' . var_export( $fds_test_id, true ) ); +``` + +```bash +python scratchpad/ssh_exec.py "cd /var/www/freunde-des-spessart && wp eval-file /root/migration-data/import.php --allow-root && wp media list --allow-root | tail -3" +``` + +Erwartet: `Test-Bild-Attachment-ID` ist eine Zahl (kein `NULL`), `wp media list` zeigt das +neu angelegte Bild. + +- [ ] **Step 3: Testaufruf-Block wieder aus `import.php` entfernen** + +Bevor Task 4 fortsetzt, den in Step 2 angehängten Testblock aus +`scratchpad/migration/import.php` löschen (er würde sonst bei jedem weiteren Lauf ein +Test-Duplikat anlegen). + +--- + +### Task 4: News-Artikel importieren + +**Files:** +- Modify: `scratchpad/migration/import.php` + +**Interfaces:** +- Konsumiert: `fds_migrate_load_json()`, `fds_migrate_create_authors()` (Task 2), + `fds_migrate_content_images()` (Task 3) +- Produziert: 163 Posts vom Typ `news` + +- [ ] **Step 1: Tag-Namen-Loader und News-Import-Funktion anhängen** + +```php +function fds_migrate_load_tag_names() { + $map = array(); + foreach ( glob( FDS_MIGRATE_DATA . '/tags/*.html' ) as $file ) { + $data = fds_migrate_load_json( $file ); + if ( $data && isset( $data['id'], $data['name'] ) ) { + $map[ $data['id'] ] = $data['name']; + } + } + return $map; +} + +function fds_migrate_news_item( $file, $author_map, $tag_names, &$image_cache ) { + $data = fds_migrate_load_json( $file ); + if ( ! $data || empty( $data['type'] ) || $data['type'] !== 'news' ) return false; + + list( $content, $first_image_id ) = fds_migrate_content_images( $data['content']['rendered'], $image_cache ); + $author_id = isset( $author_map[ $data['author'] ] ) ? $author_map[ $data['author'] ] : 1; + + $post_id = wp_insert_post( array( + 'post_type' => 'news', + 'post_title' => $data['title']['rendered'], + 'post_content' => $content, + 'post_excerpt' => wp_strip_all_tags( $data['excerpt']['rendered'] ), + 'post_status' => 'publish', + 'post_date' => $data['date'], + 'post_date_gmt' => $data['date_gmt'], + 'post_name' => $data['slug'], + 'post_author' => $author_id, + ) ); + if ( is_wp_error( $post_id ) || ! $post_id ) return false; + + if ( ! empty( $data['tags'] ) ) { + $names = array(); + foreach ( $data['tags'] as $tag_id ) { + if ( isset( $tag_names[ $tag_id ] ) ) $names[] = $tag_names[ $tag_id ]; + } + if ( $names ) wp_set_post_tags( $post_id, $names ); + } + + if ( $first_image_id ) set_post_thumbnail( $post_id, $first_image_id ); + + return $post_id; +} +``` + +- [ ] **Step 2: Treiber-Codeblock für den Testlauf (3 Artikel) anhängen** + +```php +$fds_tag_names = fds_migrate_load_tag_names(); +$fds_image_cache = array(); +$fds_news_files = glob( FDS_MIGRATE_DATA . '/news/*.html' ); +sort( $fds_news_files ); +$fds_test_files = array_slice( $fds_news_files, 0, 3 ); + +$fds_ok = 0; $fds_fail = 0; +foreach ( $fds_test_files as $file ) { + $result = fds_migrate_news_item( $file, $fds_author_map, $fds_tag_names, $fds_image_cache ); + if ( $result ) { $fds_ok++; } else { $fds_fail++; WP_CLI::warning( "Fehlgeschlagen: $file" ); } +} +WP_CLI::log( "News-Testlauf: $fds_ok erfolgreich, $fds_fail fehlgeschlagen" ); +``` + +- [ ] **Step 3: Hochladen und Testlauf ausführen** + +```bash +MSYS_NO_PATHCONV=1 python scratchpad/sftp_put.py "scratchpad/migration/import.php" "/root/migration-data/import.php" +python scratchpad/ssh_exec.py "cd /var/www/freunde-des-spessart && wp eval-file /root/migration-data/import.php --allow-root && wp post list --post_type=news --fields=ID,post_title,post_date --allow-root" +``` + +Erwartet: 3 News-Artikel in der Liste, `News-Testlauf: 3 erfolgreich, 0 fehlgeschlagen`. + +- [ ] **Step 4: Testartikel wieder löschen** + +```bash +python scratchpad/ssh_exec.py "cd /var/www/freunde-des-spessart && wp post list --post_type=news --field=ID --allow-root | xargs -r -I{} wp post delete {} --force --allow-root" +``` + +- [ ] **Step 5: Treiber-Codeblock auf den vollständigen Lauf umstellen** + +In `scratchpad/migration/import.php` den in Step 2 angehängten Block ersetzen durch: + +```php +$fds_tag_names = fds_migrate_load_tag_names(); +$fds_image_cache = array(); +$fds_news_files = glob( FDS_MIGRATE_DATA . '/news/*.html' ); +sort( $fds_news_files ); + +$fds_ok = 0; $fds_fail = 0; +foreach ( $fds_news_files as $file ) { + $result = fds_migrate_news_item( $file, $fds_author_map, $fds_tag_names, $fds_image_cache ); + if ( $result ) { $fds_ok++; } else { $fds_fail++; WP_CLI::warning( "Fehlgeschlagen: $file" ); } +} +WP_CLI::log( "News-Import: $fds_ok erfolgreich, $fds_fail fehlgeschlagen von " . count( $fds_news_files ) ); +``` + +- [ ] **Step 6: Vollständigen News-Import ausführen und verifizieren** + +```bash +MSYS_NO_PATHCONV=1 python scratchpad/sftp_put.py "scratchpad/migration/import.php" "/root/migration-data/import.php" +python scratchpad/ssh_exec.py "cd /var/www/freunde-des-spessart && wp eval-file /root/migration-data/import.php --allow-root" +python scratchpad/ssh_exec.py "cd /var/www/freunde-des-spessart && wp post list --post_type=news --allow-root | wc -l" +``` + +Erwartet: Log zeigt 163 (oder nahe daran, siehe Hinweis unten) erfolgreiche Importe, +`wp post list` zeigt 164 Zeilen (163 Artikel + Kopfzeile). + +**Hinweis:** Von den 164 gefundenen News-JSON-Dateien ist eine (`type` ungleich `news` +oder defekt) ggf. keine echte News — laut `docs/struktur-alt.md` sind 163 echte Artikel +zu erwarten. Kleinere Abweichungen (±1-2) sind plausibel und kein Abbruchkriterium, +solange die Warnmeldungen im Log nachvollziehbar sind. + +- [ ] **Step 7: Treiber-Codeblock aus Step 5 wieder aus `import.php` entfernen** + +Wichtig, bevor Task 5 fortsetzt: `wp eval-file` führt bei jedem Aufruf die komplette +Datei erneut aus. Bliebe der News-Treiber-Block (Step 5) stehen, würde Task 5 ihn beim +nächsten Lauf ein zweites Mal ausführen und alle 163 Artikel duplizieren (kein +Slug-Abgleich in `fds_migrate_news_item()`, anders als bei den Seiten in Task 5, die +über `get_page_by_path()` bereits vorhandene Einträge erkennen). In +`scratchpad/migration/import.php` bleiben nur die Funktionsdefinitionen sowie die +Zeile `$fds_author_map = fds_migrate_create_authors();` (die ist idempotent, da sie +vorhandene Nutzer per `get_user_by( 'slug', ... )` erkennt) stehen — der komplette +Block ab `$fds_tag_names = fds_migrate_load_tag_names();` bis zum abschließenden +`WP_CLI::log( "News-Import: ..." )` wird gelöscht. Datei danach erneut hochladen: + +```bash +MSYS_NO_PATHCONV=1 python scratchpad/sftp_put.py "scratchpad/migration/import.php" "/root/migration-data/import.php" +``` + +--- + +### Task 5: Standardseiten importieren (inkl. Elementor-Bereinigung) + +**Files:** +- Modify: `scratchpad/migration/import.php` + +**Interfaces:** +- Konsumiert: dieselben Hilfsfunktionen wie Task 4 + +- [ ] **Step 1: HTML-Bereinigungs- und Seiten-Import-Funktion anhängen** + +```php +function fds_migrate_clean_html( $html ) { + $allowed = array( + 'h1' => array(), 'h2' => array(), 'h3' => array(), 'h4' => array(), + 'p' => array(), + 'a' => array( 'href' => true, 'target' => true, 'rel' => true ), + 'img'=> array( 'src' => true, 'alt' => true ), + 'ul' => array(), 'ol' => array(), 'li' => array(), + 'strong' => array(), 'em' => array(), 'br' => array(), + ); + $clean = wp_kses( $html, $allowed ); + $clean = preg_replace( '/

(\s| )*<\/p>/', '', $clean ); + $clean = preg_replace( "/\n{3,}/", "\n\n", $clean ); + return trim( $clean ); +} + +function fds_migrate_page_item( $file, $author_map, &$image_cache ) { + $data = fds_migrate_load_json( $file ); + if ( ! $data ) return false; + + $raw_content = $data['content']['rendered']; + $is_elementor = strpos( $raw_content, 'data-elementor-type' ) !== false; + + list( $content, $first_image_id ) = fds_migrate_content_images( $raw_content, $image_cache ); + if ( $is_elementor ) $content = fds_migrate_clean_html( $content ); + + $author_id = isset( $author_map[ $data['author'] ] ) ? $author_map[ $data['author'] ] : 1; + + $existing = get_page_by_path( $data['slug'] ); + $postarr = array( + 'post_type' => 'page', + 'post_title' => $data['title']['rendered'], + 'post_content' => $content, + 'post_status' => 'publish', + 'post_date' => $data['date'], + 'post_date_gmt' => $data['date_gmt'], + 'post_name' => $data['slug'], + 'post_author' => $author_id, + ); + if ( $existing ) $postarr['ID'] = $existing->ID; + + $post_id = wp_insert_post( $postarr ); + if ( is_wp_error( $post_id ) || ! $post_id ) return false; + + if ( $first_image_id ) set_post_thumbnail( $post_id, $first_image_id ); + + return $post_id; +} +``` + +- [ ] **Step 2: Treiber-Codeblock für alle 12 Seiten anhängen** + +```php +$fds_image_cache = array(); +$fds_page_ids = array( 1049, 1068, 1073, 1105, 1173, 1302, 1539, 179, 186, 21, 904, 972 ); +$fds_page_ok = 0; $fds_page_fail = 0; +foreach ( $fds_page_ids as $id ) { + $file = FDS_MIGRATE_DATA . "/pages/{$id}.html"; + $result = fds_migrate_page_item( $file, $fds_author_map, $fds_image_cache ); + if ( $result ) { $fds_page_ok++; } else { $fds_page_fail++; WP_CLI::warning( "Seite fehlgeschlagen: $file" ); } +} +WP_CLI::log( "Seiten-Import: $fds_page_ok erfolgreich, $fds_page_fail fehlgeschlagen von " . count( $fds_page_ids ) ); +``` + +- [ ] **Step 3: Hochladen, ausführen, verifizieren** + +```bash +MSYS_NO_PATHCONV=1 python scratchpad/sftp_put.py "scratchpad/migration/import.php" "/root/migration-data/import.php" +python scratchpad/ssh_exec.py "cd /var/www/freunde-des-spessart && wp eval-file /root/migration-data/import.php --allow-root" +python scratchpad/ssh_exec.py "cd /var/www/freunde-des-spessart && wp post list --post_type=page --fields=ID,post_title,post_name --allow-root" +``` + +Erwartet: `Seiten-Import: 12 erfolgreich, 0 fehlgeschlagen`, 12 neue Seiten in der Liste +(zusätzlich zu den WordPress-Standardseiten aus der Grundinstallation). + +--- + +### Task 6: Gesamtverifikation und Aufräumen + +**Files:** keine + +**Interfaces:** +- Konsumiert: Ergebnisse aus Task 4 und 5 + +- [ ] **Step 1: Zähler-Verifikation** + +```bash +python scratchpad/ssh_exec.py "cd /var/www/freunde-des-spessart && echo NEWS: && wp post list --post_type=news --allow-root | wc -l && echo PAGES: && wp post list --post_type=page --allow-root | wc -l && echo MEDIA: && wp media list --allow-root | wc -l" +``` + +- [ ] **Step 2: Visuelle Stichprobe im Browser** + +Mit dem in dieser Session etablierten SSH-Tunnel-Verfahren (`scratchpad/ssh_tunnel.py`, +`siteurl`/`home` temporär auf `http://localhost:8080` umstellen, danach zurücksetzen — +siehe Vorgehen aus Phase 3) mindestens folgende Seiten aufrufen und per Screenshot +prüfen: +- Die Startseite `/` — News-Teaser-Grid zeigt jetzt echte Artikel mit Bildern +- Einen News-Artikel mit migriertem Bild im Content +- Einen News-Artikel ohne Bilder im Original (Text-only-Darstellung sauber) +- Eine der 7 ehemals Elementor-basierten Seiten — kein rohes Elementor-Markup sichtbar, + Text/Bilder vorhanden +- Eine der 5 ursprünglich einfachen Seiten + +Erwartet: keine PHP-Fehler/Warnungen sichtbar, Bilder laden, Texte lesbar formatiert. + +- [ ] **Step 3: Staging-Daten auf der VM löschen** + +```bash +python scratchpad/ssh_exec.py "rm -rf /root/migration-data" +``` + +- [ ] **Step 4: Migrations-Spec-Dokument mit Ergebnis aktualisieren und committen** + +```bash +# Lokal: +# "## Status"-Abschnitt mit den finalen Zahlen (News/Pages/Medien) an +# docs/superpowers/specs/2026-08-08-content-migration-design.md anhängen +git add docs/superpowers/specs/2026-08-08-content-migration-design.md +git commit -m "docs: mark content migration as implemented" +``` + +## Nach Abschluss + +Phase 4 ist fertig, wenn alle sechs Tasks verifiziert sind, News-Artikel und Seiten +live im Theme sichtbar sind und die Staging-Daten von der VM entfernt wurden. Nächster +Schritt: Phase 5 (Go-Live auf IONOS) — eigener Spec/Plan, deutlich später im Projekt.