Skip to content

Commit

Permalink
Merge pull request #2196 from edwinsiebel/feat/extendable-post-syncma…
Browse files Browse the repository at this point in the history
…nager

(chore): make post SyncManager extendable
  • Loading branch information
oscarssanchez authored Jun 7, 2021
2 parents 2a9ef32 + 1ad70cc commit 186fe21
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion includes/classes/Indexable.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ public function prepare_date_meta_values( $meta_types, $meta_value ) {

try {
// is this is a recognizable date format?
$new_date = new \DateTime( $meta_value, \wp_timezone() );
$new_date = new \DateTime( $meta_value, \wp_timezone() );
$timestamp = $new_date->getTimestamp();

// PHP allows DateTime to build dates with the non-existing year 0000, and this causes
Expand Down
18 changes: 13 additions & 5 deletions includes/classes/Indexable/Post/SyncManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
*/
class SyncManager extends SyncManagerAbstract {

/**
* Indexable slug
*
* @since 3.0
* @var string
*/
public $indexable_slug = 'post';

/**
* Setup actions and filters
*
Expand Down Expand Up @@ -90,7 +98,7 @@ public function action_queue_meta_sync( $meta_id, $object_id, $meta_key, $meta_v
return;
}

$indexable = Indexables::factory()->get( 'post' );
$indexable = Indexables::factory()->get( $this->indexable_slug );

$indexable_post_statuses = $indexable->get_indexable_post_status();
$post_type = get_post_type( $object_id );
Expand Down Expand Up @@ -156,7 +164,7 @@ public function action_delete_blog_from_index( $blog_id ) {
return;
}

$indexable = Indexables::factory()->get( 'post' );
$indexable = Indexables::factory()->get( $this->indexable_slug );

/**
* Filter to whether to keep index on site deletion
Expand Down Expand Up @@ -193,7 +201,7 @@ public function action_delete_post( $post_id ) {
return;
}

$indexable = Indexables::factory()->get( 'post' );
$indexable = Indexables::factory()->get( $this->indexable_slug );
$post_type = get_post_type( $post_id );

$indexable_post_types = $indexable->get_indexable_post_types();
Expand All @@ -211,7 +219,7 @@ public function action_delete_post( $post_id ) {
*/
do_action( 'ep_delete_post', $post_id );

Indexables::factory()->get( 'post' )->delete( $post_id, false );
Indexables::factory()->get( $this->indexable_slug )->delete( $post_id, false );

/**
* Make sure to reset sync queue in case an shutdown happens before a redirect
Expand All @@ -231,7 +239,7 @@ public function action_sync_on_update( $post_id ) {
return;
}

$indexable = Indexables::factory()->get( 'post' );
$indexable = Indexables::factory()->get( $this->indexable_slug );
$post_type = get_post_type( $post_id );

if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
Expand Down
2 changes: 1 addition & 1 deletion includes/mappings/post/5-0.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
'slug' => array(
'type' => 'keyword',
),
'facet' => array(
'facet' => array(
'type' => 'keyword',
),
'term_order' => array(
Expand Down
2 changes: 1 addition & 1 deletion includes/mappings/post/5-2.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
'slug' => array(
'type' => 'keyword',
),
'facet' => array(
'facet' => array(
'type' => 'keyword',
),
'term_order' => array(
Expand Down
2 changes: 1 addition & 1 deletion includes/mappings/post/7-0.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
'slug' => array(
'type' => 'keyword',
),
'facet' => array(
'facet' => array(
'type' => 'keyword',
),
'term_order' => array(
Expand Down
4 changes: 2 additions & 2 deletions includes/mappings/post/pre-5-0.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@
'type' => 'string',
'index' => 'not_analyzed',
),
'facet' => array(
'type' => 'string',
'facet' => array(
'type' => 'string',
'index' => 'not_analyzed',
),
'term_order' => array(
Expand Down

0 comments on commit 186fe21

Please sign in to comment.