Procházet zdrojové kódy

Fix ajax_import and clean debug

svalavuo před 4 dny
rodič
revize
0a9ef0b21b

+ 5 - 0
admin/ajax_import_interface.html

@@ -46,6 +46,7 @@
             <button onclick="importCategories()">Import Categories</button>
             <button onclick="importUsers()">Import Users</button>
             <button onclick="importPosts()">Import Posts</button>
+            <button onclick="importComments()">Import Comments</button>
             <button onclick="clearLog()">Clear Log</button>
         </div>
         
@@ -128,6 +129,10 @@
             makeRequest('import_posts');
         }
 
+        function importComments() {
+            makeRequest('import_comments');
+        }
+
         function clearLog() {
             document.getElementById('log').innerHTML = '';
         }

+ 17 - 0
admin/ajax_import_test.php

@@ -103,6 +103,23 @@ try {
             ]);
             break;
             
+        case 'import_comments':
+            $wpConfig = [
+                'host' => trim($_GET['wp_host'] ?? ''),
+                'database' => trim($_GET['wp_database'] ?? ''),
+                'username' => trim($_GET['wp_username'] ?? ''),
+                'password' => $_GET['wp_password'] ?? ''
+            ];
+            
+            $importer = new WordPressImport($wpConfig);
+            $result = $importer->importComments();
+            
+            sendResponse(true, 'Comments imported', [
+                'step' => $step,
+                'result' => $result
+            ]);
+            break;
+            
         default:
             sendResponse(false, 'Unknown action', ['step' => $step]);
     }

+ 0 - 125
admin/debug_main_import.php

@@ -1,125 +0,0 @@
-<?php
-// Debug script to test main wordpress_import.php hanging issue
-error_reporting(E_ALL);
-ini_set('display_errors', 1);
-ini_set('max_execution_time', 30);
-ini_set('memory_limit', '256M');
-
-echo "<h1>Debug Main WordPress Import</h1>";
-
-// Test 1: Basic PHP and includes
-echo "<p>Step 1: Testing includes...</p>";
-
-try {
-    require_once '../includes/config.php';
-    echo "<p>✓ Config included</p>";
-} catch (Exception $e) {
-    echo "<p>✗ Config error: " . $e->getMessage() . "</p>";
-    exit;
-}
-
-try {
-    require_once '../includes/database.php';
-    echo "<p>✓ Database included</p>";
-} catch (Exception $e) {
-    echo "<p>✗ Database error: " . $e->getMessage() . "</p>";
-    exit;
-}
-
-try {
-    require_once '../includes/auth.php';
-    echo "<p>✓ Auth included</p>";
-} catch (Exception $e) {
-    echo "<p>✗ Auth error: " . $e->getMessage() . "</p>";
-    exit;
-}
-
-try {
-    require_once '../includes/translation.php';
-    echo "<p>✓ Translation included</p>";
-} catch (Exception $e) {
-    echo "<p>✗ Translation error: " . $e->getMessage() . "</p>";
-    exit;
-}
-
-try {
-    require_once '../includes/wordpress_import.php';
-    echo "<p>✓ WordPressImport included</p>";
-} catch (Exception $e) {
-    echo "<p>✗ WordPressImport error: " . $e->getMessage() . "</p>";
-    exit;
-}
-
-// Test 2: Auth system
-echo "<p>Step 2: Testing auth system...</p>";
-
-try {
-    $auth = new Auth();
-    echo "<p>✓ Auth instance created</p>";
-    
-    if ($auth->isLoggedIn()) {
-        echo "<p>✓ User is logged in</p>";
-        $user = $auth->getUser();
-        echo "<p>User: " . htmlspecialchars($user['username']) . " (Role: " . $user['role'] . ")</p>";
-    } else {
-        echo "<p>⚠ User not logged in</p>";
-    }
-} catch (Exception $e) {
-    echo "<p>✗ Auth error: " . $e->getMessage() . "</p>";
-    exit;
-}
-
-// Test 3: Database connection
-echo "<p>Step 3: Testing database connection...</p>";
-
-try {
-    $db = Database::getInstance();
-    echo "<p>✓ Database instance created</p>";
-    
-    $result = $db->query("SELECT 1 as test");
-    echo "<p>✓ Database query successful</p>";
-} catch (Exception $e) {
-    echo "<p>✗ Database error: " . $e->getMessage() . "</p>";
-    exit;
-}
-
-// Test 4: WordPressImport creation (same as main interface)
-echo "<p>Step 4: Testing WordPressImport creation...</p>";
-
-try {
-    $wpConfig = [
-        'host' => '10.15.10.8',
-        'database' => 'valtsu_valtsu',
-        'username' => 'root',
-        'password' => 'jotainaivanmuuta'
-    ];
-    
-    echo "<p>About to create WordPressImport...</p>";
-    $importer = new WordPressImport($wpConfig);
-    echo "<p>✓ WordPressImport created successfully</p>";
-    
-} catch (Exception $e) {
-    echo "<p>✗ WordPressImport creation error: " . $e->getMessage() . "</p>";
-    echo "<p>File: " . $e->getFile() . "</p>";
-    echo "<p>Line: " . $e->getLine() . "</p>";
-    exit;
-}
-
-// Test 5: Test connection (same as main interface)
-echo "<p>Step 5: Testing WordPress connection...</p>";
-
-try {
-    echo "<p>About to test connection...</p>";
-    $connectionTest = $importer->testConnection();
-    echo "<p>✓ Connection test completed</p>";
-    echo "<pre>" . print_r($connectionTest, true) . "</pre>";
-    
-} catch (Exception $e) {
-    echo "<p>✗ Connection test error: " . $e->getMessage() . "</p>";
-    echo "<p>File: " . $e->getFile() . "</p>";
-    echo "<p>Line: " . $e->getLine() . "</p>";
-    exit;
-}
-
-echo "<h2>All tests completed successfully!</h2>";
-?>

