get('performance_db_rows', 3000); $config->setDbRowsPerChunk((int) $dbRows); // SQL Batch Size $sqlBatch = $settings->get('performance_sql_batch_size', 1000); $config->setSqlBatchSize((int) $sqlBatch); // Memory Limit $memoryLimit = $settings->get('performance_memory_limit'); if ($memoryLimit) { // PHP ayarlarını override etmeye çalış @ini_set('memory_limit', $memoryLimit); // phpcs:ignore Squiz.PHP.DiscouragedFunctions.Discouraged } } catch (\Throwable $e) { // Ayarlar yüklenemezse varsayılanlarla devam et (Fatal errorları yakalar) // error_log('WP Cloner Settings Load Error: ' . $e->getMessage()); // Debug log removed for production } $jobId = $progress->init('export', $config); $exportManager = new ExportManager($progress); $result = $exportManager->initialize(); wp_send_json_success([ 'job_id' => $jobId, 'next_step' => $result['next_step'], 'progress' => $progress->getProgress() ]); } // Devam eden job için yükle if (!$progress->load($jobId)) { wp_send_json_error(['message' => 'Geçersiz job ID.']); } $exportManager = new ExportManager($progress); // Adıma göre işlem yap switch ($step) { case 'analyze': $result = $exportManager->analyze(); break; case 'db_export': $result = $exportManager->exportDbChunk(); break; case 'file_archive': $result = $exportManager->archiveFilesChunk(); break; case 'package': $result = $exportManager->createPackage(); break; default: wp_send_json_error(['message' => 'Geçersiz adım: ' . $step]); } // Sonucu döndür if (isset($result['status']) && $result['status'] === 'completed') { wp_send_json_success([ 'status' => 'completed', 'result' => $result['result'], 'progress' => $progress->getProgress() ]); } else { wp_send_json_success([ 'job_id' => $jobId, 'next_step' => $result['next_step'] ?? null, 'progress' => $progress->getProgress() ]); } } catch (\Throwable $e) { // Fatal Error yakalama (PHP 7+) if (isset($progress) && $progress instanceof ProgressState) { $progress->setError($e->getMessage()); } // JSON formatında hata döndür if (!headers_sent()) { header('Content-Type: application/json'); status_header(200); // 500 dönerse JS error callback tetiklenir, 200 dönüp success:false yapıyoruz } wp_send_json_error([ 'message' => 'Sistem Hatası: ' . $e->getMessage(), 'debug' => [ 'file' => $e->getFile(), 'line' => $e->getLine() ], 'progress' => isset($progress) ? $progress->getProgress() : null ]); }