@@ -18,168 +18,168 @@ |
||
18 | 18 | |
19 | 19 | class Linked_Data_Autocomplete_Service implements Autocomplete_Service { |
20 | 20 | |
21 | - /** |
|
22 | - * A {@link Wordlift_Log_Service} instance. |
|
23 | - * |
|
24 | - * @since 3.15.0 |
|
25 | - * @access private |
|
26 | - * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
27 | - */ |
|
28 | - private $log; |
|
29 | - private $entity_helper; |
|
30 | - private $entity_uri_service; |
|
31 | - /** |
|
32 | - * @var \Wordlift_Entity_Service |
|
33 | - */ |
|
34 | - private $entity_service; |
|
35 | - |
|
36 | - /** |
|
37 | - * The {@link Class_Wordlift_Autocomplete_Service} instance. |
|
38 | - * |
|
39 | - * @param Entity_Helper $entity_helper |
|
40 | - * @param \Wordlift_Entity_Uri_Service $entity_uri_service |
|
41 | - * @param \Wordlift_Entity_Service $entity_service |
|
42 | - * |
|
43 | - * @since 3.15.0 |
|
44 | - */ |
|
45 | - public function __construct( $entity_helper, $entity_uri_service, $entity_service ) { |
|
46 | - |
|
47 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Autocomplete_Service' ); |
|
48 | - |
|
49 | - $this->entity_helper = $entity_helper; |
|
50 | - $this->entity_uri_service = $entity_uri_service; |
|
51 | - $this->entity_service = $entity_service; |
|
52 | - |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * Make request to external API and return the response. |
|
57 | - * |
|
58 | - * @param string $query The search string. |
|
59 | - * @param string $scope The search scope: "local" will search only in the local dataset; "cloud" will search also |
|
60 | - * in Wikipedia. By default is "cloud". |
|
61 | - * @param array|string $excludes The exclude parameter string. |
|
62 | - * |
|
63 | - * @return array $response The API response. |
|
64 | - * @since 3.15.0 |
|
65 | - */ |
|
66 | - public function query( $query, $scope = 'cloud', $excludes = array() ) { |
|
67 | - |
|
68 | - $results = $this->do_query( $query, $scope, $excludes ); |
|
69 | - |
|
70 | - $uris = array_reduce( |
|
71 | - $results, |
|
72 | - function ( $carry, $result ) { |
|
73 | - |
|
74 | - $carry[] = $result['id']; |
|
75 | - |
|
76 | - return array_merge( $carry, $result['sameAss'] ); |
|
77 | - }, |
|
78 | - array() |
|
79 | - ); |
|
80 | - |
|
81 | - $mappings = $this->entity_helper->map_many_to_local( $uris ); |
|
82 | - |
|
83 | - $that = $this; |
|
84 | - $mapped_results = array_map( |
|
85 | - function ( $result ) use ( $that, $mappings ) { |
|
86 | - |
|
87 | - if ( $that->entity_uri_service->is_internal( $result['id'] ) ) { |
|
88 | - return $result; |
|
89 | - } |
|
90 | - |
|
91 | - $uris = array_merge( (array) $result['id'], $result['sameAss'] ); |
|
92 | - |
|
93 | - foreach ( $uris as $uri ) { |
|
94 | - if ( isset( $mappings[ $uri ] ) ) { |
|
95 | - $local_entity = $that->entity_uri_service->get_entity( $mappings[ $uri ] ); |
|
96 | - |
|
97 | - return $that->post_to_autocomplete_result( $mappings[ $uri ], $local_entity ); |
|
98 | - } |
|
99 | - } |
|
100 | - |
|
101 | - return $result; |
|
102 | - }, |
|
103 | - $results |
|
104 | - ); |
|
105 | - |
|
106 | - return $mapped_results; |
|
107 | - } |
|
108 | - |
|
109 | - private function do_query( $query, $scope = 'cloud', $exclude = '' ) { |
|
110 | - $url = $this->build_request_url( $query, $exclude, $scope ); |
|
111 | - |
|
112 | - // Return the response. |
|
113 | - $response = Default_Api_Service::get_instance()->get( $url )->get_response(); |
|
114 | - |
|
115 | - // If the response is valid, then send the suggestions. |
|
116 | - if ( ! is_wp_error( $response ) && 200 === (int) $response['response']['code'] ) { |
|
117 | - // Echo the response. |
|
118 | - return json_decode( wp_remote_retrieve_body( $response ), true ); |
|
119 | - } else { |
|
120 | - // Default error message. |
|
121 | - $error_message = 'Something went wrong.'; |
|
122 | - |
|
123 | - // Get the real error message if there is WP_Error. |
|
124 | - if ( is_wp_error( $response ) ) { |
|
125 | - $error_message = $response->get_error_message(); |
|
126 | - } |
|
127 | - |
|
128 | - $this->log->error( $error_message ); |
|
129 | - |
|
130 | - return array(); |
|
131 | - } |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Build the autocomplete url. |
|
136 | - * |
|
137 | - * @param string $query The search string. |
|
138 | - * @param array|string $exclude The exclude parameter. |
|
139 | - * @param string $scope The search scope: "local" will search only in the local dataset; "cloud" will search also |
|
140 | - * in Wikipedia. By default is "cloud". |
|
141 | - * |
|
142 | - * @return string Built url. |
|
143 | - * @since 3.15.0 |
|
144 | - */ |
|
145 | - private function build_request_url( $query, $exclude, $scope ) { |
|
146 | - $configuration_service = Wordlift_Configuration_Service::get_instance(); |
|
147 | - |
|
148 | - $args = array( |
|
149 | - 'key' => $configuration_service->get_key(), |
|
150 | - 'language' => $configuration_service->get_language_code(), |
|
151 | - 'query' => $query, |
|
152 | - 'scope' => $scope, |
|
153 | - 'limit' => 10, |
|
154 | - ); |
|
155 | - |
|
156 | - // Add args to URL. |
|
157 | - $request_url = add_query_arg( urlencode_deep( $args ), '/autocomplete' ); |
|
158 | - |
|
159 | - // Add the exclude parameter. |
|
160 | - if ( ! empty( $exclude ) ) { |
|
161 | - $request_url .= '&exclude=' . implode( '&exclude=', array_map( 'urlencode', (array) $exclude ) ); |
|
162 | - } |
|
163 | - |
|
164 | - // return the built url. |
|
165 | - return $request_url; |
|
166 | - } |
|
167 | - |
|
168 | - private function post_to_autocomplete_result( $uri, $post ) { |
|
169 | - |
|
170 | - return array( |
|
171 | - 'id' => $uri, |
|
172 | - 'label' => array( $post->post_title ), |
|
173 | - 'labels' => $this->entity_service->get_alternative_labels( $post->ID ), |
|
174 | - 'descriptions' => array( Wordlift_Post_Excerpt_Helper::get_text_excerpt( $post ) ), |
|
175 | - 'scope' => 'local', |
|
176 | - 'sameAss' => get_post_meta( $post->ID, Wordlift_Schema_Service::FIELD_SAME_AS ), |
|
177 | - // The following properties are less relevant because we're linking entities that exist already in the |
|
178 | - // vocabulary. That's why we don't make an effort to load the real data. |
|
179 | - 'types' => array( 'http://schema.org/Thing' ), |
|
180 | - 'urls' => array(), |
|
181 | - 'images' => array(), |
|
182 | - ); |
|
183 | - } |
|
21 | + /** |
|
22 | + * A {@link Wordlift_Log_Service} instance. |
|
23 | + * |
|
24 | + * @since 3.15.0 |
|
25 | + * @access private |
|
26 | + * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
27 | + */ |
|
28 | + private $log; |
|
29 | + private $entity_helper; |
|
30 | + private $entity_uri_service; |
|
31 | + /** |
|
32 | + * @var \Wordlift_Entity_Service |
|
33 | + */ |
|
34 | + private $entity_service; |
|
35 | + |
|
36 | + /** |
|
37 | + * The {@link Class_Wordlift_Autocomplete_Service} instance. |
|
38 | + * |
|
39 | + * @param Entity_Helper $entity_helper |
|
40 | + * @param \Wordlift_Entity_Uri_Service $entity_uri_service |
|
41 | + * @param \Wordlift_Entity_Service $entity_service |
|
42 | + * |
|
43 | + * @since 3.15.0 |
|
44 | + */ |
|
45 | + public function __construct( $entity_helper, $entity_uri_service, $entity_service ) { |
|
46 | + |
|
47 | + $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Autocomplete_Service' ); |
|
48 | + |
|
49 | + $this->entity_helper = $entity_helper; |
|
50 | + $this->entity_uri_service = $entity_uri_service; |
|
51 | + $this->entity_service = $entity_service; |
|
52 | + |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * Make request to external API and return the response. |
|
57 | + * |
|
58 | + * @param string $query The search string. |
|
59 | + * @param string $scope The search scope: "local" will search only in the local dataset; "cloud" will search also |
|
60 | + * in Wikipedia. By default is "cloud". |
|
61 | + * @param array|string $excludes The exclude parameter string. |
|
62 | + * |
|
63 | + * @return array $response The API response. |
|
64 | + * @since 3.15.0 |
|
65 | + */ |
|
66 | + public function query( $query, $scope = 'cloud', $excludes = array() ) { |
|
67 | + |
|
68 | + $results = $this->do_query( $query, $scope, $excludes ); |
|
69 | + |
|
70 | + $uris = array_reduce( |
|
71 | + $results, |
|
72 | + function ( $carry, $result ) { |
|
73 | + |
|
74 | + $carry[] = $result['id']; |
|
75 | + |
|
76 | + return array_merge( $carry, $result['sameAss'] ); |
|
77 | + }, |
|
78 | + array() |
|
79 | + ); |
|
80 | + |
|
81 | + $mappings = $this->entity_helper->map_many_to_local( $uris ); |
|
82 | + |
|
83 | + $that = $this; |
|
84 | + $mapped_results = array_map( |
|
85 | + function ( $result ) use ( $that, $mappings ) { |
|
86 | + |
|
87 | + if ( $that->entity_uri_service->is_internal( $result['id'] ) ) { |
|
88 | + return $result; |
|
89 | + } |
|
90 | + |
|
91 | + $uris = array_merge( (array) $result['id'], $result['sameAss'] ); |
|
92 | + |
|
93 | + foreach ( $uris as $uri ) { |
|
94 | + if ( isset( $mappings[ $uri ] ) ) { |
|
95 | + $local_entity = $that->entity_uri_service->get_entity( $mappings[ $uri ] ); |
|
96 | + |
|
97 | + return $that->post_to_autocomplete_result( $mappings[ $uri ], $local_entity ); |
|
98 | + } |
|
99 | + } |
|
100 | + |
|
101 | + return $result; |
|
102 | + }, |
|
103 | + $results |
|
104 | + ); |
|
105 | + |
|
106 | + return $mapped_results; |
|
107 | + } |
|
108 | + |
|
109 | + private function do_query( $query, $scope = 'cloud', $exclude = '' ) { |
|
110 | + $url = $this->build_request_url( $query, $exclude, $scope ); |
|
111 | + |
|
112 | + // Return the response. |
|
113 | + $response = Default_Api_Service::get_instance()->get( $url )->get_response(); |
|
114 | + |
|
115 | + // If the response is valid, then send the suggestions. |
|
116 | + if ( ! is_wp_error( $response ) && 200 === (int) $response['response']['code'] ) { |
|
117 | + // Echo the response. |
|
118 | + return json_decode( wp_remote_retrieve_body( $response ), true ); |
|
119 | + } else { |
|
120 | + // Default error message. |
|
121 | + $error_message = 'Something went wrong.'; |
|
122 | + |
|
123 | + // Get the real error message if there is WP_Error. |
|
124 | + if ( is_wp_error( $response ) ) { |
|
125 | + $error_message = $response->get_error_message(); |
|
126 | + } |
|
127 | + |
|
128 | + $this->log->error( $error_message ); |
|
129 | + |
|
130 | + return array(); |
|
131 | + } |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Build the autocomplete url. |
|
136 | + * |
|
137 | + * @param string $query The search string. |
|
138 | + * @param array|string $exclude The exclude parameter. |
|
139 | + * @param string $scope The search scope: "local" will search only in the local dataset; "cloud" will search also |
|
140 | + * in Wikipedia. By default is "cloud". |
|
141 | + * |
|
142 | + * @return string Built url. |
|
143 | + * @since 3.15.0 |
|
144 | + */ |
|
145 | + private function build_request_url( $query, $exclude, $scope ) { |
|
146 | + $configuration_service = Wordlift_Configuration_Service::get_instance(); |
|
147 | + |
|
148 | + $args = array( |
|
149 | + 'key' => $configuration_service->get_key(), |
|
150 | + 'language' => $configuration_service->get_language_code(), |
|
151 | + 'query' => $query, |
|
152 | + 'scope' => $scope, |
|
153 | + 'limit' => 10, |
|
154 | + ); |
|
155 | + |
|
156 | + // Add args to URL. |
|
157 | + $request_url = add_query_arg( urlencode_deep( $args ), '/autocomplete' ); |
|
158 | + |
|
159 | + // Add the exclude parameter. |
|
160 | + if ( ! empty( $exclude ) ) { |
|
161 | + $request_url .= '&exclude=' . implode( '&exclude=', array_map( 'urlencode', (array) $exclude ) ); |
|
162 | + } |
|
163 | + |
|
164 | + // return the built url. |
|
165 | + return $request_url; |
|
166 | + } |
|
167 | + |
|
168 | + private function post_to_autocomplete_result( $uri, $post ) { |
|
169 | + |
|
170 | + return array( |
|
171 | + 'id' => $uri, |
|
172 | + 'label' => array( $post->post_title ), |
|
173 | + 'labels' => $this->entity_service->get_alternative_labels( $post->ID ), |
|
174 | + 'descriptions' => array( Wordlift_Post_Excerpt_Helper::get_text_excerpt( $post ) ), |
|
175 | + 'scope' => 'local', |
|
176 | + 'sameAss' => get_post_meta( $post->ID, Wordlift_Schema_Service::FIELD_SAME_AS ), |
|
177 | + // The following properties are less relevant because we're linking entities that exist already in the |
|
178 | + // vocabulary. That's why we don't make an effort to load the real data. |
|
179 | + 'types' => array( 'http://schema.org/Thing' ), |
|
180 | + 'urls' => array(), |
|
181 | + 'images' => array(), |
|
182 | + ); |
|
183 | + } |
|
184 | 184 | |
185 | 185 | } |
@@ -42,9 +42,9 @@ discard block |
||
42 | 42 | * |
43 | 43 | * @since 3.15.0 |
44 | 44 | */ |
45 | - public function __construct( $entity_helper, $entity_uri_service, $entity_service ) { |
|
45 | + public function __construct($entity_helper, $entity_uri_service, $entity_service) { |
|
46 | 46 | |
47 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Autocomplete_Service' ); |
|
47 | + $this->log = Wordlift_Log_Service::get_logger('Wordlift_Autocomplete_Service'); |
|
48 | 48 | |
49 | 49 | $this->entity_helper = $entity_helper; |
50 | 50 | $this->entity_uri_service = $entity_uri_service; |
@@ -63,38 +63,38 @@ discard block |
||
63 | 63 | * @return array $response The API response. |
64 | 64 | * @since 3.15.0 |
65 | 65 | */ |
66 | - public function query( $query, $scope = 'cloud', $excludes = array() ) { |
|
66 | + public function query($query, $scope = 'cloud', $excludes = array()) { |
|
67 | 67 | |
68 | - $results = $this->do_query( $query, $scope, $excludes ); |
|
68 | + $results = $this->do_query($query, $scope, $excludes); |
|
69 | 69 | |
70 | 70 | $uris = array_reduce( |
71 | 71 | $results, |
72 | - function ( $carry, $result ) { |
|
72 | + function($carry, $result) { |
|
73 | 73 | |
74 | 74 | $carry[] = $result['id']; |
75 | 75 | |
76 | - return array_merge( $carry, $result['sameAss'] ); |
|
76 | + return array_merge($carry, $result['sameAss']); |
|
77 | 77 | }, |
78 | 78 | array() |
79 | 79 | ); |
80 | 80 | |
81 | - $mappings = $this->entity_helper->map_many_to_local( $uris ); |
|
81 | + $mappings = $this->entity_helper->map_many_to_local($uris); |
|
82 | 82 | |
83 | 83 | $that = $this; |
84 | 84 | $mapped_results = array_map( |
85 | - function ( $result ) use ( $that, $mappings ) { |
|
85 | + function($result) use ($that, $mappings) { |
|
86 | 86 | |
87 | - if ( $that->entity_uri_service->is_internal( $result['id'] ) ) { |
|
87 | + if ($that->entity_uri_service->is_internal($result['id'])) { |
|
88 | 88 | return $result; |
89 | 89 | } |
90 | 90 | |
91 | - $uris = array_merge( (array) $result['id'], $result['sameAss'] ); |
|
91 | + $uris = array_merge((array) $result['id'], $result['sameAss']); |
|
92 | 92 | |
93 | - foreach ( $uris as $uri ) { |
|
94 | - if ( isset( $mappings[ $uri ] ) ) { |
|
95 | - $local_entity = $that->entity_uri_service->get_entity( $mappings[ $uri ] ); |
|
93 | + foreach ($uris as $uri) { |
|
94 | + if (isset($mappings[$uri])) { |
|
95 | + $local_entity = $that->entity_uri_service->get_entity($mappings[$uri]); |
|
96 | 96 | |
97 | - return $that->post_to_autocomplete_result( $mappings[ $uri ], $local_entity ); |
|
97 | + return $that->post_to_autocomplete_result($mappings[$uri], $local_entity); |
|
98 | 98 | } |
99 | 99 | } |
100 | 100 | |
@@ -106,26 +106,26 @@ discard block |
||
106 | 106 | return $mapped_results; |
107 | 107 | } |
108 | 108 | |
109 | - private function do_query( $query, $scope = 'cloud', $exclude = '' ) { |
|
110 | - $url = $this->build_request_url( $query, $exclude, $scope ); |
|
109 | + private function do_query($query, $scope = 'cloud', $exclude = '') { |
|
110 | + $url = $this->build_request_url($query, $exclude, $scope); |
|
111 | 111 | |
112 | 112 | // Return the response. |
113 | - $response = Default_Api_Service::get_instance()->get( $url )->get_response(); |
|
113 | + $response = Default_Api_Service::get_instance()->get($url)->get_response(); |
|
114 | 114 | |
115 | 115 | // If the response is valid, then send the suggestions. |
116 | - if ( ! is_wp_error( $response ) && 200 === (int) $response['response']['code'] ) { |
|
116 | + if ( ! is_wp_error($response) && 200 === (int) $response['response']['code']) { |
|
117 | 117 | // Echo the response. |
118 | - return json_decode( wp_remote_retrieve_body( $response ), true ); |
|
118 | + return json_decode(wp_remote_retrieve_body($response), true); |
|
119 | 119 | } else { |
120 | 120 | // Default error message. |
121 | 121 | $error_message = 'Something went wrong.'; |
122 | 122 | |
123 | 123 | // Get the real error message if there is WP_Error. |
124 | - if ( is_wp_error( $response ) ) { |
|
124 | + if (is_wp_error($response)) { |
|
125 | 125 | $error_message = $response->get_error_message(); |
126 | 126 | } |
127 | 127 | |
128 | - $this->log->error( $error_message ); |
|
128 | + $this->log->error($error_message); |
|
129 | 129 | |
130 | 130 | return array(); |
131 | 131 | } |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | * @return string Built url. |
143 | 143 | * @since 3.15.0 |
144 | 144 | */ |
145 | - private function build_request_url( $query, $exclude, $scope ) { |
|
145 | + private function build_request_url($query, $exclude, $scope) { |
|
146 | 146 | $configuration_service = Wordlift_Configuration_Service::get_instance(); |
147 | 147 | |
148 | 148 | $args = array( |
@@ -154,29 +154,29 @@ discard block |
||
154 | 154 | ); |
155 | 155 | |
156 | 156 | // Add args to URL. |
157 | - $request_url = add_query_arg( urlencode_deep( $args ), '/autocomplete' ); |
|
157 | + $request_url = add_query_arg(urlencode_deep($args), '/autocomplete'); |
|
158 | 158 | |
159 | 159 | // Add the exclude parameter. |
160 | - if ( ! empty( $exclude ) ) { |
|
161 | - $request_url .= '&exclude=' . implode( '&exclude=', array_map( 'urlencode', (array) $exclude ) ); |
|
160 | + if ( ! empty($exclude)) { |
|
161 | + $request_url .= '&exclude='.implode('&exclude=', array_map('urlencode', (array) $exclude)); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | // return the built url. |
165 | 165 | return $request_url; |
166 | 166 | } |
167 | 167 | |
168 | - private function post_to_autocomplete_result( $uri, $post ) { |
|
168 | + private function post_to_autocomplete_result($uri, $post) { |
|
169 | 169 | |
170 | 170 | return array( |
171 | 171 | 'id' => $uri, |
172 | - 'label' => array( $post->post_title ), |
|
173 | - 'labels' => $this->entity_service->get_alternative_labels( $post->ID ), |
|
174 | - 'descriptions' => array( Wordlift_Post_Excerpt_Helper::get_text_excerpt( $post ) ), |
|
172 | + 'label' => array($post->post_title), |
|
173 | + 'labels' => $this->entity_service->get_alternative_labels($post->ID), |
|
174 | + 'descriptions' => array(Wordlift_Post_Excerpt_Helper::get_text_excerpt($post)), |
|
175 | 175 | 'scope' => 'local', |
176 | - 'sameAss' => get_post_meta( $post->ID, Wordlift_Schema_Service::FIELD_SAME_AS ), |
|
176 | + 'sameAss' => get_post_meta($post->ID, Wordlift_Schema_Service::FIELD_SAME_AS), |
|
177 | 177 | // The following properties are less relevant because we're linking entities that exist already in the |
178 | 178 | // vocabulary. That's why we don't make an effort to load the real data. |
179 | - 'types' => array( 'http://schema.org/Thing' ), |
|
179 | + 'types' => array('http://schema.org/Thing'), |
|
180 | 180 | 'urls' => array(), |
181 | 181 | 'images' => array(), |
182 | 182 | ); |
@@ -12,62 +12,62 @@ |
||
12 | 12 | |
13 | 13 | class All_Autocomplete_Service implements Autocomplete_Service { |
14 | 14 | |
15 | - /** |
|
16 | - * One ore more {@link Autocomplete_Service} instances. |
|
17 | - * |
|
18 | - * @var Autocomplete_Service|Autocomplete_Service[] $autocomplete_services |
|
19 | - */ |
|
20 | - private $autocomplete_services; |
|
15 | + /** |
|
16 | + * One ore more {@link Autocomplete_Service} instances. |
|
17 | + * |
|
18 | + * @var Autocomplete_Service|Autocomplete_Service[] $autocomplete_services |
|
19 | + */ |
|
20 | + private $autocomplete_services; |
|
21 | 21 | |
22 | - /** |
|
23 | - * All_Autocomplete_Service constructor. |
|
24 | - * |
|
25 | - * @param Autocomplete_Service|Autocomplete_Service[] $autocomplete_services |
|
26 | - */ |
|
27 | - public function __construct( $autocomplete_services ) { |
|
22 | + /** |
|
23 | + * All_Autocomplete_Service constructor. |
|
24 | + * |
|
25 | + * @param Autocomplete_Service|Autocomplete_Service[] $autocomplete_services |
|
26 | + */ |
|
27 | + public function __construct( $autocomplete_services ) { |
|
28 | 28 | |
29 | - $this->autocomplete_services = (array) $autocomplete_services; |
|
30 | - } |
|
29 | + $this->autocomplete_services = (array) $autocomplete_services; |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * {@inheritDoc} |
|
34 | - */ |
|
35 | - public function query( $query, $scope, $excludes ) { |
|
32 | + /** |
|
33 | + * {@inheritDoc} |
|
34 | + */ |
|
35 | + public function query( $query, $scope, $excludes ) { |
|
36 | 36 | |
37 | - /** |
|
38 | - * Filter to show local entities on the entity autocompletion field. |
|
39 | - * |
|
40 | - * @param $state bool |
|
41 | - * |
|
42 | - * @return bool Whether to show local entities in the page or not. |
|
43 | - * @since 3.26.1 |
|
44 | - */ |
|
45 | - $show_local_entities = apply_filters( 'wl_show_local_entities', false ); |
|
37 | + /** |
|
38 | + * Filter to show local entities on the entity autocompletion field. |
|
39 | + * |
|
40 | + * @param $state bool |
|
41 | + * |
|
42 | + * @return bool Whether to show local entities in the page or not. |
|
43 | + * @since 3.26.1 |
|
44 | + */ |
|
45 | + $show_local_entities = apply_filters( 'wl_show_local_entities', false ); |
|
46 | 46 | |
47 | - $autocomplete_services = $this->autocomplete_services; |
|
47 | + $autocomplete_services = $this->autocomplete_services; |
|
48 | 48 | |
49 | - // Remove the local autocomplete services. |
|
50 | - if ( ! $show_local_entities ) { |
|
51 | - $autocomplete_services = array_filter( |
|
52 | - $autocomplete_services, |
|
53 | - function ( $service ) { |
|
54 | - return ! $service instanceof Local_Autocomplete_Service; |
|
55 | - } |
|
56 | - ); |
|
57 | - } |
|
49 | + // Remove the local autocomplete services. |
|
50 | + if ( ! $show_local_entities ) { |
|
51 | + $autocomplete_services = array_filter( |
|
52 | + $autocomplete_services, |
|
53 | + function ( $service ) { |
|
54 | + return ! $service instanceof Local_Autocomplete_Service; |
|
55 | + } |
|
56 | + ); |
|
57 | + } |
|
58 | 58 | |
59 | - // Query each Autocomplete service and merge the results. |
|
60 | - return array_reduce( |
|
61 | - $autocomplete_services, |
|
62 | - function ( $carry, $item ) use ( $query, $scope, $excludes ) { |
|
59 | + // Query each Autocomplete service and merge the results. |
|
60 | + return array_reduce( |
|
61 | + $autocomplete_services, |
|
62 | + function ( $carry, $item ) use ( $query, $scope, $excludes ) { |
|
63 | 63 | |
64 | - $results = $item->query( $query, $scope, $excludes ); |
|
64 | + $results = $item->query( $query, $scope, $excludes ); |
|
65 | 65 | |
66 | - return array_merge( $carry, $results ); |
|
67 | - }, |
|
68 | - array() |
|
69 | - ); |
|
66 | + return array_merge( $carry, $results ); |
|
67 | + }, |
|
68 | + array() |
|
69 | + ); |
|
70 | 70 | |
71 | - } |
|
71 | + } |
|
72 | 72 | |
73 | 73 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @param Autocomplete_Service|Autocomplete_Service[] $autocomplete_services |
26 | 26 | */ |
27 | - public function __construct( $autocomplete_services ) { |
|
27 | + public function __construct($autocomplete_services) { |
|
28 | 28 | |
29 | 29 | $this->autocomplete_services = (array) $autocomplete_services; |
30 | 30 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | /** |
33 | 33 | * {@inheritDoc} |
34 | 34 | */ |
35 | - public function query( $query, $scope, $excludes ) { |
|
35 | + public function query($query, $scope, $excludes) { |
|
36 | 36 | |
37 | 37 | /** |
38 | 38 | * Filter to show local entities on the entity autocompletion field. |
@@ -42,15 +42,15 @@ discard block |
||
42 | 42 | * @return bool Whether to show local entities in the page or not. |
43 | 43 | * @since 3.26.1 |
44 | 44 | */ |
45 | - $show_local_entities = apply_filters( 'wl_show_local_entities', false ); |
|
45 | + $show_local_entities = apply_filters('wl_show_local_entities', false); |
|
46 | 46 | |
47 | 47 | $autocomplete_services = $this->autocomplete_services; |
48 | 48 | |
49 | 49 | // Remove the local autocomplete services. |
50 | - if ( ! $show_local_entities ) { |
|
50 | + if ( ! $show_local_entities) { |
|
51 | 51 | $autocomplete_services = array_filter( |
52 | 52 | $autocomplete_services, |
53 | - function ( $service ) { |
|
53 | + function($service) { |
|
54 | 54 | return ! $service instanceof Local_Autocomplete_Service; |
55 | 55 | } |
56 | 56 | ); |
@@ -59,11 +59,11 @@ discard block |
||
59 | 59 | // Query each Autocomplete service and merge the results. |
60 | 60 | return array_reduce( |
61 | 61 | $autocomplete_services, |
62 | - function ( $carry, $item ) use ( $query, $scope, $excludes ) { |
|
62 | + function($carry, $item) use ($query, $scope, $excludes) { |
|
63 | 63 | |
64 | - $results = $item->query( $query, $scope, $excludes ); |
|
64 | + $results = $item->query($query, $scope, $excludes); |
|
65 | 65 | |
66 | - return array_merge( $carry, $results ); |
|
66 | + return array_merge($carry, $results); |
|
67 | 67 | }, |
68 | 68 | array() |
69 | 69 | ); |
@@ -11,35 +11,35 @@ |
||
11 | 11 | |
12 | 12 | abstract class Abstract_Autocomplete_Service implements Autocomplete_Service { |
13 | 13 | |
14 | - /** |
|
15 | - * Filter out results that are in the excludes list. |
|
16 | - * |
|
17 | - * @param array $results { |
|
18 | - * An array of results. |
|
19 | - * |
|
20 | - * @type array The result's data. |
|
21 | - * } |
|
22 | - * |
|
23 | - * @param array $excludes An array of URLs. |
|
24 | - * |
|
25 | - * @return array The filtered array of results. |
|
26 | - */ |
|
27 | - protected function filter( $results, $excludes ) { |
|
14 | + /** |
|
15 | + * Filter out results that are in the excludes list. |
|
16 | + * |
|
17 | + * @param array $results { |
|
18 | + * An array of results. |
|
19 | + * |
|
20 | + * @type array The result's data. |
|
21 | + * } |
|
22 | + * |
|
23 | + * @param array $excludes An array of URLs. |
|
24 | + * |
|
25 | + * @return array The filtered array of results. |
|
26 | + */ |
|
27 | + protected function filter( $results, $excludes ) { |
|
28 | 28 | |
29 | - $excludes_array = (array) $excludes; |
|
29 | + $excludes_array = (array) $excludes; |
|
30 | 30 | |
31 | - return array_filter( |
|
32 | - $results, |
|
33 | - function ( $item ) use ( $excludes_array ) { |
|
31 | + return array_filter( |
|
32 | + $results, |
|
33 | + function ( $item ) use ( $excludes_array ) { |
|
34 | 34 | |
35 | - return 0 === count( |
|
36 | - array_intersect( |
|
37 | - array_merge( (array) $item['id'], $item['sameAss'] ), |
|
38 | - $excludes_array |
|
39 | - ) |
|
40 | - ); |
|
41 | - } |
|
42 | - ); |
|
43 | - } |
|
35 | + return 0 === count( |
|
36 | + array_intersect( |
|
37 | + array_merge( (array) $item['id'], $item['sameAss'] ), |
|
38 | + $excludes_array |
|
39 | + ) |
|
40 | + ); |
|
41 | + } |
|
42 | + ); |
|
43 | + } |
|
44 | 44 | |
45 | 45 | } |
@@ -24,17 +24,17 @@ |
||
24 | 24 | * |
25 | 25 | * @return array The filtered array of results. |
26 | 26 | */ |
27 | - protected function filter( $results, $excludes ) { |
|
27 | + protected function filter($results, $excludes) { |
|
28 | 28 | |
29 | 29 | $excludes_array = (array) $excludes; |
30 | 30 | |
31 | 31 | return array_filter( |
32 | 32 | $results, |
33 | - function ( $item ) use ( $excludes_array ) { |
|
33 | + function($item) use ($excludes_array) { |
|
34 | 34 | |
35 | 35 | return 0 === count( |
36 | 36 | array_intersect( |
37 | - array_merge( (array) $item['id'], $item['sameAss'] ), |
|
37 | + array_merge((array) $item['id'], $item['sameAss']), |
|
38 | 38 | $excludes_array |
39 | 39 | ) |
40 | 40 | ); |
@@ -15,67 +15,67 @@ |
||
15 | 15 | |
16 | 16 | class Local_Autocomplete_Service extends Abstract_Autocomplete_Service { |
17 | 17 | |
18 | - /** |
|
19 | - * @inheritDoc |
|
20 | - */ |
|
21 | - public function query( $query, $scope, $excludes ) { |
|
22 | - global $wpdb; |
|
18 | + /** |
|
19 | + * @inheritDoc |
|
20 | + */ |
|
21 | + public function query( $query, $scope, $excludes ) { |
|
22 | + global $wpdb; |
|
23 | 23 | |
24 | - $posts = $wpdb->get_results( |
|
25 | - $wpdb->prepare( |
|
26 | - "SELECT * FROM {$wpdb->posts} p" |
|
27 | - . " INNER JOIN {$wpdb->term_relationships} tr" |
|
28 | - . ' ON tr.object_id = p.ID' |
|
29 | - . " INNER JOIN {$wpdb->term_taxonomy} tt" |
|
30 | - . ' ON tt.taxonomy = %s AND tt.term_taxonomy_id = tr.term_taxonomy_id' |
|
31 | - . " INNER JOIN {$wpdb->terms} t" |
|
32 | - . ' ON t.term_id = tt.term_id AND t.name != %s' |
|
33 | - . " LEFT OUTER JOIN {$wpdb->postmeta} pm" |
|
34 | - . ' ON pm.meta_key = %s AND pm.post_id = p.ID' |
|
35 | - . " WHERE p.post_type IN ( '" . implode( "', '", array_map( 'esc_sql', Wordlift_Entity_Service::valid_entity_post_types() ) ) . "' )" // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.PreparedSQLPlaceholders.QuotedDynamicPlaceholderGeneration |
|
36 | - . " AND p.post_status IN ( 'publish', 'draft', 'private', 'future' ) " |
|
37 | - . ' AND ( p.post_title LIKE %s OR pm.meta_value LIKE %s )' |
|
38 | - . ' LIMIT %d', |
|
39 | - Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, |
|
40 | - 'article', |
|
41 | - Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY, |
|
42 | - // `prepare` doesn't support argument number, hence we must repeat the query. |
|
43 | - '%' . $wpdb->esc_like( $query ) . '%', |
|
44 | - '%' . $wpdb->esc_like( $query ) . '%', |
|
45 | - 50 |
|
46 | - ) |
|
47 | - ); |
|
24 | + $posts = $wpdb->get_results( |
|
25 | + $wpdb->prepare( |
|
26 | + "SELECT * FROM {$wpdb->posts} p" |
|
27 | + . " INNER JOIN {$wpdb->term_relationships} tr" |
|
28 | + . ' ON tr.object_id = p.ID' |
|
29 | + . " INNER JOIN {$wpdb->term_taxonomy} tt" |
|
30 | + . ' ON tt.taxonomy = %s AND tt.term_taxonomy_id = tr.term_taxonomy_id' |
|
31 | + . " INNER JOIN {$wpdb->terms} t" |
|
32 | + . ' ON t.term_id = tt.term_id AND t.name != %s' |
|
33 | + . " LEFT OUTER JOIN {$wpdb->postmeta} pm" |
|
34 | + . ' ON pm.meta_key = %s AND pm.post_id = p.ID' |
|
35 | + . " WHERE p.post_type IN ( '" . implode( "', '", array_map( 'esc_sql', Wordlift_Entity_Service::valid_entity_post_types() ) ) . "' )" // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.PreparedSQLPlaceholders.QuotedDynamicPlaceholderGeneration |
|
36 | + . " AND p.post_status IN ( 'publish', 'draft', 'private', 'future' ) " |
|
37 | + . ' AND ( p.post_title LIKE %s OR pm.meta_value LIKE %s )' |
|
38 | + . ' LIMIT %d', |
|
39 | + Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, |
|
40 | + 'article', |
|
41 | + Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY, |
|
42 | + // `prepare` doesn't support argument number, hence we must repeat the query. |
|
43 | + '%' . $wpdb->esc_like( $query ) . '%', |
|
44 | + '%' . $wpdb->esc_like( $query ) . '%', |
|
45 | + 50 |
|
46 | + ) |
|
47 | + ); |
|
48 | 48 | |
49 | - $results = array_map( |
|
50 | - function ( $item ) { |
|
49 | + $results = array_map( |
|
50 | + function ( $item ) { |
|
51 | 51 | |
52 | - $entity_service = Wordlift_Entity_Service::get_instance(); |
|
53 | - $uri = $entity_service->get_uri( $item->ID ); |
|
52 | + $entity_service = Wordlift_Entity_Service::get_instance(); |
|
53 | + $uri = $entity_service->get_uri( $item->ID ); |
|
54 | 54 | |
55 | - return array( |
|
56 | - // see #1074: The value property is needed for autocomplete in category page |
|
57 | - // to function correctly, if value is not provided, then the entity |
|
58 | - // wont be correctly saved. |
|
59 | - 'value' => $uri, |
|
60 | - 'id' => $uri, |
|
61 | - 'label' => array( $item->post_title ), |
|
62 | - 'labels' => $entity_service->get_alternative_labels( $item->ID ), |
|
63 | - 'descriptions' => array( Wordlift_Post_Excerpt_Helper::get_text_excerpt( $item ) ), |
|
64 | - 'scope' => 'local', |
|
65 | - 'sameAss' => get_post_meta( $item->ID, \Wordlift_Schema_Service::FIELD_SAME_AS ), |
|
66 | - // The following properties are less relevant because we're linking entities that exist already in the |
|
67 | - // vocabulary. That's why we don't make an effort to load the real data. |
|
68 | - 'types' => array( 'http://schema.org/Thing' ), |
|
69 | - 'urls' => array(), |
|
70 | - 'images' => array(), |
|
71 | - ); |
|
72 | - }, |
|
73 | - $posts |
|
74 | - ); |
|
55 | + return array( |
|
56 | + // see #1074: The value property is needed for autocomplete in category page |
|
57 | + // to function correctly, if value is not provided, then the entity |
|
58 | + // wont be correctly saved. |
|
59 | + 'value' => $uri, |
|
60 | + 'id' => $uri, |
|
61 | + 'label' => array( $item->post_title ), |
|
62 | + 'labels' => $entity_service->get_alternative_labels( $item->ID ), |
|
63 | + 'descriptions' => array( Wordlift_Post_Excerpt_Helper::get_text_excerpt( $item ) ), |
|
64 | + 'scope' => 'local', |
|
65 | + 'sameAss' => get_post_meta( $item->ID, \Wordlift_Schema_Service::FIELD_SAME_AS ), |
|
66 | + // The following properties are less relevant because we're linking entities that exist already in the |
|
67 | + // vocabulary. That's why we don't make an effort to load the real data. |
|
68 | + 'types' => array( 'http://schema.org/Thing' ), |
|
69 | + 'urls' => array(), |
|
70 | + 'images' => array(), |
|
71 | + ); |
|
72 | + }, |
|
73 | + $posts |
|
74 | + ); |
|
75 | 75 | |
76 | - $results = array_unique( $results, SORT_REGULAR ); |
|
76 | + $results = array_unique( $results, SORT_REGULAR ); |
|
77 | 77 | |
78 | - return $this->filter( $results, $excludes ); |
|
79 | - } |
|
78 | + return $this->filter( $results, $excludes ); |
|
79 | + } |
|
80 | 80 | |
81 | 81 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * @inheritDoc |
20 | 20 | */ |
21 | - public function query( $query, $scope, $excludes ) { |
|
21 | + public function query($query, $scope, $excludes) { |
|
22 | 22 | global $wpdb; |
23 | 23 | |
24 | 24 | $posts = $wpdb->get_results( |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | . ' ON t.term_id = tt.term_id AND t.name != %s' |
33 | 33 | . " LEFT OUTER JOIN {$wpdb->postmeta} pm" |
34 | 34 | . ' ON pm.meta_key = %s AND pm.post_id = p.ID' |
35 | - . " WHERE p.post_type IN ( '" . implode( "', '", array_map( 'esc_sql', Wordlift_Entity_Service::valid_entity_post_types() ) ) . "' )" // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.PreparedSQLPlaceholders.QuotedDynamicPlaceholderGeneration |
|
35 | + . " WHERE p.post_type IN ( '".implode("', '", array_map('esc_sql', Wordlift_Entity_Service::valid_entity_post_types()))."' )" // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.PreparedSQLPlaceholders.QuotedDynamicPlaceholderGeneration |
|
36 | 36 | . " AND p.post_status IN ( 'publish', 'draft', 'private', 'future' ) " |
37 | 37 | . ' AND ( p.post_title LIKE %s OR pm.meta_value LIKE %s )' |
38 | 38 | . ' LIMIT %d', |
@@ -40,17 +40,17 @@ discard block |
||
40 | 40 | 'article', |
41 | 41 | Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY, |
42 | 42 | // `prepare` doesn't support argument number, hence we must repeat the query. |
43 | - '%' . $wpdb->esc_like( $query ) . '%', |
|
44 | - '%' . $wpdb->esc_like( $query ) . '%', |
|
43 | + '%'.$wpdb->esc_like($query).'%', |
|
44 | + '%'.$wpdb->esc_like($query).'%', |
|
45 | 45 | 50 |
46 | 46 | ) |
47 | 47 | ); |
48 | 48 | |
49 | 49 | $results = array_map( |
50 | - function ( $item ) { |
|
50 | + function($item) { |
|
51 | 51 | |
52 | 52 | $entity_service = Wordlift_Entity_Service::get_instance(); |
53 | - $uri = $entity_service->get_uri( $item->ID ); |
|
53 | + $uri = $entity_service->get_uri($item->ID); |
|
54 | 54 | |
55 | 55 | return array( |
56 | 56 | // see #1074: The value property is needed for autocomplete in category page |
@@ -58,14 +58,14 @@ discard block |
||
58 | 58 | // wont be correctly saved. |
59 | 59 | 'value' => $uri, |
60 | 60 | 'id' => $uri, |
61 | - 'label' => array( $item->post_title ), |
|
62 | - 'labels' => $entity_service->get_alternative_labels( $item->ID ), |
|
63 | - 'descriptions' => array( Wordlift_Post_Excerpt_Helper::get_text_excerpt( $item ) ), |
|
61 | + 'label' => array($item->post_title), |
|
62 | + 'labels' => $entity_service->get_alternative_labels($item->ID), |
|
63 | + 'descriptions' => array(Wordlift_Post_Excerpt_Helper::get_text_excerpt($item)), |
|
64 | 64 | 'scope' => 'local', |
65 | - 'sameAss' => get_post_meta( $item->ID, \Wordlift_Schema_Service::FIELD_SAME_AS ), |
|
65 | + 'sameAss' => get_post_meta($item->ID, \Wordlift_Schema_Service::FIELD_SAME_AS), |
|
66 | 66 | // The following properties are less relevant because we're linking entities that exist already in the |
67 | 67 | // vocabulary. That's why we don't make an effort to load the real data. |
68 | - 'types' => array( 'http://schema.org/Thing' ), |
|
68 | + 'types' => array('http://schema.org/Thing'), |
|
69 | 69 | 'urls' => array(), |
70 | 70 | 'images' => array(), |
71 | 71 | ); |
@@ -73,9 +73,9 @@ discard block |
||
73 | 73 | $posts |
74 | 74 | ); |
75 | 75 | |
76 | - $results = array_unique( $results, SORT_REGULAR ); |
|
76 | + $results = array_unique($results, SORT_REGULAR); |
|
77 | 77 | |
78 | - return $this->filter( $results, $excludes ); |
|
78 | + return $this->filter($results, $excludes); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | } |
@@ -12,44 +12,44 @@ |
||
12 | 12 | use Wordlift\Vocabulary_Terms\Jsonld\Post_Jsonld; |
13 | 13 | |
14 | 14 | class Vocabulary_Terms_Loader extends Default_Loader { |
15 | - /** |
|
16 | - * @var \Wordlift_Entity_Type_Service |
|
17 | - */ |
|
18 | - private $entity_type_service; |
|
19 | - /** |
|
20 | - * @var \Wordlift_Property_Getter |
|
21 | - */ |
|
22 | - private $property_getter; |
|
23 | - |
|
24 | - /** |
|
25 | - * Vocabulary_Terms_Loader constructor. |
|
26 | - * |
|
27 | - * @param $entity_type_service \Wordlift_Entity_Type_Service |
|
28 | - * @param \Wordlift_Property_Getter $property_getter |
|
29 | - */ |
|
30 | - public function __construct( $entity_type_service, $property_getter ) { |
|
31 | - parent::__construct(); |
|
32 | - $this->entity_type_service = $entity_type_service; |
|
33 | - $this->property_getter = $property_getter; |
|
34 | - } |
|
35 | - |
|
36 | - public function init_all_dependencies() { |
|
37 | - new Entity_Type(); |
|
38 | - new Term_Metabox(); |
|
39 | - $jsonld = new Jsonld_Generator( $this->entity_type_service, $this->property_getter ); |
|
40 | - $jsonld->init(); |
|
41 | - $term_save_hook = new Term_Save(); |
|
42 | - $term_save_hook->init(); |
|
43 | - $post_jsonld = new Post_Jsonld(); |
|
44 | - $post_jsonld->init(); |
|
45 | - } |
|
46 | - |
|
47 | - protected function get_feature_slug() { |
|
48 | - return 'no-vocabulary-terms'; |
|
49 | - } |
|
50 | - |
|
51 | - protected function get_feature_default_value() { |
|
52 | - return false; |
|
53 | - } |
|
15 | + /** |
|
16 | + * @var \Wordlift_Entity_Type_Service |
|
17 | + */ |
|
18 | + private $entity_type_service; |
|
19 | + /** |
|
20 | + * @var \Wordlift_Property_Getter |
|
21 | + */ |
|
22 | + private $property_getter; |
|
23 | + |
|
24 | + /** |
|
25 | + * Vocabulary_Terms_Loader constructor. |
|
26 | + * |
|
27 | + * @param $entity_type_service \Wordlift_Entity_Type_Service |
|
28 | + * @param \Wordlift_Property_Getter $property_getter |
|
29 | + */ |
|
30 | + public function __construct( $entity_type_service, $property_getter ) { |
|
31 | + parent::__construct(); |
|
32 | + $this->entity_type_service = $entity_type_service; |
|
33 | + $this->property_getter = $property_getter; |
|
34 | + } |
|
35 | + |
|
36 | + public function init_all_dependencies() { |
|
37 | + new Entity_Type(); |
|
38 | + new Term_Metabox(); |
|
39 | + $jsonld = new Jsonld_Generator( $this->entity_type_service, $this->property_getter ); |
|
40 | + $jsonld->init(); |
|
41 | + $term_save_hook = new Term_Save(); |
|
42 | + $term_save_hook->init(); |
|
43 | + $post_jsonld = new Post_Jsonld(); |
|
44 | + $post_jsonld->init(); |
|
45 | + } |
|
46 | + |
|
47 | + protected function get_feature_slug() { |
|
48 | + return 'no-vocabulary-terms'; |
|
49 | + } |
|
50 | + |
|
51 | + protected function get_feature_default_value() { |
|
52 | + return false; |
|
53 | + } |
|
54 | 54 | |
55 | 55 | } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | * @param $entity_type_service \Wordlift_Entity_Type_Service |
28 | 28 | * @param \Wordlift_Property_Getter $property_getter |
29 | 29 | */ |
30 | - public function __construct( $entity_type_service, $property_getter ) { |
|
30 | + public function __construct($entity_type_service, $property_getter) { |
|
31 | 31 | parent::__construct(); |
32 | 32 | $this->entity_type_service = $entity_type_service; |
33 | 33 | $this->property_getter = $property_getter; |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | public function init_all_dependencies() { |
37 | 37 | new Entity_Type(); |
38 | 38 | new Term_Metabox(); |
39 | - $jsonld = new Jsonld_Generator( $this->entity_type_service, $this->property_getter ); |
|
39 | + $jsonld = new Jsonld_Generator($this->entity_type_service, $this->property_getter); |
|
40 | 40 | $jsonld->init(); |
41 | 41 | $term_save_hook = new Term_Save(); |
42 | 42 | $term_save_hook->init(); |
@@ -4,20 +4,20 @@ |
||
4 | 4 | |
5 | 5 | interface Task { |
6 | 6 | |
7 | - /** |
|
8 | - * @return int The total number of items to process. |
|
9 | - */ |
|
10 | - public function starting(); |
|
7 | + /** |
|
8 | + * @return int The total number of items to process. |
|
9 | + */ |
|
10 | + public function starting(); |
|
11 | 11 | |
12 | - /** |
|
13 | - * @param $value mixed The incoming value. |
|
14 | - * @param $args { |
|
15 | - * |
|
16 | - * @type int $offset The index of the current item. |
|
17 | - * @type int $count The total number of items as provided by the `starting` function. |
|
18 | - * @type int $batch_size The number of items to process within this call. |
|
19 | - * } |
|
20 | - */ |
|
21 | - public function tick( $value, $args ); |
|
12 | + /** |
|
13 | + * @param $value mixed The incoming value. |
|
14 | + * @param $args { |
|
15 | + * |
|
16 | + * @type int $offset The index of the current item. |
|
17 | + * @type int $count The total number of items as provided by the `starting` function. |
|
18 | + * @type int $batch_size The number of items to process within this call. |
|
19 | + * } |
|
20 | + */ |
|
21 | + public function tick( $value, $args ); |
|
22 | 22 | |
23 | 23 | } |
@@ -18,6 +18,6 @@ |
||
18 | 18 | * @type int $batch_size The number of items to process within this call. |
19 | 19 | * } |
20 | 20 | */ |
21 | - public function tick( $value, $args ); |
|
21 | + public function tick($value, $args); |
|
22 | 22 | |
23 | 23 | } |
@@ -4,31 +4,31 @@ |
||
4 | 4 | |
5 | 5 | class Background_Task_Stopped_State extends Abstract_Background_Task_State { |
6 | 6 | |
7 | - /** |
|
8 | - * @var Background_Task |
|
9 | - */ |
|
10 | - private $context; |
|
7 | + /** |
|
8 | + * @var Background_Task |
|
9 | + */ |
|
10 | + private $context; |
|
11 | 11 | |
12 | - public function __construct( $context ) { |
|
13 | - parent::__construct( $context, Background_Task::STATE_STOPPED ); |
|
12 | + public function __construct( $context ) { |
|
13 | + parent::__construct( $context, Background_Task::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( Background_Task::STATE_STOPPED ); |
|
20 | - } |
|
18 | + public function enter() { |
|
19 | + $this->context->set_state( Background_Task::STATE_STOPPED ); |
|
20 | + } |
|
21 | 21 | |
22 | - public function leave() { |
|
23 | - $this->context->set_state( null ); |
|
24 | - } |
|
22 | + public function leave() { |
|
23 | + $this->context->set_state( null ); |
|
24 | + } |
|
25 | 25 | |
26 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
27 | - public function task( $value ) { |
|
26 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
27 | + public function task( $value ) { |
|
28 | 28 | |
29 | - $this->context->cancel_process(); |
|
29 | + $this->context->cancel_process(); |
|
30 | 30 | |
31 | - return false; |
|
32 | - } |
|
31 | + return false; |
|
32 | + } |
|
33 | 33 | |
34 | 34 | } |
@@ -9,22 +9,22 @@ |
||
9 | 9 | */ |
10 | 10 | private $context; |
11 | 11 | |
12 | - public function __construct( $context ) { |
|
13 | - parent::__construct( $context, Background_Task::STATE_STOPPED ); |
|
12 | + public function __construct($context) { |
|
13 | + parent::__construct($context, Background_Task::STATE_STOPPED); |
|
14 | 14 | |
15 | 15 | $this->context = $context; |
16 | 16 | } |
17 | 17 | |
18 | 18 | public function enter() { |
19 | - $this->context->set_state( Background_Task::STATE_STOPPED ); |
|
19 | + $this->context->set_state(Background_Task::STATE_STOPPED); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | public function leave() { |
23 | - $this->context->set_state( null ); |
|
23 | + $this->context->set_state(null); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
27 | - public function task( $value ) { |
|
27 | + public function task($value) { |
|
28 | 28 | |
29 | 29 | $this->context->cancel_process(); |
30 | 30 |
@@ -8,73 +8,73 @@ discard block |
||
8 | 8 | |
9 | 9 | class Background_Task_Page { |
10 | 10 | |
11 | - private $title; |
|
12 | - |
|
13 | - private $menu_slug; |
|
14 | - |
|
15 | - /** |
|
16 | - * @var Background_Task_Route $background_task_route |
|
17 | - */ |
|
18 | - private $background_task_route; |
|
19 | - |
|
20 | - /** |
|
21 | - * @throws Exception if one or more parameters are invalid. |
|
22 | - */ |
|
23 | - public function __construct( $title, $menu_slug, $background_task_route ) { |
|
24 | - Assertions::not_empty( $title, '`$title` cannot be empty.' ); |
|
25 | - Assertions::not_empty( $menu_slug, '`$menu_slug` cannot be empty.' ); |
|
26 | - Assertions::is_a( $background_task_route, 'Wordlift\Task\Background\Background_Task_Route', '`Background_Task_Route` must be of type `Wordlift\Task\Background\Background_Route`.' ); |
|
27 | - |
|
28 | - add_action( 'admin_menu', array( $this, 'admin_menu' ) ); |
|
29 | - |
|
30 | - $this->title = $title; |
|
31 | - $this->menu_slug = $menu_slug; |
|
32 | - $this->background_task_route = $background_task_route; |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * @throws Exception if one or more parameters are invalid. |
|
37 | - */ |
|
38 | - public static function create( $title, $menu_slug, $background_route ) { |
|
39 | - return new self( $title, $menu_slug, $background_route ); |
|
40 | - } |
|
41 | - |
|
42 | - public function admin_menu() { |
|
43 | - |
|
44 | - add_submenu_page( |
|
45 | - 'wl_admin_menu', |
|
46 | - $this->title, |
|
47 | - $this->title, |
|
48 | - 'manage_options', |
|
49 | - $this->menu_slug, |
|
50 | - array( |
|
51 | - $this, |
|
52 | - 'render', |
|
53 | - ) |
|
54 | - ); |
|
55 | - |
|
56 | - } |
|
57 | - |
|
58 | - public function render() { |
|
59 | - |
|
60 | - wp_enqueue_style( |
|
61 | - 'wl-task-page', |
|
62 | - plugin_dir_url( __FILE__ ) . 'assets/task-page.css', |
|
63 | - array(), |
|
64 | - Wordlift::get_instance()->get_version(), |
|
65 | - 'all' |
|
66 | - ); |
|
67 | - |
|
68 | - wp_enqueue_script( |
|
69 | - 'wl-task-page', |
|
70 | - plugin_dir_url( __FILE__ ) . 'assets/task-page.js', |
|
71 | - array( 'wp-api' ), |
|
72 | - WORDLIFT_VERSION, |
|
73 | - false |
|
74 | - ); |
|
75 | - |
|
76 | - wp_localize_script( 'wl-task-page', '_wlTaskPageSettings', array( 'rest_path' => $this->background_task_route->get_rest_path() ) ); |
|
77 | - ?> |
|
11 | + private $title; |
|
12 | + |
|
13 | + private $menu_slug; |
|
14 | + |
|
15 | + /** |
|
16 | + * @var Background_Task_Route $background_task_route |
|
17 | + */ |
|
18 | + private $background_task_route; |
|
19 | + |
|
20 | + /** |
|
21 | + * @throws Exception if one or more parameters are invalid. |
|
22 | + */ |
|
23 | + public function __construct( $title, $menu_slug, $background_task_route ) { |
|
24 | + Assertions::not_empty( $title, '`$title` cannot be empty.' ); |
|
25 | + Assertions::not_empty( $menu_slug, '`$menu_slug` cannot be empty.' ); |
|
26 | + Assertions::is_a( $background_task_route, 'Wordlift\Task\Background\Background_Task_Route', '`Background_Task_Route` must be of type `Wordlift\Task\Background\Background_Route`.' ); |
|
27 | + |
|
28 | + add_action( 'admin_menu', array( $this, 'admin_menu' ) ); |
|
29 | + |
|
30 | + $this->title = $title; |
|
31 | + $this->menu_slug = $menu_slug; |
|
32 | + $this->background_task_route = $background_task_route; |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * @throws Exception if one or more parameters are invalid. |
|
37 | + */ |
|
38 | + public static function create( $title, $menu_slug, $background_route ) { |
|
39 | + return new self( $title, $menu_slug, $background_route ); |
|
40 | + } |
|
41 | + |
|
42 | + public function admin_menu() { |
|
43 | + |
|
44 | + add_submenu_page( |
|
45 | + 'wl_admin_menu', |
|
46 | + $this->title, |
|
47 | + $this->title, |
|
48 | + 'manage_options', |
|
49 | + $this->menu_slug, |
|
50 | + array( |
|
51 | + $this, |
|
52 | + 'render', |
|
53 | + ) |
|
54 | + ); |
|
55 | + |
|
56 | + } |
|
57 | + |
|
58 | + public function render() { |
|
59 | + |
|
60 | + wp_enqueue_style( |
|
61 | + 'wl-task-page', |
|
62 | + plugin_dir_url( __FILE__ ) . 'assets/task-page.css', |
|
63 | + array(), |
|
64 | + Wordlift::get_instance()->get_version(), |
|
65 | + 'all' |
|
66 | + ); |
|
67 | + |
|
68 | + wp_enqueue_script( |
|
69 | + 'wl-task-page', |
|
70 | + plugin_dir_url( __FILE__ ) . 'assets/task-page.js', |
|
71 | + array( 'wp-api' ), |
|
72 | + WORDLIFT_VERSION, |
|
73 | + false |
|
74 | + ); |
|
75 | + |
|
76 | + wp_localize_script( 'wl-task-page', '_wlTaskPageSettings', array( 'rest_path' => $this->background_task_route->get_rest_path() ) ); |
|
77 | + ?> |
|
78 | 78 | <div class="wrap"> |
79 | 79 | <h2><?php echo esc_html( $this->title ); ?></h2> |
80 | 80 | |
@@ -85,17 +85,17 @@ discard block |
||
85 | 85 | |
86 | 86 | <button id="wl-start-btn" type="button" class="button button-large button-primary"> |
87 | 87 | <?php |
88 | - esc_html_e( 'Start', 'wordlift' ); |
|
89 | - ?> |
|
88 | + esc_html_e( 'Start', 'wordlift' ); |
|
89 | + ?> |
|
90 | 90 | </button> |
91 | 91 | <button id="wl-stop-btn" type="button" class="button button-large button-primary hidden"> |
92 | 92 | <?php |
93 | - esc_html_e( 'Stop', 'wordlift' ); |
|
94 | - ?> |
|
93 | + esc_html_e( 'Stop', 'wordlift' ); |
|
94 | + ?> |
|
95 | 95 | </button> |
96 | 96 | |
97 | 97 | </div> |
98 | 98 | <?php |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | 101 | } |
@@ -20,12 +20,12 @@ discard block |
||
20 | 20 | /** |
21 | 21 | * @throws Exception if one or more parameters are invalid. |
22 | 22 | */ |
23 | - public function __construct( $title, $menu_slug, $background_task_route ) { |
|
24 | - Assertions::not_empty( $title, '`$title` cannot be empty.' ); |
|
25 | - Assertions::not_empty( $menu_slug, '`$menu_slug` cannot be empty.' ); |
|
26 | - Assertions::is_a( $background_task_route, 'Wordlift\Task\Background\Background_Task_Route', '`Background_Task_Route` must be of type `Wordlift\Task\Background\Background_Route`.' ); |
|
23 | + public function __construct($title, $menu_slug, $background_task_route) { |
|
24 | + Assertions::not_empty($title, '`$title` cannot be empty.'); |
|
25 | + Assertions::not_empty($menu_slug, '`$menu_slug` cannot be empty.'); |
|
26 | + Assertions::is_a($background_task_route, 'Wordlift\Task\Background\Background_Task_Route', '`Background_Task_Route` must be of type `Wordlift\Task\Background\Background_Route`.'); |
|
27 | 27 | |
28 | - add_action( 'admin_menu', array( $this, 'admin_menu' ) ); |
|
28 | + add_action('admin_menu', array($this, 'admin_menu')); |
|
29 | 29 | |
30 | 30 | $this->title = $title; |
31 | 31 | $this->menu_slug = $menu_slug; |
@@ -35,8 +35,8 @@ discard block |
||
35 | 35 | /** |
36 | 36 | * @throws Exception if one or more parameters are invalid. |
37 | 37 | */ |
38 | - public static function create( $title, $menu_slug, $background_route ) { |
|
39 | - return new self( $title, $menu_slug, $background_route ); |
|
38 | + public static function create($title, $menu_slug, $background_route) { |
|
39 | + return new self($title, $menu_slug, $background_route); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | public function admin_menu() { |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | |
60 | 60 | wp_enqueue_style( |
61 | 61 | 'wl-task-page', |
62 | - plugin_dir_url( __FILE__ ) . 'assets/task-page.css', |
|
62 | + plugin_dir_url(__FILE__).'assets/task-page.css', |
|
63 | 63 | array(), |
64 | 64 | Wordlift::get_instance()->get_version(), |
65 | 65 | 'all' |
@@ -67,16 +67,16 @@ discard block |
||
67 | 67 | |
68 | 68 | wp_enqueue_script( |
69 | 69 | 'wl-task-page', |
70 | - plugin_dir_url( __FILE__ ) . 'assets/task-page.js', |
|
71 | - array( 'wp-api' ), |
|
70 | + plugin_dir_url(__FILE__).'assets/task-page.js', |
|
71 | + array('wp-api'), |
|
72 | 72 | WORDLIFT_VERSION, |
73 | 73 | false |
74 | 74 | ); |
75 | 75 | |
76 | - wp_localize_script( 'wl-task-page', '_wlTaskPageSettings', array( 'rest_path' => $this->background_task_route->get_rest_path() ) ); |
|
76 | + wp_localize_script('wl-task-page', '_wlTaskPageSettings', array('rest_path' => $this->background_task_route->get_rest_path())); |
|
77 | 77 | ?> |
78 | 78 | <div class="wrap"> |
79 | - <h2><?php echo esc_html( $this->title ); ?></h2> |
|
79 | + <h2><?php echo esc_html($this->title); ?></h2> |
|
80 | 80 | |
81 | 81 | <div class="wl-task__progress" style="border: 1px solid #23282D; height: 20px; margin: 8px 0;"> |
82 | 82 | <div class="wl-task__progress__bar" |
@@ -85,12 +85,12 @@ discard block |
||
85 | 85 | |
86 | 86 | <button id="wl-start-btn" type="button" class="button button-large button-primary"> |
87 | 87 | <?php |
88 | - esc_html_e( 'Start', 'wordlift' ); |
|
88 | + esc_html_e('Start', 'wordlift'); |
|
89 | 89 | ?> |
90 | 90 | </button> |
91 | 91 | <button id="wl-stop-btn" type="button" class="button button-large button-primary hidden"> |
92 | 92 | <?php |
93 | - esc_html_e( 'Stop', 'wordlift' ); |
|
93 | + esc_html_e('Stop', 'wordlift'); |
|
94 | 94 | ?> |
95 | 95 | </button> |
96 | 96 |
@@ -4,79 +4,79 @@ |
||
4 | 4 | |
5 | 5 | class Background_Task_Started_State extends Abstract_Background_Task_State { |
6 | 6 | |
7 | - /** |
|
8 | - * @var Background_Task |
|
9 | - */ |
|
10 | - private $context; |
|
7 | + /** |
|
8 | + * @var Background_Task |
|
9 | + */ |
|
10 | + private $context; |
|
11 | 11 | |
12 | - private $batch_size = 5; |
|
12 | + private $batch_size = 5; |
|
13 | 13 | |
14 | - /** |
|
15 | - * @var Task |
|
16 | - */ |
|
17 | - private $task; |
|
14 | + /** |
|
15 | + * @var Task |
|
16 | + */ |
|
17 | + private $task; |
|
18 | 18 | |
19 | - /** |
|
20 | - * Back_Started_State constructor. |
|
21 | - * |
|
22 | - * @param Background_Task $context |
|
23 | - */ |
|
24 | - public function __construct( $context, $task ) { |
|
25 | - parent::__construct( $context, Background_Task::STATE_STARTED ); |
|
19 | + /** |
|
20 | + * Back_Started_State constructor. |
|
21 | + * |
|
22 | + * @param Background_Task $context |
|
23 | + */ |
|
24 | + public function __construct( $context, $task ) { |
|
25 | + parent::__construct( $context, Background_Task::STATE_STARTED ); |
|
26 | 26 | |
27 | - $this->context = $context; |
|
28 | - $this->task = $task; |
|
29 | - } |
|
27 | + $this->context = $context; |
|
28 | + $this->task = $task; |
|
29 | + } |
|
30 | 30 | |
31 | - public function enter() { |
|
31 | + public function enter() { |
|
32 | 32 | |
33 | - $count = $this->task->starting(); |
|
33 | + $count = $this->task->starting(); |
|
34 | 34 | |
35 | - update_option( $this->context->get_option_prefix() . 'count', $count, true ); |
|
36 | - update_option( $this->context->get_option_prefix() . 'offset', 0, true ); |
|
37 | - update_option( $this->context->get_option_prefix() . 'started', time(), true ); |
|
38 | - update_option( $this->context->get_option_prefix() . 'updated', time(), true ); |
|
35 | + update_option( $this->context->get_option_prefix() . 'count', $count, true ); |
|
36 | + update_option( $this->context->get_option_prefix() . 'offset', 0, true ); |
|
37 | + update_option( $this->context->get_option_prefix() . 'started', time(), true ); |
|
38 | + update_option( $this->context->get_option_prefix() . 'updated', time(), true ); |
|
39 | 39 | |
40 | - $this->context->set_state( Background_Task::STATE_STARTED ); |
|
40 | + $this->context->set_state( Background_Task::STATE_STARTED ); |
|
41 | 41 | |
42 | - $this->resume(); |
|
43 | - } |
|
42 | + $this->resume(); |
|
43 | + } |
|
44 | 44 | |
45 | - public function resume() { |
|
46 | - $this->context->push_to_queue( true ); |
|
47 | - $this->context->save()->dispatch(); |
|
48 | - } |
|
45 | + public function resume() { |
|
46 | + $this->context->push_to_queue( true ); |
|
47 | + $this->context->save()->dispatch(); |
|
48 | + } |
|
49 | 49 | |
50 | - public function leave() { |
|
51 | - $this->context->set_state( null ); |
|
52 | - } |
|
50 | + public function leave() { |
|
51 | + $this->context->set_state( null ); |
|
52 | + } |
|
53 | 53 | |
54 | - public function task( $value ) { |
|
55 | - $offset = get_option( $this->context->get_option_prefix() . 'offset' ); |
|
56 | - $count = get_option( $this->context->get_option_prefix() . 'count' ); |
|
54 | + public function task( $value ) { |
|
55 | + $offset = get_option( $this->context->get_option_prefix() . 'offset' ); |
|
56 | + $count = get_option( $this->context->get_option_prefix() . 'count' ); |
|
57 | 57 | |
58 | - $this->task->tick( |
|
59 | - $value, |
|
60 | - array( |
|
61 | - 'offset' => $offset, |
|
62 | - 'count' => $count, |
|
63 | - 'batch_size' => $this->batch_size, |
|
64 | - ) |
|
65 | - ); |
|
58 | + $this->task->tick( |
|
59 | + $value, |
|
60 | + array( |
|
61 | + 'offset' => $offset, |
|
62 | + 'count' => $count, |
|
63 | + 'batch_size' => $this->batch_size, |
|
64 | + ) |
|
65 | + ); |
|
66 | 66 | |
67 | - update_option( $this->context->get_option_prefix() . 'updated', time(), true ); |
|
67 | + update_option( $this->context->get_option_prefix() . 'updated', time(), true ); |
|
68 | 68 | |
69 | - // Increase the offset. |
|
70 | - if ( ( $offset + $this->batch_size ) < $count ) { |
|
71 | - update_option( $this->context->get_option_prefix() . 'offset', $offset + $this->batch_size, true ); |
|
69 | + // Increase the offset. |
|
70 | + if ( ( $offset + $this->batch_size ) < $count ) { |
|
71 | + update_option( $this->context->get_option_prefix() . 'offset', $offset + $this->batch_size, true ); |
|
72 | 72 | |
73 | - return true; |
|
74 | - } |
|
73 | + return true; |
|
74 | + } |
|
75 | 75 | |
76 | - // Stop processing. |
|
77 | - $this->context->stop(); |
|
76 | + // Stop processing. |
|
77 | + $this->context->stop(); |
|
78 | 78 | |
79 | - return false; |
|
80 | - } |
|
79 | + return false; |
|
80 | + } |
|
81 | 81 | |
82 | 82 | } |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @param Background_Task $context |
23 | 23 | */ |
24 | - public function __construct( $context, $task ) { |
|
25 | - parent::__construct( $context, Background_Task::STATE_STARTED ); |
|
24 | + public function __construct($context, $task) { |
|
25 | + parent::__construct($context, Background_Task::STATE_STARTED); |
|
26 | 26 | |
27 | 27 | $this->context = $context; |
28 | 28 | $this->task = $task; |
@@ -32,28 +32,28 @@ discard block |
||
32 | 32 | |
33 | 33 | $count = $this->task->starting(); |
34 | 34 | |
35 | - update_option( $this->context->get_option_prefix() . 'count', $count, true ); |
|
36 | - update_option( $this->context->get_option_prefix() . 'offset', 0, true ); |
|
37 | - update_option( $this->context->get_option_prefix() . 'started', time(), true ); |
|
38 | - update_option( $this->context->get_option_prefix() . 'updated', time(), true ); |
|
35 | + update_option($this->context->get_option_prefix().'count', $count, true); |
|
36 | + update_option($this->context->get_option_prefix().'offset', 0, true); |
|
37 | + update_option($this->context->get_option_prefix().'started', time(), true); |
|
38 | + update_option($this->context->get_option_prefix().'updated', time(), true); |
|
39 | 39 | |
40 | - $this->context->set_state( Background_Task::STATE_STARTED ); |
|
40 | + $this->context->set_state(Background_Task::STATE_STARTED); |
|
41 | 41 | |
42 | 42 | $this->resume(); |
43 | 43 | } |
44 | 44 | |
45 | 45 | public function resume() { |
46 | - $this->context->push_to_queue( true ); |
|
46 | + $this->context->push_to_queue(true); |
|
47 | 47 | $this->context->save()->dispatch(); |
48 | 48 | } |
49 | 49 | |
50 | 50 | public function leave() { |
51 | - $this->context->set_state( null ); |
|
51 | + $this->context->set_state(null); |
|
52 | 52 | } |
53 | 53 | |
54 | - public function task( $value ) { |
|
55 | - $offset = get_option( $this->context->get_option_prefix() . 'offset' ); |
|
56 | - $count = get_option( $this->context->get_option_prefix() . 'count' ); |
|
54 | + public function task($value) { |
|
55 | + $offset = get_option($this->context->get_option_prefix().'offset'); |
|
56 | + $count = get_option($this->context->get_option_prefix().'count'); |
|
57 | 57 | |
58 | 58 | $this->task->tick( |
59 | 59 | $value, |
@@ -64,11 +64,11 @@ discard block |
||
64 | 64 | ) |
65 | 65 | ); |
66 | 66 | |
67 | - update_option( $this->context->get_option_prefix() . 'updated', time(), true ); |
|
67 | + update_option($this->context->get_option_prefix().'updated', time(), true); |
|
68 | 68 | |
69 | 69 | // Increase the offset. |
70 | - if ( ( $offset + $this->batch_size ) < $count ) { |
|
71 | - update_option( $this->context->get_option_prefix() . 'offset', $offset + $this->batch_size, true ); |
|
70 | + if (($offset + $this->batch_size) < $count) { |
|
71 | + update_option($this->context->get_option_prefix().'offset', $offset + $this->batch_size, true); |
|
72 | 72 | |
73 | 73 | return true; |
74 | 74 | } |