Completed
Pull Request — develop (#1630)
by
unknown
01:19
created
src/wordlift/dataset/background/class-sync-background-process.php 2 patches
Spacing   +11 added lines, -11 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
 
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 	 */
71 71
 	public function start() {
72 72
 		$this->state->leave();
73
-		$this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory );
73
+		$this->state = new Sync_Background_Process_Started_State($this, $this->sync_service, $this->sync_object_adapter_factory);
74 74
 		$this->state->enter();
75 75
 	}
76 76
 
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 	 */
80 80
 	public function stop() {
81 81
 		$this->state->leave();
82
-		$this->state = new Sync_Background_Process_Stopped_State( $this );
82
+		$this->state = new Sync_Background_Process_Stopped_State($this);
83 83
 		$this->state->enter();
84 84
 	}
85 85
 
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 	 * @return string Either self::STARTED_STATE or self::STOPPED_STATE (default).
94 94
 	 */
95 95
 	public function get_state() {
96
-		return get_option( '_wl_sync_background_process_state', self::STATE_STOPPED );
96
+		return get_option('_wl_sync_background_process_state', self::STATE_STOPPED);
97 97
 	}
98 98
 
99 99
 	/**
@@ -103,10 +103,10 @@  discard block
 block discarded – undo
103 103
 	 *
104 104
 	 * @return bool
105 105
 	 */
