Browse Source

Fix wordpress_import

svalavuo 4 ngày trước cách đây
mục cha
commit
8f963f363c
1 tập tin đã thay đổi với 34 bổ sung9 xóa
  1. 34 9
      includes/wordpress_import.php

+ 34 - 9
includes/wordpress_import.php

@@ -54,7 +54,15 @@ class WordPressImport {
             // Connect first
             $this->connectWordPress();
             
-            // Check if WordPress tables exist
+            // Simple connection test
+            $stmt = $this->wpDb->query("SELECT 1 as test");
+            $test = $stmt->fetch();
+            
+            if (!$test || $test['test'] != 1) {
+                throw new Exception("WordPress database connection test failed");
+            }
+            
+            // Check if WordPress tables exist (simplified)
             $tables = ['wp_posts', 'wp_users', 'wp_terms', 'wp_term_taxonomy', 'wp_term_relationships', 'wp_comments'];
             $existingTables = [];
             
@@ -69,14 +77,31 @@ class WordPressImport {
                 throw new Exception("WordPress database structure incomplete. Missing tables: " . implode(', ', array_diff($tables, $existingTables)));
             }
             
-            // Get basic stats
-            $stats = [
-                'posts' => $this->getPostCount(),
-                'pages' => $this->getPageCount(),
-                'categories' => $this->getCategoryCount(),
-                'users' => $this->getUserCount(),
-                'comments' => $this->getCommentCount()
-            ];
+            // Get basic stats with simple queries (avoid hanging)
+            $stats = [];
+            try {
+                $stats['posts'] = $this->wpDb->query("SELECT COUNT(*) FROM wp_posts WHERE post_type = 'post'")->fetchColumn();
+            } catch (Exception $e) {
+                $stats['posts'] = 0;
+            }
+            
+            try {
+                $stats['categories'] = $this->wpDb->query("SELECT COUNT(*) FROM wp_term_taxonomy WHERE taxonomy = 'category'")->fetchColumn();
+            } catch (Exception $e) {
+                $stats['categories'] = 0;
+            }
+            
+            try {
+                $stats['users'] = $this->wpDb->query("SELECT COUNT(*) FROM wp_users")->fetchColumn();
+            } catch (Exception $e) {
+                $stats['users'] = 0;
+            }
+            
+            try {
+                $stats['comments'] = $this->wpDb->query("SELECT COUNT(*) FROM wp_comments")->fetchColumn();
+            } catch (Exception $e) {
+                $stats['comments'] = 0;
+            }
             
             return ['success' => true, 'stats' => $stats, 'tables' => $existingTables];