
// Генерация отчета по проблемным листингам add_action('wp_ajax_gpt_automation_generate_failed_report', 'gpt_automation_ajax_generate_failed_report'); function gpt_automation_ajax_generate_failed_report() { check_ajax_referer('gpt_automation_nonce', 'nonce'); if (!current_user_can('manage_options')) { wp_send_json_success(array('file_path' => $temp_file)); } // Добавление проблемных листингов в retry queue add_action('wp_ajax_gpt_automation_add_failed_to_retry', 'gpt_automation_ajax_add_failed_to_retry'); function gpt_automation_ajax_add_failed_to_retry() { check_ajax_referer('gpt_automation_nonce', 'nonce'); if (!current_user_can('manage_options')) { wp_send_json_error('Insufficient permissions'); } // Получаем проблемные листинги (та же логика) $failed_slugs = array(); // Листинги без GPT описания $missing_gpt_args = array( 'post_type' => 'listings', 'post_status' => 'publish', 'posts_per_page' => -1, 'fields' => 'ids', 'meta_query' => array( 'relation' => 'OR', array( 'key' => 'full_gpt', 'compare' => 'NOT EXISTS' ), array( 'key' => 'full_gpt', 'value' => '', 'compare' => '=' ), array( 'key' => 'full_gpt', 'value' => 'No long description available.', 'compare' => '=' ) ) ); $missing_gpt_query = new WP_Query($missing_gpt_args); foreach ($missing_gpt_query->posts as $post_id) { $post = get_post($post_id); $failed_slugs[] = $post->post_name; } // Листинги без видео $missing_video_args = array( 'post_type' => 'listings', 'post_status' => 'publish', 'posts_per_page' => -1, 'fields' => 'ids', 'meta_query' => array( 'relation' => 'OR', array( 'key' => 'video_url', 'compare' => 'NOT EXISTS' ), array( 'key' => 'video_url', 'value' => '', 'compare' => '=' ) ) ); $missing_video_query = new WP_Query($missing_video_args); foreach ($missing_video_query->posts as $post_id) { $post = get_post($post_id); $failed_slugs[] = $post->post_name; } // Убираем дубликаты $failed_slugs = array_unique($failed_slugs); if (empty($failed_slugs)) { wp_send_json_success('No failed listings found'); } // Добавляем в retry queue $retry_queue = get_option('gpt_automation_retry_queue', array()); $retry_queue = array_merge($retry_queue, $failed_slugs); $retry_queue = array_unique($retry_queue); update_option('gpt_automation_retry_queue', $retry_queue); gpt_automation_write_log("Added " . count($failed_slugs) . " failed listings to retry queue"); wp_send_json_success(count($failed_slugs) . " failed listings added to retry queue"); }_error('Insufficient permissions'); } // Поиск листингов с проблемами $failed_listings = array(); // Листинги без GPT описания $missing_gpt_args = array( 'post_type' => 'listings', 'post_status' => 'publish', 'posts_per_page' => -1, 'fields' => 'ids', 'meta_query' => array( 'relation' => 'OR', array( 'key' => 'full_gpt', 'compare' => 'NOT EXISTS' ), array( 'key' => 'full_gpt', 'value' => '', 'compare' => '=' ), array( 'key' => 'full_gpt', 'value' => 'No long description available.', 'compare' => '=' ) ) ); $missing_gpt_query = new WP_Query($missing_gpt_args); foreach ($missing_gpt_query->posts as $post_id) { $post = get_post($post_id); $failed_listings[$post->post_name] = array( 'slug' => $post->post_name, 'title' => get_field('title', $post_id) ?: $post->post_title, 'missing_gpt' => true, 'missing_video' => false ); } // Листинги без видео $missing_video_args = array( 'post_type' => 'listings', 'post_status' => 'publish', 'posts_per_page' => -1, 'fields' => 'ids', 'meta_query' => array( 'relation' => 'OR', array( 'key' => 'video_url', 'compare' => 'NOT EXISTS' ), array( 'key' => 'video_url', 'value' => '', 'compare' => '=' ) ) ); $missing_video_query = new WP_Query($missing_video_args); foreach ($missing_video_query->posts as $post_id) { $post = get_post($post_id); $slug = $post->post_name; if (isset($failed_listings[$slug])) { $failed_listings[$slug]['missing_video'] = true; } else { $failed_listings[$slug] = array( 'slug' => $slug, 'title' => get_field('title', $post_id) ?: $post->post_title, 'missing_gpt' => false, 'missing_video' => true ); } } // Формируем HTML отчет $html = '
Total failed listings: ' . count($failed_listings) . '
'; if (empty($failed_listings)) { $html .= '🎉 All listings have complete data!
'; } else { $missing_gpt_count = 0; $missing_video_count = 0; $missing_both_count = 0; foreach ($failed_listings as $listing) { if ($listing['missing_gpt'] && $listing['missing_video']) { $missing_both_count++; } elseif ($listing['missing_gpt']) { $missing_gpt_count++; } elseif ($listing['missing_video']) { $missing_video_count++; } } $html .= '