| @@ -7,11 +7,10 @@ | ||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | namespace ElasticPress\Indexable\Term; |
| 10 | 10 | |
| 11 | -use ElasticPress\Indexables as Indexables; | |
| 12 | -use ElasticPress\Elasticsearch as Elasticsearch; | |
| 13 | -use ElasticPress\SyncManager as SyncManagerAbstract; | |
| 11 | +use ElasticPress\Elasticsearch; | |
| 12 | +use ElasticPress\Indexables; | |
| 14 | 13 | |
| 15 | 14 | if ( ! defined( 'ABSPATH' ) ) { |
| 16 | 15 | exit; // Exit if accessed directly. |
| 17 | 16 | } |
| @@ -18,9 +17,16 @@ | ||
| 18 | 17 | |
| 19 | 18 | /** |
| 20 | 19 | * Sync manager class |
| 21 | 20 | */ |
| 22 | -class SyncManager extends SyncManagerAbstract { | |
| 21 | +class SyncManager extends \ElasticPress\SyncManager { | |
| 22 | + /** | |
| 23 | + * Indexable slug | |
| 24 | + * | |
| 25 | + * @since 4.7.0 | |
| 26 | + * @var string | |
| 27 | + */ | |
| 28 | + public $indexable_slug = 'term'; | |
| 23 | 29 | |
| 24 | 30 | /** |
| 25 | 31 | * Setup actions and filters |
| 26 | 32 | * |
| @@ -42,8 +48,13 @@ | ||
| 42 | 48 | add_action( 'updated_term_meta', [ $this, 'action_queue_meta_sync' ], 10, 2 ); |
| 43 | 49 | add_action( 'pre_delete_term', [ $this, 'action_queue_children_sync' ] ); |
| 44 | 50 | add_action( 'pre_delete_term', [ $this, 'action_sync_on_delete' ] ); |
| 45 | 51 | add_action( 'set_object_terms', [ $this, 'action_sync_on_object_update' ], 10, 2 ); |
| 52 | + | |
| 53 | + // Clear index settings cache | |
| 54 | + add_action( 'ep_update_index_settings', [ $this, 'clear_index_settings_cache' ] ); | |
| 55 | + add_action( 'ep_after_put_mapping', [ $this, 'clear_index_settings_cache' ] ); | |
| 56 | + add_action( 'ep_saved_weighting_configuration', [ $this, 'clear_index_settings_cache' ] ); | |
| 46 | 57 | } |
| 47 | 58 | |
| 48 | 59 | /** |
| 49 | 60 | * Un-setup actions and filters (for multisite). |
| @@ -58,8 +69,13 @@ | ||
| 58 | 69 | remove_action( 'updated_term_meta', [ $this, 'action_queue_meta_sync' ] ); |
| 59 | 70 | remove_action( 'pre_delete_term', [ $this, 'action_queue_children_sync' ] ); |
| 60 | 71 | remove_action( 'pre_delete_term', [ $this, 'action_sync_on_delete' ] ); |
| 61 | 72 | remove_action( 'set_object_terms', [ $this, 'action_sync_on_object_update' ] ); |
| 73 | + | |
| 74 | + // Clear index settings cache | |
| 75 | + remove_action( 'ep_update_index_settings', [ $this, 'clear_index_settings_cache' ] ); | |
| 76 | + remove_action( 'ep_after_put_mapping', [ $this, 'clear_index_settings_cache' ] ); | |
| 77 | + remove_action( 'ep_saved_weighting_configuration', [ $this, 'clear_index_settings_cache' ] ); | |
| 62 | 78 | } |
| 63 | 79 | |
| 64 | 80 | /** |
| 65 | 81 | * Sync ES index with changes to the term being saved |
| @@ -81,9 +97,9 @@ | ||
| 81 | 97 | } |
| 82 | 98 | |
| 83 | 99 | do_action( 'ep_sync_term_on_transition', $term_id ); |
| 84 | 100 | |
| 85 | - $this->sync_queue[ $term_id ] = true; | |
| 101 | + $this->add_to_queue( $term_id ); | |
| 86 | 102 | |
| 87 | 103 | // Find all terms in the hierarchy so we resync those as well |
| 88 | 104 | $term = get_term( $term_id ); |
| 89 | 105 | $children = get_term_children( $term_id, $term->taxonomy ); |
| @@ -100,9 +116,9 @@ | ||
| 100 | 116 | } |
| 101 | 117 | |
| 102 | 118 | do_action( 'ep_sync_term_on_transition', $hierarchy_term_id ); |
| 103 | 119 | |
| 104 | - $this->sync_queue[ $hierarchy_term_id ] = true; | |
| 120 | + $this->add_to_queue( $hierarchy_term_id ); | |
| 105 | 121 | } |
| 106 | 122 | } |
| 107 | 123 | |
| 108 | 124 | /** |
| @@ -139,9 +155,9 @@ | ||
| 139 | 155 | } |
| 140 | 156 | |
| 141 | 157 | do_action( 'ep_sync_term_on_transition', $term->term_id ); |
| 142 | 158 | |
| 143 | - $this->sync_queue[ $term->term_id ] = true; | |
| 159 | + $this->add_to_queue( $term->term_id ); | |
| 144 | 160 | |
| 145 | 161 | // Find all terms in the hierarchy so we resync those as well |
| 146 | 162 | $children = get_term_children( $term->term_id, $term->taxonomy ); |
| 147 | 163 | $ancestors = get_ancestors( $term->term_id, $term->taxonomy, 'taxonomy' ); |
| @@ -157,9 +173,9 @@ | ||
| 157 | 173 | } |
| 158 | 174 | |
| 159 | 175 | do_action( 'ep_sync_term_on_transition', $hierarchy_term_id ); |
| 160 | 176 | |
| 161 | - $this->sync_queue[ $hierarchy_term_id ] = true; | |
| 177 | + $this->add_to_queue( $hierarchy_term_id ); | |
| 162 | 178 | } |
| 163 | 179 | } |
| 164 | 180 | } |
| 165 | 181 | |
| @@ -174,9 +190,9 @@ | ||
| 174 | 190 | if ( $this->kill_sync() ) { |
| 175 | 191 | return; |
| 176 | 192 | } |
| 177 | 193 | |
| 178 | - $this->sync_queue[ $term_id ] = true; | |
| 194 | + $this->add_to_queue( $term_id ); | |
| 179 | 195 | } |
| 180 | 196 | |
| 181 | 197 | /** |
| 182 | 198 | * Delete term from ES when deleted in WP |
| @@ -196,9 +212,9 @@ | ||
| 196 | 212 | Indexables::factory()->get( 'term' )->delete( $term_id, false ); |
| 197 | 213 | } |
| 198 | 214 | |
| 199 | 215 | /** |
| 200 | - * Enqueue sync of children terms in hierchy when deleting parent. Children terms will be reasigned to | |
| 216 | + * Enqueue sync of children terms in hierarchy when deleting parent. Children terms will be reasigned to | |
| 201 | 217 | * a different parent and we want to reflect that change in ElasticSearch |
| 202 | 218 | * |
| 203 | 219 | * @param int $term_id Term ID. |
| 204 | 220 | * @since 3.6.3 |
| @@ -224,9 +240,8 @@ | ||
| 224 | 240 | } |
| 225 | 241 | |
| 226 | 242 | do_action( 'ep_sync_term_on_transition', $hierarchy_term_id ); |
| 227 | 243 | |
| 228 | - $this->sync_queue[ $hierarchy_term_id ] = true; | |
| 244 | + $this->add_to_queue( $hierarchy_term_id ); | |
| 229 | 245 | } |
| 230 | 246 | } |
| 231 | - | |
| 232 | 247 | } |