106
-	public function set_state( $value ) {
106
+	public function set_state($value) {
107 107
 		return null === $value
108
-			? delete_option( '_wl_sync_background_process_state' )
109
-			: update_option( '_wl_sync_background_process_state', $value, true );
108
+			? delete_option('_wl_sync_background_process_state')
109
+			: update_option('_wl_sync_background_process_state', $value, true);
110 110
 	}
111 111
 
112 112
 	public function get_info() {
Please login to merge, or discard this patch.
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -18,97 +18,97 @@
 block discarded – undo
18 18
  */
19 19
 class Sync_Background_Process {
20 20
 
21
-	const STATE_STARTED = 'started';
22
-	const STATE_STOPPED = 'stopped';
23
-
24
-	/**
25
-	 * @var Sync_Service
26
-	 */
27
-	private $sync_service;
28
-
29
-	/**
30
-	 * @var Sync_Object_Adapter_Factory
31
-	 */
32
-	private $sync_object_adapter_factory;
33
-
34
-	/**
35
-	 * @var \Wordlift_Log_Service
36
-	 */
37
-	private $log;
38
-
39
-	/**
40
-	 * @var Sync_Background_Process_State
41
-	 */
42
-	private $state;
43
-
44
-	/**
45
-	 * Sync_Background_Process constructor.
46
-	 *
47
-	 * @param Sync_Service                $sync_service A {@link Sync_Service} instance providing the supporting functions to this background process.
48
-	 * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory
49
-	 */
50
-	public function __construct( $sync_service, $sync_object_adapter_factory ) {
51
-		// parent::__construct();
52
-
53
-		$this->log = \Wordlift_Log_Service::get_logger( get_class() );
54
-
55
-		$this->sync_service                = $sync_service;
56
-		$this->sync_object_adapter_factory = $sync_object_adapter_factory;
57
-
58
-		// Set the current state.
59
-		if ( self::STATE_STARTED === $this->get_state() ) {
60
-			$this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory );
61
-		} else {
62
-			$this->state = new Sync_Background_Process_Stopped_State( $this );
63
-		}
64
-	}
65
-
66
-	/**
67
-	 * Transition to the started state.
68
-	 */
69
-	public function start() {
70
-		$this->state->leave();
71
-		$this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory );
72
-		$this->state->enter();
73
-	}
74
-
75
-	/**
76
-	 * Transition to the stopped state.
77
-	 */
78
-	public function stop() {
79
-		$this->state->leave();
80
-		$this->state = new Sync_Background_Process_Stopped_State( $this );
81
-		$this->state->enter();
82
-	}
83
-
84
-	public function resume() {
85
-		$this->state->resume();
86
-	}
87
-
88
-	/**
89
-	 * Get the current state.
90
-	 *
91
-	 * @return string Either self::STARTED_STATE or self::STOPPED_STATE (default).
92
-	 */
93
-	public function get_state() {
94
-		return get_option( '_wl_sync_background_process_state', self::STATE_STOPPED );
95
-	}
96
-
97
-	/**
98
-	 * Persist the current state.
99
-	 *
100
-	 * @param string $value
101
-	 *
102
-	 * @return bool
103
-	 */
104
-	public function set_state( $value ) {
105
-		return null === $value
106
-			? delete_option( '_wl_sync_background_process_state' )
107
-			: update_option( '_wl_sync_background_process_state', $value, true );
108
-	}
109
-
110
-	public function get_info() {
111
-		return $this->state->get_info();
112
-	}
21
+    const STATE_STARTED = 'started';
22
+    const STATE_STOPPED = 'stopped';
23
+
24
+    /**
25
+     * @var Sync_Service
26
+     */
27
+    private $sync_service;
28
+
29
+    /**
30
+     * @var Sync_Object_Adapter_Factory
31
+     */
32
+    private $sync_object_adapter_factory;
33
+
34
+    /**
35
+     * @var \Wordlift_Log_Service
36
+     */
37
+    private $log;
38
+
39
+    /**
40
+     * @var Sync_Background_Process_State
41
+     */
42
+    private $state;
43
+
44
+    /**
45
+     * Sync_Background_Process constructor.
46
+     *
47
+     * @param Sync_Service                $sync_service A {@link Sync_Service} instance providing the supporting functions to this background process.
48
+     * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory
49
+     */
50
+    public function __construct( $sync_service, $sync_object_adapter_factory ) {
51
+        // parent::__construct();
52
+
53
+        $this->log = \Wordlift_Log_Service::get_logger( get_class() );
54
+
55
+        $this->sync_service                = $sync_service;
56
+        $this->sync_object_adapter_factory = $sync_object_adapter_factory;
57
+
58
+        // Set the current state.
59
+        if ( self::STATE_STARTED === $this->get_state() ) {
60
+            $this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory );
61
+        } else {
62
+            $this->state = new Sync_Background_Process_Stopped_State( $this );
63
+        }
64
+    }
65
+
66
+    /**
67
+     * Transition to the started state.
68
+     */
69
+    public function start() {
70
+        $this->state->leave();
71
+        $this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory );
72
+        $this->state->enter();
73
+    }
74
+
75
+    /**
76
+     * Transition to the stopped state.
77
+     */
78
+    public function stop() {
79
+        $this->state->leave();
80
+        $this->state = new Sync_Background_Process_Stopped_State( $this );
81
+        $this->state->enter();
82
+    }
83
+
84
+    public function resume() {
85
+        $this->state->resume();
86
+    }
87
+
88
+    /**
89
+     * Get the current state.
90
+     *
91
+     * @return string Either self::STARTED_STATE or self::STOPPED_STATE (default).
92
+     */
93
+    public function get_state() {
94
+        return get_option( '_wl_sync_background_process_state', self::STATE_STOPPED );
95
+    }
96
+
97
+    /**
98
+     * Persist the current state.
99
+     *
100
+     * @param string $value
101
+     *
102
+     * @return bool
103
+     */
104
+    public function set_state( $value ) {
105
+        return null === $value
106
+            ? delete_option( '_wl_sync_background_process_state' )
107
+            : update_option( '_wl_sync_background_process_state', $value, true );
108
+    }
109
+
110
+    public function get_info() {
111
+        return $this->state->get_info();
112
+    }
113 113
 
114 114
 }
Please login to merge, or discard this patch.
src/wordlift/dataset/background/class-sync-background-process-state.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -4,27 +4,27 @@
 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
-	 * @return mixed
20
-	 */
21
-	public function task();
22
-
23
-	public function get_info();
24
-
25
-	/**
26
-	 * Try to resume an interrupted task.
27
-	 */
28
-	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
+     * @return mixed
20
+     */
21
+    public function task();
22
+
23
+    public function get_info();
24
+
25
+    /**
26
+     * Try to resume an interrupted task.
27
+     */
28
+    public function resume();
29 29
 
30 30
 }
Please login to merge, or discard this patch.
wordlift/dataset/background/class-sync-background-process-stopped-state.php 2 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -4,28 +4,28 @@
 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
-	public function task() {
27
-		as_unschedule_action( 'wl_sync_data_task' );
28
-		return false;
29
-	}
26
+    public function task() {
27
+        as_unschedule_action( 'wl_sync_data_task' );
28
+        return false;
29
+    }
30 30
 
