Completed
Pull Request — master (#1641)
by Naveen
01:35
created
src/wordlift/dataset/background/class-sync-background-process-state.php 2 patches
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -4,29 +4,29 @@
 block discarded – undo
4 4
 
5 5
 interface Sync_Background_Process_State {
6 6
 
7
-	public function enter();
8
-
9
-	public function leave();
10
-
11
-	/**
12
-	 * Task
13
-	 *
14
-	 * Override this method to perform any actions required on each
15
-	 * queue item. Return the modified item for further processing
16
-	 * in the next pass through. Or, return false to remove the
17
-	 * item from the queue.
18
-	 *
19
-	 * @param mixed $item Queue item to iterate over.
20
-	 *
21
-	 * @return mixed
22
-	 */
23
-	public function task( $item );
24
-
25
-	public function get_info();
26
-
27
-	/**
28
-	 * Try to resume an interrupted task.
29
-	 */
30
-	public function resume();
7
+    public function enter();
8
+
9
+    public function leave();
10
+
11
+    /**
12
+     * Task
13
+     *
14
+     * Override this method to perform any actions required on each
15
+     * queue item. Return the modified item for further processing
16
+     * in the next pass through. Or, return false to remove the
17
+     * item from the queue.
18
+     *
19
+     * @param mixed $item Queue item to iterate over.
20
+     *
21
+     * @return mixed
22
+     */
23
+    public function task( $item );
24
+
25
+    public function get_info();
26
+
27
+    /**
28
+     * Try to resume an interrupted task.
29
+     */
30
+    public function resume();
31 31
 
32 32
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@
 block discarded – undo
20 20
 	 *
21 21
 	 * @return mixed
22 22
 	 */
23
-	public function task( $item );
23
+	public function task($item);
24 24
 
25 25
 	public function get_info();
26 26
 
Please login to merge, or discard this patch.
dataset/background/class-sync-background-process-wpjson-endpoint.php 2 patches
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -6,82 +6,82 @@
 block discarded – undo
6 6
 
7 7
 class Sync_Background_Process_Wpjson_Endpoint {
8 8
 
9
-	/**
10
-	 * @var Sync_Background_Process
11
-	 */
12
-	private $sync_background_process;
13
-
14
-	/**
15
-	 * Sync_Background_Process_Wpjson_Endpoint constructor.
16
-	 *
17
-	 * @param Sync_Background_Process $sync_background_process
18
-	 */
19
-	public function __construct( $sync_background_process ) {
20
-
21
-		add_action( 'rest_api_init', array( $this, 'rest_api_init' ) );
22
-
23
-		$this->sync_background_process = $sync_background_process;
24
-
25
-	}
26
-
27
-	public function rest_api_init() {
28
-
29
-		register_rest_route(
30
-			'wordlift/v1',
31
-			'/dataset/background/sync',
32
-			array(
33
-				'methods'             => WP_REST_Server::CREATABLE,
34
-				'callback'            => array( $this->sync_background_process, 'start' ),
35
-				'permission_callback' => function () {
36
-					$user = wp_get_current_user();
37
-
38
-					return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true );
39
-				},
40
-			)
41
-		);
42
-
43
-		register_rest_route(
44
-			'wordlift/v1',
45
-			'/dataset/background/sync',
46
-			array(
47
-				'methods'             => WP_REST_Server::READABLE,
48
-				'callback'            => array( $this->sync_background_process, 'get_info' ),
49
-				'permission_callback' => function () {
50
-					$user = wp_get_current_user();
51
-
52
-					return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true );
53
-				},
54
-			)
55
-		);
56
-
57
-		register_rest_route(
58
-			'wordlift/v1',
59
-			'/dataset/background/sync',
60
-			array(
61
-				'methods'             => WP_REST_Server::DELETABLE,
62
-				'callback'            => array( $this->sync_background_process, 'stop' ),
63
-				'permission_callback' => function () {
64
-					$user = wp_get_current_user();
65
-
66
-					return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true );
67
-				},
68
-			)
69
-		);
70
-
71
-		register_rest_route(
72
-			'wordlift/v1',
73
-			'/dataset/background/sync',
74
-			array(
75
-				'methods'             => 'PUT',
76
-				'callback'            => array( $this->sync_background_process, 'resume' ),
77
-				'permission_callback' => function () {
78
-					$user = wp_get_current_user();
79
-
80
-					return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true );
81
-				},
82
-			)
83
-		);
84
-
85
-	}
9
+    /**
10
+     * @var Sync_Background_Process
11
+     */
12
+    private $sync_background_process;
13
+
14
+    /**
15
+     * Sync_Background_Process_Wpjson_Endpoint constructor.
16
+     *
17
+     * @param Sync_Background_Process $sync_background_process
18
+     */
19
+    public function __construct( $sync_background_process ) {
20
+
21
+        add_action( 'rest_api_init', array( $this, 'rest_api_init' ) );
22
+
23
+        $this->sync_background_process = $sync_background_process;
24
+
25
+    }
26
+
27
+    public function rest_api_init() {
28
+
29
+        register_rest_route(
30
+            'wordlift/v1',
31
+            '/dataset/background/sync',
32
+            array(
33
+                'methods'             => WP_REST_Server::CREATABLE,
34
+                'callback'            => array( $this->sync_background_process, 'start' ),
35
+                'permission_callback' => function () {
36
+                    $user = wp_get_current_user();
37
+
38
+                    return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true );
39
+                },
40
+            )
41
+        );
42
+
43
+        register_rest_route(
44
+            'wordlift/v1',
45
+            '/dataset/background/sync',
46
+            array(
47
+                'methods'             => WP_REST_Server::READABLE,
48
+                'callback'            => array( $this->sync_background_process, 'get_info' ),
49
+                'permission_callback' => function () {
50
+                    $user = wp_get_current_user();
51
+
52
+                    return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true );
53
+                },
54
+            )
55
+        );
56
+
57
+        register_rest_route(
58
+            'wordlift/v1',
59
+            '/dataset/background/sync',
60
+            array(
61
+                'methods'             => WP_REST_Server::DELETABLE,
62
+                'callback'            => array( $this->sync_background_process, 'stop' ),
63
+                'permission_callback' => function () {
64
+                    $user = wp_get_current_user();
65
+
66
+                    return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true );
67
+                },
68
+            )
69
+        );
70
+
71
+        register_rest_route(
72
+            'wordlift/v1',
73
+            '/dataset/background/sync',
74
+            array(
75
+                'methods'             => 'PUT',
76
+                'callback'            => array( $this->sync_background_process, 'resume' ),
77
+                'permission_callback' => function () {
78
+                    $user = wp_get_current_user();
79
+
80
+                    return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true );
81
+                },
82
+            )
83
+        );
84
+
85
+    }
86 86
 
87 87
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -16,9 +16,9 @@  discard block
 block discarded – undo
16 16
 	 *
17 17
 	 * @param Sync_Background_Process $sync_background_process
18 18
 	 */
