|
@@ -406,26 +406,13 @@ class WordPressImport {
|
|
|
$skipped = 0;
|
|
$skipped = 0;
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- // Connect to WordPress database if not already connected
|
|
|
|
|
- if ($this->wpDb === null) {
|
|
|
|
|
- $this->connectWordPress();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Test basic WordPress comments query first
|
|
|
|
|
- $testStmt = $this->wpDb->query("SELECT COUNT(*) FROM wp_comments");
|
|
|
|
|
- $commentCount = $testStmt->fetchColumn();
|
|
|
|
|
- $this->log("WordPress comments table has {$commentCount} total comments");
|
|
|
|
|
-
|
|
|
|
|
- // Get WordPress comments with post info in one query
|
|
|
|
|
|
|
+ // Get comments from WordPress
|
|
|
$stmt = $this->wpDb->query("
|
|
$stmt = $this->wpDb->query("
|
|
|
- SELECT c.comment_ID, c.comment_post_ID, c.comment_author, c.comment_author_email,
|
|
|
|
|
- c.comment_content, c.comment_date, c.comment_approved, c.comment_parent,
|
|
|
|
|
- p.post_name, p.post_title
|
|
|
|
|
|
|
+ SELECT c.*, p.post_title
|
|
|
FROM wp_comments c
|
|
FROM wp_comments c
|
|
|
- JOIN wp_posts p ON c.comment_post_ID = p.ID
|
|
|
|
|
- WHERE p.post_type = 'post'
|
|
|
|
|
- ORDER BY c.comment_date
|
|
|
|
|
- LIMIT 2000
|
|
|
|
|
|
|
+ LEFT JOIN wp_posts p ON c.comment_post_ID = p.ID
|
|
|
|
|
+ WHERE c.comment_type = 'comment' AND c.comment_approved IN ('0', '1')
|
|
|
|
|
+ ORDER BY c.comment_date ASC
|
|
|
");
|
|
");
|
|
|
|
|
|
|
|
$comments = $stmt->fetchAll();
|
|
$comments = $stmt->fetchAll();
|
|
@@ -437,49 +424,22 @@ class WordPressImport {
|
|
|
$publicationMap = [];
|
|
$publicationMap = [];
|
|
|
|
|
|
|
|
if (!empty($postIds)) {
|
|
if (!empty($postIds)) {
|
|
|
- // Test if wp_post_id column exists and has values
|
|
|
|
|
- try {
|
|
|
|
|
- $testStmt = $this->targetDb->query("SELECT wp_post_id FROM publications LIMIT 1");
|
|
|
|
|
- $this->log("wp_post_id column exists in publications table");
|
|
|
|
|
-
|
|
|
|
|
- // Check if any publications have wp_post_id values
|
|
|
|
|
- $countStmt = $this->targetDb->query("SELECT COUNT(*) FROM publications WHERE wp_post_id IS NOT NULL");
|
|
|
|
|
- $wpPostIdCount = $countStmt->fetchColumn();
|
|
|
|
|
- $this->log("Found {$wpPostIdCount} publications with wp_post_id values");
|
|
|
|
|
-
|
|
|
|
|
- if ($wpPostIdCount == 0) {
|
|
|
|
|
- $this->log("No publications have wp_post_id values - comments cannot be mapped", 'error');
|
|
|
|
|
- return ['imported' => 0, 'skipped' => count($comments)];
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- } catch (Exception $e) {
|
|
|
|
|
- $this->log("Error: wp_post_id column does not exist in publications table: " . $e->getMessage(), 'error');
|
|
|
|
|
- $this->log("Skipping comments import - publications table needs wp_post_id column", 'error');
|
|
|
|
|
- return ['imported' => 0, 'skipped' => count($comments)];
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Try a simpler approach - query each post ID individually
|
|
|
|
|
- $this->log("Building publication map using individual queries");
|
|
|
|
|
|
|
+ // Build publication map using individual queries
|
|
|
foreach ($postIds as $postId) {
|
|
foreach ($postIds as $postId) {
|
|
|
try {
|
|
try {
|
|
|
$pubStmt = $this->targetDb->query("SELECT id FROM publications WHERE wp_post_id = ?", [$postId]);
|
|
$pubStmt = $this->targetDb->query("SELECT id FROM publications WHERE wp_post_id = ?", [$postId]);
|
|
|
$pub = $pubStmt->fetch();
|
|
$pub = $pubStmt->fetch();
|
|
|
if ($pub) {
|
|
if ($pub) {
|
|
|
$publicationMap[$postId] = $pub['id'];
|
|
$publicationMap[$postId] = $pub['id'];
|
|
|
- $this->log("Mapped WordPress post ID {$postId} to publication ID {$pub['id']}");
|
|
|
|
|
}
|
|
}
|
|
|
} catch (Exception $e) {
|
|
} catch (Exception $e) {
|
|
|
$this->log("Error mapping post ID {$postId}: " . $e->getMessage(), 'error');
|
|
$this->log("Error mapping post ID {$postId}: " . $e->getMessage(), 'error');
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- $this->log("Found " . count($publicationMap) . " publication mappings for comments");
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- foreach ($comments as $index => $wpComment) {
|
|
|
|
|
|
|
+ foreach ($comments as $wpComment) {
|
|
|
try {
|
|
try {
|
|
|
- $this->log("Processing comment {$index}: '{$wpComment['comment_content']}' (Post ID: {$wpComment['comment_post_ID']})");
|
|
|
|
|
-
|
|
|
|
|
// Find corresponding publication using wp_post_id mapping
|
|
// Find corresponding publication using wp_post_id mapping
|
|
|
$publicationId = null;
|
|
$publicationId = null;
|
|
|
$wpPostId = $wpComment['comment_post_ID'];
|
|
$wpPostId = $wpComment['comment_post_ID'];
|
|
@@ -490,7 +450,6 @@ class WordPressImport {
|
|
|
|
|
|
|
|
if (!$publicationId) {
|
|
if (!$publicationId) {
|
|
|
$skipped++;
|
|
$skipped++;
|
|
|
- $this->log("Comment skipped - no matching publication found for post ID {$wpComment['comment_post_ID']}");
|
|
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -501,7 +460,6 @@ class WordPressImport {
|
|
|
$parentId = null;
|
|
$parentId = null;
|
|
|
|
|
|
|
|
// Insert comment
|
|
// Insert comment
|
|
|
- $this->log("Executing INSERT for comment: '{$wpComment['comment_content']}' (Post ID: {$wpPostId})");
|
|
|
|
|
$pdo = $this->targetDb->getConnection();
|
|
$pdo = $this->targetDb->getConnection();
|
|
|
$commentStmt = $pdo->prepare("
|
|
$commentStmt = $pdo->prepare("
|
|
|
INSERT INTO comments (publication_id, parent_id, name, email, content, status, created_at, admin_reply, wp_comment_id)
|
|
INSERT INTO comments (publication_id, parent_id, name, email, content, status, created_at, admin_reply, wp_comment_id)
|
|
@@ -515,18 +473,15 @@ class WordPressImport {
|
|
|
$wpComment['comment_content'],
|
|
$wpComment['comment_content'],
|
|
|
$status,
|
|
$status,
|
|
|
$wpComment['comment_date'],
|
|
$wpComment['comment_date'],
|
|
|
- 0, // Use integer 0 for admin_reply instead of boolean false
|
|
|
|
|
|
|
+ 0, // Use integer 0 for admin_reply
|
|
|
$wpComment['comment_ID']
|
|
$wpComment['comment_ID']
|
|
|
]);
|
|
]);
|
|
|
|
|
|
|
|
- $commentId = $this->targetDb->getConnection()->lastInsertId();
|
|
|
|
|
-
|
|
|
|
|
$imported++;
|
|
$imported++;
|
|
|
- $this->log("Successfully imported comment: '{$wpComment['comment_content']}' (ID: {$wpComment['comment_ID']})");
|
|
|
|
|
|
|
|
|
|
} catch (Exception $e) {
|
|
} catch (Exception $e) {
|
|
|
$skipped++;
|
|
$skipped++;
|
|
|
- $this->log("Skipped comment '{$wpComment['comment_content']}' (ID: {$wpComment['comment_ID']}): " . $e->getMessage(), 'error');
|
|
|
|
|
|
|
+ $this->log("Skipped comment ID {$wpComment['comment_ID']}: " . $e->getMessage(), 'error');
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|