Completed
Push — develop ( c1be74...f8bbf2 )
by David
06:55
created
src/includes/class-wordlift-log-service.php 3 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -73,6 +73,9 @@  discard block
 block discarded – undo
73 73
 	}
74 74
 
75 75
 
76
+	/**
77
+	 * @param string $class_name
78
+	 */
76 79
 	public static function get_logger( $class_name ) {
77 80
 
78 81
 		return new Wordlift_Log_Service( $class_name );
@@ -119,6 +122,9 @@  discard block
 block discarded – undo
119 122
 
120 123
 	}
121 124
 
125
+	/**
126
+	 * @param Exception $exception
127
+	 */
122 128
 	public function error( $message, $exception ) {
123 129
 
124 130
 		$this->log( self::ERROR, $message );
Please login to merge, or discard this patch.
Indentation   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -7,146 +7,146 @@
 block discarded – undo
7 7
  */
8 8
 class Wordlift_Log_Service {
9 9
 
10
-	const MESSAGE_TEMPLATE = '%-6s [%-40.40s] %s';
11
-
12
-	const ERROR = 4;
13
-	const WARN = 3;
14
-	const INFO = 2;
15
-	const DEBUG = 1;
16
-	const TRACE = 0;
17
-
18
-	/**
19
-	 * The class related to the logs.
20
-	 *
21
-	 * @since  1.0.0
22
-	 * @access private
23
-	 * @var string $class_name The class related to the logs.
24
-	 */
25
-	private $class_name;
26
-
27
-	/**
28
-	 * The log levels for printing in log lines.
29
-	 *
30
-	 * @var array $levels An array of log levels.
31
-	 */
32
-	private static $levels = array(
33
-		self::TRACE => 'TRACE',
34
-		self::DEBUG => 'DEBUG',
35
-		self::INFO  => 'INFO',
36
-		self::WARN  => 'WARN',
37
-		self::ERROR => 'ERROR',
38
-	);
39
-
40
-	/**
41
-	 * A singleton instance for legacy logging.
42
-	 *
43
-	 * @since  3.10.0
44
-	 * @access private
45
-	 * @var \Wordlift_Log_Service $instance A singleton instance for legacy logging.
46
-	 */
47
-	private static $instance = null;
10
+    const MESSAGE_TEMPLATE = '%-6s [%-40.40s] %s';
11
+
12
+    const ERROR = 4;
13
+    const WARN = 3;
14
+    const INFO = 2;
15
+    const DEBUG = 1;
16
+    const TRACE = 0;
17
+
18
+    /**
19
+     * The class related to the logs.
20
+     *
21
+     * @since  1.0.0
22
+     * @access private
23
+     * @var string $class_name The class related to the logs.
24
+     */
25
+    private $class_name;
26
+
27
+    /**
28
+     * The log levels for printing in log lines.
29
+     *
30
+     * @var array $levels An array of log levels.
31
+     */
32
+    private static $levels = array(
33
+        self::TRACE => 'TRACE',
34
+        self::DEBUG => 'DEBUG',
35
+        self::INFO  => 'INFO',
36
+        self::WARN  => 'WARN',
37
+        self::ERROR => 'ERROR',
38
+    );
39
+
40
+    /**
41
+     * A singleton instance for legacy logging.
42
+     *
43
+     * @since  3.10.0
44
+     * @access private
45
+     * @var \Wordlift_Log_Service $instance A singleton instance for legacy logging.
46
+     */
47
+    private static $instance = null;
48 48
 
49
-	/**
50
-	 * Create an instance of the Log service.
51
-	 *
52
-	 * @param string $class_name The class related to the logs.
53
-	 *
54
-	 * @since 1.0.0
55
-	 *
56
-	 */
57
-	public function __construct( $class_name ) {
49
+    /**
50
+     * Create an instance of the Log service.
51
+     *
52
+     * @param string $class_name The class related to the logs.
53
+     *
54
+     * @since 1.0.0
55
+     *
56
+     */
57
+    public function __construct( $class_name ) {
58 58
 
59
-		$this->class_name = $class_name;
59
+        $this->class_name = $class_name;
60 60
 
61
-	}
61
+    }
62 62
 
63
-	/**
64
-	 * Get the ROOT logger.
65
-	 *
66
-	 * @return \Wordlift_Log_Service A singleton instance for legacy logging.
67
-	 * @since 3.10.0
68
-	 *
69
-	 */
70
-	public static function get_instance() {
63
+    /**
64
+     * Get the ROOT logger.
65
+     *
66
+     * @return \Wordlift_Log_Service A singleton instance for legacy logging.
67
+     * @since 3.10.0
68
+     *
69
+     */
70
+    public static function get_instance() {
71 71
 
72
-		return self::$instance ?: self::$instance = new Wordlift_Log_Service( 'ROOT' );
73
-	}
72
+        return self::$instance ?: self::$instance = new Wordlift_Log_Service( 'ROOT' );
73
+    }
74 74
 
75 75
 
76
-	public static function get_logger( $class_name ) {
76
+    public static function get_logger( $class_name ) {
77 77
 
78
-		return new Wordlift_Log_Service( $class_name );
78
+        return new Wordlift_Log_Service( $class_name );
79 79
 
80
-	}
80
+    }
81 81
 
82
-	/**
83
-	 * Log a message.
84
-	 *
85
-	 * @param string $level The log level.
86
-	 * @param string $message The message to log.
87
-	 *
88
-	 * @since 1.0.0
89
-	 *
90
-	 */
91
-	public function log( $level, $message ) {
82
+    /**
83
+     * Log a message.
84
+     *
85
+     * @param string $level The log level.
86
+     * @param string $message The message to log.
87
+     *
88
+     * @since 1.0.0
89
+     *
90
+     */
91
+    public function log( $level, $message ) {
92 92
 
93
-		// echo( sprintf( self::MESSAGE_TEMPLATE . "\n", self::$levels[ $level ], $this->class_name, is_array( $message ) ? implode( ', ', $message ) : $message ) );
93
+        // echo( sprintf( self::MESSAGE_TEMPLATE . "\n", self::$levels[ $level ], $this->class_name, is_array( $message ) ? implode( ', ', $message ) : $message ) );
94 94
 
95
-		// Bail out if `WL_DEBUG` isn't defined or it's false.
96
-		if ( ! defined( 'WL_DEBUG' ) || false === WL_DEBUG ) {
97
-			return;
98
-		}
95
+        // Bail out if `WL_DEBUG` isn't defined or it's false.
96
+        if ( ! defined( 'WL_DEBUG' ) || false === WL_DEBUG ) {
97
+            return;
98
+        }
99 99
 
100
-		// Bail out if WordLift log level isn't defined, and WP debug is disabled.
101
-		if ( ! defined( 'WL_LOG_LEVEL' ) && $level < self::ERROR
102
-		     && ( ! defined( 'WP_DEBUG' ) || false === WP_DEBUG ) ) {
103
-			return;
104
-		}
100
+        // Bail out if WordLift log level isn't defined, and WP debug is disabled.
101
+        if ( ! defined( 'WL_LOG_LEVEL' ) && $level < self::ERROR
102
+             && ( ! defined( 'WP_DEBUG' ) || false === WP_DEBUG ) ) {
103
+            return;
104
+        }
105 105
 
106
-		// Bail out if the log message is below the minimum log level.
107
-		if ( defined( 'WL_LOG_LEVEL' ) && $level < intval( WL_LOG_LEVEL ) ) {
108
-			return;
109
-		}
106
+        // Bail out if the log message is below the minimum log level.
107
+        if ( defined( 'WL_LOG_LEVEL' ) && $level < intval( WL_LOG_LEVEL ) ) {
108
+            return;
109
+        }
110 110
 
111
-		// Bail out if there's a filter and we don't match it.
112
-		$class_name = wp_slash( $this->class_name );
113
-		if ( defined( 'WL_LOG_FILTER' ) && 1 !== preg_match( "/(^|,)$class_name($|,)/", WL_LOG_FILTER ) ) {
114
-			return;
115
-		}
111
+        // Bail out if there's a filter and we don't match it.
112
+        $class_name = wp_slash( $this->class_name );
113
+        if ( defined( 'WL_LOG_FILTER' ) && 1 !== preg_match( "/(^|,)$class_name($|,)/", WL_LOG_FILTER ) ) {
114
+            return;
115
+        }
116 116
 
117
-		// Finally log the message.
118
-		error_log( sprintf( self::MESSAGE_TEMPLATE, self::$levels[ $level ], $this->class_name, is_array( $message ) ? implode( ', ', $message ) : $message ) );
117
+        // Finally log the message.
118
+        error_log( sprintf( self::MESSAGE_TEMPLATE, self::$levels[ $level ], $this->class_name, is_array( $message ) ? implode( ', ', $message ) : $message ) );
119 119
 
120
-	}
120
+    }
121 121
 
122
-	public function error( $message, $exception ) {
122
+    public function error( $message, $exception ) {
123 123
 
124
-		$this->log( self::ERROR, $message );
124
+        $this->log( self::ERROR, $message );
125 125
 
126
-	}
126
+    }
127 127
 
128
-	public function warn( $message ) {
128
+    public function warn( $message ) {
129 129
 
130
-		$this->log( self::WARN, $message );
130
+        $this->log( self::WARN, $message );
131 131
 
132
-	}
132
+    }
133 133
 
134
-	public function info( $message ) {
134
+    public function info( $message ) {
135 135
 
136
-		$this->log( self::INFO, $message );
136
+        $this->log( self::INFO, $message );
137 137
 
138
-	}
138
+    }
139 139
 
140
-	public function debug( $message ) {
140
+    public function debug( $message ) {
141 141
 
142
-		$this->log( self::DEBUG, $message );
142
+        $this->log( self::DEBUG, $message );
143 143
 
144
-	}
144
+    }
145 145
 
146
-	public function trace( $message ) {
146
+    public function trace( $message ) {
147 147
 
148
-		$this->log( self::TRACE, $message );
148
+        $this->log( self::TRACE, $message );
149 149
 
150
-	}
150
+    }
151 151
 
152 152
 }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 	 * @since 1.0.0
55 55
 	 *
56 56
 	 */
57
-	public function __construct( $class_name ) {
57
+	public function __construct($class_name) {
58 58
 
59 59
 		$this->class_name = $class_name;
60 60
 
@@ -69,13 +69,13 @@  discard block
 block discarded – undo
69 69
 	 */
70 70
 	public static function get_instance() {
71 71
 
72
-		return self::$instance ?: self::$instance = new Wordlift_Log_Service( 'ROOT' );
72
+		return self::$instance ?: self::$instance = new Wordlift_Log_Service('ROOT');
73 73
 	}
74 74
 
75 75
 
76
-	public static function get_logger( $class_name ) {
76
+	public static function get_logger($class_name) {
77 77
 
78
-		return new Wordlift_Log_Service( $class_name );
78
+		return new Wordlift_Log_Service($class_name);
79 79
 
80 80
 	}
81 81
 
@@ -88,64 +88,64 @@  discard block
 block discarded – undo
88 88
 	 * @since 1.0.0
89 89
 	 *
90 90
 	 */
91
-	public function log( $level, $message ) {
91
+	public function log($level, $message) {
92 92
 
93 93
 		// echo( sprintf( self::MESSAGE_TEMPLATE . "\n", self::$levels[ $level ], $this->class_name, is_array( $message ) ? implode( ', ', $message ) : $message ) );
94 94
 
95 95
 		// Bail out if `WL_DEBUG` isn't defined or it's false.
96
-		if ( ! defined( 'WL_DEBUG' ) || false === WL_DEBUG ) {
96
+		if ( ! defined('WL_DEBUG') || false === WL_DEBUG) {
97 97
 			return;
98 98
 		}
99 99
 
100 100
 		// Bail out if WordLift log level isn't defined, and WP debug is disabled.
101
-		if ( ! defined( 'WL_LOG_LEVEL' ) && $level < self::ERROR
102
-		     && ( ! defined( 'WP_DEBUG' ) || false === WP_DEBUG ) ) {
101
+		if ( ! defined('WL_LOG_LEVEL') && $level < self::ERROR
102
+		     && ( ! defined('WP_DEBUG') || false === WP_DEBUG)) {
103 103
 			return;
104 104
 		}
105 105
 
106 106
 		// Bail out if the log message is below the minimum log level.
107
-		if ( defined( 'WL_LOG_LEVEL' ) && $level < intval( WL_LOG_LEVEL ) ) {
107
+		if (defined('WL_LOG_LEVEL') && $level < intval(WL_LOG_LEVEL)) {
108 108
 			return;
109 109
 		}
110 110
 
111 111
 		// Bail out if there's a filter and we don't match it.
112
-		$class_name = wp_slash( $this->class_name );
113
-		if ( defined( 'WL_LOG_FILTER' ) && 1 !== preg_match( "/(^|,)$class_name($|,)/", WL_LOG_FILTER ) ) {
112
+		$class_name = wp_slash($this->class_name);
113
+		if (defined('WL_LOG_FILTER') && 1 !== preg_match("/(^|,)$class_name($|,)/", WL_LOG_FILTER)) {
114 114
 			return;
115 115
 		}
116 116
 
117 117
 		// Finally log the message.
118
-		error_log( sprintf( self::MESSAGE_TEMPLATE, self::$levels[ $level ], $this->class_name, is_array( $message ) ? implode( ', ', $message ) : $message ) );
118
+		error_log(sprintf(self::MESSAGE_TEMPLATE, self::$levels[$level], $this->class_name, is_array($message) ? implode(', ', $message) : $message));
119 119
 
120 120
 	}
121 121
 
122
-	public function error( $message, $exception ) {
122
+	public function error($message, $exception) {
123 123
 
124
-		$this->log( self::ERROR, $message );
124
+		$this->log(self::ERROR, $message);
125 125
 
126 126
 	}
127 127
 
128
-	public function warn( $message ) {
128
+	public function warn($message) {
129 129
 
130
-		$this->log( self::WARN, $message );
130
+		$this->log(self::WARN, $message);
131 131
 
132 132
 	}
133 133
 
134
-	public function info( $message ) {
134
+	public function info($message) {
135 135
 
136
-		$this->log( self::INFO, $message );
136
+		$this->log(self::INFO, $message);
137 137
 
138 138
 	}
139 139
 
140
-	public function debug( $message ) {
140
+	public function debug($message) {
141 141
 
142
-		$this->log( self::DEBUG, $message );
142
+		$this->log(self::DEBUG, $message);
143 143
 
144 144
 	}
145 145
 
146
-	public function trace( $message ) {
146
+	public function trace($message) {
147 147
 
148
-		$this->log( self::TRACE, $message );
148
+		$this->log(self::TRACE, $message);
149 149
 
150 150
 	}
151 151
 
Please login to merge, or discard this patch.
src/wordlift/dataset/class-sync-object-adapter.php 3 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -24,6 +24,7 @@
 block discarded – undo
24 24
 	 * @param int $type One of Object_Type_Enum.
25 25
 	 * @param int $object_id A post or term id.
26 26
 	 * @param Jsonld_Service
27
+	 * @param Jsonld_Service $jsonld_service
27 28
 	 *
28 29
 	 * @throws \Exception
29 30
 	 */
Please login to merge, or discard this patch.
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -7,78 +7,78 @@
 block discarded – undo
7 7
 
8 8
 class Sync_Object_Adapter {
9 9
 
10
-	const HASH = '_wl_jsonld_hash';
10
+    const HASH = '_wl_jsonld_hash';
11 11
 
12
-	private $object_id;
12
+    private $object_id;
13 13
 
14
-	private $type;
14
+    private $type;
15 15
 
16
-	private $jsonld_service;
16
+    private $jsonld_service;
17 17
 
18
-	private $get_meta;
19
-	private $update_meta;
18
+    private $get_meta;
19
+    private $update_meta;
20 20
 
21
-	/**
22
-	 * Sync_Object_Adapter constructor.
23
-	 *
24
-	 * @param int $type One of Object_Type_Enum.
25
-	 * @param int $object_id A post or term id.
26
-	 * @param Jsonld_Service
27
-	 *
28
-	 * @throws \Exception
29
-	 */
30
-	function __construct( $type, $object_id, $jsonld_service ) {
21
+    /**
22
+     * Sync_Object_Adapter constructor.
23
+     *
24
+     * @param int $type One of Object_Type_Enum.
25
+     * @param int $object_id A post or term id.
26
+     * @param Jsonld_Service
27
+     *
28
+     * @throws \Exception
29
+     */
30
+    function __construct( $type, $object_id, $jsonld_service ) {
31 31
 
32
-		$this->type = filter_var( $type, FILTER_VALIDATE_INT, array(
33
-			'options' => array(
34
-				'min_range' => 0,
35
-				'max_range' => 1,
36
-			),
37
-		) );
32
+        $this->type = filter_var( $type, FILTER_VALIDATE_INT, array(
33
+            'options' => array(
34
+                'min_range' => 0,
35
+                'max_range' => 1,
36
+            ),
37
+        ) );
38 38
 
39
-		$this->object_id = filter_var( $object_id, FILTER_VALIDATE_INT );
39
+        $this->object_id = filter_var( $object_id, FILTER_VALIDATE_INT );
40 40
 
41
-		if ( null === $this->type ) {
42
-			throw new \Exception( 'Invalid $type.' );
43
-		}
44
-		if ( null === $this->object_id ) {
45
-			throw new \Exception( 'Invalid $object.' );
46
-		}
41
+        if ( null === $this->type ) {
42
+            throw new \Exception( 'Invalid $type.' );
43
+        }
44
+        if ( null === $this->object_id ) {
45
+            throw new \Exception( 'Invalid $object.' );
46
+        }
47 47
 
48
-		$this->jsonld_service = $jsonld_service;
48
+        $this->jsonld_service = $jsonld_service;
49 49
 
50
-		if ( Object_Type_Enum::POST === $this->type ) {
51
-			$this->get_meta    = 'get_post_meta';
52
-			$this->update_meta = 'update_post_meta';
53
-		} else {
54
-			$this->get_meta    = 'get_term_meta';
55
-			$this->update_meta = 'update_term_meta';
56
-		}
57
-	}
50
+        if ( Object_Type_Enum::POST === $this->type ) {
51
+            $this->get_meta    = 'get_post_meta';
52
+            $this->update_meta = 'update_post_meta';
53
+        } else {
54
+            $this->get_meta    = 'get_term_meta';
55
+            $this->update_meta = 'update_term_meta';
56
+        }
57
+    }
58 58
 
59
-	function is_changed() {
59
+    function is_changed() {
60 60
 
61
-		$hash = call_user_func( $this->get_meta, $this->object_id, self::HASH, true );
61
+        $hash = call_user_func( $this->get_meta, $this->object_id, self::HASH, true );
62 62
 
63
-		return empty( $hash ) || $hash !== $this->hash( $this->get_jsonld() );
64
-	}
63
+        return empty( $hash ) || $hash !== $this->hash( $this->get_jsonld() );
64
+    }
65 65
 
66
-	function get_jsonld() {
66
+    function get_jsonld() {
67 67
 
68
-		return apply_filters( 'wl_dataset__sync_service__sync_item__jsonld',
69
-			$this->jsonld_service->get( $this->type, $this->object_id ), $this->type, $this->object_id );
70
-	}
68
+        return apply_filters( 'wl_dataset__sync_service__sync_item__jsonld',
69
+            $this->jsonld_service->get( $this->type, $this->object_id ), $this->type, $this->object_id );
70
+    }
71 71
 
72
-	function get_jsonld_and_update_hash() {
73
-		$jsonld = $this->get_jsonld();
72
+    function get_jsonld_and_update_hash() {
73
+        $jsonld = $this->get_jsonld();
74 74
 
75
-		call_user_func( $this->update_meta, $this->object_id, self::HASH, $this->hash( $jsonld ) );
75
+        call_user_func( $this->update_meta, $this->object_id, self::HASH, $this->hash( $jsonld ) );
76 76
 
77
-		return $jsonld;
78
-	}
77
+        return $jsonld;
78
+    }
79 79
 
80
-	private function hash( $jsonld ) {
81
-		return sha1( wp_json_encode( $jsonld ) );
82
-	}
80
+    private function hash( $jsonld ) {
81
+        return sha1( wp_json_encode( $jsonld ) );
82
+    }
83 83
 
84 84
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -27,27 +27,27 @@  discard block
 block discarded – undo
27 27
 	 *
28 28
 	 * @throws \Exception
29 29
 	 */
30
-	function __construct( $type, $object_id, $jsonld_service ) {
30
+	function __construct($type, $object_id, $jsonld_service) {
31 31
 
32
-		$this->type = filter_var( $type, FILTER_VALIDATE_INT, array(
32
+		$this->type = filter_var($type, FILTER_VALIDATE_INT, array(
33 33
 			'options' => array(
34 34
 				'min_range' => 0,
35 35
 				'max_range' => 1,
36 36
 			),
37
-		) );
37
+		));
38 38
 
39
-		$this->object_id = filter_var( $object_id, FILTER_VALIDATE_INT );
39
+		$this->object_id = filter_var($object_id, FILTER_VALIDATE_INT);
40 40
 
41
-		if ( null === $this->type ) {
42
-			throw new \Exception( 'Invalid $type.' );
41
+		if (null === $this->type) {
42
+			throw new \Exception('Invalid $type.');
43 43
 		}
44
-		if ( null === $this->object_id ) {
45
-			throw new \Exception( 'Invalid $object.' );
44
+		if (null === $this->object_id) {
45
+			throw new \Exception('Invalid $object.');
46 46
 		}
47 47
 
48 48
 		$this->jsonld_service = $jsonld_service;
49 49
 
50
-		if ( Object_Type_Enum::POST === $this->type ) {
50
+		if (Object_Type_Enum::POST === $this->type) {
51 51
 			$this->get_meta    = 'get_post_meta';
52 52
 			$this->update_meta = 'update_post_meta';
53 53
 		} else {
@@ -58,27 +58,27 @@  discard block
 block discarded – undo
58 58
 
59 59
 	function is_changed() {
60 60
 
61
-		$hash = call_user_func( $this->get_meta, $this->object_id, self::HASH, true );
61
+		$hash = call_user_func($this->get_meta, $this->object_id, self::HASH, true);
62 62
 
63
-		return empty( $hash ) || $hash !== $this->hash( $this->get_jsonld() );
63
+		return empty($hash) || $hash !== $this->hash($this->get_jsonld());
64 64
 	}
65 65
 
66 66
 	function get_jsonld() {
67 67
 
68
-		return apply_filters( 'wl_dataset__sync_service__sync_item__jsonld',
69
-			$this->jsonld_service->get( $this->type, $this->object_id ), $this->type, $this->object_id );
68
+		return apply_filters('wl_dataset__sync_service__sync_item__jsonld',
69
+			$this->jsonld_service->get($this->type, $this->object_id), $this->type, $this->object_id);
70 70
 	}
71 71
 
72 72
 	function get_jsonld_and_update_hash() {
73 73
 		$jsonld = $this->get_jsonld();
74 74
 
75
-		call_user_func( $this->update_meta, $this->object_id, self::HASH, $this->hash( $jsonld ) );
75
+		call_user_func($this->update_meta, $this->object_id, self::HASH, $this->hash($jsonld));
76 76
 
77 77
 		return $jsonld;
78 78
 	}
79 79
 
80
-	private function hash( $jsonld ) {
81
-		return sha1( wp_json_encode( $jsonld ) );
80
+	private function hash($jsonld) {
81
+		return sha1(wp_json_encode($jsonld));
82 82
 	}
83 83
 
84 84
 }
Please login to merge, or discard this patch.
src/wordlift/class-object-type-enum.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -4,9 +4,9 @@
 block discarded – undo
4 4
 
5 5
 class Object_Type_Enum {
6 6
 
7
-	const POST = 0;
8
-	const TERM = 1;
9
-	const HOMEPAGE = 2;
10
-	const USER = 3;
7
+    const POST = 0;
8
+    const TERM = 1;
9
+    const HOMEPAGE = 2;
10
+    const USER = 3;
11 11
 
12 12
 }
Please login to merge, or discard this patch.
src/wordlift/dataset/class-sync-object-adapter-factory.php 2 patches
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -5,40 +5,40 @@
 block discarded – undo
5 5
 use Wordlift\Jsonld\Jsonld_Service;
6 6
 
7 7
 class Sync_Object_Adapter_Factory {
8
-	/**
9
-	 * @var Sync_Object_Adapter_Factory
10
-	 */
11
-	private static $instance;
12
-
13
-	/**
14
-	 * @var Jsonld_Service
15
-	 */
16
-	private $jsonld_service;
17
-
18
-	/**
19
-	 * Sync_Object_Adapter_Factory constructor.
20
-	 *
21
-	 * @param $jsonld_service
22
-	 */
23
-	function __construct( $jsonld_service ) {
24
-		$this->jsonld_service = $jsonld_service;
25
-
26
-		self::$instance = $this;
27
-	}
28
-
29
-	static function get_instance() {
30
-		return self::$instance;
31
-	}
32
-
33
-	/**
34
-	 * @param $type
35
-	 * @param $object_id
36
-	 *
37
-	 * @return Sync_Object_Adapter
38
-	 * @throws \Exception
39
-	 */
40
-	function create( $type, $object_id ) {
41
-		return new Sync_Object_Adapter( $type, $object_id, $this->jsonld_service );
42
-	}
8
+    /**
9
+     * @var Sync_Object_Adapter_Factory
10
+     */
11
+    private static $instance;
12
+
13
+    /**
14
+     * @var Jsonld_Service
15
+     */
16
+    private $jsonld_service;
17
+
18
+    /**
19
+     * Sync_Object_Adapter_Factory constructor.
20
+     *
21
+     * @param $jsonld_service
22
+     */
23
+    function __construct( $jsonld_service ) {
24
+        $this->jsonld_service = $jsonld_service;
25
+
26
+        self::$instance = $this;
27
+    }
28
+
29
+    static function get_instance() {
30
+        return self::$instance;
31
+    }
32
+
33
+    /**
34
+     * @param $type
35
+     * @param $object_id
36
+     *
37
+     * @return Sync_Object_Adapter
38
+     * @throws \Exception
39
+     */
40
+    function create( $type, $object_id ) {
41
+        return new Sync_Object_Adapter( $type, $object_id, $this->jsonld_service );
42
+    }
43 43
 
44 44
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 	 *
21 21
 	 * @param $jsonld_service
22 22
 	 */
23
-	function __construct( $jsonld_service ) {
23
+	function __construct($jsonld_service) {
24 24
 		$this->jsonld_service = $jsonld_service;
25 25
 
26 26
 		self::$instance = $this;
@@ -37,8 +37,8 @@  discard block
 block discarded – undo
37 37
 	 * @return Sync_Object_Adapter
38 38
 	 * @throws \Exception
39 39
 	 */
40
-	function create( $type, $object_id ) {
41
-		return new Sync_Object_Adapter( $type, $object_id, $this->jsonld_service );
40
+	function create($type, $object_id) {
41
+		return new Sync_Object_Adapter($type, $object_id, $this->jsonld_service);
42 42
 	}
43 43
 
44 44
 }
Please login to merge, or discard this patch.
src/wordlift/dataset/class-sync-service.php 2 patches
Indentation   +223 added lines, -223 removed lines patch added patch discarded remove patch
@@ -8,102 +8,102 @@  discard block
 block discarded – undo
8 8
 
9 9
 class Sync_Service {
10 10
 
11
-	/**
12
-	 * @var \Wordlift_Log_Service
13
-	 */
14
-	private $log;
15
-
16
-	/**
17
-	 * @var Api_Service
18
-	 */
19
-	private $api_service;
20
-
21
-	/**
22
-	 * @var Jsonld_Service
23
-	 */
24
-	private $jsonld_service;
25
-
26
-	/**
27
-	 * @var Sync_Background_Process
28
-	 */
29
-	private $sync_background_process;
30
-
31
-	/**
32
-	 * The number of posts processed in one call.
33
-	 *
34
-	 * @var int The batch size.
35
-	 */
36
-	private $batch_size;
37
-
38
-	/**
39
-	 * @var Sync_Object_Adapter_Factory
40
-	 */
41
-	private $sync_object_adapter_factory;
42
-
43
-	/**
44
-	 * @var Sync_Service
45
-	 */
46
-	private static $instance;
47
-
48
-	/**
49
-	 * Constructor.
50
-	 *
51
-	 * @param Api_Service $api_service The {@link Api_Service} used to communicate with the remote APIs.
52
-	 * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory
53
-	 */
54
-	public function __construct( $api_service, $sync_object_adapter_factory ) {
55
-
56
-		$this->log = \Wordlift_Log_Service::get_logger( get_class() );
57
-
58
-		$this->api_service                 = $api_service;
59
-		$this->sync_object_adapter_factory = $sync_object_adapter_factory;
60
-		$this->batch_size                  = 10;
61
-
62
-		// You need to initialize this early, otherwise the Background Process isn't registered in AJAX calls.
63
-		$this->sync_background_process = new Sync_Background_Process( $this );;
64
-
65
-		self::$instance = $this;
66
-
67
-	}
68
-
69
-	public static function get_instance() {
70
-		return self::$instance;
71
-	}
72
-
73
-	/**
74
-	 * Starts a new synchronization.
75
-	 */
76
-	public function start() {
77
-
78
-		// Create the Sync_Background_Process.
79
-		$this->sync_background_process->start();
80
-
81
-	}
82
-
83
-	/**
84
-	 * Request to cancel a background process.
85
-	 */
86
-	public function request_cancel() {
87
-
88
-		$this->sync_background_process->request_cancel();
89
-
90
-	}
91
-
92
-	/**
93
-	 * Get the next post IDs to synchronize.
94
-	 *
95
-	 * @return array An array of post IDs.
96
-	 */
97
-	public function next() {
98
-		global $wpdb;
99
-
100
-		$state = $this->info();
101
-
102
-		// Limit the query to the allowed post types.
103
-		$post_type_in = implode( "','", array_map( 'esc_sql', \Wordlift_Entity_Service::valid_entity_post_types() ) );
104
-
105
-		// Get the next post ID.
106
-		return $wpdb->get_col( "
11
+    /**
12
+     * @var \Wordlift_Log_Service
13
+     */
14
+    private $log;
15
+
16
+    /**
17
+     * @var Api_Service
18
+     */
19
+    private $api_service;
20
+
21
+    /**
22
+     * @var Jsonld_Service
23
+     */
24
+    private $jsonld_service;
25
+
26
+    /**
27
+     * @var Sync_Background_Process
28
+     */
29
+    private $sync_background_process;
30
+
31
+    /**
32
+     * The number of posts processed in one call.
33
+     *
34
+     * @var int The batch size.
35
+     */
36
+    private $batch_size;
37
+
38
+    /**
39
+     * @var Sync_Object_Adapter_Factory
40
+     */
41
+    private $sync_object_adapter_factory;
42
+
43
+    /**
44
+     * @var Sync_Service
45
+     */
46
+    private static $instance;
47
+
48
+    /**
49
+     * Constructor.
50
+     *
51
+     * @param Api_Service $api_service The {@link Api_Service} used to communicate with the remote APIs.
52
+     * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory
53
+     */
54
+    public function __construct( $api_service, $sync_object_adapter_factory ) {
55
+
56
+        $this->log = \Wordlift_Log_Service::get_logger( get_class() );
57
+
58
+        $this->api_service                 = $api_service;
59
+        $this->sync_object_adapter_factory = $sync_object_adapter_factory;
60
+        $this->batch_size                  = 10;
61
+
62
+        // You need to initialize this early, otherwise the Background Process isn't registered in AJAX calls.
63
+        $this->sync_background_process = new Sync_Background_Process( $this );;
64
+
65
+        self::$instance = $this;
66
+
67
+    }
68
+
69
+    public static function get_instance() {
70
+        return self::$instance;
71
+    }
72
+
73
+    /**
74
+     * Starts a new synchronization.
75
+     */
76
+    public function start() {
77
+
78
+        // Create the Sync_Background_Process.
79
+        $this->sync_background_process->start();
80
+
81
+    }
82
+
83
+    /**
84
+     * Request to cancel a background process.
85
+     */
86
+    public function request_cancel() {
87
+
88
+        $this->sync_background_process->request_cancel();
89
+
90
+    }
91
+
92
+    /**
93
+     * Get the next post IDs to synchronize.
94
+     *
95
+     * @return array An array of post IDs.
96
+     */
97
+    public function next() {
98
+        global $wpdb;
99
+
100
+        $state = $this->info();
101
+
102
+        // Limit the query to the allowed post types.
103
+        $post_type_in = implode( "','", array_map( 'esc_sql', \Wordlift_Entity_Service::valid_entity_post_types() ) );
104
+
105
+        // Get the next post ID.
106
+        return $wpdb->get_col( "
107 107
 			SELECT p.ID
108 108
 			FROM $wpdb->posts p
109 109
 			WHERE p.post_status = 'publish'
@@ -111,139 +111,139 @@  discard block
 block discarded – undo
111 111
 			ORDER BY p.ID
112 112
 			LIMIT {$state->index},{$this->batch_size}
113 113
 			" );
114
-	}
114
+    }
115 115
 
116
-	public function count() {
117
-		global $wpdb;
118
-		$post_type_in = implode( "','", array_map( 'esc_sql', \Wordlift_Entity_Service::valid_entity_post_types() ) );
116
+    public function count() {
117
+        global $wpdb;
118
+        $post_type_in = implode( "','", array_map( 'esc_sql', \Wordlift_Entity_Service::valid_entity_post_types() ) );
119 119
 
120
-		return $wpdb->get_var( "
120
+        return $wpdb->get_var( "
121 121
 			SELECT COUNT(1)
122 122
 			FROM $wpdb->posts p
123 123
 			WHERE p.post_status = 'publish'
124 124
 			  AND p.post_type IN ('$post_type_in')
125 125
 			" );
126
-	}
127
-
128
-	public function info() {
129
-		return Sync_Background_Process::get_state();
130
-	}
131
-
132
-	/**
133
-	 * @param $type
134
-	 * @param $post_id
135
-	 *
136
-	 * @throws \Exception
137
-	 */
138
-	public function sync_one( $type, $post_id ) {
139
-
140
-		if ( Object_Type_Enum::POST !== $type ) {
141
-			throw new \Exception( "Type $type is unsupported." );
142
-		}
143
-
144
-		$this->sync_items( array( $post_id ), false );
145
-	}
146
-
147
-	public function sync_items( $post_ids, $clear = true ) {
148
-
149
-		$this->log->debug( sprintf( 'Synchronizing post(s) %s...', implode( ', ', $post_ids ) ) );
150
-
151
-		debug_print_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 10 );
152
-
153
-		// If we're starting the sync, try to clear the dataset.
154
-		if ( $clear && 0 === $this->info()->index ) {
155
-			$this->api_service->request( 'DELETE', '/middleware/dataset/delete' );
156
-		}
157
-
158
-		$that         = $this;
159
-		$request_body = array_filter( array_map( function ( $post_id ) use ( $that ) {
160
-			// Check if the post type is public.
161
-			$post_type     = get_post_type( $post_id );
162
-			$post_type_obj = get_post_type_object( $post_type );
163
-			if ( ! $post_type_obj->public ) {
164
-				return false;
165
-			}
166
-
167
-			$is_private       = ( 'publish' !== get_post_status( $post_id ) );
168
-			$uri              = get_post_meta( $post_id, 'entity_url', true );
169
-			$object_adapter   = $that->sync_object_adapter_factory->create( Object_Type_Enum::POST, $post_id );
170
-			$jsonld           = $object_adapter->get_jsonld_and_update_hash();
171
-			$jsonld_as_string = wp_json_encode( $jsonld );
172
-
173
-			$that->log->trace( "Posting JSON-LD:\n$jsonld_as_string" );
174
-
175
-			return array(
176
-				'uri'     => $uri,
177
-				'model'   => $jsonld_as_string,
178
-				'private' => $is_private
179
-			);
180
-		}, $post_ids ) );
181
-
182
-		// There's no point in making a request if the request is empty.
183
-		if ( empty( $request_body ) ) {
184
-			return true;
185
-		}
186
-
187
-		// Make a request to the remote endpoint.
188
-		$state              = $this->info();
189
-		$state_header_value = str_replace( "\n", '', wp_json_encode( $state ) );
190
-		$response           = $this->api_service->request(
191
-			'POST', '/middleware/dataset/batch',
192
-			array(
193
-				'Content-Type'                     => 'application/json',
194
-				'X-Wordlift-Dataset-Sync-State-V1' => $state_header_value
195
-			),
196
-			wp_json_encode( $request_body ) );
197
-
198
-		$this->log->debug( "Response received: " . ( $response->is_success() ? 'yes' : 'no' ) );
199
-
200
-		// Update the sync date in case of success, otherwise log an error.
201
-		if ( $response->is_success() ) {
202
-
203
-			foreach ( $post_ids as $post_id ) {
204
-				update_post_meta( $post_id, '_wl_synced_gmt', current_time( 'mysql', true ) );
205
-			}
206
-
207
-			$this->log->debug( sprintf( 'Posts %s synchronized.', implode( ', ', $post_ids ) ) );
208
-
209
-			return true;
210
-		} else {
211
-			// @@todo: should we put a limit retry here?
212
-			$response_dump = var_export( $response, true );
213
-			$this->log->error(
214
-				sprintf( 'An error occurred while synchronizing the data for post IDs %s: %s', implode( ', ', $post_ids ), $response_dump ) );
215
-
216
-			return false;
217
-		}
218
-
219
-	}
220
-
221
-	/**
222
-	 * @param $post_id
223
-	 *
224
-	 * @todo Complete the delete item.
225
-	 */
226
-	public function delete_item( $post_id ) {
227
-		$uri = get_post_meta( $post_id, 'entity_url', true );
228
-		// Make a request to the remote endpoint.
229
-		$state_header_value = str_replace( wp_json_encode( $this->info() ), "\n", '' );
230
-		$response           = $this->api_service->request(
231
-			'DELETE', '/middleware/dataset?uri=' . rawurlencode( $uri ),
232
-			array(
233
-				'Content-Type'                     => 'application/ld+json',
234
-				'X-Wordlift-Dataset-Sync-State-V1' => $state_header_value
235
-			) );
236
-	}
237
-
238
-	public function get_batch_size() {
239
-
240
-		return $this->batch_size;
241
-	}
242
-
243
-	public function delete_one($type, $object_id) {
244
-
245
-		// @@todo implement.
246
-
247
-	}
126
+    }
127
+
128
+    public function info() {
129
+        return Sync_Background_Process::get_state();
130
+    }
131
+
132
+    /**
133
+     * @param $type
134
+     * @param $post_id
135
+     *
136
+     * @throws \Exception
137
+     */
138
+    public function sync_one( $type, $post_id ) {
139
+
140
+        if ( Object_Type_Enum::POST !== $type ) {
141
+            throw new \Exception( "Type $type is unsupported." );
142
+        }
143
+
144
+        $this->sync_items( array( $post_id ), false );
145
+    }
146
+
147
+    public function sync_items( $post_ids, $clear = true ) {
148
+
149
+        $this->log->debug( sprintf( 'Synchronizing post(s) %s...', implode( ', ', $post_ids ) ) );
150
+
151
+        debug_print_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 10 );
152
+
153
+        // If we're starting the sync, try to clear the dataset.
154
+        if ( $clear && 0 === $this->info()->index ) {
155
+            $this->api_service->request( 'DELETE', '/middleware/dataset/delete' );
156
+        }
157
+
158
+        $that         = $this;
159
+        $request_body = array_filter( array_map( function ( $post_id ) use ( $that ) {
160
+            // Check if the post type is public.
161
+            $post_type     = get_post_type( $post_id );
162
+            $post_type_obj = get_post_type_object( $post_type );
163
+            if ( ! $post_type_obj->public ) {
164
+                return false;
165
+            }
166
+
167
+            $is_private       = ( 'publish' !== get_post_status( $post_id ) );
168
+            $uri              = get_post_meta( $post_id, 'entity_url', true );
169
+            $object_adapter   = $that->sync_object_adapter_factory->create( Object_Type_Enum::POST, $post_id );
170
+            $jsonld           = $object_adapter->get_jsonld_and_update_hash();
171
+            $jsonld_as_string = wp_json_encode( $jsonld );
172
+
173
+            $that->log->trace( "Posting JSON-LD:\n$jsonld_as_string" );
174
+
175
+            return array(
176
+                'uri'     => $uri,
177
+                'model'   => $jsonld_as_string,
178
+                'private' => $is_private
179
+            );
180
+        }, $post_ids ) );
181
+
182
+        // There's no point in making a request if the request is empty.
183
+        if ( empty( $request_body ) ) {
184
+            return true;
185
+        }
186
+
187
+        // Make a request to the remote endpoint.
188
+        $state              = $this->info();
189
+        $state_header_value = str_replace( "\n", '', wp_json_encode( $state ) );
190
+        $response           = $this->api_service->request(
191
+            'POST', '/middleware/dataset/batch',
192
+            array(
193
+                'Content-Type'                     => 'application/json',
194
+                'X-Wordlift-Dataset-Sync-State-V1' => $state_header_value
195
+            ),
196
+            wp_json_encode( $request_body ) );
197
+
198
+        $this->log->debug( "Response received: " . ( $response->is_success() ? 'yes' : 'no' ) );
199
+
200
+        // Update the sync date in case of success, otherwise log an error.
201
+        if ( $response->is_success() ) {
202
+
203
+            foreach ( $post_ids as $post_id ) {
204
+                update_post_meta( $post_id, '_wl_synced_gmt', current_time( 'mysql', true ) );
205
+            }
206
+
207
+            $this->log->debug( sprintf( 'Posts %s synchronized.', implode( ', ', $post_ids ) ) );
208
+
209
+            return true;
210
+        } else {
211
+            // @@todo: should we put a limit retry here?
212
+            $response_dump = var_export( $response, true );
213
+            $this->log->error(
214
+                sprintf( 'An error occurred while synchronizing the data for post IDs %s: %s', implode( ', ', $post_ids ), $response_dump ) );
215
+
216
+            return false;
217
+        }
218
+
219
+    }
220
+
221
+    /**
222
+     * @param $post_id
223
+     *
224
+     * @todo Complete the delete item.
225
+     */
226
+    public function delete_item( $post_id ) {
227
+        $uri = get_post_meta( $post_id, 'entity_url', true );
228
+        // Make a request to the remote endpoint.
229
+        $state_header_value = str_replace( wp_json_encode( $this->info() ), "\n", '' );
230
+        $response           = $this->api_service->request(
231
+            'DELETE', '/middleware/dataset?uri=' . rawurlencode( $uri ),
232
+            array(
233
+                'Content-Type'                     => 'application/ld+json',
234
+                'X-Wordlift-Dataset-Sync-State-V1' => $state_header_value
235
+            ) );
236
+    }
237
+
238
+    public function get_batch_size() {
239
+
240
+        return $this->batch_size;
241
+    }
242
+
243
+    public function delete_one($type, $object_id) {
244
+
245
+        // @@todo implement.
246
+
247
+    }
248 248
 
249 249
 }
Please login to merge, or discard this patch.
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -51,16 +51,16 @@  discard block
 block discarded – undo
51 51
 	 * @param Api_Service $api_service The {@link Api_Service} used to communicate with the remote APIs.
52 52
 	 * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory
53 53
 	 */
54
-	public function __construct( $api_service, $sync_object_adapter_factory ) {
54
+	public function __construct($api_service, $sync_object_adapter_factory) {
55 55
 
56
-		$this->log = \Wordlift_Log_Service::get_logger( get_class() );
56
+		$this->log = \Wordlift_Log_Service::get_logger(get_class());
57 57
 
58 58
 		$this->api_service                 = $api_service;
59 59
 		$this->sync_object_adapter_factory = $sync_object_adapter_factory;
60 60
 		$this->batch_size                  = 10;
61 61
 
62 62
 		// You need to initialize this early, otherwise the Background Process isn't registered in AJAX calls.
63
-		$this->sync_background_process = new Sync_Background_Process( $this );;
63
+		$this->sync_background_process = new Sync_Background_Process($this); ;
64 64
 
65 65
 		self::$instance = $this;
66 66
 
@@ -100,29 +100,29 @@  discard block
 block discarded – undo
100 100
 		$state = $this->info();
101 101
 
102 102
 		// Limit the query to the allowed post types.
103
-		$post_type_in = implode( "','", array_map( 'esc_sql', \Wordlift_Entity_Service::valid_entity_post_types() ) );
103
+		$post_type_in = implode("','", array_map('esc_sql', \Wordlift_Entity_Service::valid_entity_post_types()));
104 104
 
105 105
 		// Get the next post ID.
106
-		return $wpdb->get_col( "
106
+		return $wpdb->get_col("
107 107
 			SELECT p.ID
108 108
 			FROM $wpdb->posts p
109 109
 			WHERE p.post_status = 'publish'
110 110
 			  AND p.post_type IN ('$post_type_in')
111 111
 			ORDER BY p.ID
112 112
 			LIMIT {$state->index},{$this->batch_size}
113
-			" );
113
+			");
114 114
 	}
115 115
 
116 116
 	public function count() {
117 117
 		global $wpdb;
118
-		$post_type_in = implode( "','", array_map( 'esc_sql', \Wordlift_Entity_Service::valid_entity_post_types() ) );
118
+		$post_type_in = implode("','", array_map('esc_sql', \Wordlift_Entity_Service::valid_entity_post_types()));
119 119
 
120
-		return $wpdb->get_var( "
120
+		return $wpdb->get_var("
121 121
 			SELECT COUNT(1)
122 122
 			FROM $wpdb->posts p
123 123
 			WHERE p.post_status = 'publish'
124 124
 			  AND p.post_type IN ('$post_type_in')
125
-			" );
125
+			");
126 126
 	}
127 127
 
128 128
 	public function info() {
@@ -135,83 +135,83 @@  discard block
 block discarded – undo
135 135
 	 *
136 136
 	 * @throws \Exception
137 137
 	 */
138
-	public function sync_one( $type, $post_id ) {
138
+	public function sync_one($type, $post_id) {
139 139
 
140
-		if ( Object_Type_Enum::POST !== $type ) {
141
-			throw new \Exception( "Type $type is unsupported." );
140
+		if (Object_Type_Enum::POST !== $type) {
141
+			throw new \Exception("Type $type is unsupported.");
142 142
 		}
143 143
 
144
-		$this->sync_items( array( $post_id ), false );
144
+		$this->sync_items(array($post_id), false);
145 145
 	}
146 146
 
147
-	public function sync_items( $post_ids, $clear = true ) {
147
+	public function sync_items($post_ids, $clear = true) {
148 148
 
149
-		$this->log->debug( sprintf( 'Synchronizing post(s) %s...', implode( ', ', $post_ids ) ) );
149
+		$this->log->debug(sprintf('Synchronizing post(s) %s...', implode(', ', $post_ids)));
150 150
 
151
-		debug_print_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 10 );
151
+		debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 10);
152 152
 
153 153
 		// If we're starting the sync, try to clear the dataset.
154
-		if ( $clear && 0 === $this->info()->index ) {
155
-			$this->api_service->request( 'DELETE', '/middleware/dataset/delete' );
154
+		if ($clear && 0 === $this->info()->index) {
155
+			$this->api_service->request('DELETE', '/middleware/dataset/delete');
156 156
 		}
157 157
 
158 158
 		$that         = $this;
159
-		$request_body = array_filter( array_map( function ( $post_id ) use ( $that ) {
159
+		$request_body = array_filter(array_map(function($post_id) use ($that) {
160 160
 			// Check if the post type is public.
161
-			$post_type     = get_post_type( $post_id );
162
-			$post_type_obj = get_post_type_object( $post_type );
163
-			if ( ! $post_type_obj->public ) {
161
+			$post_type     = get_post_type($post_id);
162
+			$post_type_obj = get_post_type_object($post_type);
163
+			if ( ! $post_type_obj->public) {
164 164
 				return false;
165 165
 			}
166 166
 
167
-			$is_private       = ( 'publish' !== get_post_status( $post_id ) );
168
-			$uri              = get_post_meta( $post_id, 'entity_url', true );
169
-			$object_adapter   = $that->sync_object_adapter_factory->create( Object_Type_Enum::POST, $post_id );
167
+			$is_private       = ('publish' !== get_post_status($post_id));
168
+			$uri              = get_post_meta($post_id, 'entity_url', true);
169
+			$object_adapter   = $that->sync_object_adapter_factory->create(Object_Type_Enum::POST, $post_id);
170 170
 			$jsonld           = $object_adapter->get_jsonld_and_update_hash();
171
-			$jsonld_as_string = wp_json_encode( $jsonld );
171
+			$jsonld_as_string = wp_json_encode($jsonld);
172 172
 
173
-			$that->log->trace( "Posting JSON-LD:\n$jsonld_as_string" );
173
+			$that->log->trace("Posting JSON-LD:\n$jsonld_as_string");
174 174
 
175 175
 			return array(
176 176
 				'uri'     => $uri,
177 177
 				'model'   => $jsonld_as_string,
178 178
 				'private' => $is_private
179 179
 			);
180
-		}, $post_ids ) );
180
+		}, $post_ids));
181 181
 
182 182
 		// There's no point in making a request if the request is empty.
183
-		if ( empty( $request_body ) ) {
183
+		if (empty($request_body)) {
184 184
 			return true;
185 185
 		}
186 186
 
187 187
 		// Make a request to the remote endpoint.
188 188
 		$state              = $this->info();
189
-		$state_header_value = str_replace( "\n", '', wp_json_encode( $state ) );
189
+		$state_header_value = str_replace("\n", '', wp_json_encode($state));
190 190
 		$response           = $this->api_service->request(
191 191
 			'POST', '/middleware/dataset/batch',
192 192
 			array(
193 193
 				'Content-Type'                     => 'application/json',
194 194
 				'X-Wordlift-Dataset-Sync-State-V1' => $state_header_value
195 195
 			),
196
-			wp_json_encode( $request_body ) );
196
+			wp_json_encode($request_body) );
197 197
 
198
-		$this->log->debug( "Response received: " . ( $response->is_success() ? 'yes' : 'no' ) );
198
+		$this->log->debug("Response received: ".($response->is_success() ? 'yes' : 'no'));
199 199
 
200 200
 		// Update the sync date in case of success, otherwise log an error.
201
-		if ( $response->is_success() ) {
201
+		if ($response->is_success()) {
202 202
 
203
-			foreach ( $post_ids as $post_id ) {
204
-				update_post_meta( $post_id, '_wl_synced_gmt', current_time( 'mysql', true ) );
203
+			foreach ($post_ids as $post_id) {
204
+				update_post_meta($post_id, '_wl_synced_gmt', current_time('mysql', true));
205 205
 			}
206 206
 
207
-			$this->log->debug( sprintf( 'Posts %s synchronized.', implode( ', ', $post_ids ) ) );
207
+			$this->log->debug(sprintf('Posts %s synchronized.', implode(', ', $post_ids)));
208 208
 
209 209
 			return true;
210 210
 		} else {
211 211
 			// @@todo: should we put a limit retry here?
212
-			$response_dump = var_export( $response, true );
212
+			$response_dump = var_export($response, true);
213 213
 			$this->log->error(
214
-				sprintf( 'An error occurred while synchronizing the data for post IDs %s: %s', implode( ', ', $post_ids ), $response_dump ) );
214
+				sprintf('An error occurred while synchronizing the data for post IDs %s: %s', implode(', ', $post_ids), $response_dump) );
215 215
 
216 216
 			return false;
217 217
 		}
@@ -223,12 +223,12 @@  discard block
 block discarded – undo
223 223
 	 *
224 224
 	 * @todo Complete the delete item.
225 225
 	 */
226
-	public function delete_item( $post_id ) {
227
-		$uri = get_post_meta( $post_id, 'entity_url', true );
226
+	public function delete_item($post_id) {
227
+		$uri = get_post_meta($post_id, 'entity_url', true);
228 228
 		// Make a request to the remote endpoint.
229
-		$state_header_value = str_replace( wp_json_encode( $this->info() ), "\n", '' );
229
+		$state_header_value = str_replace(wp_json_encode($this->info()), "\n", '');
230 230
 		$response           = $this->api_service->request(
231
-			'DELETE', '/middleware/dataset?uri=' . rawurlencode( $uri ),
231
+			'DELETE', '/middleware/dataset?uri='.rawurlencode($uri),
232 232
 			array(
233 233
 				'Content-Type'                     => 'application/ld+json',
234 234
 				'X-Wordlift-Dataset-Sync-State-V1' => $state_header_value
Please login to merge, or discard this patch.
src/wordlift/dataset/class-sync-hooks-entity-relation.php 2 patches
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -15,57 +15,57 @@
 block discarded – undo
15 15
  */
16 16
 class Sync_Hooks_Entity_Relation {
17 17
 
18
-	/**
19
-	 * @var \Wordlift_Entity_Service
20
-	 */
21
-	private $entity_service;
22
-
23
-	/**
24
-	 * Entity_Dct_Relation constructor.
25
-	 *
26
-	 * @param $entity_service \Wordlift_Entity_Service
27
-	 */
28
-	public function __construct( $entity_service ) {
29
-		$this->entity_service = $entity_service;
30
-
31
-		add_filter( 'wl_dataset__sync_service__sync_item__jsonld', array( $this, 'jsonld' ), 10, 3 );
32
-	}
33
-
34
-	public function jsonld( $jsonld, $type, $post_id ) {
35
-
36
-		// @@todo add support for terms.
37
-		if ( Object_Type_Enum::TERM === $type ) {
38
-			return $jsonld;
39
-		}
40
-
41
-		// Choose the dcterm property according to the post type.
42
-		$property = $this->entity_service->is_entity( $post_id )
43
-			? 'http://purl.org/dc/terms/relation'
44
-			: 'http://purl.org/dc/terms/references';
45
-
46
-		$references = array_unique( $this->entity_service->get_related_entities( $post_id ) );
47
-
48
-		// Bail out if there are no references.
49
-		if ( empty( $references ) ) {
50
-			return $jsonld;
51
-		}
52
-
53
-		if ( ! isset( $jsonld[0][ $property ] ) ) {
54
-			$jsonld[0][ $property ] = array();
55
-		}
56
-
57
-		if ( ! is_array( $jsonld[0][ $property ] ) ) {
58
-			$jsonld[0][ $property ] = array( $jsonld[0][ $property ] );
59
-		}
60
-
61
-		$that             = $this;
62
-		$references_array = array_values( array_map( function ( $item ) use ( $that ) {
63
-			return array( '@id' => $that->entity_service->get_uri( $item ) );
64
-		}, $references ) );
65
-
66
-		$jsonld[0][ $property ] = array_merge( $jsonld[0][ $property ], $references_array );
67
-
68
-		return $jsonld;
69
-	}
18
+    /**
19
+     * @var \Wordlift_Entity_Service
20
+     */
21
+    private $entity_service;
22
+
23
+    /**
24
+     * Entity_Dct_Relation constructor.
25
+     *
26
+     * @param $entity_service \Wordlift_Entity_Service
27
+     */
28
+    public function __construct( $entity_service ) {
29
+        $this->entity_service = $entity_service;
30
+
31
+        add_filter( 'wl_dataset__sync_service__sync_item__jsonld', array( $this, 'jsonld' ), 10, 3 );
32
+    }
33
+
34
+    public function jsonld( $jsonld, $type, $post_id ) {
35
+
36
+        // @@todo add support for terms.
37
+        if ( Object_Type_Enum::TERM === $type ) {
38
+            return $jsonld;
39
+        }
40
+
41
+        // Choose the dcterm property according to the post type.
42
+        $property = $this->entity_service->is_entity( $post_id )
43
+            ? 'http://purl.org/dc/terms/relation'
44
+            : 'http://purl.org/dc/terms/references';
45
+
46
+        $references = array_unique( $this->entity_service->get_related_entities( $post_id ) );
47
+
48
+        // Bail out if there are no references.
49
+        if ( empty( $references ) ) {
50
+            return $jsonld;
51
+        }
52
+
53
+        if ( ! isset( $jsonld[0][ $property ] ) ) {
54
+            $jsonld[0][ $property ] = array();
55
+        }
56
+
57
+        if ( ! is_array( $jsonld[0][ $property ] ) ) {
58
+            $jsonld[0][ $property ] = array( $jsonld[0][ $property ] );
59
+        }
60
+
61
+        $that             = $this;
62
+        $references_array = array_values( array_map( function ( $item ) use ( $that ) {
63
+            return array( '@id' => $that->entity_service->get_uri( $item ) );
64
+        }, $references ) );
65
+
66
+        $jsonld[0][ $property ] = array_merge( $jsonld[0][ $property ], $references_array );
67
+
68
+        return $jsonld;
69
+    }
70 70
 
71 71
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -25,45 +25,45 @@
 block discarded – undo
25 25
 	 *
26 26
 	 * @param $entity_service \Wordlift_Entity_Service
27 27
 	 */
28
-	public function __construct( $entity_service ) {
28
+	public function __construct($entity_service) {
29 29
 		$this->entity_service = $entity_service;
30 30
 
31
-		add_filter( 'wl_dataset__sync_service__sync_item__jsonld', array( $this, 'jsonld' ), 10, 3 );
31
+		add_filter('wl_dataset__sync_service__sync_item__jsonld', array($this, 'jsonld'), 10, 3);
32 32
 	}
33 33
 
34
-	public function jsonld( $jsonld, $type, $post_id ) {
34
+	public function jsonld($jsonld, $type, $post_id) {
35 35
 
36 36
 		// @@todo add support for terms.
37
-		if ( Object_Type_Enum::TERM === $type ) {
37
+		if (Object_Type_Enum::TERM === $type) {
38 38
 			return $jsonld;
39 39
 		}
40 40
 
41 41
 		// Choose the dcterm property according to the post type.
42
-		$property = $this->entity_service->is_entity( $post_id )
42
+		$property = $this->entity_service->is_entity($post_id)
43 43
 			? 'http://purl.org/dc/terms/relation'
44 44
 			: 'http://purl.org/dc/terms/references';
45 45
 
46
-		$references = array_unique( $this->entity_service->get_related_entities( $post_id ) );
46
+		$references = array_unique($this->entity_service->get_related_entities($post_id));
47 47
 
48 48
 		// Bail out if there are no references.
49
-		if ( empty( $references ) ) {
49
+		if (empty($references)) {
50 50
 			return $jsonld;
51 51
 		}
52 52
 
53
-		if ( ! isset( $jsonld[0][ $property ] ) ) {
54
-			$jsonld[0][ $property ] = array();
53
+		if ( ! isset($jsonld[0][$property])) {
54
+			$jsonld[0][$property] = array();
55 55
 		}
56 56
 
57
-		if ( ! is_array( $jsonld[0][ $property ] ) ) {
58
-			$jsonld[0][ $property ] = array( $jsonld[0][ $property ] );
57
+		if ( ! is_array($jsonld[0][$property])) {
58
+			$jsonld[0][$property] = array($jsonld[0][$property]);
59 59
 		}
60 60
 
61 61
 		$that             = $this;
62
-		$references_array = array_values( array_map( function ( $item ) use ( $that ) {
63
-			return array( '@id' => $that->entity_service->get_uri( $item ) );
64
-		}, $references ) );
62
+		$references_array = array_values(array_map(function($item) use ($that) {
63
+			return array('@id' => $that->entity_service->get_uri($item));
64
+		}, $references));
65 65
 
66
-		$jsonld[0][ $property ] = array_merge( $jsonld[0][ $property ], $references_array );
66
+		$jsonld[0][$property] = array_merge($jsonld[0][$property], $references_array);
67 67
 
68 68
 		return $jsonld;
69 69
 	}
Please login to merge, or discard this patch.
src/wordlift/dataset/index.php 2 patches
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -9,28 +9,28 @@
 block discarded – undo
9 9
 use Wordlift\Jsonld\Jsonld_Service;
10 10
 
11 11
 if ( ! defined( 'ABSPATH' ) ) {
12
-	exit;
12
+    exit;
13 13
 }
14 14
 // Register the Dataset JSON Endpoint. The `$api_service` variable must be defined in the calling file (wordlift.php).
15 15
 if ( apply_filters( 'wl_feature__enable__dataset-ng', false ) ) {
16
-	/*
16
+    /*
17 17
 	 * Add Composer Autoload with Mozart support.
18 18
 	 *
19 19
 	 * @since 3.27.6
20 20
 	 */
21 21
 //	require dirname( dirname( dirname( __FILE__ ) ) ) . '/vendor/autoload.php';
22 22
 
23
-	$sync_object_adapter_factory = new Sync_Object_Adapter_Factory( Jsonld_Service::get_instance() );
24
-	$sync_service                = new Sync_Service( $api_service, $sync_object_adapter_factory );
25
-	new Sync_Post_Hooks( $sync_service );
26
-	new Sync_User_Hooks( $sync_service );
27
-	new Sync_Wpjson_Endpoint( $sync_service );
28
-	new Sync_Page();
23
+    $sync_object_adapter_factory = new Sync_Object_Adapter_Factory( Jsonld_Service::get_instance() );
24
+    $sync_service                = new Sync_Service( $api_service, $sync_object_adapter_factory );
25
+    new Sync_Post_Hooks( $sync_service );
26
+    new Sync_User_Hooks( $sync_service );
27
+    new Sync_Wpjson_Endpoint( $sync_service );
28
+    new Sync_Page();
29 29
 
30
-	/**
31
-	 * @since 3.28.0
32
-	 * @see https://github.com/insideout10/wordlift-plugin/issues/1186
33
-	 */
34
-	new Sync_Hooks_Entity_Relation( Wordlift_Entity_Service::get_instance() );
30
+    /**
31
+     * @since 3.28.0
32
+     * @see https://github.com/insideout10/wordlift-plugin/issues/1186
33
+     */
34
+    new Sync_Hooks_Entity_Relation( Wordlift_Entity_Service::get_instance() );
35 35
 
36 36
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -8,11 +8,11 @@  discard block
 block discarded – undo
8 8
 use Wordlift\Dataset\Sync_Wpjson_Endpoint;
9 9
 use Wordlift\Jsonld\Jsonld_Service;
10 10
 
11
-if ( ! defined( 'ABSPATH' ) ) {
11
+if ( ! defined('ABSPATH')) {
12 12
 	exit;
13 13
 }
14 14
 // Register the Dataset JSON Endpoint. The `$api_service` variable must be defined in the calling file (wordlift.php).
15
-if ( apply_filters( 'wl_feature__enable__dataset-ng', false ) ) {
15
+if (apply_filters('wl_feature__enable__dataset-ng', false)) {
16 16
 	/*
17 17
 	 * Add Composer Autoload with Mozart support.
18 18
 	 *
@@ -20,17 +20,17 @@  discard block
 block discarded – undo
20 20
 	 */
21 21
 //	require dirname( dirname( dirname( __FILE__ ) ) ) . '/vendor/autoload.php';
22 22
 
23
-	$sync_object_adapter_factory = new Sync_Object_Adapter_Factory( Jsonld_Service::get_instance() );
24
-	$sync_service                = new Sync_Service( $api_service, $sync_object_adapter_factory );
25
-	new Sync_Post_Hooks( $sync_service );
26
-	new Sync_User_Hooks( $sync_service );
27
-	new Sync_Wpjson_Endpoint( $sync_service );
23
+	$sync_object_adapter_factory = new Sync_Object_Adapter_Factory(Jsonld_Service::get_instance());
24
+	$sync_service                = new Sync_Service($api_service, $sync_object_adapter_factory);
25
+	new Sync_Post_Hooks($sync_service);
26
+	new Sync_User_Hooks($sync_service);
27
+	new Sync_Wpjson_Endpoint($sync_service);
28 28
 	new Sync_Page();
29 29
 
30 30
 	/**
31 31
 	 * @since 3.28.0
32 32
 	 * @see https://github.com/insideout10/wordlift-plugin/issues/1186
33 33
 	 */
34
-	new Sync_Hooks_Entity_Relation( Wordlift_Entity_Service::get_instance() );
34
+	new Sync_Hooks_Entity_Relation(Wordlift_Entity_Service::get_instance());
35 35
 
36 36
 }
Please login to merge, or discard this patch.
src/wordlift/dataset/class-sync-user-hooks.php 2 patches
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -5,88 +5,88 @@
 block discarded – undo
5 5
 use Wordlift\Object_Type_Enum;
6 6
 
7 7
 class Sync_User_Hooks {
8
-	/**
9
-	 * @var \Wordlift_Log_Service
10
-	 */
11
-	private $log;
8
+    /**
9
+     * @var \Wordlift_Log_Service
10
+     */
11
+    private $log;
12 12
 
13
-	/**
14
-	 * @var Sync_Service
15
-	 */
16
-	private $sync_service;
13
+    /**
14
+     * @var Sync_Service
15
+     */
16
+    private $sync_service;
17 17
 
18
-	/**
19
-	 * Sync_User_Hooks constructor.
20
-	 *
21
-	 * @param Sync_Service $sync_service
22
-	 */
23
-	function __construct( Sync_Service $sync_service ) {
18
+    /**
19
+     * Sync_User_Hooks constructor.
20
+     *
21
+     * @param Sync_Service $sync_service
22
+     */
23
+    function __construct( Sync_Service $sync_service ) {
24 24
 
25
-		$this->log = \Wordlift_Log_Service::get_logger( get_class() );
25
+        $this->log = \Wordlift_Log_Service::get_logger( get_class() );
26 26
 
27
-		$this->sync_service = $sync_service;
27
+        $this->sync_service = $sync_service;
28 28
 
29
-		$this->register_hooks();
29
+        $this->register_hooks();
30 30
 
31
-	}
31
+    }
32 32
 
33
-	private function register_hooks() {
34
-		/**
35
-		 * Register hooks for user and meta.
36
-		 */
37
-		add_action( 'user_register', array( $this, 'changed_user' ) );
38
-		add_action( 'profile_update', array( $this, 'changed_user' ) );
39
-		add_action( 'added_user_meta', array( $this, 'changed_user_meta' ), 10, 3 );
40
-		add_action( 'updated_user_meta', array( $this, 'changed_user_meta' ), 10, 3 );
41
-		add_action( 'deleted_user_meta', array( $this, 'changed_user_meta' ), 10, 3 );
42
-		add_action( 'delete_user', array( $this, 'delete_user' ) );
33
+    private function register_hooks() {
34
+        /**
35
+         * Register hooks for user and meta.
36
+         */
37
+        add_action( 'user_register', array( $this, 'changed_user' ) );
38
+        add_action( 'profile_update', array( $this, 'changed_user' ) );
39
+        add_action( 'added_user_meta', array( $this, 'changed_user_meta' ), 10, 3 );
40
+        add_action( 'updated_user_meta', array( $this, 'changed_user_meta' ), 10, 3 );
41
+        add_action( 'deleted_user_meta', array( $this, 'changed_user_meta' ), 10, 3 );
42
+        add_action( 'delete_user', array( $this, 'delete_user' ) );
43 43
 
44
-	}
44
+    }
45 45
 
46
-	public function changed_user( $user_id ) {
46
+    public function changed_user( $user_id ) {
47 47
 
48
-		$this->sync( $user_id );
48
+        $this->sync( $user_id );
49 49
 
50
-	}
50
+    }
51 51
 
52
-	public function changed_user_meta( $meta_id, $user_id, $meta_key ) {
52
+    public function changed_user_meta( $meta_id, $user_id, $meta_key ) {
53 53
 
54
-		if ( in_array( $meta_key, apply_filters( 'wl_dataset__sync_user_hooks__ignored_meta_keys', array(
55
-			'rich_editing',
56
-			'comment_shortcuts',
57
-			'admin_color',
58
-			'use_ssl',
59
-			'show_admin_bar_front',
60
-			'wptests_capabilities',
61
-			'wptests_user_level',
62
-			'dismissed_wp_pointers',
63
-			'entity_url',
64
-		) ) ) ) {
65
-			return;
66
-		}
54
+        if ( in_array( $meta_key, apply_filters( 'wl_dataset__sync_user_hooks__ignored_meta_keys', array(
55
+            'rich_editing',
56
+            'comment_shortcuts',
57
+            'admin_color',
58
+            'use_ssl',
59
+            'show_admin_bar_front',
60
+            'wptests_capabilities',
61
+            'wptests_user_level',
62
+            'dismissed_wp_pointers',
63
+            'entity_url',
64
+        ) ) ) ) {
65
+            return;
66
+        }
67 67
 
68
-		$this->sync( $user_id );
68
+        $this->sync( $user_id );
69 69
 
70
-	}
70
+    }
71 71
 
72
-	private function sync( $user_id ) {
72
+    private function sync( $user_id ) {
73 73
 
74
-		try {
75
-			$this->sync_service->sync_one( Object_Type_Enum::USER, (int) $user_id );
76
-		} catch ( \Exception $e ) {
77
-			$this->log->error( "An error occurred while trying to sync user $user_id: " . $e->getMessage(), $e );
78
-		}
74
+        try {
75
+            $this->sync_service->sync_one( Object_Type_Enum::USER, (int) $user_id );
76
+        } catch ( \Exception $e ) {
77
+            $this->log->error( "An error occurred while trying to sync user $user_id: " . $e->getMessage(), $e );
78
+        }
79 79
 
80
-	}
80
+    }
81 81
 
82
-	public function delete_user( $user_id ) {
82
+    public function delete_user( $user_id ) {
83 83
 
84
-		try {
85
-			$this->sync_service->delete_one( Object_Type_Enum::USER, $user_id );
86
-		} catch ( \Exception $e ) {
87
-			$this->log->error( "An error occurred while trying to delete user $user_id: " . $e->getMessage(), $e );
88
-		}
84
+        try {
85
+            $this->sync_service->delete_one( Object_Type_Enum::USER, $user_id );
86
+        } catch ( \Exception $e ) {
87
+            $this->log->error( "An error occurred while trying to delete user $user_id: " . $e->getMessage(), $e );
88
+        }
89 89
 
90
-	}
90
+    }
91 91
 
92 92
 }
93 93
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -20,9 +20,9 @@  discard block
 block discarded – undo
20 20
 	 *
21 21
 	 * @param Sync_Service $sync_service
22 22
 	 */
23
-	function __construct( Sync_Service $sync_service ) {
23
+	function __construct(Sync_Service $sync_service) {
24 24
 
25
-		$this->log = \Wordlift_Log_Service::get_logger( get_class() );
25
+		$this->log = \Wordlift_Log_Service::get_logger(get_class());
26 26
 
27 27
 		$this->sync_service = $sync_service;
28 28
 
@@ -34,24 +34,24 @@  discard block
 block discarded – undo
34 34
 		/**
35 35
 		 * Register hooks for user and meta.
36 36
 		 */
37
-		add_action( 'user_register', array( $this, 'changed_user' ) );
38
-		add_action( 'profile_update', array( $this, 'changed_user' ) );
39
-		add_action( 'added_user_meta', array( $this, 'changed_user_meta' ), 10, 3 );
40
-		add_action( 'updated_user_meta', array( $this, 'changed_user_meta' ), 10, 3 );
41
-		add_action( 'deleted_user_meta', array( $this, 'changed_user_meta' ), 10, 3 );
42
-		add_action( 'delete_user', array( $this, 'delete_user' ) );
37
+		add_action('user_register', array($this, 'changed_user'));
38
+		add_action('profile_update', array($this, 'changed_user'));
39
+		add_action('added_user_meta', array($this, 'changed_user_meta'), 10, 3);
40
+		add_action('updated_user_meta', array($this, 'changed_user_meta'), 10, 3);
41
+		add_action('deleted_user_meta', array($this, 'changed_user_meta'), 10, 3);
42
+		add_action('delete_user', array($this, 'delete_user'));
43 43
 
44 44
 	}
45 45
 
46
-	public function changed_user( $user_id ) {
46
+	public function changed_user($user_id) {
47 47
 
48
-		$this->sync( $user_id );
48
+		$this->sync($user_id);
49 49
 
50 50
 	}
51 51
 
52
-	public function changed_user_meta( $meta_id, $user_id, $meta_key ) {
52
+	public function changed_user_meta($meta_id, $user_id, $meta_key) {
53 53
 
54
-		if ( in_array( $meta_key, apply_filters( 'wl_dataset__sync_user_hooks__ignored_meta_keys', array(
54
+		if (in_array($meta_key, apply_filters('wl_dataset__sync_user_hooks__ignored_meta_keys', array(
55 55
 			'rich_editing',
56 56
 			'comment_shortcuts',
57 57
 			'admin_color',
@@ -61,30 +61,30 @@  discard block
 block discarded – undo
61 61
 			'wptests_user_level',
62 62
 			'dismissed_wp_pointers',
63 63
 			'entity_url',
64
-		) ) ) ) {
64
+		)))) {
65 65
 			return;
66 66
 		}
67 67
 
68
-		$this->sync( $user_id );
68
+		$this->sync($user_id);
69 69
 
70 70
 	}
71 71
 
72
-	private function sync( $user_id ) {
72
+	private function sync($user_id) {
73 73
 
74 74
 		try {
75
-			$this->sync_service->sync_one( Object_Type_Enum::USER, (int) $user_id );
76
-		} catch ( \Exception $e ) {
77
-			$this->log->error( "An error occurred while trying to sync user $user_id: " . $e->getMessage(), $e );
75
+			$this->sync_service->sync_one(Object_Type_Enum::USER, (int) $user_id);
76
+		} catch (\Exception $e) {
77
+			$this->log->error("An error occurred while trying to sync user $user_id: ".$e->getMessage(), $e);
78 78
 		}
79 79
 
80 80
 	}
81 81
 
82
-	public function delete_user( $user_id ) {
82
+	public function delete_user($user_id) {
83 83
 
84 84
 		try {
85
-			$this->sync_service->delete_one( Object_Type_Enum::USER, $user_id );
86
-		} catch ( \Exception $e ) {
87
-			$this->log->error( "An error occurred while trying to delete user $user_id: " . $e->getMessage(), $e );
85
+			$this->sync_service->delete_one(Object_Type_Enum::USER, $user_id);
86
+		} catch (\Exception $e) {
87
+			$this->log->error("An error occurred while trying to delete user $user_id: ".$e->getMessage(), $e);
88 88
 		}
89 89
 
90 90
 	}
Please login to merge, or discard this patch.
src/wordlift/dataset/class-sync-post-hooks.php 2 patches
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -5,81 +5,81 @@
 block discarded – undo
5 5
 use Wordlift\Object_Type_Enum;
6 6
 
7 7
 class Sync_Post_Hooks {
8
-	/**
9
-	 * @var \Wordlift_Log_Service
10
-	 */
11
-	private $log;
8
+    /**
9
+     * @var \Wordlift_Log_Service
10
+     */
11
+    private $log;
12 12
 
13
-	/**
14
-	 * @var Sync_Service
15
-	 */
16
-	private $sync_service;
13
+    /**
14
+     * @var Sync_Service
15
+     */
16
+    private $sync_service;
17 17
 
18
-	/**
19
-	 * Sync_Post_Hooks constructor.
20
-	 *
21
-	 * @param Sync_Service $sync_service
22
-	 */
23
-	function __construct( $sync_service ) {
18
+    /**
19
+     * Sync_Post_Hooks constructor.
20
+     *
21
+     * @param Sync_Service $sync_service
22
+     */
23
+    function __construct( $sync_service ) {
24 24
 
25
-		$this->log = \Wordlift_Log_Service::get_logger( get_class() );
25
+        $this->log = \Wordlift_Log_Service::get_logger( get_class() );
26 26
 
27
-		$this->sync_service = $sync_service;
27
+        $this->sync_service = $sync_service;
28 28
 
29
-		$this->register_hooks();
29
+        $this->register_hooks();
30 30
 
31
-	}
31
+    }
32 32
 
33
-	private function register_hooks() {
34
-		/**
35
-		 * Register hooks for post and meta.
36
-		 */
37
-		add_action( 'save_post', array( $this, 'save_post' ) );
38
-		add_action( 'added_post_meta', array( $this, 'changed_post_meta' ), 10, 4 );
39
-		add_action( 'updated_post_meta', array( $this, 'changed_post_meta' ), 10, 4 );
40
-		add_action( 'deleted_post_meta', array( $this, 'changed_post_meta' ), 10, 4 );
41
-		add_action( 'delete_post', array( $this, 'delete_post' ) );
33
+    private function register_hooks() {
34
+        /**
35
+         * Register hooks for post and meta.
36
+         */
37
+        add_action( 'save_post', array( $this, 'save_post' ) );
38
+        add_action( 'added_post_meta', array( $this, 'changed_post_meta' ), 10, 4 );
39
+        add_action( 'updated_post_meta', array( $this, 'changed_post_meta' ), 10, 4 );
40
+        add_action( 'deleted_post_meta', array( $this, 'changed_post_meta' ), 10, 4 );
41
+        add_action( 'delete_post', array( $this, 'delete_post' ) );
42 42
 
43
-	}
43
+    }
44 44
 
45
-	public function save_post( $post_id ) {
45
+    public function save_post( $post_id ) {
46 46
 
47
-		$this->sync( $post_id );
47
+        $this->sync( $post_id );
48 48
 
49
-	}
49
+    }
50 50
 
51
-	public function changed_post_meta( $meta_id, $post_id, $meta_key, $_meta_value ) {
51
+    public function changed_post_meta( $meta_id, $post_id, $meta_key, $_meta_value ) {
52 52
 
53
-		if ( in_array( $meta_key, apply_filters( 'wl_dataset__sync_post_hooks__ignored_meta_keys', array(
54
-			'_pingme',
55
-			'_encloseme',
56
-			'entity_url',
57
-		) ) ) ) {
58
-			return;
59
-		}
53
+        if ( in_array( $meta_key, apply_filters( 'wl_dataset__sync_post_hooks__ignored_meta_keys', array(
54
+            '_pingme',
55
+            '_encloseme',
56
+            'entity_url',
57
+        ) ) ) ) {
58
+            return;
59
+        }
60 60
 
61
-		$this->sync( $post_id );
61
+        $this->sync( $post_id );
62 62
 
63
-	}
63
+    }
64 64
 
65
-	private function sync( $post_id ) {
65
+    private function sync( $post_id ) {
66 66
 
67
-		try {
68
-			$this->sync_service->sync_one( Object_Type_Enum::POST, $post_id );
69
-		} catch ( \Exception $e ) {
70
-			$this->log->error( "An error occurred while trying to sync post $post_id: " . $e->getMessage(), $e );
71
-		}
67
+        try {
68
+            $this->sync_service->sync_one( Object_Type_Enum::POST, $post_id );
69
+        } catch ( \Exception $e ) {
70
+            $this->log->error( "An error occurred while trying to sync post $post_id: " . $e->getMessage(), $e );
71
+        }
72 72
 
73
-	}
73
+    }
74 74
 
75
-	public function delete_post( $post_id ) {
75
+    public function delete_post( $post_id ) {
76 76
 
77
-		try {
78
-			$this->sync_service->delete_one( Object_Type_Enum::POST, $post_id );
79
-		} catch ( \Exception $e ) {
80
-			$this->log->error( "An error occurred while trying to delete post $post_id: " . $e->getMessage(), $e );
81
-		}
77
+        try {
78
+            $this->sync_service->delete_one( Object_Type_Enum::POST, $post_id );
79
+        } catch ( \Exception $e ) {
80
+            $this->log->error( "An error occurred while trying to delete post $post_id: " . $e->getMessage(), $e );
81
+        }
82 82
 
83
-	}
83
+    }
84 84
 
85 85
 }
86 86
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -20,9 +20,9 @@  discard block
 block discarded – undo
20 20
 	 *
21 21
 	 * @param Sync_Service $sync_service
22 22
 	 */
23
-	function __construct( $sync_service ) {
23
+	function __construct($sync_service) {
24 24
 
25
-		$this->log = \Wordlift_Log_Service::get_logger( get_class() );
25
+		$this->log = \Wordlift_Log_Service::get_logger(get_class());
26 26
 
27 27
 		$this->sync_service = $sync_service;
28 28
 
@@ -34,50 +34,50 @@  discard block
 block discarded – undo
34 34
 		/**
35 35
 		 * Register hooks for post and meta.
36 36
 		 */
37
-		add_action( 'save_post', array( $this, 'save_post' ) );
38
-		add_action( 'added_post_meta', array( $this, 'changed_post_meta' ), 10, 4 );
39
-		add_action( 'updated_post_meta', array( $this, 'changed_post_meta' ), 10, 4 );
40
-		add_action( 'deleted_post_meta', array( $this, 'changed_post_meta' ), 10, 4 );
41
-		add_action( 'delete_post', array( $this, 'delete_post' ) );
37
+		add_action('save_post', array($this, 'save_post'));
38
+		add_action('added_post_meta', array($this, 'changed_post_meta'), 10, 4);
39
+		add_action('updated_post_meta', array($this, 'changed_post_meta'), 10, 4);
40
+		add_action('deleted_post_meta', array($this, 'changed_post_meta'), 10, 4);
41
+		add_action('delete_post', array($this, 'delete_post'));
42 42
 
43 43
 	}
44 44
 
45
-	public function save_post( $post_id ) {
45
+	public function save_post($post_id) {
46 46
 
47
-		$this->sync( $post_id );
47
+		$this->sync($post_id);
48 48
 
49 49
 	}
50 50
 
51
-	public function changed_post_meta( $meta_id, $post_id, $meta_key, $_meta_value ) {
51
+	public function changed_post_meta($meta_id, $post_id, $meta_key, $_meta_value) {
52 52
 
53
-		if ( in_array( $meta_key, apply_filters( 'wl_dataset__sync_post_hooks__ignored_meta_keys', array(
53
+		if (in_array($meta_key, apply_filters('wl_dataset__sync_post_hooks__ignored_meta_keys', array(
54 54
 			'_pingme',
55 55
 			'_encloseme',
56 56
 			'entity_url',
57
-		) ) ) ) {
57
+		)))) {
58 58
 			return;
59 59
 		}
60 60
 
61
-		$this->sync( $post_id );
61
+		$this->sync($post_id);
62 62
 
63 63
 	}
64 64
 
65
-	private function sync( $post_id ) {
65
+	private function sync($post_id) {
66 66
 
67 67
 		try {
68
-			$this->sync_service->sync_one( Object_Type_Enum::POST, $post_id );
69
-		} catch ( \Exception $e ) {
70
-			$this->log->error( "An error occurred while trying to sync post $post_id: " . $e->getMessage(), $e );
68
+			$this->sync_service->sync_one(Object_Type_Enum::POST, $post_id);
69
+		} catch (\Exception $e) {
70
+			$this->log->error("An error occurred while trying to sync post $post_id: ".$e->getMessage(), $e);
71 71
 		}
72 72
 
73 73
 	}
74 74
 
75
-	public function delete_post( $post_id ) {
75
+	public function delete_post($post_id) {
76 76
 
77 77
 		try {
78
-			$this->sync_service->delete_one( Object_Type_Enum::POST, $post_id );
79
-		} catch ( \Exception $e ) {
80
-			$this->log->error( "An error occurred while trying to delete post $post_id: " . $e->getMessage(), $e );
78
+			$this->sync_service->delete_one(Object_Type_Enum::POST, $post_id);
79
+		} catch (\Exception $e) {
80
+			$this->log->error("An error occurred while trying to delete post $post_id: ".$e->getMessage(), $e);
81 81
 		}
82 82
 
83 83
 	}
Please login to merge, or discard this patch.