+ 0 - 122
admin/minimal_import_test.php

@@ -1,122 +0,0 @@
-<?php
-// Minimal test to isolate exact hanging point in wordpress_import.php
-error_reporting(E_ALL);
-ini_set('display_errors', 1);
-ini_set('max_execution_time', 30);
-ini_set('memory_limit', '256M');
-
-echo "<h1>Minimal WordPress Import Test</h1>";
-echo "<p>Step 1: PHP working</p>";
-
-// Test 2: Basic includes without auth
-echo "<p>Step 2: Testing basic includes...</p>";
-
-try {
-    require_once '../includes/config.php';
-    echo "<p>✓ Config included</p>";
-} catch (Exception $e) {
-    echo "<p>✗ Config error: " . $e->getMessage() . "</p>";
-    exit;
-}
-
-try {
-    require_once '../includes/database.php';
-    echo "<p>✓ Database included</p>";
-} catch (Exception $e) {
-    echo "<p>✗ Database error: " . $e->getMessage() . "</p>";
-    exit;
-}
-
-// Test 3: Database connection
-echo "<p>Step 3: Testing database connection...</p>";
-
-try {
-    $db = Database::getInstance();
-    echo "<p>✓ Database instance created</p>";
-    
-    $result = $db->query("SELECT 1 as test");
-    echo "<p>✓ Database query successful</p>";
-} catch (Exception $e) {
-    echo "<p>✗ Database error: " . $e->getMessage() . "</p>";
-    exit;
-}
-
-// Test 4: WordPress connection (same as main interface)
-echo "<p>Step 4: Testing WordPress connection...</p>";
-
-$wpConfig = [
-    'host' => '10.15.10.8',
-    'database' => 'valtsu_valtsu',
-    'username' => 'root',
-    'password' => 'jotainaivanmuuta'
-];
-
-try {
-    echo "<p>About to connect to WordPress...</p>";
-    
-    // Set timeout options
-    $options = [
-        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
-        PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
-        PDO::ATTR_TIMEOUT => 10,
-        PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8mb4"
-    ];
-    
-    $dsn = "mysql:host={$wpConfig['host']};dbname={$wpConfig['database']};charset=utf8mb4";
-    echo "<p>DSN: $dsn</p>";
-    
-    $wpDb = new PDO($dsn, $wpConfig['username'], $wpConfig['password'], $options);
-    echo "<p>✓ WordPress PDO created</p>";
-    
-    // Test connection
-    $wpDb->query("SELECT 1");
-    echo "<p>✓ WordPress connection test successful</p>";
-    
-    // Get stats
-    echo "<p>Getting stats...</p>";
-    $stats = [];
-    
-    try {
-        $stats['posts'] = $wpDb->query("SELECT COUNT(*) FROM wp_posts WHERE post_type = 'post'")->fetchColumn();
-        echo "<p>✓ Posts count: {$stats['posts']}</p>";
-    } catch (Exception $e) {
-        echo "<p>⚠ Posts query failed: " . $e->getMessage() . "</p>";
-        $stats['posts'] = 0;
-    }
-    
-    try {
-        $stats['categories'] = $wpDb->query("SELECT COUNT(*) FROM wp_term_taxonomy WHERE taxonomy = 'category'")->fetchColumn();
-        echo "<p>✓ Categories count: {$stats['categories']}</p>";
-    } catch (Exception $e) {
-        echo "<p>⚠ Categories query failed: " . $e->getMessage() . "</p>";
-        $stats['categories'] = 0;
-    }
-    
-    try {
-        $stats['users'] = $wpDb->query("SELECT COUNT(*) FROM wp_users")->fetchColumn();
-        echo "<p>✓ Users count: {$stats['users']}</p>";
-    } catch (Exception $e) {
-        echo "<p>⚠ Users query failed: " . $e->getMessage() . "</p>";
-        $stats['users'] = 0;
-    }
-    
-    try {
-        $stats['comments'] = $wpDb->query("SELECT COUNT(*) FROM wp_comments")->fetchColumn();
-        echo "<p>✓ Comments count: {$stats['comments']}</p>";
-    } catch (Exception $e) {
-        echo "<p>⚠ Comments query failed: " . $e->getMessage() . "</p>";
-        $stats['comments'] = 0;
-    }
-    
-    echo "<h2>✓ All tests completed successfully!</h2>";
-    echo "<p>Stats: " . print_r($stats, true) . "</p>";
-    
-} catch (Exception $e) {
-    echo "<p>✗ WordPress connection error: " . $e->getMessage() . "</p>";
-    echo "<p>File: " . $e->getFile() . "</p>";
-    echo "<p>Line: " . $e->getLine() . "</p>";
-    exit;
-}
-
-echo "<h2>Test completed - WordPress connection works!</h2>";
-?>