19
-	public function __construct( $sync_background_process ) {
19
+	public function __construct($sync_background_process) {
20 20
 
21
-		add_action( 'rest_api_init', array( $this, 'rest_api_init' ) );
21
+		add_action('rest_api_init', array($this, 'rest_api_init'));
22 22
 
23 23
 		$this->sync_background_process = $sync_background_process;
24 24
 
@@ -31,11 +31,11 @@  discard block
 block discarded – undo
31 31
 			'/dataset/background/sync',
32 32
 			array(
33 33
 				'methods'             => WP_REST_Server::CREATABLE,
34
-				'callback'            => array( $this->sync_background_process, 'start' ),
35
-				'permission_callback' => function () {
34
+				'callback'            => array($this->sync_background_process, 'start'),
35
+				'permission_callback' => function() {
36 36
 					$user = wp_get_current_user();
37 37
 
38
-					return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true );
38
+					return is_super_admin($user->ID) || in_array('administrator', (array) $user->roles, true);
39 39
 				},
40 40
 			)
41 41
 		);
@@ -45,11 +45,11 @@  discard block
 block discarded – undo
45 45
 			'/dataset/background/sync',
46 46
 			array(
47 47
 				'methods'             => WP_REST_Server::READABLE,
48
-				'callback'            => array( $this->sync_background_process, 'get_info' ),
49
-				'permission_callback' => function () {
48
+				'callback'            => array($this->sync_background_process, 'get_info'),
49
+				'permission_callback' => function() {
50 50
 					$user = wp_get_current_user();
51 51
 
52
-					return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true );
52
+					return is_super_admin($user->ID) || in_array('administrator', (array) $user->roles, true);
53 53
 				},
54 54
 			)
55 55
 		);
@@ -59,11 +59,11 @@  discard block
 block discarded – undo
59 59
 			'/dataset/background/sync',
60 60
 			array(
61 61
 				'methods'             => WP_REST_Server::DELETABLE,
62
-				'callback'            => array( $this->sync_background_process, 'stop' ),
63
-				'permission_callback' => function () {
62
+				'callback'            => array($this->sync_background_process, 'stop'),
63
+				'permission_callback' => function() {
64 64
 					$user = wp_get_current_user();
65 65
 
66
-					return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true );
66
+					return is_super_admin($user->ID) || in_array('administrator', (array) $user->roles, true);
67 67
 				},
68 68
 			)
69 69
 		);
@@ -73,11 +73,11 @@  discard block
 block discarded – undo
73 73
 			'/dataset/background/sync',
74 74
 			array(
75 75
 				'methods'             => 'PUT',
76
-				'callback'            => array( $this->sync_background_process, 'resume' ),
77
-				'permission_callback' => function () {
76
+				'callback'            => array($this->sync_background_process, 'resume'),
77
+				'permission_callback' => function() {
78 78
 					$user = wp_get_current_user();
79 79
 
80
-					return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true );
80
+					return is_super_admin($user->ID) || in_array('administrator', (array) $user->roles, true);
81 81
 				},
82 82
 			)
83 83
 		);
Please login to merge, or discard this patch.
src/wordlift/dataset/background/class-sync-background-process.php 2 patches
Indentation   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -18,116 +18,116 @@
 block discarded – undo
18 18
  */
19 19
 class Sync_Background_Process extends \Wordlift_Plugin_WP_Background_Process {
20 20
 
21
-	const STATE_STARTED = 'started';
22
-	const STATE_STOPPED = 'stopped';
23
-
24
-	protected $action = 'wl_dataset__sync';
25
-
26
-	/**
27
-	 * @var Sync_Service
28
-	 */
29
-	private $sync_service;
30
-
31
-	/**
32
-	 * @var Sync_Object_Adapter_Factory
33
-	 */
34
-	private $sync_object_adapter_factory;
35
-
36
-	/**
37
-	 * @var \Wordlift_Log_Service
38
-	 */
39
-	private $log;
40
-
41
-	/**
42
-	 * @var Sync_Background_Process_State
43
-	 */
44
-	private $state;
45
-
46
-	/**
47
-	 * Sync_Background_Process constructor.
48
-	 *
49
-	 * @param Sync_Service                $sync_service A {@link Sync_Service} instance providing the supporting functions to this background process.
50
-	 * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory
51
-	 */
52
-	public function __construct( $sync_service, $sync_object_adapter_factory ) {
53
-		parent::__construct();
54
-
55
-		$this->log = \Wordlift_Log_Service::get_logger( get_class() );
56
-
57
-		$this->sync_service                = $sync_service;
58
-		$this->sync_object_adapter_factory = $sync_object_adapter_factory;
59
-
60
-		// Set the current state.
61
-		if ( self::STATE_STARTED === $this->get_state() ) {
62
-			$this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory );
63
-		} else {
64
-			$this->state = new Sync_Background_Process_Stopped_State( $this );
65
-		}
66
-
67
-	}
68
-
69
-	/**
70
-	 * This function is called:
71
-	 *  - To start a new Synchronization, by passing a {@link Sync_Start_Message} instance.
72
-	 *  - To synchronize a post, by passing a numeric ID.
73
-	 *
74
-	 * This function returns the parameter for the next call or NULL if there are no more posts to process.
75
-	 *
76
-	 * @param mixed $item Queue item to iterate over.
77
-	 *
78
-	 * @return int[]|false The next post IDs or false if there are no more.
79
-	 */
80
-	protected function task( $item ) {
81
-
82
-		return $this->state->task( $item );
83
-	}
84
-
85
-	/**
86
-	 * Transition to the started state.
87
-	 */
88
-	public function start() {
89
-		$this->state->leave();
90
-		$this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory );
91
-		$this->state->enter();
92
-	}
93
-
94
-	/**
95
-	 * Transition to the stopped state.
96
-	 */
97
-	public function stop() {
98
-		$this->state->leave();
99
-		$this->state = new Sync_Background_Process_Stopped_State( $this );
100
-		$this->state->enter();
101
-	}
102
-
103
-	public function resume() {
104
-		$this->state->resume();
105
-	}
106
-
107
-	/**
108
-	 * Get the current state.
109
-	 *
110
-	 * @return string Either self::STARTED_STATE or self::STOPPED_STATE (default).
111
-	 */
112
-	public function get_state() {
113
-		return get_option( '_wl_sync_background_process_state', self::STATE_STOPPED );
114
-	}
115
-
116
-	/**
117
-	 * Persist the current state.
118
-	 *
119
-	 * @param string $value
120
-	 *
121
-	 * @return bool
122
-	 */
123
-	public function set_state( $value ) {
124
-		return null === $value
125
-			? delete_option( '_wl_sync_background_process_state' )
126
-			: update_option( '_wl_sync_background_process_state', $value, true );
127
-	}
128
-
129
-	public function get_info() {
130
-		return $this->state->get_info();
131
-	}
21
+    const STATE_STARTED = 'started';
22
+    const STATE_STOPPED = 'stopped';
23
+
24
+    protected $action = 'wl_dataset__sync';
25
+
26
+    /**
27
+     * @var Sync_Service
28
+     */
29
+    private $sync_service;
30
+
31
+    /**
32
+     * @var Sync_Object_Adapter_Factory
33
+     */
34
+    private $sync_object_adapter_factory;
35
+
36
+    /**
37
+     * @var \Wordlift_Log_Service
38
+     */
39
+    private $log;
40
+
41
+    /**
42
+     * @var Sync_Background_Process_State
43
+     */
44
+    private $state;
45
+
46
+    /**
47
+     * Sync_Background_Process constructor.
48
+     *
49
+     * @param Sync_Service                $sync_service A {@link Sync_Service} instance providing the supporting functions to this background process.
50
+     * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory
51
+     */
52
+    public function __construct( $sync_service, $sync_object_adapter_factory ) {
53
+        parent::__construct();
54
+
55
+        $this->log = \Wordlift_Log_Service::get_logger( get_class() );
56
+
57
+        $this->sync_service                = $sync_service;
58
+        $this->sync_object_adapter_factory = $sync_object_adapter_factory;
59
+
60
+        // Set the current state.
61
+        if ( self::STATE_STARTED === $this->get_state() ) {
62
+            $this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory );
63
+        } else {
64
+            $this->state = new Sync_Background_Process_Stopped_State( $this );
65
+        }
66
+
67
+    }
68
+
69
+    /**
70
+     * This function is called:
71
+     *  - To start a new Synchronization, by passing a {@link Sync_Start_Message} instance.
72
+     *  - To synchronize a post, by passing a numeric ID.
73
+     *
74
+     * This function returns the parameter for the next call or NULL if there are no more posts to process.
75
+     *
76
+     * @param mixed $item Queue item to iterate over.
77
+     *
78
+     * @return int[]|false The next post IDs or false if there are no more.
79
+     */
80
+    protected function task( $item ) {
81
+
82
+        return $this->state->task( $item );
83
+    }
84
+
85
+    /**
86
+     * Transition to the started state.
87
+     */
88
+    public function start() {
89
+        $this->state->leave();
90
+        $this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory );
91
+        $this->state->enter();
92
+    }
93
+
94
+    /**
95
+     * Transition to the stopped state.
96
+     */
97
+    public function stop() {
98
+        $this->state->leave();
99
+        $this->state = new Sync_Background_Process_Stopped_State( $this );
100
+        $this->state->enter();
101
+    }
102
+
103
+    public function resume() {
104
+        $this->state->resume();
105
+    }
106
+
107
+    /**
108
+     * Get the current state.
109
+     *
110
+     * @return string Either self::STARTED_STATE or self::STOPPED_STATE (default).
111
+     */
112
+    public function get_state() {
113
+        return get_option( '_wl_sync_background_process_state', self::STATE_STOPPED );
114
+    }
115
+
116
+    /**
117
+     * Persist the current state.
118
+     *
119
+     * @param string $value
120
+     *
121
+     * @return bool
122
+     */
123
+    public function set_state( $value ) {
124
+        return null === $value
125
+            ? delete_option( '_wl_sync_background_process_state' )
126
+            : update_option( '_wl_sync_background_process_state', $value, true );
127
+    }
128
+
129
+    public function get_info() {
130
+        return $this->state->get_info();
131
+    }
132 132
 