31 31
 }
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
 	public function task() {
27
-		as_unschedule_action( 'wl_sync_data_task' );
27
+		as_unschedule_action('wl_sync_data_task');
28 28
 		return false;
29 29
 	}
30 30
 
Please login to merge, or discard this patch.
wordlift/dataset/background/class-sync-background-process-started-state.php 2 patches
Indentation   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -11,142 +11,142 @@
 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
-		as_enqueue_async_action( 'wl_sync_data_task' );
57
-		add_action( 'wl_sync_data_task', array( $this, 'task' ), 10, 0 );
58
-	}
59
-
60
-	public function enter() {
61
-		// Delete the KG contents.
62
-		$this->sync_service->delete_all();
63
-
64
-		// Clear caches.
65
-		do_action( 'wl_ttl_cache_cleaner__flush' );
66
-
67
-		$counts = array_map(
68
-			function ( $item ) {
69
-				return $item->count();
70
-			},
71
-			$this->stages
72
-		);
73
-
74
-		update_option( '_wl_sync_background_process_count', $counts, true );
75
-		update_option( '_wl_sync_background_process_stage', 0, true );
76
-		update_option( '_wl_sync_background_process_offset', 0, true );
77
-		update_option( '_wl_sync_background_process_started', time(), true );
78
-		update_option( '_wl_sync_background_process_updated', time(), true );
79
-
80
-		$this->context->set_state( Sync_Background_Process::STATE_STARTED );
81
-
82
-		$this->resume();
83
-	}
84
-
85
-	public function resume() {
86
-		// TODO : Resume Functionality.
87
-		// $this->context->push_to_queue( true );
88
-		// $this->context->save()->dispatch();
89
-	}
90
-
91
-	public function leave() {
92
-		$this->context->set_state( null );
93
-	}
94
-
95
-	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
96
-	public function task() {
97
-
98
-		$offset     = get_option( '_wl_sync_background_process_offset' );
99
-		$stage      = get_option( '_wl_sync_background_process_stage' );
100
-		$counts     = get_option( '_wl_sync_background_process_count' );
101
-		$batch_size = min( $counts[ $stage ] - $offset, $this->batch_size );
102
-
103
-		add_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) );
104
-		try {
105
-			$object_adapters = $this->stages[ $stage ]->get_sync_object_adapters( $offset, $batch_size );
106
-			$this->sync_service->sync_many( $object_adapters, true );
107
-		// phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
108
-		} catch ( \Exception $e ) {
109
-			// ignored.
110
-		}
111
-		remove_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) );
112
-
113
-		update_option( '_wl_sync_background_process_updated', time(), true );
114
-
115
-		// Increase the offset.
116
-		if ( ( $offset + $batch_size ) < $counts[ $stage ] ) {
117
-			update_option( '_wl_sync_background_process_offset', $offset + $batch_size, true );
118
-
119
-			return true;
120
-		}
121
-
122
-		// Increase the stage.
123
-		if ( ( $stage + 1 ) < count( $this->stages ) ) {
124
-			update_option( '_wl_sync_background_process_stage', $stage + 1, true );
125
-			update_option( '_wl_sync_background_process_offset', 0, true );
126
-
127
-			return true;
128
-		}
129
-
130
-		// Stop processing.
131
-		$this->context->stop();
132
-
133
-		return false;
134
-	}
135
-
136
-	/**
137
-	 * Hook to provide a request to update the status on the server.
138
-	 *
139
-	 * @param array $args
140
-	 *
141
-	 * @return mixed
142
-	 */
143
-	public function api_service__request( $args ) {
144
-
145
-		$state_header_value = str_replace( "\n", '', wp_json_encode( $this->context->get_info() ) );
146
-
147
-		$args['headers']['X-Wordlift-Dataset-Sync-State-V1'] = $state_header_value;
148
-
149
-		return $args;
150
-	}
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
+        as_enqueue_async_action( 'wl_sync_data_task' );
57
+        add_action( 'wl_sync_data_task', array( $this, 'task' ), 10, 0 );
58
+    }
59
+
60
+    public function enter() {
61
+        // Delete the KG contents.
62
+        $this->sync_service->delete_all();
63
+
64
+        // Clear caches.
65
+        do_action( 'wl_ttl_cache_cleaner__flush' );
66
+
67
+        $counts = array_map(
68
+            function ( $item ) {
69
+                return $item->count();
70
+            },
71
+            $this->stages
72
+        );
73
+
74
+        update_option( '_wl_sync_background_process_count', $counts, true );
75
+        update_option( '_wl_sync_background_process_stage', 0, true );
76
+        update_option( '_wl_sync_background_process_offset', 0, true );
77
+        update_option( '_wl_sync_background_process_started', time(), true );
78
+        update_option( '_wl_sync_background_process_updated', time(), true );
79
+
80
+        $this->context->set_state( Sync_Background_Process::STATE_STARTED );
81
+
82
+        $this->resume();
83
+    }
84
+
85
+    public function resume() {
86
+        // TODO : Resume Functionality.
87
+        // $this->context->push_to_queue( true );
88
+        // $this->context->save()->dispatch();
89
+    }
90
+
91
+    public function leave() {
92
+        $this->context->set_state( null );
93
+    }
94
+
95
+    // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
96
+    public function task() {
97
+
98
+        $offset     = get_option( '_wl_sync_background_process_offset' );
99
+        $stage      = get_option( '_wl_sync_background_process_stage' );
100
+        $counts     = get_option( '_wl_sync_background_process_count' );
101
+        $batch_size = min( $counts[ $stage ] - $offset, $this->batch_size );
102
+
103
+        add_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) );
104
+        try {
105
+            $object_adapters = $this->stages[ $stage ]->get_sync_object_adapters( $offset, $batch_size );
106
+            $this->sync_service->sync_many( $object_adapters, true );
107
+        // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
108
+        } catch ( \Exception $e ) {
109
+            // ignored.
110
+        }
111
+        remove_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) );
112
+
113
+        update_option( '_wl_sync_background_process_updated', time(), true );
114
+
115
+        // Increase the offset.
116
+        if ( ( $offset + $batch_size ) < $counts[ $stage ] ) {
117
+            update_option( '_wl_sync_background_process_offset', $offset + $batch_size, true );
118
+
119
+            return true;
120
+        }
121
+
122
+        // Increase the stage.
123
+        if ( ( $stage + 1 ) < count( $this->stages ) ) {
124
+            update_option( '_wl_sync_background_process_stage', $stage + 1, true );
125
+            update_option( '_wl_sync_background_process_offset', 0, true );
126
+
127
+            return true;
128
+        }
129
+
130
+        // Stop processing.
131
+        $this->context->stop();
132
+
133
+        return false;
134
+    }
135
+
136
+    /**
137
+     * Hook to provide a request to update the status on the server.
138
+     *
139
+     * @param array $args
140
+     *
141
+     * @return mixed
142
+     */
143
+    public function api_service__request( $args ) {
144
+
145
+        $state_header_value = str_replace( "\n", '', wp_json_encode( $this->context->get_info() ) );
146
+
147
+        $args['headers']['X-Wordlift-Dataset-Sync-State-V1'] = $state_header_value;
148
+
149
+        return $args;
150
+    }
151 151
 
