Skip to content

Commit 0493cdb

Browse files
committed
feat: skip single fetches on synchronization for full live fetch bridges
1 parent 503ec76 commit 0493cdb

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

posts-bridge/includes/class-posts-synchronizer.php

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -754,29 +754,35 @@ private static function sync( $bridge, $scheduled = false, $queue = null ) {
754754

755755
$rcpt = new Remote_CPT( $post, $foreign_id );
756756

757-
$data = $rcpt->fetch();
757+
$remote_fields = $bridge->remote_fields();
758758

759-
if ( is_wp_error( $data ) || empty( $data ) ) {
760-
Logger::log( 'Exit synchronization after a fetch error', Logger::ERROR );
761-
Logger::log( $data, Logger::ERROR );
762-
throw new Exception( 'sync_error', 500 );
763-
}
759+
if ( $remote_fields ) {
760+
$data = $rcpt->fetch();
764761

765-
$skip = apply_filters(
766-
'posts_bridge_skip_synchronization',
767-
false,
768-
$rcpt,
769-
$data
770-
);
762+
if ( is_wp_error( $data ) || empty( $data ) ) {
763+
Logger::log( 'Exit synchronization after a fetch error', Logger::ERROR );
764+
Logger::log( $data, Logger::ERROR );
765+
throw new Exception( 'sync_error', 500 );
766+
}
771767

772-
if ( $skip ) {
773-
Logger::log( "Skip synchrionization for Remote CPT({$post_type}) with foreign id {$foreign_id}" );
768+
$skip = apply_filters(
769+
'posts_bridge_skip_synchronization',
770+
false,
771+
$rcpt,
772+
$data
773+
);
774774

775-
$rcpt->ID && wp_delete_post( $rcpt->ID );
776-
continue;
777-
}
775+
if ( $skip ) {
776+
Logger::log( "Skip synchrionization for Remote CPT({$post_type}) with foreign id {$foreign_id}" );
778777

779-
$post_data = $bridge->apply_mappers( $data );
778+
$rcpt->ID && wp_delete_post( $rcpt->ID );
779+
continue;
780+
}
781+
782+
$post_data = $bridge->apply_mappers( $data );
783+
} else {
784+
$post_data = array( 'post_status' => 'publish' );
785+
}
780786

781787
$post_title = $post_data['post_title'] ?? "Remote CPT({$post_type}) #{$foreign_id}";
782788

0 commit comments

Comments
 (0)