Completed
Pull Request — develop (#1403)
by Naveen
04:33 queued 01:30
created
src/wordlift/dataset/class-sync-post-hooks.php 2 patches
Indentation   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -5,113 +5,113 @@
 block discarded – undo
5 5
 use Wordlift\Object_Type_Enum;
6 6
 
7 7
 class Sync_Post_Hooks extends Abstract_Sync_Hooks {
8
-	/**
9
-	 * @var \Wordlift_Log_Service
10
-	 */
11
-	private $log;
12
-
13
-	/**
14
-	 * @var Sync_Service
15
-	 */
16
-	private $sync_service;
17
-
18
-	/**
19
-	 * @var Sync_Object_Adapter_Factory
20
-	 */
21
-	private $sync_object_factory;
22
-
23
-	/**
24
-	 * Sync_Post_Hooks constructor.
25
-	 *
26
-	 * @param Sync_Service $sync_service
27
-	 * @param Sync_Object_Adapter_Factory $sync_object_factory
28
-	 */
29
-	function __construct( $sync_service, $sync_object_factory ) {
30
-		parent::__construct();
31
-
32
-		$this->log = \Wordlift_Log_Service::get_logger( get_class() );
33
-
34
-		$this->sync_service        = $sync_service;
35
-		$this->sync_object_factory = $sync_object_factory;
36
-
37
-		$this->register_hooks();
38
-	}
39
-
40
-	private function register_hooks() {
41
-		/**
42
-		 * Register hooks for post and meta.
43
-		 */
44
-		add_action( 'save_post', array( $this, 'save_post' ) );
45
-		add_action( 'added_post_meta', array( $this, 'changed_post_meta' ), 10, 4 );
46
-		add_action( 'updated_post_meta', array( $this, 'changed_post_meta' ), 10, 4 );
47
-		add_action( 'deleted_post_meta', array( $this, 'changed_post_meta' ), 10, 4 );
48
-		add_action( 'delete_post', array( $this, 'delete_post' ) );
49
-		// Remove post when its trashed.
50
-		add_action( 'trashed_post', array( $this, 'delete_post' ) );
51
-		// Save the post when its untrashed.
52
-		add_action( 'untrashed_post', array( $this, 'save_post' ) );
53
-
54
-	}
55
-
56
-	public function save_post( $post_id ) {
57
-
58
-		if ( ! in_array( get_post_type( $post_id ), \Wordlift_Entity_Service::valid_entity_post_types() ) ) {
59
-			return;
60
-		}
61
-
62
-		$this->sync( $post_id );
63
-
64
-	}
65
-
66
-	public function changed_post_meta( $meta_id, $post_id, $meta_key, $_meta_value ) {
67
-
68
-		if ( in_array( $meta_key,
69
-				apply_filters( 'wl_dataset__sync_post_hooks__ignored_meta_keys',
70
-					apply_filters( 'wl_dataset__sync_hooks__ignored_meta_keys',
71
-						array(
72
-							'_pingme',
73
-							'_encloseme',
74
-							'entity_url',
75
-						) ) ) )
76
-		     || ! in_array( get_post_type( $post_id ), \Wordlift_Entity_Service::valid_entity_post_types() )
77
-		) {
78
-			return;
79
-		}
80
-
81
-		$this->sync( $post_id );
82
-
83
-	}
84
-
85
-	private function sync( $post_id ) {
86
-		$this->enqueue( array( 'do_sync', $post_id ) );
87
-	}
88
-
89
-	public function do_sync( $post_id ) {
90
-		try {
91
-			$post = get_post( $post_id );
92
-			if ( ! isset( $post ) ) {
93
-				return;
94
-			}
95
-			$this->sync_service->sync_many( array(
96
-				$this->sync_object_factory->create( Object_Type_Enum::POST, $post_id ),
97
-				$this->sync_object_factory->create( Object_Type_Enum::USER, $post->post_author )
98
-			) );
99
-		} catch ( \Exception $e ) {
100
-			$this->log->error( "An error occurred while trying to sync post $post_id: " . $e->getMessage(), $e );
101
-		}
102
-
103
-	}
104
-
105
-	public function delete_post( $post_id ) {
106
-		$this->enqueue( array( 'do_delete', $post_id ) );
107
-	}
108
-
109
-	public function do_delete( $post_id ) {
110
-		try {
111
-			$this->sync_service->delete_one( Object_Type_Enum::POST, $post_id );
112
-		} catch ( \Exception $e ) {
113
-			$this->log->error( "An error occurred while trying to delete post $post_id: " . $e->getMessage(), $e );
114
-		}
115
-	}
8
+    /**
9
+     * @var \Wordlift_Log_Service
10
+     */
11
+    private $log;
12
+
13
+    /**
14
+     * @var Sync_Service
15
+     */
16
+    private $sync_service;
17
+
18
+    /**
19
+     * @var Sync_Object_Adapter_Factory
20
+     */
21
+    private $sync_object_factory;
22
+
23
+    /**
24
+     * Sync_Post_Hooks constructor.
25
+     *
26
+     * @param Sync_Service $sync_service
27
+     * @param Sync_Object_Adapter_Factory $sync_object_factory
28
+     */
29
+    function __construct( $sync_service, $sync_object_factory ) {
30
+        parent::__construct();
31
+
32
+        $this->log = \Wordlift_Log_Service::get_logger( get_class() );
33
+
34
+        $this->sync_service        = $sync_service;
35
+        $this->sync_object_factory = $sync_object_factory;
36
+
37
+        $this->register_hooks();
38
+    }
39
+
40
+    private function register_hooks() {
41
+        /**
42
+         * Register hooks for post and meta.
43
+         */
44
+        add_action( 'save_post', array( $this, 'save_post' ) );
45
+        add_action( 'added_post_meta', array( $this, 'changed_post_meta' ), 10, 4 );
46
+        add_action( 'updated_post_meta', array( $this, 'changed_post_meta' ), 10, 4 );
47
+        add_action( 'deleted_post_meta', array( $this, 'changed_post_meta' ), 10, 4 );
48
+        add_action( 'delete_post', array( $this, 'delete_post' ) );
49
+        // Remove post when its trashed.
50
+        add_action( 'trashed_post', array( $this, 'delete_post' ) );
51
+        // Save the post when its untrashed.
52
+        add_action( 'untrashed_post', array( $this, 'save_post' ) );
53
+
54
+    }
55
+
56
+    public function save_post( $post_id ) {
57
+
58
+        if ( ! in_array( get_post_type( $post_id ), \Wordlift_Entity_Service::valid_entity_post_types() ) ) {
59
+            return;
60
+        }
61
+
62
+        $this->sync( $post_id );
63
+
64
+    }
65
+
66
+    public function changed_post_meta( $meta_id, $post_id, $meta_key, $_meta_value ) {
67
+
68
+        if ( in_array( $meta_key,
69
+                apply_filters( 'wl_dataset__sync_post_hooks__ignored_meta_keys',
70
+                    apply_filters( 'wl_dataset__sync_hooks__ignored_meta_keys',
71
+                        array(
72
+                            '_pingme',
73
+                            '_encloseme',
74
+                            'entity_url',
75
+                        ) ) ) )
76
+             || ! in_array( get_post_type( $post_id ), \Wordlift_Entity_Service::valid_entity_post_types() )
77
+        ) {
78
+            return;
79
+        }
80
+
81
+        $this->sync( $post_id );
82
+
83
+    }
84
+
85
+    private function sync( $post_id ) {
86
+        $this->enqueue( array( 'do_sync', $post_id ) );
87
+    }
88
+
89
+    public function do_sync( $post_id ) {
90
+        try {
91
+            $post = get_post( $post_id );
92
+            if ( ! isset( $post ) ) {
93
+                return;
94
+            }
95
+            $this->sync_service->sync_many( array(
96
+                $this->sync_object_factory->create( Object_Type_Enum::POST, $post_id ),
97
+                $this->sync_object_factory->create( Object_Type_Enum::USER, $post->post_author )
98
+            ) );
99
+        } catch ( \Exception $e ) {
100
+            $this->log->error( "An error occurred while trying to sync post $post_id: " . $e->getMessage(), $e );
101
+        }
102
+
103
+    }
104
+
105
+    public function delete_post( $post_id ) {
106
+        $this->enqueue( array( 'do_delete', $post_id ) );
107
+    }
108
+
109
+    public function do_delete( $post_id ) {
110
+        try {
111
+            $this->sync_service->delete_one( Object_Type_Enum::POST, $post_id );
112
+        } catch ( \Exception $e ) {
113
+            $this->log->error( "An error occurred while trying to delete post $post_id: " . $e->getMessage(), $e );
114
+        }
115
+    }
116 116
 
117 117
 }
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -26,10 +26,10 @@  discard block
 block discarded – undo
26 26
 	 * @param Sync_Service $sync_service
27 27
 	 * @param Sync_Object_Adapter_Factory $sync_object_factory
28 28
 	 */
29
-	function __construct( $sync_service, $sync_object_factory ) {
29
+	function __construct($sync_service, $sync_object_factory) {
30 30
 		parent::__construct();
31 31
 
32
-		$this->log = \Wordlift_Log_Service::get_logger( get_class() );
32
+		$this->log = \Wordlift_Log_Service::get_logger(get_class());
33 33
 
34 34
 		$this->sync_service        = $sync_service;
35 35
 		$this->sync_object_factory = $sync_object_factory;
@@ -41,76 +41,76 @@  discard block
 block discarded – undo
41 41
 		/**
42 42
 		 * Register hooks for post and meta.
43 43
 		 */
44
-		add_action( 'save_post', array( $this, 'save_post' ) );
45
-		add_action( 'added_post_meta', array( $this, 'changed_post_meta' ), 10, 4 );
46
-		add_action( 'updated_post_meta', array( $this, 'changed_post_meta' ), 10, 4 );
47
-		add_action( 'deleted_post_meta', array( $this, 'changed_post_meta' ), 10, 4 );
48
-		add_action( 'delete_post', array( $this, 'delete_post' ) );
44
+		add_action('save_post', array($this, 'save_post'));
45
+		add_action('added_post_meta', array($this, 'changed_post_meta'), 10, 4);
46
+		add_action('updated_post_meta', array($this, 'changed_post_meta'), 10, 4);
47
+		add_action('deleted_post_meta', array($this, 'changed_post_meta'), 10, 4);
48
+		add_action('delete_post', array($this, 'delete_post'));
49 49
 		// Remove post when its trashed.
50
-		add_action( 'trashed_post', array( $this, 'delete_post' ) );
50
+		add_action('trashed_post', array($this, 'delete_post'));
51 51
 		// Save the post when its untrashed.
52
-		add_action( 'untrashed_post', array( $this, 'save_post' ) );
52
+		add_action('untrashed_post', array($this, 'save_post'));
53 53
 
54 54
 	}
55 55
 
56
-	public function save_post( $post_id ) {
56
+	public function save_post($post_id) {
57 57
 
58
-		if ( ! in_array( get_post_type( $post_id ), \Wordlift_Entity_Service::valid_entity_post_types() ) ) {
58
+		if ( ! in_array(get_post_type($post_id), \Wordlift_Entity_Service::valid_entity_post_types())) {
59 59
 			return;
60 60
 		}
61 61
 
62
-		$this->sync( $post_id );
62
+		$this->sync($post_id);
63 63
 
64 64
 	}
65 65
 
66
-	public function changed_post_meta( $meta_id, $post_id, $meta_key, $_meta_value ) {
66
+	public function changed_post_meta($meta_id, $post_id, $meta_key, $_meta_value) {
67 67
 
68
-		if ( in_array( $meta_key,
69
-				apply_filters( 'wl_dataset__sync_post_hooks__ignored_meta_keys',
70
-					apply_filters( 'wl_dataset__sync_hooks__ignored_meta_keys',
68
+		if (in_array($meta_key,
69
+				apply_filters('wl_dataset__sync_post_hooks__ignored_meta_keys',
70
+					apply_filters('wl_dataset__sync_hooks__ignored_meta_keys',
71 71
 						array(
72 72
 							'_pingme',
73 73
 							'_encloseme',
74 74
 							'entity_url',
75
-						) ) ) )
76
-		     || ! in_array( get_post_type( $post_id ), \Wordlift_Entity_Service::valid_entity_post_types() )
75
+						))))
76
+		     || ! in_array(get_post_type($post_id), \Wordlift_Entity_Service::valid_entity_post_types())
77 77
 		) {
78 78
 			return;
79 79
 		}
80 80
 
81
-		$this->sync( $post_id );
81
+		$this->sync($post_id);
82 82
 
83 83
 	}
84 84
 
85
-	private function sync( $post_id ) {
86
-		$this->enqueue( array( 'do_sync', $post_id ) );
85
+	private function sync($post_id) {
86
+		$this->enqueue(array('do_sync', $post_id));
87 87
 	}
88 88
 
89
-	public function do_sync( $post_id ) {
89
+	public function do_sync($post_id) {
90 90
 		try {
91
-			$post = get_post( $post_id );
92
-			if ( ! isset( $post ) ) {
91
+			$post = get_post($post_id);
92
+			if ( ! isset($post)) {
93 93
 				return;
94 94
 			}
95
-			$this->sync_service->sync_many( array(
96
-				$this->sync_object_factory->create( Object_Type_Enum::POST, $post_id ),
97
-				$this->sync_object_factory->create( Object_Type_Enum::USER, $post->post_author )
98
-			) );
99
-		} catch ( \Exception $e ) {
100
-			$this->log->error( "An error occurred while trying to sync post $post_id: " . $e->getMessage(), $e );
95
+			$this->sync_service->sync_many(array(
96
+				$this->sync_object_factory->create(Object_Type_Enum::POST, $post_id),
97
+				$this->sync_object_factory->create(Object_Type_Enum::USER, $post->post_author)
98
+			));
99
+		} catch (\Exception $e) {
100
+			$this->log->error("An error occurred while trying to sync post $post_id: ".$e->getMessage(), $e);
101 101
 		}
102 102
 
103 103
 	}
104 104
 
105
-	public function delete_post( $post_id ) {
106
-		$this->enqueue( array( 'do_delete', $post_id ) );
105
+	public function delete_post($post_id) {
106
+		$this->enqueue(array('do_delete', $post_id));
107 107
 	}
108 108
 
109
-	public function do_delete( $post_id ) {
109
+	public function do_delete($post_id) {
110 110
 		try {
111
-			$this->sync_service->delete_one( Object_Type_Enum::POST, $post_id );
112
-		} catch ( \Exception $e ) {
113
-			$this->log->error( "An error occurred while trying to delete post $post_id: " . $e->getMessage(), $e );
111
+			$this->sync_service->delete_one(Object_Type_Enum::POST, $post_id);
112
+		} catch (\Exception $e) {
113
+			$this->log->error("An error occurred while trying to delete post $post_id: ".$e->getMessage(), $e);
114 114
 		}
115 115
 	}
116 116
 
Please login to merge, or discard this patch.