152 152
 }
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -41,20 +41,20 @@  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
-		as_enqueue_async_action( 'wl_sync_data_task' );
57
-		add_action( 'wl_sync_data_task', array( $this, 'task' ), 10, 0 );
56
+		as_enqueue_async_action('wl_sync_data_task');
57
+		add_action('wl_sync_data_task', array($this, 'task'), 10, 0);
58 58
 	}
59 59
 
60 60
 	public function enter() {
@@ -62,22 +62,22 @@  discard block
 block discarded – undo
62 62
 		$this->sync_service->delete_all();
63 63
 
64 64
 		// Clear caches.
65
-		do_action( 'wl_ttl_cache_cleaner__flush' );
65
+		do_action('wl_ttl_cache_cleaner__flush');
66 66
 
67 67
 		$counts = array_map(
68
-			function ( $item ) {
68
+			function($item) {
69 69
 				return $item->count();
70 70
 			},
71 71
 			$this->stages
72 72
 		);
73 73
 
74
-		update_option( '_wl_sync_background_process_count', $counts, true );
75
-		update_option( '_wl_sync_background_process_stage', 0, true );
76
-		update_option( '_wl_sync_background_process_offset', 0, true );
77
-		update_option( '_wl_sync_background_process_started', time(), true );
78
-		update_option( '_wl_sync_background_process_updated', time(), true );
74
+		update_option('_wl_sync_background_process_count', $counts, true);
75
+		update_option('_wl_sync_background_process_stage', 0, true);
76
+		update_option('_wl_sync_background_process_offset', 0, true);
77
+		update_option('_wl_sync_background_process_started', time(), true);
78
+		update_option('_wl_sync_background_process_updated', time(), true);
79 79
 
80
-		$this->context->set_state( Sync_Background_Process::STATE_STARTED );
80
+		$this->context->set_state(Sync_Background_Process::STATE_STARTED);
81 81
 
82 82
 		$this->resume();
83 83
 	}
@@ -89,40 +89,40 @@  discard block
 block discarded – undo
89 89
 	}
