PluginProbe
ElasticPress / 5.3.5
ElasticPress v5.3.5
5.3.5 5.3.4 3.6.5 3.6.6 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.7.0 4.7.1 4.7.2 5.0.0 5.0.1 5.0.2 All 108 releases
← All changes | includes/classes/Upgrades.php +137 -26 4.2.05.3.5 View file →
@@ -7,8 +7,11 @@
7 7 */
8 8
9 9 namespace ElasticPress;
10 10
11 +use ElasticPress\Features;
12 +use ElasticPress\Utils;
13 +
11 14 if ( ! defined( 'ABSPATH' ) ) {
12 15 exit; // Exit if accessed directly.
13 16 }
14 17
@@ -30,13 +33,9 @@
30 33 /**
31 34 * Initialize class
32 35 */
33 36 public function setup() {
34 - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
35 - $this->old_version = get_site_option( 'ep_version', false );
36 - } else {
37 - $this->old_version = get_option( 'ep_version', false );
38 - }
37 + $this->old_version = Utils\get_option( 'ep_version', false );
39 38
40 39 /**
41 40 * An array with the upgrades routines.
42 41 * Indexes are the ElasticPress version and values
@@ -46,8 +45,13 @@
46 45 $routines = [
47 46 '3.5.2' => [ 'upgrade_3_5_2', 'init' ],
48 47 '3.5.3' => [ 'upgrade_3_5_3', 'init' ],
49 48 '3.6.6' => [ 'upgrade_3_6_6', 'init' ],
49 + '4.2.2' => [ 'upgrade_4_2_2', 'init' ],
50 + '4.4.0' => [ 'upgrade_4_4_0', 'init' ],
51 + '4.5.0' => [ 'upgrade_4_5_0', 'init' ],
52 + '4.7.0' => [ 'upgrade_4_7_0', 'init' ],
53 + '5.0.0' => [ 'upgrade_5_0_0', 'init' ],
50 54 ];
51 55
52 56 array_walk( $routines, [ $this, 'run_upgrade_routine' ] );
53 57
@@ -60,13 +64,9 @@
60 64 * Update the version number.
61 65 * Note: if a upgrade routine method is hooked to some action,
62 66 * this code will be executed *earlier* than the routine method.
63 67 */
64 - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
65 - update_site_option( 'ep_version', sanitize_text_field( EP_VERSION ) );
66 - } else {
67 - update_option( 'ep_version', sanitize_text_field( EP_VERSION ) );
68 - }
68 + Utils\update_option( 'ep_version', sanitize_text_field( EP_VERSION ) );
69 69
70 70 add_filter( 'ep_admin_notices', [ $this, 'resync_notice_4_0_0_instant_results' ] );
71 71 }
72 72
@@ -150,8 +150,9 @@
150 150 if ( ! $synonyms ) {
151 151 return;
152 152 }
153 153
154 + // phpcs:disable WordPress.DB.DirectDatabaseQuery
154 155 $synonyms_example_ids = $wpdb->get_col(
155 156 $wpdb->prepare(
156 157 "SELECT ID FROM {$wpdb->posts} WHERE post_type = %s AND post_content = %s LIMIT 100",
157 158 $synonyms::POST_TYPE_NAME,
@@ -157,8 +158,9 @@
157 158 $synonyms::POST_TYPE_NAME,
158 159 $synonyms->example_synonym_list()
159 160 )
160 161 );
162 + // phpcs:enable WordPress.DB.DirectDatabaseQuery
161 163
162 164 if ( ! $synonyms_example_ids ) {
163 165 return;
164 166 }
@@ -168,8 +170,125 @@
168 170 }
169 171 }
170 172
171 173 /**
174 + * Upgrade routine of v4.2.2.
175 + *
176 + * Delete the transient with ES info, so EP is forced to fetch it again,
177 + * determining the correct software type (elasticsearch or opensearch, for example)
178 + *
179 + * @see https://github.com/10up/ElasticPress/issues/2882
180 + */
181 + public function upgrade_4_2_2() {
182 + if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
183 + delete_site_transient( 'ep_es_info' );
184 + } else {
185 + delete_transient( 'ep_es_info' );
186 + }
187 + }
188 +
189 + /**
190 + * Upgrade routine of v4.4.0.
191 + *
192 + * Delete the ep_prefix option, as that is now obtained via ep_credentials
193 + *
194 + * @see https://github.com/10up/ElasticPress/issues/2739
195 + */
196 + public function upgrade_4_4_0() {
197 + Utils\delete_option( 'ep_prefix' );
198 + }
199 +
200 + /**
201 + * Upgrade routine of v4.5.0.
202 + *
203 + * Add the ElasticPress capability to admins
204 + *
205 + * @see https://github.com/10up/ElasticPress/pull/3313
206 + */
207 + public function upgrade_4_5_0() {
208 + setup_roles();
209 + }
210 +
211 + /**
212 + * Upgrade routine of v4.7.0.
213 + *
214 + * Remove old total_fields_limit transients
215 + * Remove cached autosuggest requests
216 + *
217 + * @see https://github.com/10up/ElasticPress/pull/3552
218 + */
219 + public function upgrade_4_7_0() {
220 + global $wpdb;
221 +
222 + if ( is_multisite() ) {
223 + $sites = \get_sites( [ 'number' => 0 ] );
224 + foreach ( $sites as $site ) {
225 + $blog_option = get_blog_option( $site->blog_id, 'ep_indexable' );
226 + if ( $blog_option ) {
227 + update_site_meta( $site->blog_id, 'ep_indexable', $blog_option );
228 + }
229 + }
230 + }
231 +
232 + $transients = $wpdb->get_col( // phpcs:ignore WordPress.DB.DirectDatabaseQuery
233 + "SELECT option_name
234 + FROM {$wpdb->prefix}options
235 + WHERE option_name LIKE '_transient_ep_total_fields_limit_%'"
236 + );
237 +
238 + foreach ( $transients as $transient ) {
239 + $transient_name = str_replace( '_transient_', '', $transient );
240 + delete_site_transient( $transient_name );
241 + delete_transient( $transient_name );
242 + }
243 +
244 + if ( function_exists( 'wp_cache_supports' ) && wp_cache_supports( 'flush_group' ) ) {
245 + wp_cache_flush_group( 'ep_autosuggest' );
246 + }
247 + delete_transient( 'ep_autosuggest_query_request_cache' );
248 + }
249 +
250 + /**
251 + * Upgrade routine of v5.0.0.
252 + */
253 + public function upgrade_5_0_0() {
254 + $features_in_settings = Features::factory()->get_feature_settings();
255 + if ( ! empty( $features_in_settings ) ) {
256 + foreach ( $features_in_settings as $feature_slug => $feature_settings ) {
257 + $feature = Features::factory()->get_registered_feature( $feature_slug );
258 + if ( ! $feature ) {
259 + continue;
260 + }
261 +
262 + $settings_schema = $feature->get_settings_schema();
263 + foreach ( $settings_schema as $setting_schema ) {
264 + if ( ! isset( $feature_settings[ $setting_schema['key'] ] ) ) {
265 + continue;
266 + }
267 +
268 + $value = $feature_settings[ $setting_schema['key'] ];
269 +
270 + if ( ! in_array( $setting_schema['type'], [ 'checkbox', 'radio' ], true ) || ! is_bool( $value ) ) {
271 + continue;
272 + }
273 +
274 + $features_in_settings[ $feature_slug ][ $setting_schema['key'] ] = $value ? '1' : '0';
275 + }
276 + }
277 + Utils\update_option( 'ep_feature_settings', $features_in_settings );
278 + }
279 +
280 + /**
281 + * Remove the 'ep_last_index' option and store it as an entry of 'ep_sync_history'
282 + */
283 + $last_sync = Utils\get_option( 'ep_last_index', [] );
284 + if ( ! empty( $last_sync ) ) {
285 + Utils\delete_option( 'ep_last_index' );
286 + Utils\update_option( 'ep_sync_history', [ $last_sync ] );
287 + }
288 + }
289 +
290 + /**
172 291 * Adjust the upgrade sync notice to warn users about Instant Results.
173 292 *
174 293 * As 4.0.0 introduces this new feature and it requires a resync, admin users
175 294 * might want to enable the feature before the resync (and then resync only once.)
@@ -189,9 +308,9 @@
189 308 }
190 309
191 310 $feature_status = $instant_results->requirements_status();
192 311 $appended_message = '';
193 - if ( 1 >= $feature_status->code ) {
312 + if ( 1 >= $feature_status->get_code() ) {
194 313 if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
195 314 $features_url = admin_url( 'network/admin.php?page=elasticpress' );
196 315 } else {
197 316 $features_url = admin_url( 'admin.php?page=elasticpress' );
@@ -198,11 +317,11 @@
198 317 }
199 318
200 319 $appended_message = wp_kses_post(
201 320 sprintf(
202 - /* translators: 1: <a> tag (Zendesk article); 2. </a>; 3: <a> tag (link to Features screen); 4. </a>; */
321 + /* translators: 1: <a> tag (Support article); 2. </a>; 3: <a> tag (link to Features screen); 4. </a>; */
203 322 __( '%1$sInstant Results%2$s is now available in ElasticPress, but requires a re-sync before activation. If you would like to use Instant Results, click %3$shere%4$s to activate the feature and start your sync.', 'elasticpress' ),
204 - '<a href="https://elasticpress.zendesk.com/hc/en-us/articles/360050447492#instant-results">',
323 + '<a href="https://www.elasticpress.io/resources/articles/configuring-elasticpress-via-the-plugin-dashboard/#instant-results">',
205 324 '</a>',
206 325 '<a href="' . $features_url . '">',
207 326 '</a>'
208 327 )
@@ -209,13 +328,13 @@
209 328 );
210 329 } else {
211 330 $appended_message = wp_kses_post(
212 331 sprintf(
213 - /* translators: 1: <a> tag (Zendesk article about Instant Results); 2. </a>; 3: <a> tag (Zendesk article about self hosted Elasticsearch setups); 4. </a>; */
332 + /* translators: 1: <a> tag (Support article about Instant Results); 2. </a>; 3: <a> tag (Support article about self hosted Elasticsearch setups); 4. </a>; */
214 333 __( '%1$sInstant Results%2$s is now available in ElasticPress, but requires a re-sync before activation. If you would like to use Instant Results, since you are not using ElasticPress.io, you will also need to %3$sinstall and configure a PHP proxy%4$s.', 'elasticpress' ),
215 - '<a href="https://elasticpress.zendesk.com/hc/en-us/articles/360050447492#instant-results">',
334 + '<a href="https://www.elasticpress.io/resources/articles/configuring-elasticpress-via-the-plugin-dashboard/#instant-results">',
216 335 '</a>',
217 - '<a href="https://elasticpress.zendesk.com/hc/en-us/articles/4413938931853-Considerations-for-self-hosted-Elasticsearch-setups">',
336 + '<a href="https://www.elasticpress.io/resources/articles/considerations-for-self-hosted-elasticsearch-setups/">',
218 337 '</a>'
219 338 )
220 339 );
221 340 }
@@ -232,13 +351,9 @@
232 351 if ( ! is_admin() || defined( 'DOING_AJAX' ) ) {
233 352 return;
234 353 }
235 354
236 - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
237 - $last_sync = get_site_option( 'ep_last_sync', 'never' );
238 - } else {
239 - $last_sync = get_option( 'ep_last_sync', 'never' );
240 - }
355 + $last_sync = Utils\get_option( 'ep_last_sync', 'never' );
241 356
242 357 // No need to upgrade since we've never synced.
243 358 if ( empty( $last_sync ) || 'never' === $last_sync ) {
244 359 return;
@@ -277,13 +392,9 @@
277 392 }
278 393 }
279 394
280 395 if ( $need_upgrade_sync ) {
281 - if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
282 - update_site_option( 'ep_need_upgrade_sync', true );
283 - } else {
284 - update_option( 'ep_need_upgrade_sync', true );
285 - }
396 + Utils\update_option( 'ep_need_upgrade_sync', true );
286 397 }
287 398 }
288 399
289 400 /**