From 987f280048d65fd7f2a2cf93539b93603279b3a1 Mon Sep 17 00:00:00 2001
From: Mohammad Jangda <batmoo@gmail.com>
Date: Tue, 15 Oct 2013 05:37:56 +0000
Subject: [PATCH] Update slave_post_states immediately after push.

Even though this is more resource-intensive, this helps In case our push process fails halfway through, at least we'll have some
of the site data retained.
---
 includes/class-wp-push-syndication-server.php | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/includes/class-wp-push-syndication-server.php b/includes/class-wp-push-syndication-server.php
index df590aa..5884e70 100644
--- a/includes/class-wp-push-syndication-server.php
+++ b/includes/class-wp-push-syndication-server.php
@@ -820,7 +820,7 @@ class WP_Push_Syndication_Server {
 
 		// if another process running on it return
 		if( get_transient( 'syn_syndicate_lock' ) == 'locked' )
-			return
+			return;
 
 		// set value as locked, valid for 5 mins
 		set_transient( 'syn_syndicate_lock', 'locked', 60*5 );
@@ -850,6 +850,7 @@ class WP_Push_Syndication_Server {
 					$result = $client->new_post( $post_ID );
 
 					$this->validate_result_new_post( $result, $slave_post_states, $site->ID, $client );
+					$this->update_slave_post_states( $post_id, $slave_post_states );
 
 					do_action( 'syn_post_push_new_post', $result, $post_ID, $site, $transport_type, $client, $info );
 					
@@ -861,6 +862,7 @@ class WP_Push_Syndication_Server {
 					$result = $client->edit_post( $post_ID, $info['ext_ID'] );
 
 					$this->validate_result_edit_post( $result, $slave_post_states, $site->ID, $client );
+					$this->update_slave_post_states( $post_id, $slave_post_states );
 
 					do_action( 'syn_post_push_edit_post', $result, $post_ID, $site, $transport_type, $client, $info );
 				}
@@ -882,6 +884,7 @@ class WP_Push_Syndication_Server {
 					$result = $client->delete_post( $info['ext_ID'] );
 					if ( is_wp_error( $result ) ) {
 						$slave_post_states[ 'remove-error' ][ $site->ID ] = $result;
+						$this->update_slave_post_states( $post_id, $slave_post_states );
 					}
 
 				}
@@ -890,7 +893,6 @@ class WP_Push_Syndication_Server {
 
 		}
 
-		update_post_meta( $post_ID, '_syn_slave_post_states', $slave_post_states );
 
 		/** end of critical section **/
 
@@ -1049,6 +1051,10 @@ class WP_Push_Syndication_Server {
 		return $result;
 	}
 
+	private update_slave_post_states( $post_id, $slave_post_states ) {
+		update_post_meta( $post_id, '_syn_slave_post_states', $slave_post_states );
+	}
+
 	public function pre_schedule_delete_content( $post_id ) {
 
 		// if slave post deletion is not enabled return
-- 
GitLab