90 90
 
91 91
 	public function leave() {
92
-		$this->context->set_state( null );
92
+		$this->context->set_state(null);
93 93
 	}
94 94
 
95 95
 	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
96 96
 	public function task() {
97 97
 
98
-		$offset     = get_option( '_wl_sync_background_process_offset' );
99
-		$stage      = get_option( '_wl_sync_background_process_stage' );
100
-		$counts     = get_option( '_wl_sync_background_process_count' );
101
-		$batch_size = min( $counts[ $stage ] - $offset, $this->batch_size );
98
+		$offset     = get_option('_wl_sync_background_process_offset');
99
+		$stage      = get_option('_wl_sync_background_process_stage');
100
+		$counts     = get_option('_wl_sync_background_process_count');
101
+		$batch_size = min($counts[$stage] - $offset, $this->batch_size);
102 102
 
103
-		add_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) );
103
+		add_filter('wl_api_service__request', array($this, 'api_service__request'));
104 104
 		try {
105
-			$object_adapters = $this->stages[ $stage ]->get_sync_object_adapters( $offset, $batch_size );
106
-			$this->sync_service->sync_many( $object_adapters, true );
105
+			$object_adapters = $this->stages[$stage]->get_sync_object_adapters($offset, $batch_size);
106
+			$this->sync_service->sync_many($object_adapters, true);
107 107
 		// phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
108
-		} catch ( \Exception $e ) {
108
+		} catch (\Exception $e) {
109 109
 			// ignored.
110 110
 		}
111
-		remove_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) );
111
+		remove_filter('wl_api_service__request', array($this, 'api_service__request'));
112 112
 
113
-		update_option( '_wl_sync_background_process_updated', time(), true );
113
+		update_option('_wl_sync_background_process_updated', time(), true);
114 114
 
115 115
 		// Increase the offset.
