Completed
Pull Request — develop (#1554)
by Naveen
48s
created
dataset/background/class-abstract-sync-background-process-state.php 2 patches
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -4,33 +4,33 @@
 block discarded – undo
4 4
 
5 5
 abstract class Abstract_Sync_Background_Process_State implements Sync_Background_Process_State {
6 6
 
7
-	private $state;
8
-
9
-	function __construct( $state ) {
10
-		$this->state = $state;
11
-	}
12
-
13
-	function get_info() {
14
-		$started     = get_option( '_wl_sync_background_process_started' );
15
-		$offset      = get_option( '_wl_sync_background_process_offset' );
16
-		$stage       = get_option( '_wl_sync_background_process_stage' );
17
-		$counts      = get_option( '_wl_sync_background_process_count', array( 0 ) );
18
-		$last_update = get_option( '_wl_sync_background_process_updated' );
19
-
20
-		// Calculate the overall index by adding the count of completed stages.
21
-		$index = $offset + 1;
22
-		for ( $i = 0; $i < $stage; $i ++ ) {
23
-			$index += $counts[ $i ];
24
-		}
25
-
26
-		// Get the total count.
27
-		$total_count = array_sum( $counts );
28
-
29
-		return new Sync_Background_Process_Info( $this->state, $started, $index, $total_count, $last_update );
30
-	}
31
-
32
-	function resume() {
33
-		// do nothing.
34
-	}
7
+    private $state;
8
+
9
+    function __construct( $state ) {
10
+        $this->state = $state;
11
+    }
12
+
13
+    function get_info() {
14
+        $started     = get_option( '_wl_sync_background_process_started' );
15
+        $offset      = get_option( '_wl_sync_background_process_offset' );
16
+        $stage       = get_option( '_wl_sync_background_process_stage' );
17
+        $counts      = get_option( '_wl_sync_background_process_count', array( 0 ) );
18
+        $last_update = get_option( '_wl_sync_background_process_updated' );
19
+
20
+        // Calculate the overall index by adding the count of completed stages.
21
+        $index = $offset + 1;
22
+        for ( $i = 0; $i < $stage; $i ++ ) {
23
+            $index += $counts[ $i ];
24
+        }
25
+
26
+        // Get the total count.
27
+        $total_count = array_sum( $counts );
28
+
29
+        return new Sync_Background_Process_Info( $this->state, $started, $index, $total_count, $last_update );
30
+    }
31
+
32
+    function resume() {
33
+        // do nothing.
34
+    }
35 35
 
36 36
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -6,27 +6,27 @@
 block discarded – undo
6 6
 
7 7
 	private $state;
8 8
 
9
-	function __construct( $state ) {
9
+	function __construct($state) {
10 10
 		$this->state = $state;
11 11
 	}
12 12
 
13 13
 	function get_info() {
14
-		$started     = get_option( '_wl_sync_background_process_started' );
15
-		$offset      = get_option( '_wl_sync_background_process_offset' );
16
-		$stage       = get_option( '_wl_sync_background_process_stage' );
17
-		$counts      = get_option( '_wl_sync_background_process_count', array( 0 ) );
18
-		$last_update = get_option( '_wl_sync_background_process_updated' );
14
+		$started     = get_option('_wl_sync_background_process_started');
15
+		$offset      = get_option('_wl_sync_background_process_offset');
16
+		$stage       = get_option('_wl_sync_background_process_stage');
17
+		$counts      = get_option('_wl_sync_background_process_count', array(0));
18
+		$last_update = get_option('_wl_sync_background_process_updated');
19 19
 
20 20
 		// Calculate the overall index by adding the count of completed stages.
21 21
 		$index = $offset + 1;
22
-		for ( $i = 0; $i < $stage; $i ++ ) {
23
-			$index += $counts[ $i ];
22
+		for ($i = 0; $i < $stage; $i++) {
23
+			$index += $counts[$i];
24 24
 		}
25 25
 
26 26
 		// Get the total count.
27
-		$total_count = array_sum( $counts );
27
+		$total_count = array_sum($counts);
28 28
 
29
-		return new Sync_Background_Process_Info( $this->state, $started, $index, $total_count, $last_update );
29
+		return new Sync_Background_Process_Info($this->state, $started, $index, $total_count, $last_update);
30 30
 	}
31 31
 
32 32
 	function resume() {
Please login to merge, or discard this patch.
dataset/background/class-sync-background-process-wpjson-endpoint.php 2 patches
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -6,66 +6,66 @@
 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
-	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
-	function rest_api_init() {
28
-
29
-		register_rest_route( 'wordlift/v1', '/dataset/background/sync', array(
30
-			'methods'             => WP_REST_Server::CREATABLE,
31
-			'callback'            => array( $this->sync_background_process, 'start' ),
32
-			'permission_callback' => function () {
33
-				$user = wp_get_current_user();
34
-
35
-				return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles );
36
-			}
37
-		) );
38
-
39
-		register_rest_route( 'wordlift/v1', '/dataset/background/sync', array(
40
-			'methods'             => WP_REST_Server::READABLE,
41
-			'callback'            => array( $this->sync_background_process, 'get_info' ),
42
-			'permission_callback' => function () {
43
-				$user = wp_get_current_user();
44
-
45
-				return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles );
46
-			}
47
-		) );
48
-
49
-		register_rest_route( 'wordlift/v1', '/dataset/background/sync', array(
50
-			'methods'             => WP_REST_Server::DELETABLE,
51
-			'callback'            => array( $this->sync_background_process, 'stop' ),
52
-			'permission_callback' => function () {
53
-				$user = wp_get_current_user();
54
-
55
-				return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles );
56
-			}
57
-		) );
58
-
59
-		register_rest_route( 'wordlift/v1', '/dataset/background/sync', array(
60
-			'methods'             => 'PUT',
61
-			'callback'            => array( $this->sync_background_process, 'resume' ),
62
-			'permission_callback' => function () {
63
-				$user = wp_get_current_user();
64
-
65
-				return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles );
66
-			}
67
-		) );
68
-
69
-	}
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
+    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
+    function rest_api_init() {
28
+
29
+        register_rest_route( 'wordlift/v1', '/dataset/background/sync', array(
30
+            'methods'             => WP_REST_Server::CREATABLE,
31
+            'callback'            => array( $this->sync_background_process, 'start' ),
32
+            'permission_callback' => function () {
33
+                $user = wp_get_current_user();
34
+
35
+                return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles );
36
+            }
37
+        ) );
38
+
39
+        register_rest_route( 'wordlift/v1', '/dataset/background/sync', array(
40
+            'methods'             => WP_REST_Server::READABLE,
41
+            'callback'            => array( $this->sync_background_process, 'get_info' ),
42
+            'permission_callback' => function () {
43
+                $user = wp_get_current_user();
44
+
45
+                return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles );
46
+            }
47
+        ) );
48
+
49
+        register_rest_route( 'wordlift/v1', '/dataset/background/sync', array(
50
+            'methods'             => WP_REST_Server::DELETABLE,
51
+            'callback'            => array( $this->sync_background_process, 'stop' ),
52
+            'permission_callback' => function () {
53
+                $user = wp_get_current_user();
54
+
55
+                return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles );
56
+            }
57
+        ) );
58
+
59
+        register_rest_route( 'wordlift/v1', '/dataset/background/sync', array(
60
+            'methods'             => 'PUT',
61
+            'callback'            => array( $this->sync_background_process, 'resume' ),
62
+            'permission_callback' => function () {
63
+                $user = wp_get_current_user();
64
+
65
+                return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles );
66
+            }
67
+        ) );
68
+
69
+    }
70 70
 
