|
@@ -14,7 +14,7 @@ class WordPressImport {
|
|
|
public function __construct($wpConfig) {
|
|
public function __construct($wpConfig) {
|
|
|
$this->wpConfig = $wpConfig;
|
|
$this->wpConfig = $wpConfig;
|
|
|
$this->targetDb = Database::getInstance();
|
|
$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() {
|
|
private function connectWordPress() {
|
|
|
try {
|
|
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";
|
|
$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');
|
|
$this->log('Connected to WordPress database successfully');
|
|
|
- } catch (Exception $e) {
|
|
|
|
|
|
|
+ } catch (PDOException $e) {
|
|
|
throw new Exception("Failed to connect to WordPress database: " . $e->getMessage());
|
|
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() {
|
|
public function testConnection() {
|
|
|
try {
|
|
try {
|
|
|
|
|
+ // Connect first
|
|
|
|
|
+ $this->connectWordPress();
|
|
|
|
|
+
|
|
|
// Check if WordPress tables exist
|
|
// Check if WordPress tables exist
|
|
|
$tables = ['wp_posts', 'wp_users', 'wp_terms', 'wp_term_taxonomy', 'wp_term_relationships', 'wp_comments'];
|
|
$tables = ['wp_posts', 'wp_users', 'wp_terms', 'wp_term_taxonomy', 'wp_term_relationships', 'wp_comments'];
|
|
|
$existingTables = [];
|
|
$existingTables = [];
|
|
@@ -75,6 +90,9 @@ class WordPressImport {
|
|
|
$results = [];
|
|
$results = [];
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
|
|
+ // Connect to WordPress database first
|
|
|
|
|
+ $this->connectWordPress();
|
|
|
|
|
+
|
|
|
// Start transaction
|
|
// Start transaction
|
|
|
$this->targetDb->beginTransaction();
|
|
$this->targetDb->beginTransaction();
|
|
|
|
|
|