133 133
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -49,19 +49,19 @@  discard block
 block discarded – undo
49 49
 	 * @param Sync_Service                $sync_service A {@link Sync_Service} instance providing the supporting functions to this background process.
50 50
 	 * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory
51 51
 	 */
52
-	public function __construct( $sync_service, $sync_object_adapter_factory ) {
52
+	public function __construct($sync_service, $sync_object_adapter_factory) {
53 53
 		parent::__construct();
54 54
 
55
-		$this->log = \Wordlift_Log_Service::get_logger( get_class() );
55
+		$this->log = \Wordlift_Log_Service::get_logger(get_class());
56 56
 
57 57
 		$this->sync_service                = $sync_service;
58 58
 		$this->sync_object_adapter_factory = $sync_object_adapter_factory;
59 59
 
60 60
 		// Set the current state.
61
-		if ( self::STATE_STARTED === $this->get_state() ) {
62
-			$this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory );
61
+		if (self::STATE_STARTED === $this->get_state()) {
62
+			$this->state = new Sync_Background_Process_Started_State($this, $this->sync_service, $this->sync_object_adapter_factory);
63 63
 		} else {
64
-			$this->state = new Sync_Background_Process_Stopped_State( $this );
64
+			$this->state = new Sync_Background_Process_Stopped_State($this);
65 65
 		}
66 66
 
67 67
 	}
@@ -77,9 +77,9 @@  discard block
 block discarded – undo
77 77
 	 *
78 78
 	 * @return int[]|false The next post IDs or false if there are no more.
79 79
 	 */
80
-	protected function task( $item ) {
80
+	protected function task($item) {
81 81
 
82
-		return $this->state->task( $item );
82
+		return $this->state->task($item);
83 83
 	}
84 84
 
85 85
 	/**
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 	 */
88 88
 	public function start() {
89 89
 		$this->state->leave();
90
-		$this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory );
90
+		$this->state = new Sync_Background_Process_Started_State($this, $this->sync_service, $this->sync_object_adapter_factory);
91 91
 		$this->state->enter();
92 92
 	}
93 93
 
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 	 */
97 97
 	public function stop() {
98 98
 		$this->state->leave();
99
-		$this->state = new Sync_Background_Process_Stopped_State( $this );
99
+		$this->state = new Sync_Background_Process_Stopped_State($this);
100 100
 		$this->state->enter();
101 101
 	}
102 102
 
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	 * @return string Either self::STARTED_STATE or self::STOPPED_STATE (default).
111 111
 	 */
112 112
 	public function get_state() {
113
-		return get_option( '_wl_sync_background_process_state', self::STATE_STOPPED );
113
+		return get_option('_wl_sync_background_process_state', self::STATE_STOPPED);
114 114
 	}
115 115
 
116 116
 	/**
@@ -120,10 +120,10 @@  discard block
 block discarded – undo
120 120
 	 *
121 121
 	 * @return bool
122 122
 	 */
123
-	public function set_state( $value ) {
123
+	public function set_state($value) {
124 124
 		return null === $value
125
-			? delete_option( '_wl_sync_background_process_state' )
126
-			: update_option( '_wl_sync_background_process_state', $value, true );
125
+			? delete_option('_wl_sync_background_process_state')
126
+			: update_option('_wl_sync_background_process_state', $value, true);
127 127
 	}
128 128
 
129 129
 	public function get_info() {
Please login to merge, or discard this patch.
dataset/background/stages/class-sync-background-process-terms-stage.php 2 patches
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -7,42 +7,42 @@  discard block
 block discarded – undo
7 7
 
8 8
 class Sync_Background_Process_Terms_Stage {
9 9
 
10
-	/**
11
-	 * @var Sync_Object_Adapter_Factory
12
-	 */
13
-	private $sync_object_adapter_factory;
14
-
15
-	/**
16
-	 * Sync_Background_Process_Posts_Stage constructor.
17
-	 *
18
-	 * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory
19
-	 */
20
-	public function __construct( $sync_object_adapter_factory ) {
21
-		$this->sync_object_adapter_factory = $sync_object_adapter_factory;
22
-	}
23
-
24
-	public function count() {
25
-
26
-		$taxonomies    = get_taxonomies( array( 'public' => true ) );
27
-		$in_taxonomies = implode( "','", array_map( 'esc_sql', $taxonomies ) );
28
-
29
-		global $wpdb;
30
-		$sql = "
10
+    /**
11
+     * @var Sync_Object_Adapter_Factory
12
+     */
13
+    private $sync_object_adapter_factory;
14
+
15
+    /**
16
+     * Sync_Background_Process_Posts_Stage constructor.
17
+     *
18
+     * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory
19
+     */
20
+    public function __construct( $sync_object_adapter_factory ) {
21
+        $this->sync_object_adapter_factory = $sync_object_adapter_factory;
22
+    }
23
+
24
+    public function count() {
25
+
26
+        $taxonomies    = get_taxonomies( array( 'public' => true ) );
27
+        $in_taxonomies = implode( "','", array_map( 'esc_sql', $taxonomies ) );
28
+
29
+        global $wpdb;
30
+        $sql = "
31 31
 			SELECT COUNT( 1 )
32 32
 			FROM $wpdb->term_taxonomy
33 33
 			WHERE taxonomy IN ('$in_taxonomies')
34 34
 			";
35 35
 
36
-		return $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
37
-	}
36
+        return $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
37
+    }
38 38
 
39
-	public function get_sync_object_adapters( $offset, $limit ) {
39
+    public function get_sync_object_adapters( $offset, $limit ) {
40 40
 
41
-		$taxonomies    = get_taxonomies( array( 'public' => true ) );
42
-		$in_taxonomies = implode( "','", array_map( 'esc_sql', $taxonomies ) );
41
+        $taxonomies    = get_taxonomies( array( 'public' => true ) );
42
+        $in_taxonomies = implode( "','", array_map( 'esc_sql', $taxonomies ) );
43 43
 
44
-		global $wpdb;
45
-		$sql = "
44
+        global $wpdb;
45
+        $sql = "
46 46
 			SELECT term_id
47 47
 			FROM $wpdb->term_taxonomy
48 48
 		    WHERE taxonomy IN ('$in_taxonomies')
@@ -50,9 +50,9 @@  discard block
 block discarded – undo
50 50
 			LIMIT %d, %d
51 51
 			";
52 52
 
53
-		$ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
53
+        $ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
54 54
 
55
-		return $this->sync_object_adapter_factory->create_many( Object_Type_Enum::TERM, $ids );
56
-	}
55
+        return $this->sync_object_adapter_factory->create_many( Object_Type_Enum::TERM, $ids );
56
+    }
57 57
 
58 58
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -17,14 +17,14 @@  discard block
 block discarded – undo
17 17
 	 *
18 18
 	 * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory
19 19
 	 */
20
-	public function __construct( $sync_object_adapter_factory ) {
20
+	public function __construct($sync_object_adapter_factory) {
21 21
 		$this->sync_object_adapter_factory = $sync_object_adapter_factory;
22 22
 	}
23 23
 
24 24
 	public function count() {
25 25
 
26
-		$taxonomies    = get_taxonomies( array( 'public' => true ) );
27
-		$in_taxonomies = implode( "','", array_map( 'esc_sql', $taxonomies ) );
26
+		$taxonomies    = get_taxonomies(array('public' => true));
27
+		$in_taxonomies = implode("','", array_map('esc_sql', $taxonomies));
28 28
 
29 29
 		global $wpdb;
30 30
 		$sql = "
@@ -33,13 +33,13 @@  discard block
 block discarded – undo
33 33
 			WHERE taxonomy IN ('$in_taxonomies')
34 34
 			";
35 35
 
36
-		return $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
36
+		return $wpdb->get_var($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
37 37
 	}
38 38
 
39
-	public function get_sync_object_adapters( $offset, $limit ) {
39
+	public function get_sync_object_adapters($offset, $limit) {
40 40
 
41
-		$taxonomies    = get_taxonomies( array( 'public' => true ) );
42
-		$in_taxonomies = implode( "','", array_map( 'esc_sql', $taxonomies ) );
41
+		$taxonomies    = get_taxonomies(array('public' => true));
42
+		$in_taxonomies = implode("','", array_map('esc_sql', $taxonomies));
43 43
 
44 44
 		global $wpdb;
45 45
 		$sql = "
@@ -50,9 +50,9 @@  discard block
 block discarded – undo
50 50
 			LIMIT %d, %d
51 51
 			";
52 52
 
53
-		$ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
53
+		$ids = $wpdb->get_col($wpdb->prepare($sql, $offset, $limit)); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
54 54
 
55
-		return $this->sync_object_adapter_factory->create_many( Object_Type_Enum::TERM, $ids );
55
+		return $this->sync_object_adapter_factory->create_many(Object_Type_Enum::TERM, $ids);
56 56
 	}
57 57
 
58 58
 }
Please login to merge, or discard this patch.
dataset/background/stages/class-sync-background-process-posts-stage.php 2 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -8,49 +8,49 @@  discard block
 block discarded – undo
8 8
 
9 9
 class Sync_Background_Process_Posts_Stage {
10 10
 
11
-	/**
12
-	 * @var Sync_Object_Adapter_Factory
13
-	 */
14
-	private $sync_object_adapter_factory;
11
+    /**
12
+     * @var Sync_Object_Adapter_Factory
13
+     */
14
+    private $sync_object_adapter_factory;
15 15
 
16
-	/**
17
-	 * Sync_Background_Process_Posts_Stage constructor.
18
-	 *
19
-	 * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory
20
-	 */
21
-	public function __construct( $sync_object_adapter_factory ) {
22
-		$this->sync_object_adapter_factory = $sync_object_adapter_factory;
23
-	}
16
+    /**
17
+     * Sync_Background_Process_Posts_Stage constructor.
18
+     *
19
+     * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory
20
+     */
21
+    public function __construct( $sync_object_adapter_factory ) {
22
+        $this->sync_object_adapter_factory = $sync_object_adapter_factory;
23
+    }
24 24
 
25
-	public function count() {
25
+    public function count() {
26 26
 
27
-		$post_types = get_post_types( array( 'public' => true ) );
27
+        $post_types = get_post_types( array( 'public' => true ) );
28 28
 
29
-		global $wpdb;
30
-		$in_post_type = implode( "','", array_map( 'esc_sql', $post_types ) );
31
-		$sql          = "
29
+        global $wpdb;
30
+        $in_post_type = implode( "','", array_map( 'esc_sql', $post_types ) );
31
+        $sql          = "
32 32
 			SELECT COUNT( 1 )
33 33
 			FROM $wpdb->posts
34 34
 			WHERE post_type IN ('$in_post_type')
35 35
 				AND post_status IN ( 'publish',  'future', 'draft', 'pending', 'private' )
36 36
 			";
37 37
 
38
-		return $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
39
-	}
38
+        return $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
39
+    }
40 40
 
41
-	/**
42
-	 * @param int $offset
43
-	 * @param int $limit
44
-	 *
45
-	 * @return Sync_Object_Adapter[]
46
-	 */
47
-	public function get_sync_object_adapters( $offset, $limit ) {
41
+    /**
42
+     * @param int $offset
43
+     * @param int $limit
44
+     *
45
+     * @return Sync_Object_Adapter[]
46
+     */
47
+    public function get_sync_object_adapters( $offset, $limit ) {
48 48
 
49
-		$post_types = get_post_types( array( 'public' => true ) );
49
+        $post_types = get_post_types( array( 'public' => true ) );
50 50
 
51
-		global $wpdb;
52
-		$in_post_type = implode( "','", array_map( 'esc_sql', $post_types ) );
53
-		$sql          = "
51
+        global $wpdb;
52
+        $in_post_type = implode( "','", array_map( 'esc_sql', $post_types ) );
53
+        $sql          = "
54 54
 			SELECT ID
55 55
 			FROM $wpdb->posts
56 56
 			WHERE post_type IN ('$in_post_type')
@@ -59,10 +59,10 @@  discard block
 block discarded – undo
59 59
 			LIMIT %d, %d
60 60
 			";
61 61
 
62
-		$ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
62
+        $ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
63 63
 
64
-		return $this->sync_object_adapter_factory
65
-			->create_many( Object_Type_Enum::POST, array_map( 'intval', $ids ) );
66
-	}
64
+        return $this->sync_object_adapter_factory
65
+            ->create_many( Object_Type_Enum::POST, array_map( 'intval', $ids ) );
66
+    }
67 67
 
68 68
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -18,16 +18,16 @@  discard block
 block discarded – undo
18 18
 	 *
19 19
 	 * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory
20 20
 	 */
21
-	public function __construct( $sync_object_adapter_factory ) {
21
+	public function __construct($sync_object_adapter_factory) {
22 22
 		$this->sync_object_adapter_factory = $sync_object_adapter_factory;
23 23
 	}
24 24
 
25 25
 	public function count() {
26 26
 
27
-		$post_types = get_post_types( array( 'public' => true ) );
27
+		$post_types = get_post_types(array('public' => true));
28 28
 
29 29
 		global $wpdb;
30
-		$in_post_type = implode( "','", array_map( 'esc_sql', $post_types ) );
30
+		$in_post_type = implode("','", array_map('esc_sql', $post_types));
31 31
 		$sql          = "
32 32
 			SELECT COUNT( 1 )
33 33
 			FROM $wpdb->posts
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 				AND post_status IN ( 'publish',  'future', 'draft', 'pending', 'private' )
36 36
 			";
37 37
 
38
-		return $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
38
+		return $wpdb->get_var($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
39 39
 	}
40 40
 
41 41
 	/**
@@ -44,12 +44,12 @@  discard block
 block discarded – undo
44 44
 	 *
45 45
 	 * @return Sync_Object_Adapter[]
46 46
 	 */
47
-	public function get_sync_object_adapters( $offset, $limit ) {
47
+	public function get_sync_object_adapters($offset, $limit) {
48 48
 
49
-		$post_types = get_post_types( array( 'public' => true ) );
49
+		$post_types = get_post_types(array('public' => true));
50 50
 
51 51
 		global $wpdb;
52
-		$in_post_type = implode( "','", array_map( 'esc_sql', $post_types ) );
52
+		$in_post_type = implode("','", array_map('esc_sql', $post_types));
53 53
 		$sql          = "
54 54
 			SELECT ID
55 55
 			FROM $wpdb->posts
@@ -59,10 +59,10 @@  discard block
 block discarded – undo
59 59
 			LIMIT %d, %d
60 60
 			";
61 61
 
62
-		$ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
62
+		$ids = $wpdb->get_col($wpdb->prepare($sql, $offset, $limit)); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
63 63
 
64 64
 		return $this->sync_object_adapter_factory
65
-			->create_many( Object_Type_Enum::POST, array_map( 'intval', $ids ) );
65
+			->create_many(Object_Type_Enum::POST, array_map('intval', $ids));
66 66
 	}
67 67
 
68 68
 }
Please login to merge, or discard this patch.
dataset/background/stages/class-sync-background-process-users-stage.php 2 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -7,39 +7,39 @@  discard block
 block discarded – undo
7 7
 
8 8
 class Sync_Background_Process_Users_Stage {
9 9
 
10
-	/**
11
-	 * @var Sync_Object_Adapter_Factory
12
-	 */
13
-	private $sync_object_adapter_factory;
10
+    /**
11
+     * @var Sync_Object_Adapter_Factory
12
+     */
13
+    private $sync_object_adapter_factory;
14 14
 
15
-	/**
16
-	 * Sync_Background_Process_Posts_Stage constructor.
17
-	 *
18
-	 * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory
19
-	 */
20
-	public function __construct( $sync_object_adapter_factory ) {
21
-		$this->sync_object_adapter_factory = $sync_object_adapter_factory;
22
-	}
15
+    /**
16
+     * Sync_Background_Process_Posts_Stage constructor.
17
+     *
18
+     * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory
19
+     */
20
+    public function __construct( $sync_object_adapter_factory ) {
21
+        $this->sync_object_adapter_factory = $sync_object_adapter_factory;
22
+    }
23 23
 
24
-	public function count() {
24
+    public function count() {
25 25
 
26
-		global $wpdb;
27
-		$in_post_type = $this->get_post_types_string();
28
-		$sql          = "
26
+        global $wpdb;
27
+        $in_post_type = $this->get_post_types_string();
28
+        $sql          = "
29 29
 			SELECT COUNT( DISTINCT post_author )
30 30
 			FROM $wpdb->posts
31 31
 			WHERE post_type IN ('$in_post_type')
32 32
 			AND post_status IN ( 'publish',  'future', 'draft', 'pending', 'private' )
33 33
 			";
34 34
 
35
-		return $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
36
-	}
35
+        return $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
36
+    }
37 37
 
38
-	public function get_sync_object_adapters( $offset, $limit ) {
38
+    public function get_sync_object_adapters( $offset, $limit ) {
39 39
 
40
-		global $wpdb;
41
-		$in_post_type = $this->get_post_types_string();
42
-		$sql          = "
40
+        global $wpdb;
41
+        $in_post_type = $this->get_post_types_string();
42
+        $sql          = "
43 43
 			SELECT DISTINCT post_author
44 44
 			FROM $wpdb->posts
45 45
 			WHERE post_type IN ('$in_post_type')
@@ -47,18 +47,18 @@  discard block
 block discarded – undo
47 47
 			LIMIT %d, %d
48 48
 			";
49 49
 
50
-		$ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
50
+        $ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
51 51
 
52
-		return $this->sync_object_adapter_factory->create_many( Object_Type_Enum::USER, $ids );
53
-	}
52
+        return $this->sync_object_adapter_factory->create_many( Object_Type_Enum::USER, $ids );
53
+    }
54 54
 
55
-	/**
56
-	 * @return string
57
-	 */
58
-	protected function get_post_types_string() {
59
-		$post_types = get_post_types( array( 'public' => true ) );
55
+    /**
56
+     * @return string
57
+     */
58
+    protected function get_post_types_string() {
59
+        $post_types = get_post_types( array( 'public' => true ) );
60 60
 
61
-		return implode( "','", array_map( 'esc_sql', $post_types ) );
62
-	}
61
+        return implode( "','", array_map( 'esc_sql', $post_types ) );
62
+    }
63 63
 
64 64
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 	 *
18 18
 	 * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory
19 19
 	 */
20
-	public function __construct( $sync_object_adapter_factory ) {
20
+	public function __construct($sync_object_adapter_factory) {
21 21
 		$this->sync_object_adapter_factory = $sync_object_adapter_factory;
22 22
 	}
23 23
 
@@ -32,10 +32,10 @@  discard block
 block discarded – undo
32 32
 			AND post_status IN ( 'publish',  'future', 'draft', 'pending', 'private' )
33 33
 			";
34 34
 
35
-		return $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
35
+		return $wpdb->get_var($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
36 36
 	}
37 37
 
38
-	public function get_sync_object_adapters( $offset, $limit ) {
38
+	public function get_sync_object_adapters($offset, $limit) {
39 39
 
40 40
 		global $wpdb;
41 41
 		$in_post_type = $this->get_post_types_string();
@@ -47,18 +47,18 @@  discard block
 block discarded – undo
47 47
 			LIMIT %d, %d
48 48
 			";
49 49
 
50
-		$ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
50
+		$ids = $wpdb->get_col($wpdb->prepare($sql, $offset, $limit)); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
51 51
 
52
-		return $this->sync_object_adapter_factory->create_many( Object_Type_Enum::USER, $ids );
52
+		return $this->sync_object_adapter_factory->create_many(Object_Type_Enum::USER, $ids);
53 53
 	}
54 54
 
55 55
 	/**
56 56
 	 * @return string
57 57
 	 */
58 58
 	protected function get_post_types_string() {
59
-		$post_types = get_post_types( array( 'public' => true ) );
59
+		$post_types = get_post_types(array('public' => true));
60 60
 
61
-		return implode( "','", array_map( 'esc_sql', $post_types ) );
61
+		return implode("','", array_map('esc_sql', $post_types));
62 62
 	}
63 63
 
64 64
 }
Please login to merge, or discard this patch.
src/wordlift/dataset/background/stages/class-sync-background-stage.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -4,8 +4,8 @@
 block discarded – undo
4 4
 
5 5
 interface Sync_Background_Process_Stage {
6 6
 
7
-	public function count();
7
+    public function count();
8 8
 
9
-	public function get_sync_object_adapters( $offset, $batch_size );
9
+    public function get_sync_object_adapters( $offset, $batch_size );
10 10
 
11 11
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,6 +6,6 @@
 block discarded – undo
6 6
 
7 7
 	public function count();
8 8
 
9
-	public function get_sync_object_adapters( $offset, $batch_size );
9
+	public function get_sync_object_adapters($offset, $batch_size);
10 10
 
11 11
 }
Please login to merge, or discard this patch.
wordlift/dataset/background/class-sync-background-process-stopped-state.php 2 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -4,31 +4,31 @@
 block discarded – undo
4 4
 
5 5
 class Sync_Background_Process_Stopped_State extends Abstract_Sync_Background_Process_State {
6 6
 
7
-	/**
8
-	 * @var Sync_Background_Process
9
-	 */
10
-	private $context;
7
+    /**
8
+     * @var Sync_Background_Process
9
+     */
10
+    private $context;
11 11
 
12
-	public function __construct( $context ) {
13
-		parent::__construct( Sync_Background_Process::STATE_STOPPED );
12
+    public function __construct( $context ) {
13
+        parent::__construct( Sync_Background_Process::STATE_STOPPED );
14 14
 
15
-		$this->context = $context;
16
-	}
15
+        $this->context = $context;
16
+    }
17 17
 
18
-	public function enter() {
19
-		$this->context->set_state( Sync_Background_Process::STATE_STOPPED );
20
-	}
18
+    public function enter() {
19
+        $this->context->set_state( Sync_Background_Process::STATE_STOPPED );
20
+    }
21 21
 
22
-	public function leave() {
23
-		$this->context->set_state( null );
24
-	}
22
+    public function leave() {
23
+        $this->context->set_state( null );
24
+    }
25 25
 
26
-	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
27
-	public function task( $item ) {
26
+    // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
27
+    public function task( $item ) {
28 28
 
29
-		$this->context->cancel_process();
29
+        $this->context->cancel_process();
30 30
 
31
-		return false;
32
-	}
31
+        return false;
32
+    }
33 33
 
34 34
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -9,22 +9,22 @@
 block discarded – undo
9 9
 	 */
10 10
 	private $context;
11 11
 
12
-	public function __construct( $context ) {
13
-		parent::__construct( Sync_Background_Process::STATE_STOPPED );
12
+	public function __construct($context) {
13
+		parent::__construct(Sync_Background_Process::STATE_STOPPED);
14 14
 
15 15
 		$this->context = $context;
16 16
 	}
17 17
 
18 18
 	public function enter() {
19
-		$this->context->set_state( Sync_Background_Process::STATE_STOPPED );
19
+		$this->context->set_state(Sync_Background_Process::STATE_STOPPED);
20 20
 	}
21 21
 
22 22
 	public function leave() {
23
-		$this->context->set_state( null );
23
+		$this->context->set_state(null);
24 24
 	}
25 25
 
26 26
 	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
27
-	public function task( $item ) {
27
+	public function task($item) {
28 28
 
29 29
 		$this->context->cancel_process();
30 30
 
Please login to merge, or discard this patch.
wordlift/dataset/background/class-sync-background-process-started-state.php 2 patches
Indentation   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -11,138 +11,138 @@
 block discarded – undo
11 11
 
12 12
 class Sync_Background_Process_Started_State extends Abstract_Sync_Background_Process_State {
13 13
 
14
-	/**
15
-	 * @var Sync_Background_Process
16
-	 */
17
-	private $context;
18
-
19
-	/**
20
-	 * @var Sync_Service
21
-	 */
22
-	private $sync_service;
23
-
24
-	/**
25
-	 * @var Sync_Background_Process_Stage[]
26
-	 */
27
-	private $stages;
28
-
29
-	private $batch_size = 5;
30
-	/**
31
-	 * @var bool
32
-	 */
33
-	private $reset;
34
-
35
-	/**
36
-	 * Sync_Background_Process_Started_State constructor.
37
-	 *
38
-	 * @param Sync_Background_Process     $context
39
-	 * @param Sync_Service                $sync_service
40
-	 * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory
41
-	 * @param bool                        $reset Whether to reset the counters
42
-	 */
43
-	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
44
-	public function __construct( $context, $sync_service, $sync_object_adapter_factory, $reset = true ) {
45
-		parent::__construct( Sync_Background_Process::STATE_STARTED );
46
-
47
-		$this->context      = $context;
48
-		$this->sync_service = $sync_service;
49
-
50
-		$this->stages = array(
51
-			new Sync_Background_Process_Posts_Stage( $sync_object_adapter_factory ),
52
-			new Sync_Background_Process_Terms_Stage( $sync_object_adapter_factory ),
53
-			new Sync_Background_Process_Users_Stage( $sync_object_adapter_factory ),
54
-		);
55
-	}
56
-
57
-	public function enter() {
58
-		// Delete the KG contents.
59
-		$this->sync_service->delete_all();
60
-
61
-		// Clear caches.
62
-		do_action( 'wl_ttl_cache_cleaner__flush' );
63
-
64
-		$counts = array_map(
65
-			function ( $item ) {
66
-				return $item->count();
67
-			},
68
-			$this->stages
69
-		);
70
-
71
-		update_option( '_wl_sync_background_process_count', $counts, true );
72
-		update_option( '_wl_sync_background_process_stage', 0, true );
73
-		update_option( '_wl_sync_background_process_offset', 0, true );
74
-		update_option( '_wl_sync_background_process_started', time(), true );
75
-		update_option( '_wl_sync_background_process_updated', time(), true );
76
-
77
-		$this->context->set_state( Sync_Background_Process::STATE_STARTED );
78
-
79
-		$this->resume();
80
-	}
81
-
82
-	public function resume() {
83
-		$this->context->push_to_queue( true );
84
-		$this->context->save()->dispatch();
85
-	}
86
-
87
-	public function leave() {
88
-		$this->context->set_state( null );
89
-	}
90
-
91
-	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
92
-	public function task( $args ) {
93
-
94
-		$offset     = get_option( '_wl_sync_background_process_offset' );
95
-		$stage      = get_option( '_wl_sync_background_process_stage' );
96
-		$counts     = get_option( '_wl_sync_background_process_count' );
97
-		$batch_size = min( $counts[ $stage ] - $offset, $this->batch_size );
98
-
99
-		add_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) );
100
-		try {
101
-			$object_adapters = $this->stages[ $stage ]->get_sync_object_adapters( $offset, $batch_size );
102
-			$this->sync_service->sync_many( $object_adapters, true );
103
-		// phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
104
-		} catch ( \Exception $e ) {
105
-			// ignored.
106
-		}
107
-		remove_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) );
108
-
109
-		update_option( '_wl_sync_background_process_updated', time(), true );
110
-
111
-		// Increase the offset.
112
-		if ( ( $offset + $batch_size ) < $counts[ $stage ] ) {
113
-			update_option( '_wl_sync_background_process_offset', $offset + $batch_size, true );
114
-
115
-			return true;
116
-		}
117
-
118
-		// Increase the stage.
119
-		if ( ( $stage + 1 ) < count( $this->stages ) ) {
120
-			update_option( '_wl_sync_background_process_stage', $stage + 1, true );
121
-			update_option( '_wl_sync_background_process_offset', 0, true );
122
-
123
-			return true;
124
-		}
125
-
126
-		// Stop processing.
127
-		$this->context->stop();
128
-
129
-		return false;
130
-	}
131
-
132
-	/**
133
-	 * Hook to provide a request to update the status on the server.
134
-	 *
135
-	 * @param array $args
136
-	 *
137
-	 * @return mixed
138
-	 */
139
-	public function api_service__request( $args ) {
140
-
141
-		$state_header_value = str_replace( "\n", '', wp_json_encode( $this->context->get_info() ) );
142
-
143
-		$args['headers']['X-Wordlift-Dataset-Sync-State-V1'] = $state_header_value;
144
-
145
-		return $args;
146
-	}
14
+    /**
15
+     * @var Sync_Background_Process
16
+     */
17
+    private $context;
18
+
19
+    /**
20
+     * @var Sync_Service
21
+     */
22
+    private $sync_service;
23
+
24
+    /**
25
+     * @var Sync_Background_Process_Stage[]
26
+     */
27
+    private $stages;
28
+
29
+    private $batch_size = 5;
30
+    /**
31
+     * @var bool
32
+     */
33
+    private $reset;
34
+
35
+    /**
36
+     * Sync_Background_Process_Started_State constructor.
37
+     *
38
+     * @param Sync_Background_Process     $context
39
+     * @param Sync_Service                $sync_service
40
+     * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory
41
+     * @param bool                        $reset Whether to reset the counters
42
+     */
43
+    // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
44
+    public function __construct( $context, $sync_service, $sync_object_adapter_factory, $reset = true ) {
45
+        parent::__construct( Sync_Background_Process::STATE_STARTED );
46
+
47
+        $this->context      = $context;
48
+        $this->sync_service = $sync_service;
49
+
50
+        $this->stages = array(
51
+            new Sync_Background_Process_Posts_Stage( $sync_object_adapter_factory ),
52
+            new Sync_Background_Process_Terms_Stage( $sync_object_adapter_factory ),
53
+            new Sync_Background_Process_Users_Stage( $sync_object_adapter_factory ),
54
+        );
55
+    }
56
+
57
+    public function enter() {
58
+        // Delete the KG contents.
59
+        $this->sync_service->delete_all();
60
+
61
+        // Clear caches.
62
+        do_action( 'wl_ttl_cache_cleaner__flush' );
63
+
64
+        $counts = array_map(
65
+            function ( $item ) {
66
+                return $item->count();
67
+            },
68
+            $this->stages
69
+        );
70
+
71
+        update_option( '_wl_sync_background_process_count', $counts, true );
72
+        update_option( '_wl_sync_background_process_stage', 0, true );
73
+        update_option( '_wl_sync_background_process_offset', 0, true );
74
+        update_option( '_wl_sync_background_process_started', time(), true );
75
+        update_option( '_wl_sync_background_process_updated', time(), true );
76
+
77
+        $this->context->set_state( Sync_Background_Process::STATE_STARTED );
78
+
79
+        $this->resume();
80
+    }
81
+
82
+    public function resume() {
83
+        $this->context->push_to_queue( true );
84
+        $this->context->save()->dispatch();
85
+    }
86
+
87
+    public function leave() {
88
+        $this->context->set_state( null );
89
+    }
90
+
91
+    // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
92
+    public function task( $args ) {
93
+
94
+        $offset     = get_option( '_wl_sync_background_process_offset' );
95
+        $stage      = get_option( '_wl_sync_background_process_stage' );
96
+        $counts     = get_option( '_wl_sync_background_process_count' );
97
+        $batch_size = min( $counts[ $stage ] - $offset, $this->batch_size );
98
+
99
+        add_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) );
100
+        try {
101
+            $object_adapters = $this->stages[ $stage ]->get_sync_object_adapters( $offset, $batch_size );
102
+            $this->sync_service->sync_many( $object_adapters, true );
103
+        // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
104
+        } catch ( \Exception $e ) {
105
+            // ignored.
106
+        }
107
+        remove_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) );
108
+
109
+        update_option( '_wl_sync_background_process_updated', time(), true );
110
+
111
+        // Increase the offset.
112
+        if ( ( $offset + $batch_size ) < $counts[ $stage ] ) {
113
+            update_option( '_wl_sync_background_process_offset', $offset + $batch_size, true );
114
+
115
+            return true;
116
+        }
117
+
118
+        // Increase the stage.
119
+        if ( ( $stage + 1 ) < count( $this->stages ) ) {
120
+            update_option( '_wl_sync_background_process_stage', $stage + 1, true );
121
+            update_option( '_wl_sync_background_process_offset', 0, true );
122
+
123
+            return true;
124
+        }
125
+
126
+        // Stop processing.
127
+        $this->context->stop();
128
+
129
+        return false;
130
+    }
131
+
132
+    /**
133
+     * Hook to provide a request to update the status on the server.
134
+     *
135
+     * @param array $args
136
+     *
137
+     * @return mixed
138
+     */
139
+    public function api_service__request( $args ) {
140
+
141
+        $state_header_value = str_replace( "\n", '', wp_json_encode( $this->context->get_info() ) );
142
+
143
+        $args['headers']['X-Wordlift-Dataset-Sync-State-V1'] = $state_header_value;
144
+
145
+        return $args;
146
+    }
147 147
 
148 148
 }
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -41,16 +41,16 @@  discard block
 block discarded – undo
41 41
 	 * @param bool                        $reset Whether to reset the counters
42 42
 	 */
43 43
 	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
44
-	public function __construct( $context, $sync_service, $sync_object_adapter_factory, $reset = true ) {
45
-		parent::__construct( Sync_Background_Process::STATE_STARTED );
44
+	public function __construct($context, $sync_service, $sync_object_adapter_factory, $reset = true) {
45
+		parent::__construct(Sync_Background_Process::STATE_STARTED);
46 46
 
47 47
 		$this->context      = $context;
48 48
 		$this->sync_service = $sync_service;
49 49
 
50 50
 		$this->stages = array(
51
-			new Sync_Background_Process_Posts_Stage( $sync_object_adapter_factory ),
52
-			new Sync_Background_Process_Terms_Stage( $sync_object_adapter_factory ),
53
-			new Sync_Background_Process_Users_Stage( $sync_object_adapter_factory ),
51
+			new Sync_Background_Process_Posts_Stage($sync_object_adapter_factory),
52
+			new Sync_Background_Process_Terms_Stage($sync_object_adapter_factory),
53
+			new Sync_Background_Process_Users_Stage($sync_object_adapter_factory),
54 54
 		);
55 55
 	}
56 56
 
@@ -59,66 +59,66 @@  discard block
 block discarded – undo
59 59
 		$this->sync_service->delete_all();
60 60
 
61 61
 		// Clear caches.
62
-		do_action( 'wl_ttl_cache_cleaner__flush' );
62
+		do_action('wl_ttl_cache_cleaner__flush');
63 63
 
64 64
 		$counts = array_map(
65
-			function ( $item ) {
65
+			function($item) {
66 66
 				return $item->count();
67 67
 			},
68 68
 			$this->stages
69 69
 		);
70 70
 
71
-		update_option( '_wl_sync_background_process_count', $counts, true );
72
-		update_option( '_wl_sync_background_process_stage', 0, true );
73
-		update_option( '_wl_sync_background_process_offset', 0, true );
74
-		update_option( '_wl_sync_background_process_started', time(), true );
75
-		update_option( '_wl_sync_background_process_updated', time(), true );
71
+		update_option('_wl_sync_background_process_count', $counts, true);
72
+		update_option('_wl_sync_background_process_stage', 0, true);
73
+		update_option('_wl_sync_background_process_offset', 0, true);
74
+		update_option('_wl_sync_background_process_started', time(), true);
75
+		update_option('_wl_sync_background_process_updated', time(), true);
76 76
 
77
-		$this->context->set_state( Sync_Background_Process::STATE_STARTED );
77
+		$this->context->set_state(Sync_Background_Process::STATE_STARTED);
78 78
 
79 79
 		$this->resume();
80 80
 	}
81 81
 
82 82
 	public function resume() {
83
-		$this->context->push_to_queue( true );
83
+		$this->context->push_to_queue(true);
84 84
 		$this->context->save()->dispatch();
85 85
 	}
86 86
 
87 87
 	public function leave() {
88
-		$this->context->set_state( null );
88
+		$this->context->set_state(null);
89 89
 	}
90 90
 
91 91
 	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
92
-	public function task( $args ) {
92
+	public function task($args) {
93 93
 
94
-		$offset     = get_option( '_wl_sync_background_process_offset' );
95
-		$stage      = get_option( '_wl_sync_background_process_stage' );
96
-		$counts     = get_option( '_wl_sync_background_process_count' );
97
-		$batch_size = min( $counts[ $stage ] - $offset, $this->batch_size );
94
+		$offset     = get_option('_wl_sync_background_process_offset');
95
+		$stage      = get_option('_wl_sync_background_process_stage');
96
+		$counts     = get_option('_wl_sync_background_process_count');
97
+		$batch_size = min($counts[$stage] - $offset, $this->batch_size);
98 98
 
99
-		add_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) );
99
+		add_filter('wl_api_service__request', array($this, 'api_service__request'));
100 100
 		try {
101
-			$object_adapters = $this->stages[ $stage ]->get_sync_object_adapters( $offset, $batch_size );
102
-			$this->sync_service->sync_many( $object_adapters, true );
101
+			$object_adapters = $this->stages[$stage]->get_sync_object_adapters($offset, $batch_size);
102
+			$this->sync_service->sync_many($object_adapters, true);
103 103
 		// phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
104
-		} catch ( \Exception $e ) {
104
+		} catch (\Exception $e) {
105 105
 			// ignored.
106 106
 		}
107
-		remove_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) );
107
+		remove_filter('wl_api_service__request', array($this, 'api_service__request'));
108 108
 
109
-		update_option( '_wl_sync_background_process_updated', time(), true );
109
+		update_option('_wl_sync_background_process_updated', time(), true);
110 110
 
111 111
 		// Increase the offset.
112
-		if ( ( $offset + $batch_size ) < $counts[ $stage ] ) {
113
-			update_option( '_wl_sync_background_process_offset', $offset + $batch_size, true );
112
+		if (($offset + $batch_size) < $counts[$stage]) {
113
+			update_option('_wl_sync_background_process_offset', $offset + $batch_size, true);
114 114
 
115 115
 			return true;
116 116
 		}
117 117
 
118 118
 		// Increase the stage.
119
-		if ( ( $stage + 1 ) < count( $this->stages ) ) {
120
-			update_option( '_wl_sync_background_process_stage', $stage + 1, true );
121
-			update_option( '_wl_sync_background_process_offset', 0, true );
119
+		if (($stage + 1) < count($this->stages)) {
120
+			update_option('_wl_sync_background_process_stage', $stage + 1, true);
121
+			update_option('_wl_sync_background_process_offset', 0, true);
122 122
 
123 123
 			return true;
124 124
 		}
@@ -136,9 +136,9 @@  discard block
 block discarded – undo
136 136
 	 *
137 137
 	 * @return mixed
138 138
 	 */
139
-	public function api_service__request( $args ) {
139
+	public function api_service__request($args) {
140 140
 
141
-		$state_header_value = str_replace( "\n", '', wp_json_encode( $this->context->get_info() ) );
141
+		$state_header_value = str_replace("\n", '', wp_json_encode($this->context->get_info()));
142 142
 
143 143
 		$args['headers']['X-Wordlift-Dataset-Sync-State-V1'] = $state_header_value;
144 144
 
Please login to merge, or discard this patch.