71 71
 }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 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
-	function __construct( $sync_background_process ) {
19
+	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
 
@@ -26,45 +26,45 @@  discard block
 block discarded – undo
26 26
 
27 27
 	function rest_api_init() {
28 28
 
29
-		register_rest_route( 'wordlift/v1', '/dataset/background/sync', array(
29
+		register_rest_route('wordlift/v1', '/dataset/background/sync', array(
30 30
 			'methods'             => WP_REST_Server::CREATABLE,
31
-			'callback'            => array( $this->sync_background_process, 'start' ),
32
-			'permission_callback' => function () {
31
+			'callback'            => array($this->sync_background_process, 'start'),
32
+			'permission_callback' => function() {
33 33
 				$user = wp_get_current_user();
34 34
 
35
-				return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles );
35
+				return is_super_admin($user->ID) || in_array('administrator', (array) $user->roles);
36 36
 			}
37
-		) );
37
+		));
38 38
 
39
-		register_rest_route( 'wordlift/v1', '/dataset/background/sync', array(
39
+		register_rest_route('wordlift/v1', '/dataset/background/sync', array(
40 40
 			'methods'             => WP_REST_Server::READABLE,
41
-			'callback'            => array( $this->sync_background_process, 'get_info' ),
42
-			'permission_callback' => function () {
41
+			'callback'            => array($this->sync_background_process, 'get_info'),
42
+			'permission_callback' => function() {
43 43
 				$user = wp_get_current_user();
44 44
 
45
-				return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles );
45
+				return is_super_admin($user->ID) || in_array('administrator', (array) $user->roles);
46 46
 			}
47
-		) );
47
+		));
48 48
 
49
-		register_rest_route( 'wordlift/v1', '/dataset/background/sync', array(
49
+		register_rest_route('wordlift/v1', '/dataset/background/sync', array(
50 50
 			'methods'             => WP_REST_Server::DELETABLE,
51
-			'callback'            => array( $this->sync_background_process, 'stop' ),
52
-			'permission_callback' => function () {
51
+			'callback'            => array($this->sync_background_process, 'stop'),
52
+			'permission_callback' => function() {
53 53
 				$user = wp_get_current_user();
54 54
 
55
-				return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles );
55
+				return is_super_admin($user->ID) || in_array('administrator', (array) $user->roles);
56 56
 			}
57
-		) );
57
+		));
58 58
 
59
-		register_rest_route( 'wordlift/v1', '/dataset/background/sync', array(
59
+		register_rest_route('wordlift/v1', '/dataset/background/sync', array(
60 60
 			'methods'             => 'PUT',
61
-			'callback'            => array( $this->sync_background_process, 'resume' ),
62
-			'permission_callback' => function () {
61
+			'callback'            => array($this->sync_background_process, 'resume'),
62
+			'permission_callback' => function() {
63 63
 				$user = wp_get_current_user();
64 64
 
65
-				return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles );
65
+				return is_super_admin($user->ID) || in_array('administrator', (array) $user->roles);
66 66
 			}
67
-		) );
67
+		));
68 68
 
69 69
 	}
70 70
 
Please login to merge, or discard this patch.
wordlift/dataset/background/class-sync-background-process-started-state.php 2 patches
Indentation   +127 added lines, -127 removed lines patch added patch discarded remove patch
@@ -11,132 +11,132 @@
 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
-	function __construct( $context, $sync_service, $sync_object_adapter_factory, $reset = true ) {
44
-		parent::__construct( Sync_Background_Process::STATE_STARTED );
45
-
46
-		$this->context      = $context;
47
-		$this->sync_service = $sync_service;
48
-
49
-		$this->stages = array(
50
-			new Sync_Background_Process_Posts_Stage( $sync_object_adapter_factory ),
51
-			new Sync_Background_Process_Terms_Stage( $sync_object_adapter_factory ),
52
-			new Sync_Background_Process_Users_Stage( $sync_object_adapter_factory ),
53
-		);
54
-	}
55
-
56
-	function enter() {
57
-		// Delete the KG contents.
58
-		$this->sync_service->delete_all();
59
-
60
-		// Clear caches.
61
-		do_action( 'wl_ttl_cache_cleaner__flush' );
62
-
63
-		$counts = array_map( function ( $item ) {
64
-			return $item->count();
65
-		}, $this->stages );
66
-
67
-		update_option( '_wl_sync_background_process_count', $counts, true );
68
-		update_option( '_wl_sync_background_process_stage', 0, true );
69
-		update_option( '_wl_sync_background_process_offset', 0, true );
70
-		update_option( '_wl_sync_background_process_started', time(), true );
71
-		update_option( '_wl_sync_background_process_updated', time(), true );
72
-
73
-		$this->context->set_state( Sync_Background_Process::STATE_STARTED );
74
-
75
-		$this->resume();
76
-	}
77
-
78
-	function resume() {
79
-		$this->context->push_to_queue( true );
80
-		$this->context->save()->dispatch();
81
-	}
82
-
83
-	function leave() {
84
-		$this->context->set_state( null );
85
-	}
86
-
87
-	function task( $args ) {
88
-
89
-		$offset     = get_option( '_wl_sync_background_process_offset' );
90
-		$stage      = get_option( '_wl_sync_background_process_stage' );
91
-		$counts     = get_option( '_wl_sync_background_process_count' );
92
-		$batch_size = min( $counts[ $stage ] - $offset, $this->batch_size );
93
-
94
-		add_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) );
95
-		try {
96
-			$object_adapters = $this->stages[ $stage ]->get_sync_object_adapters( $offset, $batch_size );
97
-			$this->sync_service->sync_many( $object_adapters, true );
98
-		} catch ( \Exception $e ) {
99
-			// ignored.
100
-		}
101
-		remove_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) );
102
-
103
-		update_option( '_wl_sync_background_process_updated', time(), true );
104
-
105
-		// Increase the offset.
106
-		if ( ( $offset + $batch_size ) < $counts[ $stage ] ) {
107
-			update_option( '_wl_sync_background_process_offset', $offset + $batch_size, true );
108
-
109
-			return true;
110
-		}
111
-
112
-		// Increase the stage.
113
-		if ( ( $stage + 1 ) < count( $this->stages ) ) {
114
-			update_option( '_wl_sync_background_process_stage', $stage + 1, true );
115
-			update_option( '_wl_sync_background_process_offset', 0, true );
116
-
117
-			return true;
118
-		}
119
-
120
-		// Stop processing.
121
-		$this->context->stop();
122
-
123
-		return false;
124
-	}
125
-
126
-	/**
127
-	 * Hook to provide a request to update the status on the server.
128
-	 *
129
-	 * @param array $args
130
-	 *
131
-	 * @return mixed
132
-	 */
133
-	public function api_service__request( $args ) {
134
-
135
-		$state_header_value = str_replace( "\n", '', wp_json_encode( $this->context->get_info() ) );
136
-
137
-		$args['headers']['X-Wordlift-Dataset-Sync-State-V1'] = $state_header_value;
138
-
139
-		return $args;
140
-	}
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
+    function __construct( $context, $sync_service, $sync_object_adapter_factory, $reset = true ) {
44
+        parent::__construct( Sync_Background_Process::STATE_STARTED );
45
+
46
+        $this->context      = $context;
47
+        $this->sync_service = $sync_service;
48
+
49
+        $this->stages = array(
50
+            new Sync_Background_Process_Posts_Stage( $sync_object_adapter_factory ),
51
+            new Sync_Background_Process_Terms_Stage( $sync_object_adapter_factory ),
52
+            new Sync_Background_Process_Users_Stage( $sync_object_adapter_factory ),
53
+        );
54
+    }
55
+
56
+    function enter() {
57
+        // Delete the KG contents.
58
+        $this->sync_service->delete_all();
59
+
60
+        // Clear caches.
61
+        do_action( 'wl_ttl_cache_cleaner__flush' );
62
+
63
+        $counts = array_map( function ( $item ) {
64
+            return $item->count();
65
+        }, $this->stages );
66
+
67
+        update_option( '_wl_sync_background_process_count', $counts, true );
68
+        update_option( '_wl_sync_background_process_stage', 0, true );
69
+        update_option( '_wl_sync_background_process_offset', 0, true );
70
+        update_option( '_wl_sync_background_process_started', time(), true );
71
+        update_option( '_wl_sync_background_process_updated', time(), true );
72
+
73
+        $this->context->set_state( Sync_Background_Process::STATE_STARTED );
74
+
75
+        $this->resume();
76
+    }
77
+
78
+    function resume() {
79
+        $this->context->push_to_queue( true );
80
+        $this->context->save()->dispatch();
81
+    }
82
+
83
+    function leave() {
84
+        $this->context->set_state( null );
85
+    }
86
+
87
+    function task( $args ) {
88
+
89
+        $offset     = get_option( '_wl_sync_background_process_offset' );
90
+        $stage      = get_option( '_wl_sync_background_process_stage' );
91
+        $counts     = get_option( '_wl_sync_background_process_count' );
92
+        $batch_size = min( $counts[ $stage ] - $offset, $this->batch_size );
93
+
94
+        add_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) );
95
+        try {
96
+            $object_adapters = $this->stages[ $stage ]->get_sync_object_adapters( $offset, $batch_size );
97
+            $this->sync_service->sync_many( $object_adapters, true );
98
+        } catch ( \Exception $e ) {
99
+            // ignored.
100
+        }
101
+        remove_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) );
102
+
103
+        update_option( '_wl_sync_background_process_updated', time(), true );
104
+
105
+        // Increase the offset.
106
+        if ( ( $offset + $batch_size ) < $counts[ $stage ] ) {
107
+            update_option( '_wl_sync_background_process_offset', $offset + $batch_size, true );
108
+
109
+            return true;
110
+        }
111
+
112
+        // Increase the stage.
113
+        if ( ( $stage + 1 ) < count( $this->stages ) ) {
114
+            update_option( '_wl_sync_background_process_stage', $stage + 1, true );
115
+            update_option( '_wl_sync_background_process_offset', 0, true );
116
+
117
+            return true;
118
+        }
119
+
120
+        // Stop processing.
121
+        $this->context->stop();
122
+
123
+        return false;
124
+    }
125
+
126
+    /**
127
+     * Hook to provide a request to update the status on the server.
128
+     *
129
+     * @param array $args
130
+     *
131
+     * @return mixed
132
+     */
133
+    public function api_service__request( $args ) {
134
+
135
+        $state_header_value = str_replace( "\n", '', wp_json_encode( $this->context->get_info() ) );
136
+
137
+        $args['headers']['X-Wordlift-Dataset-Sync-State-V1'] = $state_header_value;
138
+
139
+        return $args;
140
+    }
141 141
 
