Skip to content

Commit

Permalink
Merge pull request #1903 from Automattic/update/search_versioning_hoo…
Browse files Browse the repository at this point in the history
…k_on_init

Moves versioning hook from plugin_loaded to init
  • Loading branch information
nickdaugherty authored Dec 15, 2020
2 parents 211d7da + 0d2d169 commit 3e15d96
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
6 changes: 3 additions & 3 deletions search/includes/classes/class-versioning.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public function __construct() {
// the Queue to take over EP's queue, at which point we don't need to insert them here, as they are handled during Queue::queue_object())
add_filter( 'pre_ep_index_sync_queue', [ $this, 'filter__pre_ep_index_sync_queue' ], 100, 3 );

add_action( 'plugins_loaded', [ $this, 'action__plugins_loaded' ] );
add_action( 'init', [ $this, 'action__elasticpress_loaded' ] );
}

public function action__plugins_loaded() {
public function action__elasticpress_loaded() {
// Hook into the delete action of all known indexables, to replicate those deletes out to all inactive index versions
// NOTE - runs on plugins_loaded so Indexables are properly registered beforehand
// NOTE - runs on init as features including some indexables are registered after plugin loaded also on init hook
$all_indexables = \ElasticPress\Indexables::factory()->get_all();

foreach ( $all_indexables as $indexable ) {
Expand Down
15 changes: 8 additions & 7 deletions tests/search/includes/classes/test-class-versioning.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public static function setUpBeforeClass() {

// Required so that EP registers the Indexables
do_action( 'plugins_loaded' );
do_action( 'init' );

self::$version_instance = self::$search->versioning;
}
Expand Down Expand Up @@ -287,7 +288,7 @@ public function normalize_version_number_data() {
array(
// Input array of versions
array(
1 => array(
1 => array(
'number' => 1,
'active' => false,
),
Expand All @@ -312,7 +313,7 @@ public function normalize_version_number_data() {
array(
// Input array of versions
array(
1 => array(
1 => array(
'number' => 1,
'active' => false,
),
Expand All @@ -337,7 +338,7 @@ public function normalize_version_number_data() {
array(
// Input array of versions
array(
1 => array(
1 => array(
'number' => 1,
'active' => false,
),
Expand All @@ -362,7 +363,7 @@ public function normalize_version_number_data() {
array(
// Input array of versions
array(
1 => array(
1 => array(
'number' => 1,
'active' => false,
),
Expand Down Expand Up @@ -504,11 +505,11 @@ public function add_version_data() {
// Expected new versions
array(
2 => array(
'number' => 2,
'number' => 2,
'active' => false,
),
3 => array(
'number' => 3,
'number' => 3,
'active' => false,
),
),
Expand All @@ -521,7 +522,7 @@ public function add_version_data() {
'active' => true,
),
3 => array(
'number' => 3,
'number' => 3,
'active' => false,
),
),
Expand Down

0 comments on commit 3e15d96

Please sign in to comment.