feat(import): store primary destination; crawl configured cities

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-29 15:20:29 +03:30
parent 614ea98825
commit 02b6ce0ff4
4 changed files with 16 additions and 6 deletions

View File

@@ -156,10 +156,14 @@ class VC_Cron {
$map = get_transient( 'vc_destination_map' ); $map = get_transient( 'vc_destination_map' );
// A destination allowlist (comma-separated IDs) narrows the crawl to a // Cities configured on the Viator Structure screen define the crawl.
// focused set; empty means the whole catalogue. // Without any, a destination allowlist (comma-separated IDs) narrows
$allow = array_filter( array_map( 'trim', explode( ',', (string) vc_get_option( 'crawl_destinations', '' ) ) ) ); // the crawl to a focused set; empty means the whole catalogue.
if ( ! empty( $allow ) ) { $cities = array_map( 'strval', array_keys( VC_Structure::cities( VC_Structure::get() ) ) );
$allow = array_filter( array_map( 'trim', explode( ',', (string) vc_get_option( 'crawl_destinations', '' ) ) ) );
if ( ! empty( $cities ) ) {
$queue = $cities;
} elseif ( ! empty( $allow ) ) {
$queue = array_values( array_unique( $allow ) ); $queue = array_values( array_unique( $allow ) );
} else { } else {
$queue = is_array( $map ) ? array_keys( $map ) : array(); $queue = is_array( $map ) ? array_keys( $map ) : array();
@@ -191,7 +195,11 @@ class VC_Cron {
); );
update_option( 'vc_ingest_in_progress', 1, false ); update_option( 'vc_ingest_in_progress', 1, false );
update_option( 'vc_last_sync_started_at', current_time( 'mysql' ), false ); update_option( 'vc_last_sync_started_at', current_time( 'mysql' ), false );
VC_Logger::info( sprintf( 'Sync run started — %d destinations queued.', count( $queue ) ) ); if ( ! empty( $cities ) ) {
VC_Logger::info( sprintf( 'Sync run started from structure — %d cities queued.', count( $queue ) ) );
} else {
VC_Logger::info( sprintf( 'Sync run started — %d destinations queued.', count( $queue ) ) );
}
return true; return true;
} }

View File

@@ -368,6 +368,7 @@ class VC_Importer {
'_vc_cancellation_policy' => wp_json_encode( vc_first_non_empty( array( vc_array_get( $product, 'cancellationPolicy' ), vc_array_get( $product, 'cancellation' ) ), array() ) ), '_vc_cancellation_policy' => wp_json_encode( vc_first_non_empty( array( vc_array_get( $product, 'cancellationPolicy' ), vc_array_get( $product, 'cancellation' ) ), array() ) ),
'_vc_supplier' => sanitize_text_field( $supplier ), '_vc_supplier' => sanitize_text_field( $supplier ),
'_vc_destinations' => wp_json_encode( vc_array_get( $product, 'destinations', array() ) ), '_vc_destinations' => wp_json_encode( vc_array_get( $product, 'destinations', array() ) ),
'_vc_primary_destination' => VC_Structure::primary_destination_id( (array) vc_array_get( $product, 'destinations', array() ) ),
'_vc_tags' => wp_json_encode( vc_array_get( $product, 'tags', array() ) ), '_vc_tags' => wp_json_encode( vc_array_get( $product, 'tags', array() ) ),
'_vc_rating' => sanitize_text_field( (string) $rating ), '_vc_rating' => sanitize_text_field( (string) $rating ),
'_vc_review_count' => absint( $review_count ), '_vc_review_count' => absint( $review_count ),

View File

@@ -30,6 +30,7 @@ final class VC_Plugin {
'includes/class-vc-logger.php', 'includes/class-vc-logger.php',
'includes/class-vc-cpt.php', 'includes/class-vc-cpt.php',
'includes/class-vc-taxonomies.php', 'includes/class-vc-taxonomies.php',
'includes/class-vc-structure.php',
'includes/class-vc-api.php', 'includes/class-vc-api.php',
'includes/class-vc-importer.php', 'includes/class-vc-importer.php',
'includes/class-vc-cron.php', 'includes/class-vc-cron.php',

View File

@@ -345,7 +345,7 @@ class VC_Settings {
<th scope="row"><label for="vc_crawl_destinations"><?php echo esc_html__( 'Destination filter', 'viator-collector' ); ?></label></th> <th scope="row"><label for="vc_crawl_destinations"><?php echo esc_html__( 'Destination filter', 'viator-collector' ); ?></label></th>
<td> <td>
<input id="vc_crawl_destinations" type="text" class="large-text" name="vc_settings[crawl_destinations]" value="<?php echo esc_attr( $options['crawl_destinations'] ); ?>" placeholder="<?php echo esc_attr__( 'e.g. 664, 662, 761', 'viator-collector' ); ?>"> <input id="vc_crawl_destinations" type="text" class="large-text" name="vc_settings[crawl_destinations]" value="<?php echo esc_attr( $options['crawl_destinations'] ); ?>" placeholder="<?php echo esc_attr__( 'e.g. 664, 662, 761', 'viator-collector' ); ?>">
<p class="description"><?php echo esc_html__( 'Comma-separated Viator destination IDs to crawl. Leave empty to crawl the whole catalogue. Use the search below to find IDs.', 'viator-collector' ); ?></p> <p class="description"><?php echo esc_html__( 'Comma-separated Viator destination IDs to crawl. Leave empty to crawl the whole catalogue. Use the search below to find IDs. Used only when no cities are set on the Viator Structure screen.', 'viator-collector' ); ?></p>
<div class="vc-dest-finder" style="margin-top:8px;max-width:640px;"> <div class="vc-dest-finder" style="margin-top:8px;max-width:640px;">
<input type="search" id="vc-dest-search" class="regular-text" placeholder="<?php echo esc_attr__( 'Search destinations, e.g. Orlando', 'viator-collector' ); ?>"> <input type="search" id="vc-dest-search" class="regular-text" placeholder="<?php echo esc_attr__( 'Search destinations, e.g. Orlando', 'viator-collector' ); ?>">
<button type="button" class="button" id="vc-dest-search-btn"><?php echo esc_html__( 'Search', 'viator-collector' ); ?></button> <button type="button" class="button" id="vc-dest-search-btn"><?php echo esc_html__( 'Search', 'viator-collector' ); ?></button>