142 142
 }
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -40,16 +40,16 @@  discard block
 block discarded – undo
40 40
 	 * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory
41 41
 	 * @param bool $reset Whether to reset the counters
42 42
 	 */
43
-	function __construct( $context, $sync_service, $sync_object_adapter_factory, $reset = true ) {
44
-		parent::__construct( Sync_Background_Process::STATE_STARTED );
43
+	function __construct($context, $sync_service, $sync_object_adapter_factory, $reset = true) {
44
+		parent::__construct(Sync_Background_Process::STATE_STARTED);
45 45
 
46 46
 		$this->context      = $context;
47 47
 		$this->sync_service = $sync_service;
48 48
 
49 49
 		$this->stages = array(
50
-			new Sync_Background_Process_Posts_Stage( $sync_object_adapter_factory ),
51
-			new Sync_Background_Process_Terms_Stage( $sync_object_adapter_factory ),
52
-			new Sync_Background_Process_Users_Stage( $sync_object_adapter_factory ),
50
+			new Sync_Background_Process_Posts_Stage($sync_object_adapter_factory),
51
+			new Sync_Background_Process_Terms_Stage($sync_object_adapter_factory),
52
+			new Sync_Background_Process_Users_Stage($sync_object_adapter_factory),
53 53
 		);
54 54
 	}
55 55
 
@@ -58,61 +58,61 @@  discard block
 block discarded – undo
58 58
 		$this->sync_service->delete_all();
59 59
 
60 60
 		// Clear caches.
61
-		do_action( 'wl_ttl_cache_cleaner__flush' );
61
+		do_action('wl_ttl_cache_cleaner__flush');
62 62
 
63
-		$counts = array_map( function ( $item ) {
63
+		$counts = array_map(function($item) {
64 64
 			return $item->count();
65
-		}, $this->stages );
65
+		}, $this->stages);
66 66
 
67
-		update_option( '_wl_sync_background_process_count', $counts, true );
68
-		update_option( '_wl_sync_background_process_stage', 0, true );
69
-		update_option( '_wl_sync_background_process_offset', 0, true );
70
-		update_option( '_wl_sync_background_process_started', time(), true );
71
-		update_option( '_wl_sync_background_process_updated', time(), true );
67
+		update_option('_wl_sync_background_process_count', $counts, true);
68
+		update_option('_wl_sync_background_process_stage', 0, true);
69
+		update_option('_wl_sync_background_process_offset', 0, true);
70
+		update_option('_wl_sync_background_process_started', time(), true);
71
+		update_option('_wl_sync_background_process_updated', time(), true);
72 72
 
73
-		$this->context->set_state( Sync_Background_Process::STATE_STARTED );
73
+		$this->context->set_state(Sync_Background_Process::STATE_STARTED);
74 74
 
75 75
 		$this->resume();
76 76
 	}
77 77
 
78 78
 	function resume() {
79
-		$this->context->push_to_queue( true );
79
+		$this->context->push_to_queue(true);
80 80
 		$this->context->save()->dispatch();
81 81
 	}
82 82
 
83 83
 	function leave() {
84
-		$this->context->set_state( null );
84
+		$this->context->set_state(null);
85 85
 	}
86 86
 
87
-	function task( $args ) {
87
+	function task($args) {
88 88
 
89
-		$offset     = get_option( '_wl_sync_background_process_offset' );
90
-		$stage      = get_option( '_wl_sync_background_process_stage' );
91
-		$counts     = get_option( '_wl_sync_background_process_count' );
92
-		$batch_size = min( $counts[ $stage ] - $offset, $this->batch_size );
89
+		$offset     = get_option('_wl_sync_background_process_offset');
90
+		$stage      = get_option('_wl_sync_background_process_stage');
91
+		$counts     = get_option('_wl_sync_background_process_count');
92
+		$batch_size = min($counts[$stage] - $offset, $this->batch_size);
93 93
 
94
-		add_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) );
94
+		add_filter('wl_api_service__request', array($this, 'api_service__request'));
95 95
 		try {
96
-			$object_adapters = $this->stages[ $stage ]->get_sync_object_adapters( $offset, $batch_size );
97
-			$this->sync_service->sync_many( $object_adapters, true );
98
-		} catch ( \Exception $e ) {
96
+			$object_adapters = $this->stages[$stage]->get_sync_object_adapters($offset, $batch_size);
97
+			$this->sync_service->sync_many($object_adapters, true);
98
+		} catch (\Exception $e) {
99 99
 			// ignored.
100 100
 		}
