|
@@ -311,6 +311,8 @@ class WordPressImport {
|
|
|
|
|
|
|
|
$posts = $stmt->fetchAll();
|
|
$posts = $stmt->fetchAll();
|
|
|
|
|
|
|
|
|
|
+ $this->log("Found " . count($posts) . " WordPress posts to import");
|
|
|
|
|
+
|
|
|
// Get all categories for all posts in one query
|
|
// Get all categories for all posts in one query
|
|
|
$postIds = array_column($posts, 'ID');
|
|
$postIds = array_column($posts, 'ID');
|
|
|
$categoriesMap = [];
|
|
$categoriesMap = [];
|
|
@@ -331,8 +333,10 @@ class WordPressImport {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- foreach ($posts as $wpPost) {
|
|
|
|
|
|
|
+ foreach ($posts as $index => $wpPost) {
|
|
|
try {
|
|
try {
|
|
|
|
|
+ $this->log("Processing post {$index}: '{$wpPost['post_title']}' (ID: {$wpPost['ID']})");
|
|
|
|
|
+
|
|
|
// Generate slug from post_name or title
|
|
// Generate slug from post_name or title
|
|
|
$slug = !empty($wpPost['post_name']) ? $wpPost['post_name'] : $this->generateSlug($wpPost['post_title']);
|
|
$slug = !empty($wpPost['post_name']) ? $wpPost['post_name'] : $this->generateSlug($wpPost['post_title']);
|
|
|
|
|
|
|
@@ -367,15 +371,20 @@ class WordPressImport {
|
|
|
|
|
|
|
|
// Link categories
|
|
// Link categories
|
|
|
if (!empty($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++;
|
|
$imported++;
|
|
|
- $this->log("Imported post: '{$wpPost['post_title']}'");
|
|
|
|
|
|
|
+ $this->log("Successfully imported post: '{$wpPost['post_title']}' (ID: {$wpPost['ID']})");
|
|
|
|
|
|
|
|
} catch (Exception $e) {
|
|
} 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');
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|