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/IndexHelper.php +52 -34 5.0.15.3.5 View file →
@@ -6,9 +6,9 @@
6 6 * call, to respond to the AJAX request. That means this script will be called several times
7 7 * while syncing via dashboard, relying on the index_meta to pick it up where it stopped.
8 8 *
9 9 * @since 4.0.0
10 - * @see https://elasticpress.zendesk.com/hc/en-us/articles/16672117103501-Sync-Process
10 + * @see https://www.elasticpress.io/resources/articles/sync-process/
11 11 * @package elasticpress
12 12 */
13 13
14 14 namespace ElasticPress;
@@ -249,9 +249,9 @@
249 249 */
250 250 protected function filter_indexables( $indexables ) {
251 251 return array_filter(
252 252 $indexables,
253 - function( $indexable ) {
253 + function ( $indexable ) {
254 254 return empty( $this->args['indexables'] ) || in_array( $indexable, $this->args['indexables'], true );
255 255 }
256 256 );
257 257 }
@@ -571,9 +571,9 @@
571 571 $queued_items = [];
572 572
573 573 foreach ( $this->current_query['objects'] as $object ) {
574 574 if ( $this->should_skip_object_index( $object, $indexable ) ) {
575 - $this->index_meta['current_sync_item']['skipped']++;
575 + ++$this->index_meta['current_sync_item']['skipped'];
576 576 } else {
577 577 $queued_items[ $object->ID ] = true;
578 578 }
579 579 }
@@ -674,9 +674,9 @@
674 674 $failed_objects = array_merge(
675 675 $failed_objects,
676 676 array_filter(
677 677 $return['items'],
678 - function( $item ) {
678 + function ( $item ) {
679 679 return ! empty( $item['index']['error'] );
680 680 }
681 681 )
682 682 );
@@ -917,9 +917,9 @@
917 917 */
918 918 protected function add_last_sync( array $last_sync_info ) {
919 919 // Remove error messages from previous syncs - we only store msgs for the newest one.
920 920 $last_syncs = array_map(
921 - function( $sync ) {
921 + function ( $sync ) {
922 922 unset( $sync['errors'] );
923 923 return $sync;
924 924 },
925 925 $this->get_sync_history()
@@ -952,11 +952,12 @@
952 952 /**
953 953 * Fires after executing a reindex
954 954 *
955 955 * @since 4.0.0
956 + * @param array $args Sync arguments.
956 957 * @hook ep_after_sync_index
957 958 */
958 - do_action( 'ep_after_sync_index' );
959 + do_action( 'ep_after_sync_index', $this->args );
959 960
960 961 /**
961 962 * Fires after executing a reindex
962 963 *
@@ -1090,9 +1091,9 @@
1090 1091 return $error_text;
1091 1092 }
1092 1093
1093 1094 /**
1094 - * Utilitary function to check if the indexable is being fully reindexed, i.e.,
1095 + * Utility function to check if the indexable is being fully reindexed, i.e.,
1095 1096 * the index was deleted, a new mapping was sent and content is being reindexed.
1096 1097 *
1097 1098 * @param string $indexable_slug Indexable slug.
1098 1099 * @param int|null $blog_id Blog ID
@@ -1143,9 +1144,9 @@
1143 1144 *
1144 1145 * @since 5.0.0
1145 1146 * @return array
1146 1147 */
1147 - public function get_sync_history() : array {
1148 + public function get_sync_history(): array {
1148 1149 return Utils\get_option( 'ep_sync_history', [] );
1149 1150 }
1150 1151
1151 1152 /**
@@ -1153,9 +1154,9 @@
1153 1154 *
1154 1155 * @since 5.0.0
1155 1156 * @return array
1156 1157 */
1157 - public function get_last_sync() : array {
1158 + public function get_last_sync(): array {
1158 1159 $syncs = $this->get_sync_history();
1159 1160 if ( empty( $syncs ) ) {
1160 1161 return [];
1161 1162 }
@@ -1167,35 +1168,42 @@
1167 1168 *
1168 1169 * We used to have two different filters for this (one for the dashboard, another for CLI),
1169 1170 * this method combines both.
1170 1171 *
1171 - * @param {stdClass} $object Object to be checked
1172 + * @param {stdClass} $indexable_object Object to be checked
1172 1173 * @param {Indexable} $indexable Indexable
1173 1174 * @return boolean
1174 1175 */
1175 - protected function should_skip_object_index( $object, $indexable ) {
1176 + protected function should_skip_object_index( $indexable_object, $indexable ) {
1176 1177 /**
1177 1178 * Filter whether to not sync specific item in dashboard or not
1178 1179 *
1179 1180 * @since 2.1
1181 + * @deprecated 5.3.3 Use ep_{indexable_slug}_sync_kill instead
1180 1182 * @hook ep_item_sync_kill
1181 1183 * @param {boolean} $kill False means dont sync
1182 - * @param {array} $object Object to sync
1184 + * @param {array} $indexable_object Object to sync
1183 1185 * @return {Indexable} Indexable that object belongs to
1184 1186 */
1185 - $ep_item_sync_kill = apply_filters( 'ep_item_sync_kill', false, $object, $indexable );
1187 + $ep_item_sync_kill = apply_filters_deprecated(
1188 + 'ep_item_sync_kill',
1189 + [ false, $indexable_object, $indexable ],
1190 + 'ElasticPress 5.3.3',
1191 + 'ep_' . $indexable->slug . '_sync_kill'
1192 + );
1186 1193
1187 - /**
1188 - * Conditionally kill indexing for a post
1189 - *
1190 - * @hook ep_{indexable_slug}_index_kill
1191 - * @param {bool} $index True means dont index
1192 - * @param {int} $object_id Object ID
1193 - * @return {bool} New value
1194 - */
1195 - $ep_indexable_sync_kill = apply_filters( 'ep_' . $indexable->slug . '_index_kill', false, $object->ID );
1194 + /** This filter is documented in includes/classes/Indexable.php */
1195 + $ep_indexable_index_kill = apply_filters_deprecated(
1196 + 'ep_' . $indexable->slug . '_index_kill',
1197 + [ false, $indexable_object->ID ],
1198 + 'ElasticPress 5.3.3',
1199 + 'ep_' . $indexable->slug . '_sync_kill'
1200 + );
1196 1201
1197 - return $ep_item_sync_kill || $ep_indexable_sync_kill;
1202 + /** This filter is documented in includes/classes/Indexable.php */
1203 + $ep_indexable_sync_kill = apply_filters( 'ep_' . $indexable->slug . '_sync_kill', false, $indexable_object->ID );
1204 +
1205 + return $ep_item_sync_kill || $ep_indexable_sync_kill || $ep_indexable_index_kill;
1198 1206 }
1199 1207
1200 1208 /**
1201 1209 * Given an array, create a new sync item and add it to the stack.
@@ -1276,16 +1284,14 @@
1276 1284 * in-memory cache for persistent object caches
1277 1285 */
1278 1286 if ( function_exists( 'wp_cache_flush_runtime' ) ) {
1279 1287 wp_cache_flush_runtime();
1280 - } else {
1288 + } elseif ( ! wp_using_ext_object_cache() ) {
1281 1289 /*
1282 1290 * In the case where we're not using an external object cache, we need to call flush on the default
1283 1291 * WordPress object cache class to clear the values from the cache property
1284 1292 */
1285 - if ( ! wp_using_ext_object_cache() ) {
1286 - wp_cache_flush();
1287 - }
1293 + wp_cache_flush();
1288 1294 }
1289 1295
1290 1296 if ( is_object( $wp_object_cache ) ) {
1291 1297 $wp_object_cache->group_ops = [];
@@ -1326,9 +1332,9 @@
1326 1332 do_action( 'ep_stop_the_insanity' );
1327 1333 }
1328 1334
1329 1335 /**
1330 - * Utilitary function to delete the index meta option.
1336 + * Utility function to delete the index meta option.
1331 1337 *
1332 1338 * @since 4.0.0
1333 1339 */
1334 1340 public function clear_index_meta() {
@@ -1339,9 +1345,9 @@
1339 1345 Utils\delete_option( 'ep_index_meta', false );
1340 1346 }
1341 1347
1342 1348 /**
1343 - * Utilitary function to get the index meta option.
1349 + * Utility function to get the index meta option.
1344 1350 *
1345 1351 * @return array
1346 1352 * @since 4.0.0
1347 1353 */
@@ -1411,10 +1417,12 @@
1411 1417 /* translators: Error message */
1412 1418 esc_html__( 'Mapping failed: %s', 'elasticpress' ),
1413 1419 Utils\get_elasticsearch_error_reason( $error['message'] )
1414 1420 );
1415 - $message .= "\n";
1416 - $message .= esc_html__( 'Mapping has failed, which will cause ElasticPress search results to be incorrect. Please click `Delete all Data and Start a Fresh Sync` to retry mapping.', 'elasticpress' );
1421 + if ( $this->should_suggest_retry( $message ) ) {
1422 + $message .= "\n";
1423 + $message .= esc_html__( 'Mapping has failed, which will cause ElasticPress search results to be incorrect. Please click `Delete all Data and Start a Fresh Sync` to retry mapping.', 'elasticpress' );
1424 + }
1417 1425 break;
1418 1426 default:
1419 1427 /* translators: Error message */
1420 1428 $message = sprintf( esc_html__( 'Index failed: %s', 'elasticpress' ), $error['message'] );
@@ -1429,9 +1437,9 @@
1429 1437 *
1430 1438 * @since 4.4.0
1431 1439 * @return integer
1432 1440 */
1433 - public function get_index_default_per_page() : int {
1441 + public function get_index_default_per_page(): int {
1434 1442 /**
1435 1443 * Filter number of items to index per cycle in the dashboard
1436 1444 *
1437 1445 * @since 2.1
@@ -1489,9 +1497,9 @@
1489 1497 * @since 5.0.0
1490 1498 * @param string|array $messages Messages
1491 1499 * @return array
1492 1500 */
1493 - protected function build_message_errors_data( $messages ) : array {
1501 + protected function build_message_errors_data( $messages ): array {
1494 1502 $messages = (array) $messages;
1495 1503 $error_interpreter = new \ElasticPress\ElasticsearchErrorInterpreter();
1496 1504
1497 1505 $errors_list = [];
@@ -1503,9 +1511,9 @@
1503 1511 'solution' => $error['solution'],
1504 1512 'count' => 1,
1505 1513 ];
1506 1514 } else {
1507 - $errors_list[ $error['error'] ]['count']++;
1515 + ++$errors_list[ $error['error'] ]['count'];
1508 1516 }
1509 1517 }
1510 1518 return $errors_list;
1511 1519 }
@@ -1520,8 +1528,18 @@
1520 1528 return;
1521 1529 }
1522 1530
1523 1531 Features::factory()->apply_draft_feature_settings();
1532 + }
1533 +
1534 + /**
1535 + * Whether to suggest retrying the sync or not.
1536 + *
1537 + * @param string $message The message returned by the hosting server
1538 + * @return boolean
1539 + */
1540 + protected function should_suggest_retry( $message ) {
1541 + return ! preg_match( '/you have reached the limit of indices your plan supports/', $message );
1524 1542 }
1525 1543
1526 1544 /**
1527 1545 * Return singleton instance of class.