101
-		remove_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) );
101
+		remove_filter('wl_api_service__request', array($this, 'api_service__request'));
102 102
 
103
-		update_option( '_wl_sync_background_process_updated', time(), true );
103
+		update_option('_wl_sync_background_process_updated', time(), true);
104 104
 
105 105
 		// Increase the offset.
106
-		if ( ( $offset + $batch_size ) < $counts[ $stage ] ) {
107
-			update_option( '_wl_sync_background_process_offset', $offset + $batch_size, true );
106
+		if (($offset + $batch_size) < $counts[$stage]) {
107
+			update_option('_wl_sync_background_process_offset', $offset + $batch_size, true);
108 108
 
109 109
 			return true;
110 110
 		}
111 111
 
112 112
 		// Increase the stage.
113
-		if ( ( $stage + 1 ) < count( $this->stages ) ) {
114
-			update_option( '_wl_sync_background_process_stage', $stage + 1, true );
115
-			update_option( '_wl_sync_background_process_offset', 0, true );
113
+		if (($stage + 1) < count($this->stages)) {
114
+			update_option('_wl_sync_background_process_stage', $stage + 1, true);
115
+			update_option('_wl_sync_background_process_offset', 0, true);
116 116
 
117 117
 			return true;
118 118
 		}
@@ -130,9 +130,9 @@  discard block
 block discarded – undo
130 130
 	 *
131 131
 	 * @return mixed
132 132
 	 */
133
-	public function api_service__request( $args ) {
133
+	public function api_service__request($args) {
134 134
 
135
-		$state_header_value = str_replace( "\n", '', wp_json_encode( $this->context->get_info() ) );
135
+		$state_header_value = str_replace("\n", '', wp_json_encode($this->context->get_info()));
136 136
 
137 137
 		$args['headers']['X-Wordlift-Dataset-Sync-State-V1'] = $state_header_value;
138 138
 
Please login to merge, or discard this patch.
src/wordlift/admin/class-admin-user-option.php 2 patches
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -7,45 +7,45 @@
 block discarded – undo
7 7
  */
8 8
 class Admin_User_Option {
9 9
 
10
-	const WORDLIFT_ADMIN = 'wl_is_wordlift_admin';
11
-
12
-	public static function is_wordlift_admin() {
13
-		return intval( get_user_meta( get_current_user_id(), self::WORDLIFT_ADMIN, true ) ) === 1;
14
-	}
15
-
16
-	public function connect_hook() {
17
-		add_action( 'wordlift_user_settings_page', array( $this, 'render_checkbox' ) );
18
-		add_action( 'edit_user_profile_update', array( $this, 'save_checkbox' ) );
19
-		add_action( 'personal_options_update', array( $this, 'save_checkbox' ) );
20
-	}
21
-
22
-	public function save_checkbox() {
23
-
24
-		if ( ! current_user_can( 'manage_options' ) ) {
25
-			return;
26
-		}
27
-
28
-		if ( ! isset( $_POST[ self::WORDLIFT_ADMIN ] ) ) {
29
-			delete_user_meta( get_current_user_id(), self::WORDLIFT_ADMIN );
30
-
31
-			return;
32
-		}
33
-		update_user_meta( get_current_user_id(), self::WORDLIFT_ADMIN, 1 );
34
-	}
35
-
36
-	public function render_checkbox() {
37
-		if ( ! current_user_can( 'manage_options' ) ) {
38
-			return;
39
-		}
40
-		$is_checked = intval( get_user_meta( get_current_user_id(), self::WORDLIFT_ADMIN, true ) ) === 1;
41
-		echo $this->get_checkbox( $is_checked );
42
-	}
43
-
44
-	public static function get_checkbox( $is_checked ) {
45
-		$checked    = $is_checked ? "checked='checked'" : '';
46
-		$admin_text = __( 'Wordlift Admin', 'wordlift' );
47
-
48
-		return "<tr><th>$admin_text</th><td><input type='checkbox' name='wl_is_wordlift_admin' $checked></td></tr>";
49
-	}
10
+    const WORDLIFT_ADMIN = 'wl_is_wordlift_admin';
11
+
12
+    public static function is_wordlift_admin() {
13
+        return intval( get_user_meta( get_current_user_id(), self::WORDLIFT_ADMIN, true ) ) === 1;
14
+    }
15
+
16
+    public function connect_hook() {
17
+        add_action( 'wordlift_user_settings_page', array( $this, 'render_checkbox' ) );
18
+        add_action( 'edit_user_profile_update', array( $this, 'save_checkbox' ) );
19
+        add_action( 'personal_options_update', array( $this, 'save_checkbox' ) );
20
+    }
21
+
22
+    public function save_checkbox() {
23
+
24
+        if ( ! current_user_can( 'manage_options' ) ) {
25
+            return;
26
+        }
27
+
28
+        if ( ! isset( $_POST[ self::WORDLIFT_ADMIN ] ) ) {
29
+            delete_user_meta( get_current_user_id(), self::WORDLIFT_ADMIN );
30
+
31
+            return;
32
+        }
33
+        update_user_meta( get_current_user_id(), self::WORDLIFT_ADMIN, 1 );
34
+    }
35
+
36
+    public function render_checkbox() {
37
+        if ( ! current_user_can( 'manage_options' ) ) {
38
+            return;
39
+        }
40
+        $is_checked = intval( get_user_meta( get_current_user_id(), self::WORDLIFT_ADMIN, true ) ) === 1;
41
+        echo $this->get_checkbox( $is_checked );
42
+    }
43
+
44
+    public static function get_checkbox( $is_checked ) {
45
+        $checked    = $is_checked ? "checked='checked'" : '';
46
+        $admin_text = __( 'Wordlift Admin', 'wordlift' );
47
+
48
+        return "<tr><th>$admin_text</th><td><input type='checkbox' name='wl_is_wordlift_admin' $checked></td></tr>";
49
+    }
50 50
 
51 51
 }
52 52
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -10,40 +10,40 @@
 block discarded – undo
10 10
 	const WORDLIFT_ADMIN = 'wl_is_wordlift_admin';
11 11
 
12 12
 	public static function is_wordlift_admin() {
13
-		return intval( get_user_meta( get_current_user_id(), self::WORDLIFT_ADMIN, true ) ) === 1;
13
+		return intval(get_user_meta(get_current_user_id(), self::WORDLIFT_ADMIN, true)) === 1;
14 14
 	}
15 15
 
16 16
 	public function connect_hook() {
17
-		add_action( 'wordlift_user_settings_page', array( $this, 'render_checkbox' ) );
18
-		add_action( 'edit_user_profile_update', array( $this, 'save_checkbox' ) );
19
-		add_action( 'personal_options_update', array( $this, 'save_checkbox' ) );
17
+		add_action('wordlift_user_settings_page', array($this, 'render_checkbox'));
18
+		add_action('edit_user_profile_update', array($this, 'save_checkbox'));
19
+		add_action('personal_options_update', array($this, 'save_checkbox'));
20 20
 	}
21 21
 
22 22
 	public function save_checkbox() {
23 23
 
24
-		if ( ! current_user_can( 'manage_options' ) ) {
24
+		if ( ! current_user_can('manage_options')) {
25 25
 			return;
26 26
 		}
27 27
 
28
-		if ( ! isset( $_POST[ self::WORDLIFT_ADMIN ] ) ) {
29
-			delete_user_meta( get_current_user_id(), self::WORDLIFT_ADMIN );
28
+		if ( ! isset($_POST[self::WORDLIFT_ADMIN])) {
29
+			delete_user_meta(get_current_user_id(), self::WORDLIFT_ADMIN);
30 30
 
31 31
 			return;
32 32
 		}
33
-		update_user_meta( get_current_user_id(), self::WORDLIFT_ADMIN, 1 );
33
+		update_user_meta(get_current_user_id(), self::WORDLIFT_ADMIN, 1);
34 34
 	}
35 35
 
36 36
 	public function render_checkbox() {
37
-		if ( ! current_user_can( 'manage_options' ) ) {
37
+		if ( ! current_user_can('manage_options')) {
38 38
 			return;
39 39
 		}
40
-		$is_checked = intval( get_user_meta( get_current_user_id(), self::WORDLIFT_ADMIN, true ) ) === 1;
41
-		echo $this->get_checkbox( $is_checked );
40
+		$is_checked = intval(get_user_meta(get_current_user_id(), self::WORDLIFT_ADMIN, true)) === 1;
41
+		echo $this->get_checkbox($is_checked);
42 42
 	}
43 43
 
44
-	public static function get_checkbox( $is_checked ) {
44
+	public static function get_checkbox($is_checked) {
45 45
 		$checked    = $is_checked ? "checked='checked'" : '';
46
-		$admin_text = __( 'Wordlift Admin', 'wordlift' );
46
+		$admin_text = __('Wordlift Admin', 'wordlift');
47 47
 
48 48
 		return "<tr><th>$admin_text</th><td><input type='checkbox' name='wl_is_wordlift_admin' $checked></td></tr>";
49 49
 	}
Please login to merge, or discard this patch.
src/wordlift/features/class-feature.php 2 patches
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -4,32 +4,32 @@
 block discarded – undo
4 4
 
5 5
 class Feature {
6 6
 
7
-	/**
8
-	 * @var string
9
-	 */
10
-	public $feature_slug;
7
+    /**
8
+     * @var string
9
+     */
10
+    public $feature_slug;
11 11
 
12
-	/**
13
-	 * @var bool
14
-	 */
15
-	public $default_value;
12
+    /**
13
+     * @var bool
14
+     */
15
+    public $default_value;
16 16
 
17
-	/**
18
-	 * @var Callable
19
-	 */
20
-	public $callback;
17
+    /**
18
+     * @var Callable
19
+     */
20
+    public $callback;
21 21
 
22
-	/**
23
-	 * Feature constructor.
24
-	 *
25
-	 * @param $feature_slug string Slug for feature without wl__feature__enable
26
-	 * @param $default_value bool Default value for the flag, true or false.
27
-	 * @param $callback Callable Callback for the feature.
28
-	 */
29
-	public function __construct( $feature_slug, $default_value, $callback ) {
30
-		$this->feature_slug  = $feature_slug;
31
-		$this->default_value = $default_value;
32
-		$this->callback      = $callback;
33
-	}
22
+    /**
23
+     * Feature constructor.
24
+     *
25
+     * @param $feature_slug string Slug for feature without wl__feature__enable
26
+     * @param $default_value bool Default value for the flag, true or false.
27
+     * @param $callback Callable Callback for the feature.
28
+     */
29
+    public function __construct( $feature_slug, $default_value, $callback ) {
30
+        $this->feature_slug  = $feature_slug;
31
+        $this->default_value = $default_value;
32
+        $this->callback      = $callback;
33
+    }
34 34
 
35 35
 }
36 36
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@
 block discarded – undo
26 26
 	 * @param $default_value bool Default value for the flag, true or false.
27 27
 	 * @param $callback Callable Callback for the feature.
28 28
 	 */
29
-	public function __construct( $feature_slug, $default_value, $callback ) {
29
+	public function __construct($feature_slug, $default_value, $callback) {
30 30
 		$this->feature_slug  = $feature_slug;
31 31
 		$this->default_value = $default_value;
32 32
 		$this->callback      = $callback;
Please login to merge, or discard this patch.
src/wordlift/vocabulary/dashboard/class-term-matches-widget.php 2 patches
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -10,35 +10,35 @@  discard block
 block discarded – undo
10 10
  * @author Naveen Muthusamy <[email protected]>
11 11
  */
12 12
 class Term_Matches_Widget {
13
-	/**
14
-	 * @var Term_Count
15
-	 */
16
-	private $term_count;
13
+    /**
14
+     * @var Term_Count
15
+     */
16
+    private $term_count;
17 17
 
18
-	/**
19
-	 * Term_Matches_Widget constructor.
20
-	 *
21
-	 * @param $term_count Term_Count
22
-	 */
23
-	public function __construct( $term_count ) {
24
-		$this->term_count = $term_count;
25
-	}
18
+    /**
19
+     * Term_Matches_Widget constructor.
20
+     *
21
+     * @param $term_count Term_Count
22
+     */
23
+    public function __construct( $term_count ) {
24
+        $this->term_count = $term_count;
25
+    }
26 26
 
27
-	public function connect_hook() {
28
-		add_action( 'wl_admin_dashboard_widgets', array( $this, 'render_widget' ) );
29
-	}
27
+    public function connect_hook() {
28
+        add_action( 'wl_admin_dashboard_widgets', array( $this, 'render_widget' ) );
29
+    }
30 30
 
31
-	public function render_widget() {
32
-		$term_count  = $this->term_count->get_term_count();
33
-		if ( $term_count <= 0 ) {
34
-			return;
35
-		}
31
+    public function render_widget() {
32
+        $term_count  = $this->term_count->get_term_count();
33
+        if ( $term_count <= 0 ) {
34
+            return;
35
+        }
36 36
 
37
-		$match_terms_url = menu_page_url('wl-vocabulary-match-terms', false);
38
-		$term_count_link = "<a href='$match_terms_url'>" . Badge_Generator::get_formatted_count_string( $term_count ) . " term(s)</a>";
39
-		$match_terms = __('Match terms', 'wordlift');
40
-		$additional_text = __(' waiting to be matched with entities.', 'wordlift');
41
-		echo <<<EOF
37
+        $match_terms_url = menu_page_url('wl-vocabulary-match-terms', false);
38
+        $term_count_link = "<a href='$match_terms_url'>" . Badge_Generator::get_formatted_count_string( $term_count ) . " term(s)</a>";
39
+        $match_terms = __('Match terms', 'wordlift');
40
+        $additional_text = __(' waiting to be matched with entities.', 'wordlift');
41
+        echo <<<EOF
42 42
         <div id="wl-match-terms" class="wl-dashboard__block wl-dashboard__block--match-terms">
43 43
             <header>
44 44
                 <h3>$match_terms</h3>
@@ -48,6 +48,6 @@  discard block
 block discarded – undo
48 48
                 </p>
49 49
         </div>
50 50
 EOF;
51
-	}
51
+    }
52 52
 
53 53
 }
54 54
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -20,22 +20,22 @@
 block discarded – undo
20 20
 	 *
21 21
 	 * @param $term_count Term_Count
22 22
 	 */
23
-	public function __construct( $term_count ) {
23
+	public function __construct($term_count) {
24 24
 		$this->term_count = $term_count;
25 25
 	}
26 26
 
27 27
 	public function connect_hook() {
28
-		add_action( 'wl_admin_dashboard_widgets', array( $this, 'render_widget' ) );
28
+		add_action('wl_admin_dashboard_widgets', array($this, 'render_widget'));
29 29
 	}
30 30
 
31 31
 	public function render_widget() {
32
-		$term_count  = $this->term_count->get_term_count();
33
-		if ( $term_count <= 0 ) {
32
+		$term_count = $this->term_count->get_term_count();
33
+		if ($term_count <= 0) {
34 34
 			return;
35 35
 		}
36 36
 
37 37
 		$match_terms_url = menu_page_url('wl-vocabulary-match-terms', false);
38
-		$term_count_link = "<a href='$match_terms_url'>" . Badge_Generator::get_formatted_count_string( $term_count ) . " term(s)</a>";
38
+		$term_count_link = "<a href='$match_terms_url'>".Badge_Generator::get_formatted_count_string($term_count)." term(s)</a>";
39 39
 		$match_terms = __('Match terms', 'wordlift');
40 40
 		$additional_text = __(' waiting to be matched with entities.', 'wordlift');
41 41
 		echo <<<EOF
Please login to merge, or discard this patch.
src/wordlift/vocabulary/menu/badge/class-badge-generator.php 2 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -10,38 +10,38 @@
 block discarded – undo
10 10
  */
11 11
 class Badge_Generator {
12 12
 
13
-	/**
14
-	 * Returns the term count which needs to be shown on ui.
15
-	 * @param $number
16
-	 *
17
-	 * @return int
18
-	 */
19
-	public static function get_ui_count( $number ) {
20
-
21
-		$number = (int) $number;
22
-
23
-		if ( $number < 100 ) {
24
-			return $number;
25
-		}
26
-
27
-		return 100;
28
-	}
29
-
30
-	public static function generate_html( $number ) {
31
-		$count_string = self::get_formatted_count_string( $number );
32
-		return "<span class=\"wl-admin-menu-badge\">$count_string</span>";
33
-	}
34
-
35
-	/**
36
-	 * @param $number
37
-	 *
38
-	 * @return string
39
-	 */
40
-	public static function get_formatted_count_string( $number ) {
41
-		$round        = self::get_ui_count( $number );
42
-
43
-		return $round < 100 ? "$round" : "$round+";
44
-	}
13
+    /**
14
+     * Returns the term count which needs to be shown on ui.
15
+     * @param $number
16
+     *
17
+     * @return int
18
+     */
19
+    public static function get_ui_count( $number ) {
20
+
21
+        $number = (int) $number;
22
+
23
+        if ( $number < 100 ) {
24
+            return $number;
25
+        }
26
+
27
+        return 100;
28
+    }
29
+
30
+    public static function generate_html( $number ) {
31
+        $count_string = self::get_formatted_count_string( $number );
32
+        return "<span class=\"wl-admin-menu-badge\">$count_string</span>";
33
+    }
34
+
35
+    /**
36
+     * @param $number
37
+     *
38
+     * @return string
39
+     */
40
+    public static function get_formatted_count_string( $number ) {
41
+        $round        = self::get_ui_count( $number );
42
+
43
+        return $round < 100 ? "$round" : "$round+";
44
+    }
45 45
 
46 46
 
47 47
 }
48 48
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -16,19 +16,19 @@  discard block
 block discarded – undo
16 16
 	 *
17 17
 	 * @return int
18 18
 	 */
19
-	public static function get_ui_count( $number ) {
19
+	public static function get_ui_count($number) {
20 20
 
21 21
 		$number = (int) $number;
22 22
 
23
-		if ( $number < 100 ) {
23
+		if ($number < 100) {
24 24
 			return $number;
25 25
 		}
26 26
 
27 27
 		return 100;
28 28
 	}
29 29
 
30
-	public static function generate_html( $number ) {
31
-		$count_string = self::get_formatted_count_string( $number );
30
+	public static function generate_html($number) {
31
+		$count_string = self::get_formatted_count_string($number);
32 32
 		return "<span class=\"wl-admin-menu-badge\">$count_string</span>";
33 33
 	}
34 34
 
@@ -37,8 +37,8 @@  discard block
 block discarded – undo
37 37
 	 *
38 38
 	 * @return string
39 39
 	 */
40
-	public static function get_formatted_count_string( $number ) {
41
-		$round        = self::get_ui_count( $number );
40
+	public static function get_formatted_count_string($number) {
41
+		$round = self::get_ui_count($number);
42 42
 
43 43
 		return $round < 100 ? "$round" : "$round+";
44 44
 	}
Please login to merge, or discard this patch.
src/wordlift/vocabulary/data/entity-list/class-legacy-entity-list.php 2 patches
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -12,49 +12,49 @@
 block discarded – undo
12 12
  */
13 13
 class Legacy_Entity_List extends Entity_List {
14 14
 
15
-	/**
16
-	 * This function is called when default entity doesnt find any data.
17
-	 * @return array
18
-	 */
19
-	public function get_jsonld_data() {
20
-		$tag  = get_term( $this->term_id );
21
-		$type = get_term_meta( $tag->term_id, Entity_Rest_Endpoint::TYPE_META_KEY, true );
22
-		if ( $type === '' ) {
23
-			return array();
24
-		}
25
-
26
-		return array(
27
-			array(
28
-				'@id'           => get_term_link( $tag->term_id ) . '#id',
29
-				'@type'         => $type,
30
-				'name'          => $tag->name,
31
-				'description'   => ! empty( $tag->description ) ?: get_term_meta( $tag->term_id, Entity_Rest_Endpoint::DESCRIPTION_META_KEY, true ),
32
-				'sameAs'        => get_term_meta( $tag->term_id, Entity_Rest_Endpoint::SAME_AS_META_KEY ),
33
-				'alternateName' => get_term_meta( $tag->term_id, Entity_Rest_Endpoint::ALTERNATIVE_LABEL_META_KEY )
34
-			)
35
-		);
36
-	}
37
-
38
-	/**
39
-	 * This function is never used.
40
-	 *
41
-	 * @param \WP_REST_Request $request
42
-	 *
43
-	 * @return bool
44
-	 */
45
-	public function save_jsonld_data( $request ) {
46
-		return false;
47
-	}
48
-
49
-	public function clear_data() {
50
-		delete_term_meta( $this->term_id, Entity_Rest_Endpoint::SAME_AS_META_KEY );
51
-		delete_term_meta( $this->term_id, Entity_Rest_Endpoint::ALTERNATIVE_LABEL_META_KEY );
52
-		delete_term_meta( $this->term_id, Entity_Rest_Endpoint::DESCRIPTION_META_KEY );
53
-		delete_term_meta( $this->term_id, Entity_Rest_Endpoint::TYPE_META_KEY );
54
-		delete_term_meta( $this->term_id, Entity_Rest_Endpoint::EXTERNAL_ENTITY_META_KEY );
55
-	}
56
-
57
-	public function remove_entity_by_id( $entity_id ) {
58
-		$this->clear_data();
59
-	}
15
+    /**
16
+     * This function is called when default entity doesnt find any data.
17
+     * @return array
18
+     */
19
+    public function get_jsonld_data() {
20
+        $tag  = get_term( $this->term_id );
21
+        $type = get_term_meta( $tag->term_id, Entity_Rest_Endpoint::TYPE_META_KEY, true );
22
+        if ( $type === '' ) {
23
+            return array();
24
+        }
25
+
26
+        return array(
27
+            array(
28
+                '@id'           => get_term_link( $tag->term_id ) . '#id',
29
+                '@type'         => $type,
30
+                'name'          => $tag->name,
31
+                'description'   => ! empty( $tag->description ) ?: get_term_meta( $tag->term_id, Entity_Rest_Endpoint::DESCRIPTION_META_KEY, true ),
32
+                'sameAs'        => get_term_meta( $tag->term_id, Entity_Rest_Endpoint::SAME_AS_META_KEY ),
33
+                'alternateName' => get_term_meta( $tag->term_id, Entity_Rest_Endpoint::ALTERNATIVE_LABEL_META_KEY )
34
+            )
35
+        );
36
+    }
37
+
38
+    /**
39
+     * This function is never used.
40
+     *
41
+     * @param \WP_REST_Request $request
42
+     *
43
+     * @return bool
44
+     */
45
+    public function save_jsonld_data( $request ) {
46
+        return false;
47
+    }
48
+
49
+    public function clear_data() {
50
+        delete_term_meta( $this->term_id, Entity_Rest_Endpoint::SAME_AS_META_KEY );
51
+        delete_term_meta( $this->term_id, Entity_Rest_Endpoint::ALTERNATIVE_LABEL_META_KEY );
52
+        delete_term_meta( $this->term_id, Entity_Rest_Endpoint::DESCRIPTION_META_KEY );
53
+        delete_term_meta( $this->term_id, Entity_Rest_Endpoint::TYPE_META_KEY );
54
+        delete_term_meta( $this->term_id, Entity_Rest_Endpoint::EXTERNAL_ENTITY_META_KEY );
55
+    }
56
+
57
+    public function remove_entity_by_id( $entity_id ) {
58
+        $this->clear_data();
59
+    }
60 60
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -17,20 +17,20 @@  discard block
 block discarded – undo
17 17
 	 * @return array
18 18
 	 */
19 19
 	public function get_jsonld_data() {
20
-		$tag  = get_term( $this->term_id );
21
-		$type = get_term_meta( $tag->term_id, Entity_Rest_Endpoint::TYPE_META_KEY, true );
22
-		if ( $type === '' ) {
20
+		$tag  = get_term($this->term_id);
21
+		$type = get_term_meta($tag->term_id, Entity_Rest_Endpoint::TYPE_META_KEY, true);
22
+		if ($type === '') {
23 23
 			return array();
24 24
 		}
25 25
 
26 26
 		return array(
27 27
 			array(
28
-				'@id'           => get_term_link( $tag->term_id ) . '#id',
28
+				'@id'           => get_term_link($tag->term_id).'#id',
29 29
 				'@type'         => $type,
30 30
 				'name'          => $tag->name,
31
-				'description'   => ! empty( $tag->description ) ?: get_term_meta( $tag->term_id, Entity_Rest_Endpoint::DESCRIPTION_META_KEY, true ),
32
-				'sameAs'        => get_term_meta( $tag->term_id, Entity_Rest_Endpoint::SAME_AS_META_KEY ),
33
-				'alternateName' => get_term_meta( $tag->term_id, Entity_Rest_Endpoint::ALTERNATIVE_LABEL_META_KEY )
31
+				'description'   => ! empty($tag->description) ?: get_term_meta($tag->term_id, Entity_Rest_Endpoint::DESCRIPTION_META_KEY, true),
32
+				'sameAs'        => get_term_meta($tag->term_id, Entity_Rest_Endpoint::SAME_AS_META_KEY),
33
+				'alternateName' => get_term_meta($tag->term_id, Entity_Rest_Endpoint::ALTERNATIVE_LABEL_META_KEY)
34 34
 			)
35 35
 		);
36 36
 	}
@@ -42,19 +42,19 @@  discard block
 block discarded – undo
42 42
 	 *
43 43
 	 * @return bool
44 44
 	 */
45
-	public function save_jsonld_data( $request ) {
45
+	public function save_jsonld_data($request) {
46 46
 		return false;
47 47
 	}
48 48
 
49 49
 	public function clear_data() {
50
-		delete_term_meta( $this->term_id, Entity_Rest_Endpoint::SAME_AS_META_KEY );
51
-		delete_term_meta( $this->term_id, Entity_Rest_Endpoint::ALTERNATIVE_LABEL_META_KEY );
52
-		delete_term_meta( $this->term_id, Entity_Rest_Endpoint::DESCRIPTION_META_KEY );
53
-		delete_term_meta( $this->term_id, Entity_Rest_Endpoint::TYPE_META_KEY );
54
-		delete_term_meta( $this->term_id, Entity_Rest_Endpoint::EXTERNAL_ENTITY_META_KEY );
50
+		delete_term_meta($this->term_id, Entity_Rest_Endpoint::SAME_AS_META_KEY);
51
+		delete_term_meta($this->term_id, Entity_Rest_Endpoint::ALTERNATIVE_LABEL_META_KEY);
52
+		delete_term_meta($this->term_id, Entity_Rest_Endpoint::DESCRIPTION_META_KEY);
53
+		delete_term_meta($this->term_id, Entity_Rest_Endpoint::TYPE_META_KEY);
54
+		delete_term_meta($this->term_id, Entity_Rest_Endpoint::EXTERNAL_ENTITY_META_KEY);
55 55
 	}
56 56
 
57
-	public function remove_entity_by_id( $entity_id ) {
57
+	public function remove_entity_by_id($entity_id) {
58 58
 		$this->clear_data();
59 59
 	}
60 60
 }
Please login to merge, or discard this patch.
src/admin/class-wordlift-admin-page.php 2 patches
Indentation   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -18,138 +18,138 @@
 block discarded – undo
18 18
  */
19 19
 abstract class Wordlift_Admin_Page {
20 20
 
21
-	/**
22
-	 * Define the {@link Wordlift_Admin_Page} constructor.
23
-	 *
24
-	 * @since 3.20.0
25
-	 */
26
-	public function __construct() {
27
-		add_action( 'admin_menu', array( $this, 'admin_menu' ), 10, 0 );
28
-	}
29
-
30
-	/**
31
-	 * Get the parent slug.
32
-	 *
33
-	 * @return string The parent slug (default 'wl_admin_menu').
34
-	 * @since 3.11.0
35
-	 *
36
-	 */
37
-	protected function get_parent_slug() {
38
-
39
-		return 'wl_admin_menu';
40
-	}
41
-
42
-	/**
43
-	 * Get the required capability.
44
-	 *
45
-	 * @return string The capability (default 'manage_options').
46
-	 * @since 3.11.0
47
-	 *
48
-	 */
49
-	protected function get_capability() {
50
-
51
-		return 'manage_options';
52
-	}
53
-
54
-	/**
55
-	 * Get the page title. Will be translated.
56
-	 *
57
-	 * @return string The page title.
58
-	 * @since 3.11.0
59
-	 *
60
-	 */
61
-	abstract function get_page_title();
62
-
63
-	/**
64
-	 * Get the menu title. Will be translated.
65
-	 *
66
-	 * @return string The menu title.
67
-	 * @since 3.11.0
68
-	 *
69
-	 */
70
-	abstract function get_menu_title();
71
-
72
-	/**
73
-	 * Get the menu slug.
74
-	 *
75
-	 * @return string The menu slug.
76
-	 * @since 3.11.0
77
-	 *
78
-	 */
79
-	abstract function get_menu_slug();
80
-
81
-	/**
82
-	 * Get the page url.
83
-	 *
84
-	 * @return string The escaped url of the admin page
85
-	 * @since 3.14.0
86
-	 *
87
-	 */
88
-	function get_url() {
89
-
90
-		// ideally should have used menu_page_url, but it is loaded later than some usages.
91
-		$url = admin_url( 'admin.php?page=' . $this->get_menu_slug() );
92
-
93
-		return esc_url( $url );
94
-	}
95
-
96
-	/**
97
-	 * Get the partial file name, used in the {@link render} function.
98
-	 *
99
-	 * @return string The partial file name.
100
-	 * @since 3.11.0
101
-	 *
102
-	 */
103
-	abstract function get_partial_name();
104
-
105
-	/**
106
-	 * The `admin_menu` callback. Will call {@link add_submenu_page} to add the
107
-	 * page to the admin menu.
108
-	 *
109
-	 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
110
-	 * @since 3.11.0
111
-	 *
112
-	 */
113
-	public function admin_menu() {
114
-		// Add the sub-menu page.
115
-		//
116
-		// See http://codex.wordpress.org/Function_Reference/add_submenu_page
117
-		$page = add_submenu_page(
118
-			$this->get_parent_slug(),
119
-			$this->get_page_title(),
120
-			$this->get_menu_title(),
121
-			$this->get_capability(),                   // The required capability, provided by the calling hook.
122
-			$this->get_menu_slug(),
123
-			array( $this, 'render' )
124
-		);
125
-
126
-		// Set a hook to enqueue scripts only when the settings page is displayed.
127
-		add_action( 'admin_print_scripts-' . $page, array(
128
-			$this,
129
-			'enqueue_scripts',
130
-		) );
131
-
132
-		// Finally return the page hook_suffix.
133
-		return $page;
134
-	}
135
-
136
-	/**
137
-	 * Enqueue scripts for the specific page. Subclasses can override this function
138
-	 * to provide their own styles/scripts.
139
-	 *
140
-	 * @since 3.11.0
141
-	 */
142
-	public function enqueue_scripts() {
143
-	}
144
-
145
-	/**
146
-	 * Render the page.
147
-	 */
148
-	public function render() {
149
-
150
-		// Include the partial.
151
-		include( plugin_dir_path( __FILE__ ) . 'partials/' . $this->get_partial_name() );
152
-
153
-	}
21
+    /**
22
+     * Define the {@link Wordlift_Admin_Page} constructor.
23
+     *
24
+     * @since 3.20.0
25
+     */
26
+    public function __construct() {
27
+        add_action( 'admin_menu', array( $this, 'admin_menu' ), 10, 0 );
28
+    }
29
+
30
+    /**
31
+     * Get the parent slug.
32
+     *
33
+     * @return string The parent slug (default 'wl_admin_menu').
34
+     * @since 3.11.0
35
+     *
36
+     */
37
+    protected function get_parent_slug() {
38
+
39
+        return 'wl_admin_menu';
40
+    }
41
+
42
+    /**
43
+     * Get the required capability.
44
+     *
45
+     * @return string The capability (default 'manage_options').
46
+     * @since 3.11.0
47
+     *
48
+     */
49
+    protected function get_capability() {
50
+
51
+        return 'manage_options';
52
+    }
53
+
54
+    /**
55
+     * Get the page title. Will be translated.
56
+     *
57
+     * @return string The page title.
58
+     * @since 3.11.0
59
+     *
60
+     */
61
+    abstract function get_page_title();
62
+
63
+    /**
64
+     * Get the menu title. Will be translated.
65
+     *
66
+     * @return string The menu title.
67
+     * @since 3.11.0
68
+     *
69
+     */
70
+    abstract function get_menu_title();
71
+
72
+    /**
73
+     * Get the menu slug.
74
+     *
75
+     * @return string The menu slug.
76
+     * @since 3.11.0
77
+     *
78
+     */
79
+    abstract function get_menu_slug();
80
+
81
+    /**
82
+     * Get the page url.
83
+     *
84
+     * @return string The escaped url of the admin page
85
+     * @since 3.14.0
86
+     *
87
+     */
88
+    function get_url() {
89
+
90
+        // ideally should have used menu_page_url, but it is loaded later than some usages.
91
+        $url = admin_url( 'admin.php?page=' . $this->get_menu_slug() );
92
+
93
+        return esc_url( $url );
94
+    }
95
+
96
+    /**
97
+     * Get the partial file name, used in the {@link render} function.
98
+     *
99
+     * @return string The partial file name.
100
+     * @since 3.11.0
101
+     *
102
+     */
103
+    abstract function get_partial_name();
104
+
105
+    /**
106
+     * The `admin_menu` callback. Will call {@link add_submenu_page} to add the
107
+     * page to the admin menu.
108
+     *
109
+     * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
110
+     * @since 3.11.0
111
+     *
112
+     */
113
+    public function admin_menu() {
114
+        // Add the sub-menu page.
115
+        //
116
+        // See http://codex.wordpress.org/Function_Reference/add_submenu_page
117
+        $page = add_submenu_page(
118
+            $this->get_parent_slug(),
119
+            $this->get_page_title(),
120
+            $this->get_menu_title(),
121
+            $this->get_capability(),                   // The required capability, provided by the calling hook.
122
+            $this->get_menu_slug(),
123
+            array( $this, 'render' )
124
+        );
125
+
126
+        // Set a hook to enqueue scripts only when the settings page is displayed.
127
+        add_action( 'admin_print_scripts-' . $page, array(
128
+            $this,
129
+            'enqueue_scripts',
130
+        ) );
131
+
132
+        // Finally return the page hook_suffix.
133
+        return $page;
134
+    }
135
+
136
+    /**
137
+     * Enqueue scripts for the specific page. Subclasses can override this function
138
+     * to provide their own styles/scripts.
139
+     *
140
+     * @since 3.11.0
141
+     */
142
+    public function enqueue_scripts() {
143
+    }
144
+
145
+    /**
146
+     * Render the page.
147
+     */
148
+    public function render() {
149
+
150
+        // Include the partial.
151
+        include( plugin_dir_path( __FILE__ ) . 'partials/' . $this->get_partial_name() );
152
+
153
+    }
154 154
 
155 155
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 * @since 3.20.0
25 25
 	 */
26 26
 	public function __construct() {
27
-		add_action( 'admin_menu', array( $this, 'admin_menu' ), 10, 0 );
27
+		add_action('admin_menu', array($this, 'admin_menu'), 10, 0);
28 28
 	}
29 29
 
30 30
 	/**
@@ -88,9 +88,9 @@  discard block
 block discarded – undo
88 88
 	function get_url() {
89 89
 
90 90
 		// ideally should have used menu_page_url, but it is loaded later than some usages.
91
-		$url = admin_url( 'admin.php?page=' . $this->get_menu_slug() );
91
+		$url = admin_url('admin.php?page='.$this->get_menu_slug());
92 92
 
93
-		return esc_url( $url );
93
+		return esc_url($url);
94 94
 	}
95 95
 
96 96
 	/**
@@ -118,16 +118,16 @@  discard block
 block discarded – undo
118 118
 			$this->get_parent_slug(),
119 119
 			$this->get_page_title(),
120 120
 			$this->get_menu_title(),
121
-			$this->get_capability(),                   // The required capability, provided by the calling hook.
121
+			$this->get_capability(), // The required capability, provided by the calling hook.
122 122
 			$this->get_menu_slug(),
123
-			array( $this, 'render' )
123
+			array($this, 'render')
124 124
 		);
125 125
 
126 126
 		// Set a hook to enqueue scripts only when the settings page is displayed.
127
-		add_action( 'admin_print_scripts-' . $page, array(
127
+		add_action('admin_print_scripts-'.$page, array(
128 128
 			$this,
129 129
 			'enqueue_scripts',
130
-		) );
130
+		));
131 131
 
132 132
 		// Finally return the page hook_suffix.
133 133
 		return $page;
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 	public function render() {
149 149
 
150 150
 		// Include the partial.
151
-		include( plugin_dir_path( __FILE__ ) . 'partials/' . $this->get_partial_name() );
151
+		include(plugin_dir_path(__FILE__).'partials/'.$this->get_partial_name());
152 152
 
153 153
 	}
154 154
 
Please login to merge, or discard this patch.