116
-		if ( ( $offset + $batch_size ) < $counts[ $stage ] ) {
117
-			update_option( '_wl_sync_background_process_offset', $offset + $batch_size, true );
116
+		if (($offset + $batch_size) < $counts[$stage]) {
117
+			update_option('_wl_sync_background_process_offset', $offset + $batch_size, true);
118 118
 
119 119
 			return true;
120 120
 		}
121 121
 
122 122
 		// Increase the stage.
123
-		if ( ( $stage + 1 ) < count( $this->stages ) ) {
124
-			update_option( '_wl_sync_background_process_stage', $stage + 1, true );
125
-			update_option( '_wl_sync_background_process_offset', 0, true );
123
+		if (($stage + 1) < count($this->stages)) {
124
+			update_option('_wl_sync_background_process_stage', $stage + 1, true);
125
+			update_option('_wl_sync_background_process_offset', 0, true);
126 126
 
127 127
 			return true;
128 128
 		}
@@ -140,9 +140,9 @@  discard block
 block discarded – undo
140 140
 	 *
141 141
 	 * @return mixed
142 142
 	 */
143
-	public function api_service__request( $args ) {
143
+	public function api_service__request($args) {
144 144
 
145
-		$state_header_value = str_replace( "\n", '', wp_json_encode( $this->context->get_info() ) );
145
+		$state_header_value = str_replace("\n", '', wp_json_encode($this->context->get_info()));
146 146
 
147 147
 		$args['headers']['X-Wordlift-Dataset-Sync-State-V1'] = $state_header_value;
148 148
 
Please login to merge, or discard this patch.
src/wordlift.php 1 patch
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -32,27 +32,27 @@  discard block
 block discarded – undo
32 32
 use Wordlift\Post\Post_Adapter;
33 33
 
34 34
 // If this file is called directly, abort.
35
-if ( ! defined( 'WPINC' ) ) {
35
+if ( ! defined('WPINC')) {
36 36
 	die;
37 37
 }
38 38
 
39
-define( 'WORDLIFT_VERSION', '3.40.2' );
39
+define('WORDLIFT_VERSION', '3.40.2');
40 40
 
41
-require_once __DIR__ . '/modules/common/load.php';
42
-require_once __DIR__ . '/modules/include-exclude/load.php';
41
+require_once __DIR__.'/modules/common/load.php';
42
+require_once __DIR__.'/modules/include-exclude/load.php';
43 43
 
44 44
 /**
45 45
  * Filter to disable WLP on any request, defaults to true.
46 46
  *
47 47
  * @since 3.33.6
48 48
  */
49
-if ( ! apply_filters( 'wl_is_enabled', true ) ) {
49
+if ( ! apply_filters('wl_is_enabled', true)) {
50 50
 	return;
51 51
 }
52 52
 
53
-require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
53
+require_once plugin_dir_path(__FILE__).'vendor/autoload.php';
54 54
 // Action Scheduler.
55
-require_once plugin_dir_path( __FILE__ ) . '/ext/dependencies/action-scheduler/action-scheduler.php';
55
+require_once plugin_dir_path(__FILE__).'/ext/dependencies/action-scheduler/action-scheduler.php';
56 56
 
57 57
 /*
58 58
 	 * We introduce the WordLift autoloader, since we start using classes in namespaces, i.e. Wordlift\Http.
@@ -62,15 +62,15 @@  discard block
 block discarded – undo
62 62
 wordlift_plugin_autoload_register();
63 63
 
64 64
 // Include WordLift constants.
65
-require_once plugin_dir_path( __FILE__ ) . 'wordlift-constants.php';
65
+require_once plugin_dir_path(__FILE__).'wordlift-constants.php';
66 66
 
67 67
 // Load modules.
68
-require_once plugin_dir_path( __FILE__ ) . 'modules/core/wordlift-core.php';
68
+require_once plugin_dir_path(__FILE__).'modules/core/wordlift-core.php';
69 69
 
70
-require_once plugin_dir_path( __FILE__ ) . 'deprecations.php';
70
+require_once plugin_dir_path(__FILE__).'deprecations.php';
71 71
 
72 72
 // Load early to enable/disable features.
73
-require_once plugin_dir_path( __FILE__ ) . 'wordlift/features/index.php';
73
+require_once plugin_dir_path(__FILE__).'wordlift/features/index.php';
74 74
 
75 75
 /**
76 76
  * The code that runs during plugin activation.
@@ -78,11 +78,11 @@  discard block
 block discarded – undo
78 78
  */
79 79
 function activate_wordlift() {
80 80
 
81
-	$log = Wordlift_Log_Service::get_logger( 'activate_wordlift' );
81
+	$log = Wordlift_Log_Service::get_logger('activate_wordlift');
82 82
 
83
-	$log->info( 'Activating WordLift...' );
83
+	$log->info('Activating WordLift...');
84 84
 
85
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
85
+	require_once plugin_dir_path(__FILE__).'includes/class-wordlift-activator.php';
86 86
 	Wordlift_Activator::activate();
87 87
 
88 88
 	/**
@@ -102,8 +102,8 @@  discard block
 block discarded – undo
102 102
 	 */
103 103
 	Top_Entities::activate();
104 104
 
105
-	if ( ! wp_next_scheduled( 'wl_daily_cron' ) ) {
106
-		wp_schedule_event( time(), 'daily', 'wl_daily_cron' );
105
+	if ( ! wp_next_scheduled('wl_daily_cron')) {
106
+		wp_schedule_event(time(), 'daily', 'wl_daily_cron');
107 107
 	}
108 108
 
109 109
 }
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
  */
115 115
 function deactivate_wordlift() {
116 116
 
117
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
117
+	require_once plugin_dir_path(__FILE__).'includes/class-wordlift-deactivator.php';
118 118
 	Wordlift_Deactivator::deactivate();
119 119
 	Wordlift_Http_Api::deactivate();
120 120
 	Ttl_Cache_Cleaner::deactivate();
@@ -130,18 +130,18 @@  discard block
 block discarded – undo
130 130
 	Key_Validation_Notice::remove_notification_flag();
131 131
 	flush_rewrite_rules();
132 132
 
133
-	wp_clear_scheduled_hook( 'wl_daily_cron' );
133
+	wp_clear_scheduled_hook('wl_daily_cron');
134 134
 
135 135
 }
136 136
 
137
-register_activation_hook( __FILE__, 'activate_wordlift' );
138
-register_deactivation_hook( __FILE__, 'deactivate_wordlift' );
137
+register_activation_hook(__FILE__, 'activate_wordlift');
138
+register_deactivation_hook(__FILE__, 'deactivate_wordlift');
139 139
 
140 140
 /**
141 141
  * The core plugin class that is used to define internationalization,
142 142
  * admin-specific hooks, and public-facing site hooks.
143 143
  */
144
-require plugin_dir_path( __FILE__ ) . 'includes/class-wordlift.php';
144
+require plugin_dir_path(__FILE__).'includes/class-wordlift.php';
145 145
 
146 146
 /**
147 147
  * Begins execution of the plugin.
@@ -161,12 +161,12 @@  discard block
 block discarded – undo
161 161
 	 * @return bool
162 162
 	 * @since 3.27.6
163 163
 	 */
164
-	if ( apply_filters( 'wl_feature__enable__widgets', true ) ) {
165
-		add_action( 'widgets_init', 'wl_register_chord_widget' );
166
-		add_action( 'widgets_init', 'wl_register_geo_widget' );
167
-		add_action( 'widgets_init', 'wl_register_timeline_widget' );
164
+	if (apply_filters('wl_feature__enable__widgets', true)) {
165
+		add_action('widgets_init', 'wl_register_chord_widget');
166
+		add_action('widgets_init', 'wl_register_geo_widget');
167
+		add_action('widgets_init', 'wl_register_timeline_widget');
168 168
 	}
169
-	add_filter( 'widget_text', 'do_shortcode' );
169
+	add_filter('widget_text', 'do_shortcode');
170 170
 
171 171
 	/**
172 172
 	 * Filter: wl_feature__enable__analysis
@@ -176,10 +176,10 @@  discard block
 block discarded – undo
176 176
 	 * @return bool
177 177
 	 * @since 3.27.6
178 178
 	 */
179
-	if ( apply_filters( 'wl_feature__enable__analysis', true ) ) {
180
-		add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' );
179
+	if (apply_filters('wl_feature__enable__analysis', true)) {
180
+		add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_action');
181 181
 	} else {
182
-		add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' );
182
+		add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action');
183 183
 	}
184 184
 
185 185
 	$plugin = new Wordlift();
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 
197 197
 	add_action(
198 198
 		'plugins_loaded',
199
-		function () {
199
+		function() {
200 200
 			// All features from registry should be initialized here.
201 201
 			$features_registry = Features_Registry::get_instance();
202 202
 			$features_registry->initialize_all_features();
@@ -207,27 +207,27 @@  discard block
 block discarded – undo
207 207
 	add_action(
208 208
 		'plugins_loaded',
209 209
 		// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
210
-		function () use ( $plugin ) {
210
+		function() use ($plugin) {
211 211
 
212 212
 			new Wordlift_Products_Navigator_Shortcode_REST();
213 213
 
214 214
 			// Register the Dataset module, requires `$api_service`.
215
-			require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php';
216
-			require_once plugin_dir_path( __FILE__ ) . 'wordlift/shipping-data/index.php';
215
+			require_once plugin_dir_path(__FILE__).'wordlift/dataset/index.php';
216
+			require_once plugin_dir_path(__FILE__).'wordlift/shipping-data/index.php';
217 217
 
218 218
 			/*
219 219
 			* Require the Entity annotation cleanup module.
220 220
 			*
221 221
 			* @since 3.34.6
222 222
 			*/
223
-			require_once plugin_dir_path( __FILE__ ) . 'wordlift/cleanup/index.php';
223
+			require_once plugin_dir_path(__FILE__).'wordlift/cleanup/index.php';
224 224
 
225 225
 			/*
226 226
 			* Import LOD entities.
227 227
 			*
228 228
 			* @since 3.35.0
229 229
 			*/
230
-			require_once plugin_dir_path( __FILE__ ) . 'wordlift/lod-import/index.php';
230
+			require_once plugin_dir_path(__FILE__).'wordlift/lod-import/index.php';
231 231
 
232 232
 		}
233 233
 	);
@@ -245,23 +245,23 @@  discard block
 block discarded – undo
245 245
 function wordlift_plugin_autoload_register() {
246 246
 
247 247
 	spl_autoload_register(
248
-		function ( $class_name ) {
248
+		function($class_name) {
249 249
 
250 250
 			// Bail out if these are not our classes.
251
-			if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) {
251
+			if (0 !== strpos($class_name, 'Wordlift\\')) {
252 252
 				return false;
253 253
 			}
254 254
 
255
-			$class_name_lc = strtolower( str_replace( '_', '-', $class_name ) );
255
+			$class_name_lc = strtolower(str_replace('_', '-', $class_name));
256 256
 
257
-			preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches );
257
+			preg_match('|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches);
258 258
 
259
-			$path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] );
260
-			$file = 'class-' . $matches[2] . '.php';
259
+			$path = str_replace('\\', DIRECTORY_SEPARATOR, $matches[1]);
260
+			$file = 'class-'.$matches[2].'.php';
261 261
 
262
-			$full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file;
262
+			$full_path = plugin_dir_path(__FILE__).$path.DIRECTORY_SEPARATOR.$file;
263 263
 
264
-			if ( ! file_exists( $full_path ) ) {
264
+			if ( ! file_exists($full_path)) {
265 265
 				return false;
266 266
 			}
267 267
 
@@ -273,13 +273,13 @@  discard block
 block discarded – undo
273 273
 
274 274
 }
275 275
 
276
-function wl_block_categories( $categories ) {
276
+function wl_block_categories($categories) {
277 277
 	return array_merge(
278 278
 		$categories,
279 279
 		array(
280 280
 			array(
281 281
 				'slug'  => 'wordlift',
282
-				'title' => __( 'WordLift', 'wordlift' ),
282
+				'title' => __('WordLift', 'wordlift'),
283 283
 			),
284 284
 		)
285 285
 	);
@@ -289,23 +289,23 @@  discard block
 block discarded – undo
289 289
  * This function is created temporarily to handle the legacy library,
290 290
  * this has to be removed when removing the legacy fields from the ui.
291 291
  */
292
-function wl_enqueue_leaflet( $in_footer = false ) {
292
+function wl_enqueue_leaflet($in_footer = false) {
293 293
 	// Leaflet.
294
-	wp_enqueue_style( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.css', array(), '1.6.0' );
295
-	wp_enqueue_script( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer );
294
+	wp_enqueue_style('wl-leaflet', plugin_dir_url(__FILE__).'js/leaflet/leaflet.css', array(), '1.6.0');
295
+	wp_enqueue_script('wl-leaflet', plugin_dir_url(__FILE__).'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer);
296 296
 }
297 297
 
298
-add_filter( 'block_categories', 'wl_block_categories', 10 );
298
+add_filter('block_categories', 'wl_block_categories', 10);
299 299
 
300 300
 // Temporary fix for a typo in WooCommerce Extension.
301 301
 add_filter(
302 302
 	'wl_feature__enable__dataset',
303
-	function ( $value ) {
304
-		return apply_filters( 'wl_features__enable__dataset', $value );
303
+	function($value) {
304
+		return apply_filters('wl_features__enable__dataset', $value);
305 305
 	}
306 306
 );
307 307
 
308
-require_once __DIR__ . '/modules/food-kg/load.php';
309
-require_once __DIR__ . '/modules/acf4so/load.php';
310
-require_once __DIR__ . '/modules/pods/load.php';
311
-require_once __DIR__ . '/modules/include-exclude-push-config/load.php';
308
+require_once __DIR__.'/modules/food-kg/load.php';
309
+require_once __DIR__.'/modules/acf4so/load.php';
310
+require_once __DIR__.'/modules/pods/load.php';
311
+require_once __DIR__.'/modules/include-exclude-push-config/load.php';
Please login to merge, or discard this patch.