Переглянути джерело

Debugging wordpress import

svalavuo 4 днів тому
батько
коміт
3b13a7e8db
2 змінених файлів з 51 додано та 9 видалено
  1. 28 4
      admin/wordpress_import.php
  2. 23 5
      includes/wordpress_import.php

+ 28 - 4
admin/wordpress_import.php

@@ -23,25 +23,49 @@ $connectionTest = null;
 // Handle form submission
 if ($_SERVER['REQUEST_METHOD'] === 'POST') {
     try {
+        // Debug: Log form submission
+        error_log('WordPress import form submitted');
+        
         // Get WordPress database configuration
         $wpConfig = [
-            'host' => trim($_POST['wp_host']),
-            'database' => trim($_POST['wp_database']),
-            'username' => trim($_POST['wp_username']),
-            'password' => $_POST['wp_password']
+            'host' => trim($_POST['wp_host'] ?? ''),
+            'database' => trim($_POST['wp_database'] ?? ''),
+            'username' => trim($_POST['wp_username'] ?? ''),
+            'password' => $_POST['wp_password'] ?? ''
         ];
         
+        // Debug: Log config (without password)
+        error_log('WP Config: ' . print_r([
+            'host' => $wpConfig['host'],
+            'database' => $wpConfig['database'],
+            'username' => $wpConfig['username'],
+            'password' => !empty($wpConfig['password']) ? '[SET]' : '[EMPTY]'
+        ], true));
+        
         // Validate required fields
         if (empty($wpConfig['host']) || empty($wpConfig['database']) || empty($wpConfig['username'])) {
             throw new Exception(t('wordpress_import_config_required'));
         }
         
+        // Debug: About to create importer
+        error_log('About to create WordPressImport instance');
+        
         // Create import instance
         $importer = new WordPressImport($wpConfig);
         
+        // Debug: Importer created successfully
+        error_log('WordPressImport instance created successfully');
+        
         if (isset($_POST['test_connection'])) {
+            // Debug: Testing connection
+            error_log('About to test WordPress connection');
+            
             // Test connection only
             $connectionTest = $importer->testConnection();
+            
+            // Debug: Connection test result
+            error_log('Connection test result: ' . print_r($connectionTest, true));
+            
             if ($connectionTest['success']) {
                 $message = t('wordpress_connection_success') . ': ' . 
                           t('posts') . ': ' . $connectionTest['stats']['posts'] . ', ' .

+ 23 - 5
includes/wordpress_import.php

@@ -14,7 +14,7 @@ class WordPressImport {
     public function __construct($wpConfig) {
         $this->wpConfig = $wpConfig;
         $this->targetDb = Database::getInstance();
-        $this->connectWordPress();
+        // Don't connect in constructor - connect on demand to avoid hanging
     }
     
     /**
@@ -22,13 +22,25 @@ class WordPressImport {
      */
     private function connectWordPress() {
         try {
+            // Set timeout options
+            $options = [
+                PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
+                PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
+                PDO::ATTR_TIMEOUT => 10, // 10 second timeout
+                PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8mb4"
+            ];
+            
             $dsn = "mysql:host={$this->wpConfig['host']};dbname={$this->wpConfig['database']};charset=utf8mb4";
-            $this->wpDb = new PDO($dsn, $this->wpConfig['username'], $this->wpConfig['password']);
-            $this->wpDb->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
-            $this->wpDb->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
+            $this->wpDb = new PDO($dsn, $this->wpConfig['username'], $this->wpConfig['password'], $options);
+            
+            // Test connection with a simple query
+            $this->wpDb->query("SELECT 1");
+            
             $this->log('Connected to WordPress database successfully');
-        } catch (Exception $e) {
+        } catch (PDOException $e) {
             throw new Exception("Failed to connect to WordPress database: " . $e->getMessage());
+        } catch (Exception $e) {
+            throw new Exception("WordPress database connection error: " . $e->getMessage());
         }
     }
     
@@ -37,6 +49,9 @@ class WordPressImport {
      */
     public function testConnection() {
         try {
+            // Connect first
+            $this->connectWordPress();
+            
             // Check if WordPress tables exist
             $tables = ['wp_posts', 'wp_users', 'wp_terms', 'wp_term_taxonomy', 'wp_term_relationships', 'wp_comments'];
             $existingTables = [];
@@ -75,6 +90,9 @@ class WordPressImport {
         $results = [];
         
         try {
+            // Connect to WordPress database first
+            $this->connectWordPress();
+            
             // Start transaction
             $this->targetDb->beginTransaction();