+ 0 - 387
admin/wordpress_import_old.php

@@ -1,387 +0,0 @@
-<?php
-// Simplified WordPress import interface - bypass problematic components
-error_reporting(E_ALL);
-ini_set('display_errors', 0);
-ini_set('max_execution_time', 120);
-ini_set('memory_limit', '512M');
-
-// Start session for basic functionality
-if (session_status() === PHP_SESSION_NONE) {
-    session_start();
-}
-
-require_once '../includes/config.php';
-require_once '../includes/database.php';
-
-// Simple auth check - just check if user is logged in without complex auth system
-$isAdmin = false;
-if (isset($_SESSION['logged_in']) && $_SESSION['logged_in'] === true && isset($_SESSION['role']) && $_SESSION['role'] === 'admin') {
-    $isAdmin = true;
-}
-
-// Redirect if not admin
-if (!$isAdmin) {
-    header('Location: login.php');
-    exit;
-}
-
-$message = '';
-$importResults = null;
-$connectionTest = null;
-
-// Handle form submission with simplified processing
-if ($_SERVER['REQUEST_METHOD'] === 'POST') {
-    try {
-        // Get WordPress database configuration
-        $wpConfig = [
-            'host' => trim($_POST['wp_host'] ?? ''),
-            'database' => trim($_POST['wp_database'] ?? ''),
-            'username' => trim($_POST['wp_username'] ?? ''),
-            'password' => $_POST['wp_password'] ?? ''
-        ];
-        
-        // Validate required fields
-        if (empty($wpConfig['host']) || empty($wpConfig['database']) || empty($wpConfig['username'])) {
-            throw new Exception("WordPress database configuration is required. Please provide host, database, and username.");
-        }
-        
-        // Direct WordPress connection test (bypass WordPressImport class)
-        try {
-            // Set timeout options
-            $options = [
-                PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
-                PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
-                PDO::ATTR_TIMEOUT => 10,
-                PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8mb4"
-            ];
-            
-            $dsn = "mysql:host={$wpConfig['host']};dbname={$wpConfig['database']};charset=utf8mb4";
-            $wpDb = new PDO($dsn, $wpConfig['username'], $wpConfig['password'], $options);
-            
-            // Test connection
-            $wpDb->query("SELECT 1");
-            
-            if (isset($_POST['test_connection'])) {
-                // Get stats with direct queries
-                $stats = [];
-                try {
-                    $stats['posts'] = $wpDb->query("SELECT COUNT(*) FROM wp_posts WHERE post_type = 'post'")->fetchColumn();
-                } catch (Exception $e) {
-                    $stats['posts'] = 0;
-                }
-                
-                try {
-                    $stats['categories'] = $wpDb->query("SELECT COUNT(*) FROM wp_term_taxonomy WHERE taxonomy = 'category'")->fetchColumn();
-                } catch (Exception $e) {
-                    $stats['categories'] = 0;
-                }
-                
-                try {
-                    $stats['users'] = $wpDb->query("SELECT COUNT(*) FROM wp_users")->fetchColumn();
-                } catch (Exception $e) {
-                    $stats['users'] = 0;
-                }
-                
-                try {
-                    $stats['comments'] = $wpDb->query("SELECT COUNT(*) FROM wp_comments")->fetchColumn();
-                } catch (Exception $e) {
-                    $stats['comments'] = 0;
-                }
-                
-                $message = "WordPress connection successful: " . 
-                          "Posts: " . $stats['posts'] . ", " .
-                          "Categories: " . $stats['categories'] . ", " .
-                          "Users: " . $stats['users'] . ", " .
-                          "Comments: " . $stats['comments'];
-            }
-        } catch (Exception $e) {
-            throw new Exception("WordPress connection failed: " . $e->getMessage());
-        }
-        
-        if (isset($_POST['start_import'])) {
-            // For now, just show a message that import is not implemented in this simplified version
-            throw new Exception("Import functionality is temporarily disabled. Please use the AJAX import tool for importing data.");
-        }
-        
-    } catch (Exception $e) {
-        $message = $e->getMessage();
-    }
-}
-?>
-<!DOCTYPE html>
-<html lang="en">
-<head>
-    <meta charset="UTF-8">
-    <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <title>WordPress Import - <?php echo SITE_TITLE; ?></title>
-    <link rel="stylesheet" href="../css/style.css">
-    <link rel="stylesheet" href="../css/admin-import.css">
-</head>
-<body>
-    <div class="admin-layout">
-        <header class="admin-header">
-            <div class="header-content">
-                <h1><a href="/index.php"><?php echo SITE_TITLE; ?></a></h1>
-                <nav class="admin-nav">
-                    <a href="index.php" class="nav-link">Dashboard</a>
-                    <a href="publications.php" class="nav-link">Publications</a>
-                    <a href="categories.php" class="nav-link">Categories</a>
-                    <a href="comments.php" class="nav-link">Comments</a>
-                    <a href="users.php" class="nav-link">Users</a>
-                    <a href="wordpress_import.php" class="nav-link active">WordPress Import</a>
-                    <?php if (LDAP_ENABLED): ?>
-                        <a href="ldap-users.php" class="nav-link">LDAP Users</a>
-                    <?php endif; ?>
-                    <a href="logout.php" class="nav-link">Logout</a>
-                </nav>
-                <div class="user-info">
-                    Welcome, <?php echo htmlspecialchars($_SESSION['username'] ?? 'Admin'); ?>
-                </div>
-            </div>
-        </header>
-
-        <main class="admin-main">
-            <div class="page-header">
-                <h2>WordPress Import</h2>
-                <p class="page-description">Import WordPress data into your system.</p>
-                <p class="page-description">Import posts, categories, users, and comments from a WordPress database to your publication system.</p>
-            </div>
-            
-            <?php if ($message): ?>
-                <div class="alert alert-<?php echo strpos($message, 'Error') === false && strpos($message, 'failed') === false ? 'success' : 'error'; ?>">
-                    <?php echo $message; ?>
-                </div>
-            <?php endif; ?>
-
-            <!-- Import Form -->
-            <div class="import-form-container">
-                <form method="post" class="import-form">
-                    <div class="form-section">
-                        <h3>WordPress Database Configuration</h3>
-                        
-                        <div class="form-row">
-                            <div class="form-group">
-                                <label for="wp_host">Database Host *</label>
-                                <input type="text" id="wp_host" name="wp_host" 
-                                       value="<?php echo htmlspecialchars($_POST['wp_host'] ?? 'localhost'); ?>" 
-                                       placeholder="localhost" required>
-                            </div>
-                            
-                            <div class="form-group">
-                                <label for="wp_database">Database Name *</label>
-                                <input type="text" id="wp_database" name="wp_database" 
-                                       value="<?php echo htmlspecialchars($_POST['wp_database'] ?? ''); ?>" 
-                                       placeholder="wordpress_database" required>
-                            </div>
-                        </div>
-                        
-                        <div class="form-row">
-                            <div class="form-group">
-                                <label for="wp_username">Database Username *</label>
-                                <input type="text" id="wp_username" name="wp_username" 
-                                       value="<?php echo htmlspecialchars($_POST['wp_username'] ?? ''); ?>" 
-                                       placeholder="wp_username" required>
-                            </div>
-                            
-                            <div class="form-group">
-                                <label for="wp_password">Database Password</label>
-                                <input type="password" id="wp_password" name="wp_password" 
-                                       value="<?php echo htmlspecialchars($_POST['wp_password'] ?? ''); ?>" 
-                                       placeholder="Leave empty if no password">
-                            </div>
-                        </div>
-                    </div>
-                    
-                    <div class="form-section">
-                        <h3>Import Options</h3>
-                        
-                        <div class="form-row">
-                            <div class="form-group">
-                                <label class="checkbox-label">
-                                    <input type="checkbox" name="import_categories" checked>
-                                    Import Categories
-                                </label>
-                            </div>
-                            
-                            <div class="form-group">
-                                <label class="checkbox-label">
-                                    <input type="checkbox" name="import_users" checked>
-                                    Import Users
-                                </label>
-                            </div>
-                        </div>
-                        
-                        <div class="form-row">
-                            <div class="form-group">
-                                <label class="checkbox-label">
-                                    <input type="checkbox" name="import_posts" checked>
-                                    Import Posts
-                                </label>
-                            </div>
-                            
-                            <div class="form-group">
-                                <label class="checkbox-label">
-                                    <input type="checkbox" name="import_comments" checked>
-                                    Import Comments
-                                </label>
-                            </div>
-                        </div>
-                    </div>
-                    
-                    <div class="form-actions">
-                        <button type="submit" name="test_connection" class="btn btn-primary">
-                            Test Connection
-                        </button>
-                        <button type="submit" name="start_import" class="btn btn-success" 
-                                onclick="return confirm('Are you sure you want to start the import? This will import data from WordPress into your system.')">
-                            Start Import
-                        </button>
-                    </div>
-                </form>
-            </div>
-
-            <!-- Import Results -->
-            <?php if ($importResults): ?>
-                <div class="import-results">
-                    <h3>Import Results</h3>
-                    
-                    <?php if ($importResults['success']): ?>
-                        <div class="success-summary">
-                            <p class="success-message">WordPress import completed successfully!</p>
-                        </div>
-                        
-                        <div class="results-details">
-                            <?php foreach ($importResults['results'] as $type => $result): ?>
-                                <div class="result-item">
-                                    <h4><?php echo ucfirst($type); ?></h4>
-                                    <div class="result-stats">
-                                        <span class="stat success">
-                                            Imported: <strong><?php echo $result['imported']; ?></strong>
-                                        </span>
-                                        <span class="stat warning">
-                                            Skipped: <strong><?php echo $result['skipped']; ?></strong>
-                                        </span>
-                                    </div>
-                                </div>
-                            <?php endforeach; ?>
-                        </div>
-                        
-                        <?php if (!empty($importResults['log'])): ?>
-                            <div class="import-log">
-                                <h4>Import Log</h4>
-                                <div class="log-container">
-                                    <?php foreach ($importResults['log'] as $logEntry): ?>
-                                        <div class="log-entry log-<?php echo $logEntry['level']; ?>">
-                                            <span class="log-time"><?php echo $logEntry['timestamp']; ?></span>
-                                            <span class="log-message"><?php echo htmlspecialchars($logEntry['message']); ?></span>
-                                        </div>
-                                    <?php endforeach; ?>
-                                </div>
-                            </div>
-                        <?php endif; ?>
-                        
-                        <?php if (!empty($importResults['errors'])): ?>
-                            <div class="import-errors">
-                                <h4>Import Errors</h4>
-                                <div class="error-list">
-                                    <?php foreach ($importResults['errors'] as $error): ?>
-                                        <div class="error-item">
-                                            <?php echo htmlspecialchars($error); ?>
-                                        </div>
-                                    <?php endforeach; ?>
-                                </div>
-                            </div>
-                        <?php endif; ?>
-                        
-                    <?php else: ?>
-                        <div class="error-summary">
-                            <p class="error-message"><?php echo htmlspecialchars($importResults['error']); ?></p>
-                        </div>
-                    <?php endif; ?>
-                </div>
-            <?php endif; ?>
-
-            <!-- Information Section -->
-            <div class="info-section">
-                <h3>WordPress Import Information</h3>
-                <div class="info-content">
-                    <div class="info-item">
-                        <h4>What Gets Imported</h4>
-                        <ul>
-                            <li>Posts (title, content, author, publication date)</li>
-                            <li>Categories (name and description)</li>
-                            <li>Users (username, email, display name)</li>
-                            <li>Comments (content, author, date, threading)</li>
-                        </ul>
-                    </div>
-                    
-                    <div class="info-item">
-                        <h4>Requirements</h4>
-                        <ul>
-                            <li>Database access to WordPress database</li>
-                            <li>WordPress database with standard structure</li>
-                            <li>Backup of your current data (recommended)</li>
-                        </ul>
-                    </div>
-                    
-                    <div class="info-item">
-                        <h4>Important Notes</h4>
-                        <ul>
-                            <li>Existing data with same identifiers will be skipped</li>
-                            <li>WordPress content is processed for compatibility</li>
-                            <li>WordPress users are mapped to your user system</li>
-                        </ul>
-                    </div>
-                </div>
-            </div>
-        </main>
-    </div>
-
-    <script>
-        // WordPress Import JavaScript
-        document.addEventListener('DOMContentLoaded', function() {
-            const form = document.querySelector('.import-form');
-            const testBtn = document.querySelector('button[name="test_connection"]');
-            const importBtn = document.querySelector('button[name="start_import"]');
-            
-            // Show loading state
-            function setLoading(button, loading) {
-                if (loading) {
-                    button.disabled = true;
-                    button.dataset.originalText = button.textContent;
-                    button.textContent = button.dataset.loadingText || 'Loading...';
-                } else {
-                    button.disabled = false;
-                    button.textContent = button.dataset.originalText;
-                }
-            }
-            
-            // Test connection loading
-            testBtn.addEventListener('click', function() {
-                setLoading(this, true);
-                this.dataset.loadingText = 'Testing connection...';
-            });
-            
-            // Import loading
-            importBtn.addEventListener('click', function() {
-                setLoading(this, true);
-                this.dataset.loadingText = 'Importing...';
-            });
-            
-            // Reset loading on form submit
-            form.addEventListener('submit', function() {
-                setTimeout(() => {
-                    setLoading(testBtn, false);
-                    setLoading(importBtn, false);
-                }, 1000);
-            });
-            
-            // Auto-focus first empty field
-            const firstEmpty = form.querySelector('input[value=""], input:not([value])');
-            if (firstEmpty) {
-                firstEmpty.focus();
-            }
-        });
-    </script>
-</body>
-</html>