svalavuo 4 dni temu
rodzic
commit
9737bccdd7
2 zmienionych plików z 240 dodań i 0 usunięć
  1. 110 0
      admin/ajax_import_test.php
  2. 130 0
      admin/ajax_test_interface.html

+ 110 - 0
admin/ajax_import_test.php

@@ -0,0 +1,110 @@
+<?php
+// AJAX-based WordPress import test to bypass form submission issues
+header('Content-Type: application/json');
+error_reporting(E_ALL);
+ini_set('display_errors', 1);
+ini_set('max_execution_time', 60);
+ini_set('memory_limit', '512M');
+
+require_once '../includes/config.php';
+require_once '../includes/database.php';
+require_once '../includes/wordpress_import.php';
+
+$response = ['success' => false, 'message' => '', 'step' => ''];
+
+try {
+    $action = $_GET['action'] ?? '';
+    $response['step'] = $action;
+    
+    switch ($action) {
+        case 'test_connection':
+            // Test connection only
+            $wpConfig = [
+                'host' => trim($_GET['wp_host'] ?? ''),
+                'database' => trim($_GET['wp_database'] ?? ''),
+                'username' => trim($_GET['wp_username'] ?? ''),
+                'password' => $_GET['wp_password'] ?? ''
+            ];
+            
+            $response['message'] = 'Testing connection...';
+            $importer = new WordPressImport($wpConfig);
+            $connectionTest = $importer->testConnection();
+            
+            if ($connectionTest['success']) {
+                $response['success'] = true;
+                $response['message'] = 'Connection successful';
+                $response['stats'] = $connectionTest['stats'];
+            } else {
+                $response['message'] = $connectionTest['error'];
+            }
+            break;
+            
+        case 'import_categories':
+            // Import categories only
+            $wpConfig = [
+                'host' => trim($_GET['wp_host'] ?? ''),
+                'database' => trim($_GET['wp_database'] ?? ''),
+                'username' => trim($_GET['wp_username'] ?? ''),
+                'password' => $_GET['wp_password'] ?? ''
+            ];
+            
+            $response['message'] = 'Importing categories...';
+            $importer = new WordPressImport($wpConfig);
+            $result = $importer->importCategories();
+            
+            $response['success'] = true;
+            $response['message'] = 'Categories imported';
+            $response['result'] = $result;
+            break;
+            
+        case 'import_users':
+            // Import users only
+            $wpConfig = [
+                'host' => trim($_GET['wp_host'] ?? ''),
+                'database' => trim($_GET['wp_database'] ?? ''),
+                'username' => trim($_GET['wp_username'] ?? ''),
+                'password' => $_GET['wp_password'] ?? ''
+            ];
+            
+            $response['message'] = 'Importing users...';
+            $importer = new WordPressImport($wpConfig);
+            $result = $importer->importUsers();
+            
+            $response['success'] = true;
+            $response['message'] = 'Users imported';
+            $response['result'] = $result;
+            break;
+            
+        case 'import_posts':
+            // Import posts only (small batch)
+            $wpConfig = [
+                'host' => trim($_GET['wp_host'] ?? ''),
+                'database' => trim($_GET['wp_database'] ?? ''),
+                'username' => trim($_GET['wp_username'] ?? ''),
+                'password' => $_GET['wp_password'] ?? ''
+            ];
+            
+            $response['message'] = 'Importing posts (batch)...';
+            $importer = new WordPressImport($wpConfig);
+            $result = $importer->importPosts();
+            
+            $response['success'] = true;
+            $response['message'] = 'Posts imported';
+            $response['result'] = $result;
+            break;
+            
+        default:
+            $response['message'] = 'Unknown action';
+    }
+    
+} catch (Exception $e) {
+    $response['message'] = 'Error: ' . $e->getMessage();
+    $response['error'] = [
+        'file' => $e->getFile(),
+        'line' => $e->getLine(),
+        'trace' => $e->getTraceAsString()
+    ];
+}
+
+echo json_encode($response);
+?>

+ 130 - 0
admin/ajax_test_interface.html

