瀏覽代碼

fixing WP import

svalavuo 4 天之前
父節點
當前提交
b8dbbe3170
共有 1 個文件被更改,包括 14 次插入5 次删除
  1. 14 5
      includes/wordpress_import.php

+ 14 - 5
includes/wordpress_import.php

@@ -311,6 +311,8 @@ class WordPressImport {
             
             $posts = $stmt->fetchAll();
             
+            $this->log("Found " . count($posts) . " WordPress posts to import");
+            
             // Get all categories for all posts in one query
             $postIds = array_column($posts, 'ID');
             $categoriesMap = [];
@@ -331,8 +333,10 @@ class WordPressImport {
                 }
             }
             
-            foreach ($posts as $wpPost) {
+            foreach ($posts as $index => $wpPost) {
                 try {
+                    $this->log("Processing post {$index}: '{$wpPost['post_title']}' (ID: {$wpPost['ID']})");
+                    
                     // Generate slug from post_name or title
                     $slug = !empty($wpPost['post_name']) ? $wpPost['post_name'] : $this->generateSlug($wpPost['post_title']);
                     
@@ -367,15 +371,20 @@ class WordPressImport {
                     
                     // Link categories
                     if (!empty($categories)) {
-                        $this->linkPostCategories($publicationId, $categories);
+                        $placeholders = str_repeat('?,', count($categories) - 1) . '?';
+                        $this->targetDb->query("
+                            INSERT INTO publication_categories (publication_id, category_id) 
+                            SELECT ?, c.id FROM categories c 
+                            WHERE c.name IN ($placeholders)
+                        ", array_merge([$publicationId], $categories));
                     }
                     
                     $imported++;
-                    $this->log("Imported post: '{$wpPost['post_title']}'");
+                    $this->log("Successfully imported post: '{$wpPost['post_title']}' (ID: {$wpPost['ID']})");
                     
                 } catch (Exception $e) {
-                    $this->errors[] = "Error importing post '{$wpPost['post_title']}': " . $e->getMessage();
-                    $this->log("Error importing post '{$wpPost['post_title']}': " . $e->getMessage(), 'error');
+                    $skipped++;
+                    $this->log("Skipped post '{$wpPost['post_title']}' (ID: {$wpPost['ID']}): " . $e->getMessage(), 'error');
                 }
             }