|
|
@@ -347,7 +347,7 @@ class WordPressImport {
|
|
|
|
|
|
// Insert post
|
|
|
$this->targetDb->query(
|
|
|
- "INSERT INTO publications (title, slug, content, summary, author, status, created_at, updated_at, published_at)
|
|
|
+ "INSERT INTO publications (title, slug, content, summary, author, status, created_at, updated_at, published_at,wp_post_id)
|
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
|
|
[
|
|
|
$wpPost['post_title'],
|
|
|
@@ -358,7 +358,8 @@ class WordPressImport {
|
|
|
$status,
|
|
|
$wpPost['post_date'],
|
|
|
$wpPost['post_modified'],
|
|
|
- ($status === 'published') ? $wpPost['post_date'] : null
|
|
|
+ ($status === 'published') ? $wpPost['post_date'] : null,
|
|
|
+ $wpPost['ID']
|
|
|
]
|
|
|
);
|
|
|
|
|
|
@@ -415,35 +416,31 @@ class WordPressImport {
|
|
|
|
|
|
$comments = $stmt->fetchAll();
|
|
|
|
|
|
- // Build a map of post IDs to publication IDs
|
|
|
+ // Build a map of WordPress post IDs to publication IDs using wp_post_id field
|
|
|
$postIds = array_unique(array_column($comments, 'comment_post_ID'));
|
|
|
$publicationMap = [];
|
|
|
|
|
|
if (!empty($postIds)) {
|
|
|
$placeholders = str_repeat('?,', count($postIds) - 1) . '?';
|
|
|
$pubStmt = $this->targetDb->query("
|
|
|
- SELECT id, slug, title FROM publications
|
|
|
- WHERE slug IN ($placeholders) OR title IN ($placeholders)
|
|
|
- ", array_merge($postIds, $postIds));
|
|
|
+ SELECT id, wp_post_id FROM publications
|
|
|
+ WHERE wp_post_id IN ($placeholders)
|
|
|
+ ", $postIds);
|
|
|
|
|
|
foreach ($pubStmt->fetchAll() as $pub) {
|
|
|
- // Map both slug and title for easier lookup
|
|
|
- $publicationMap[strtolower($pub['slug'])] = $pub['id'];
|
|
|
- $publicationMap[strtolower($pub['title'])] = $pub['id'];
|
|
|
+ // Map WordPress post ID to publication ID
|
|
|
+ $publicationMap[$pub['wp_post_id']] = $pub['id'];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
foreach ($comments as $wpComment) {
|
|
|
try {
|
|
|
- // Find corresponding publication using preloaded map
|
|
|
+ // Find corresponding publication using wp_post_id mapping
|
|
|
$publicationId = null;
|
|
|
- $postSlug = !empty($wpComment['post_name']) ? strtolower($wpComment['post_name']) : null;
|
|
|
- $postTitle = strtolower($wpComment['post_title']);
|
|
|
+ $wpPostId = $wpComment['comment_post_ID'];
|
|
|
|
|
|
- if ($postSlug && isset($publicationMap[$postSlug])) {
|
|
|
- $publicationId = $publicationMap[$postSlug];
|
|
|
- } elseif (isset($publicationMap[$postTitle])) {
|
|
|
- $publicationId = $publicationMap[$postTitle];
|
|
|
+ if (isset($publicationMap[$wpPostId])) {
|
|
|
+ $publicationId = $publicationMap[$wpPostId];
|
|
|
}
|
|
|
|
|
|
if (!$publicationId) {
|