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 +53 -36 5.0.05.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 );
@@ -821,8 +821,9 @@
821 821
822 822 $current_sync_item = $this->index_meta['current_sync_item'];
823 823
824 824 $this->index_meta['current_sync_item'] = null;
825 + $this->index_meta['offset'] = 0;
825 826
826 827 if ( $current_sync_item['failed'] ) {
827 828 if ( ! empty( $current_sync_item['blog_id'] ) && defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
828 829 $message = sprintf(
@@ -843,10 +844,8 @@
843 844
844 845 $this->output( $message, 'warning' );
845 846 }
846 847
847 - $this->index_meta['offset'] = 0;
848 -
849 848 if ( ! empty( $current_sync_item['blog_id'] ) && defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
850 849 $message = sprintf(
851 850 /* translators: 1: indexable (plural), 2: Blog ID, 3: number of synced objects */
852 851 esc_html__( 'Number of %1$s indexed on site %2$d: %3$d', 'elasticpress' ),
@@ -918,9 +917,9 @@
918 917 */
919 918 protected function add_last_sync( array $last_sync_info ) {
920 919 // Remove error messages from previous syncs - we only store msgs for the newest one.
921 920 $last_syncs = array_map(
922 - function( $sync ) {
921 + function ( $sync ) {
923 922 unset( $sync['errors'] );
924 923 return $sync;
925 924 },
926 925 $this->get_sync_history()
@@ -953,11 +952,12 @@
953 952 /**
954 953 * Fires after executing a reindex
955 954 *
956 955 * @since 4.0.0
956 + * @param array $args Sync arguments.
957 957 * @hook ep_after_sync_index
958 958 */
959 - do_action( 'ep_after_sync_index' );
959 + do_action( 'ep_after_sync_index', $this->args );
960 960
961 961 /**
962 962 * Fires after executing a reindex
963 963 *
@@ -1091,9 +1091,9 @@
1091 1091 return $error_text;
1092 1092 }
1093 1093
1094 1094 /**
1095 - * 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.,
1096 1096 * the index was deleted, a new mapping was sent and content is being reindexed.
1097 1097 *
1098 1098 * @param string $indexable_slug Indexable slug.
1099 1099 * @param int|null $blog_id Blog ID
@@ -1144,9 +1144,9 @@
1144 1144 *
1145 1145 * @since 5.0.0
1146 1146 * @return array
1147 1147 */
1148 - public function get_sync_history() : array {
1148 + public function get_sync_history(): array {
1149 1149 return Utils\get_option( 'ep_sync_history', [] );
1150 1150 }
1151 1151
1152 1152 /**
@@ -1154,9 +1154,9 @@
1154 1154 *
1155 1155 * @since 5.0.0
1156 1156 * @return array
1157 1157 */
1158 - public function get_last_sync() : array {
1158 + public function get_last_sync(): array {
1159 1159 $syncs = $this->get_sync_history();
1160 1160 if ( empty( $syncs ) ) {
1161 1161 return [];
1162 1162 }
@@ -1168,35 +1168,42 @@
1168 1168 *
1169 1169 * We used to have two different filters for this (one for the dashboard, another for CLI),
1170 1170 * this method combines both.
1171 1171 *
1172 - * @param {stdClass} $object Object to be checked
1172 + * @param {stdClass} $indexable_object Object to be checked
1173 1173 * @param {Indexable} $indexable Indexable
1174 1174 * @return boolean
1175 1175 */
1176 - protected function should_skip_object_index( $object, $indexable ) {
1176 + protected function should_skip_object_index( $indexable_object, $indexable ) {
1177 1177 /**
1178 1178 * Filter whether to not sync specific item in dashboard or not
1179 1179 *
1180 1180 * @since 2.1
1181 + * @deprecated 5.3.3 Use ep_{indexable_slug}_sync_kill instead
1181 1182 * @hook ep_item_sync_kill
1182 1183 * @param {boolean} $kill False means dont sync
1183 - * @param {array} $object Object to sync
1184 + * @param {array} $indexable_object Object to sync
1184 1185 * @return {Indexable} Indexable that object belongs to
1185 1186 */
1186 - $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 + );
1187 1193
1188 - /**
1189 - * Conditionally kill indexing for a post
1190 - *
1191 - * @hook ep_{indexable_slug}_index_kill
1192 - * @param {bool} $index True means dont index
1193 - * @param {int} $object_id Object ID
1194 - * @return {bool} New value
1195 - */
1196 - $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 + );
1197 1201
1198 - 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;
1199 1206 }
1200 1207
1201 1208 /**
1202 1209 * Given an array, create a new sync item and add it to the stack.
@@ -1277,16 +1284,14 @@
1277 1284 * in-memory cache for persistent object caches
1278 1285 */
1279 1286 if ( function_exists( 'wp_cache_flush_runtime' ) ) {
1280 1287 wp_cache_flush_runtime();
1281 - } else {
1288 + } elseif ( ! wp_using_ext_object_cache() ) {
1282 1289 /*
1283 1290 * In the case where we're not using an external object cache, we need to call flush on the default
1284 1291 * WordPress object cache class to clear the values from the cache property
1285 1292 */
1286 - if ( ! wp_using_ext_object_cache() ) {
1287 - wp_cache_flush();
1288 - }
1293 + wp_cache_flush();
1289 1294 }
1290 1295
1291 1296 if ( is_object( $wp_object_cache ) ) {
1292 1297 $wp_object_cache->group_ops = [];
@@ -1327,9 +1332,9 @@
1327 1332 do_action( 'ep_stop_the_insanity' );
1328 1333 }
1329 1334
1330 1335 /**
1331 - * Utilitary function to delete the index meta option.
1336 + * Utility function to delete the index meta option.
1332 1337 *
1333 1338 * @since 4.0.0
1334 1339 */
1335 1340 public function clear_index_meta() {
@@ -1340,9 +1345,9 @@
1340 1345 Utils\delete_option( 'ep_index_meta', false );
1341 1346 }
1342 1347
1343 1348 /**
1344 - * Utilitary function to get the index meta option.
1349 + * Utility function to get the index meta option.
1345 1350 *
1346 1351 * @return array
1347 1352 * @since 4.0.0
1348 1353 */
@@ -1412,10 +1417,12 @@
1412 1417 /* translators: Error message */
1413 1418 esc_html__( 'Mapping failed: %s', 'elasticpress' ),
1414 1419 Utils\get_elasticsearch_error_reason( $error['message'] )
1415 1420 );
1416 - $message .= "\n";
1417 - $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 + }
1418 1425 break;
1419 1426 default:
1420 1427 /* translators: Error message */
1421 1428 $message = sprintf( esc_html__( 'Index failed: %s', 'elasticpress' ), $error['message'] );
@@ -1430,9 +1437,9 @@
1430 1437 *
1431 1438 * @since 4.4.0
1432 1439 * @return integer
1433 1440 */
1434 - public function get_index_default_per_page() : int {
1441 + public function get_index_default_per_page(): int {
1435 1442 /**
1436 1443 * Filter number of items to index per cycle in the dashboard
1437 1444 *
1438 1445 * @since 2.1
@@ -1490,9 +1497,9 @@
1490 1497 * @since 5.0.0
1491 1498 * @param string|array $messages Messages
1492 1499 * @return array
1493 1500 */
1494 - protected function build_message_errors_data( $messages ) : array {
1501 + protected function build_message_errors_data( $messages ): array {
1495 1502 $messages = (array) $messages;
1496 1503 $error_interpreter = new \ElasticPress\ElasticsearchErrorInterpreter();
1497 1504
1498 1505 $errors_list = [];
@@ -1504,9 +1511,9 @@
1504 1511 'solution' => $error['solution'],
1505 1512 'count' => 1,
1506 1513 ];
1507 1514 } else {
1508 - $errors_list[ $error['error'] ]['count']++;
1515 + ++$errors_list[ $error['error'] ]['count'];
1509 1516 }
1510 1517 }
1511 1518 return $errors_list;
1512 1519 }
@@ -1521,8 +1528,18 @@
1521 1528 return;
1522 1529 }
1523 1530
1524 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 );
1525 1542 }
1526 1543
1527 1544 /**
1528 1545 * Return singleton instance of class.