@@ -0,0 +1,130 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <title>AJAX WordPress Import Test</title>
+    <style>
+        body { font-family: Arial, sans-serif; margin: 20px; }
+        .container { max-width: 800px; margin: 0 auto; }
+        .form-group { margin-bottom: 15px; }
+        label { display: block; margin-bottom: 5px; font-weight: bold; }
+        input, button { padding: 8px; margin-bottom: 10px; }
+        button { background: #007cba; color: white; border: none; cursor: pointer; margin-right: 10px; }
+        button:hover { background: #005a87; }
+        .log { background: #f5f5f5; border: 1px solid #ddd; padding: 10px; margin-top: 20px; height: 300px; overflow-y: auto; font-family: monospace; font-size: 12px; }
+        .success { color: green; }
+        .error { color: red; }
+        .info { color: blue; }
+    </style>
+</head>
+<body>
+    <div class="container">
+        <h1>AJAX WordPress Import Test</h1>
+        <p>This bypasses form submission issues by using AJAX requests.</p>
+        
+        <div class="form-group">
+            <label>Host:</label>
+            <input type="text" id="wp_host" value="10.15.10.8">
+        </div>
+        
+        <div class="form-group">
+            <label>Database:</label>
+            <input type="text" id="wp_database" value="valtsu_valtsu">
+        </div>
+        
+        <div class="form-group">
+            <label>Username:</label>
+            <input type="text" id="wp_username" value="">
+        </div>
+        
+        <div class="form-group">
+            <label>Password:</label>
+            <input type="password" id="wp_password" value="">
+        </div>
+        
+        <div class="form-group">
+            <button onclick="testConnection()">Test Connection</button>
+            <button onclick="importCategories()">Import Categories</button>
+            <button onclick="importUsers()">Import Users</button>
+            <button onclick="importPosts()">Import Posts</button>
+            <button onclick="clearLog()">Clear Log</button>
+        </div>
+        
+        <div id="log" class="log"></div>
+    </div>
+
+    <script>
+        function log(message, type = 'info') {
+            const logDiv = document.getElementById('log');
+            const timestamp = new Date().toLocaleTimeString();
+            const className = type === 'error' ? 'error' : type === 'success' ? 'success' : 'info';
+            logDiv.innerHTML += `<div class="${className}">[${timestamp}] ${message}</div>`;
+            logDiv.scrollTop = logDiv.scrollHeight;
+        }
+
+        function getConfig() {
+            return {
+                wp_host: document.getElementById('wp_host').value,
+                wp_database: document.getElementById('wp_database').value,
+                wp_username: document.getElementById('wp_username').value,
+                wp_password: document.getElementById('wp_password').value
+            };
+        }
+
+        function makeRequest(action) {
+            const config = getConfig();
+            const params = new URLSearchParams({...config, action});
+            
+            log(`Making request: ${action}`, 'info');
+            
+            return fetch(`ajax_import_test.php?${params}`)
+                .then(response => response.json())
+                .then(data => {
+                    if (data.success) {
+                        log(`✓ ${data.message} (${data.step})`, 'success');
+                        if (data.stats) {
+                            log(`Stats: ${JSON.stringify(data.stats)}`, 'info');
+                        }
+                        if (data.result) {
+                            log(`Result: ${JSON.stringify(data.result)}`, 'info');
+                        }
+                    } else {
+                        log(`✗ ${data.message} (${data.step})`, 'error');
+                        if (data.error) {
+                            log(`Error details: ${data.error.file}:${data.error.line}`, 'error');
+                        }
+                    }
+                    return data;
+                })
+                .catch(error => {
+                    log(`Network error: ${error.message}`, 'error');
+                    throw error;
+                });
+        }
+
+        function testConnection() {
+            makeRequest('test_connection');
+        }
+
+        function importCategories() {
+            makeRequest('import_categories');
+        }
+
+        function importUsers() {
+            makeRequest('import_users');
+        }
+
+        function importPosts() {
+            makeRequest('import_posts');
+        }
+
+        function clearLog() {
+            document.getElementById('log').innerHTML = '';
+        }
+
+        // Auto-focus username field
+        document.addEventListener('DOMContentLoaded', function() {
+            document.getElementById('wp_username').focus();
+        });
+    </script>
+</body>
+</html>