| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Yoast\WP\SEO\Builders; |
| 4 | 4 | |
| 5 | +use Yoast\WP\SEO\Helpers\Indexable_Helper; | |
| 5 | 6 | use Yoast\WP\SEO\Helpers\Meta_Helper; |
| 6 | 7 | use Yoast\WP\SEO\Helpers\Primary_Term_Helper; |
| 7 | 8 | use Yoast\WP\SEO\Repositories\Primary_Term_Repository; |
| 8 | 9 | |
| @@ -20,8 +21,15 @@ | ||
| 20 | 21 | */ |
| 21 | 22 | protected $repository; |
| 22 | 23 | |
| 23 | 24 | /** |
| 25 | + * The indexable helper. | |
| 26 | + * | |
| 27 | + * @var Indexable_Helper | |
| 28 | + */ | |
| 29 | + private $indexable_helper; | |
| 30 | + | |
| 31 | + /** | |
| 24 | 32 | * The primary term helper. |
| 25 | 33 | * |
| 26 | 34 | * @var Primary_Term_Helper |
| 27 | 35 | */ |
| @@ -36,20 +44,23 @@ | ||
| 36 | 44 | |
| 37 | 45 | /** |
| 38 | 46 | * Primary_Term_Builder constructor. |
| 39 | 47 | * |
| 40 | - * @param Primary_Term_Repository $repository The primary term repository. | |
| 41 | - * @param Primary_Term_Helper $primary_term The primary term helper. | |
| 42 | - * @param Meta_Helper $meta The meta helper. | |
| 48 | + * @param Primary_Term_Repository $repository The primary term repository. | |
| 49 | + * @param Indexable_Helper $indexable_helper The indexable helper. | |
| 50 | + * @param Primary_Term_Helper $primary_term The primary term helper. | |
| 51 | + * @param Meta_Helper $meta The meta helper. | |
| 43 | 52 | */ |
| 44 | 53 | public function __construct( |
| 45 | 54 | Primary_Term_Repository $repository, |
| 55 | + Indexable_Helper $indexable_helper, | |
| 46 | 56 | Primary_Term_Helper $primary_term, |
| 47 | 57 | Meta_Helper $meta |
| 48 | 58 | ) { |
| 49 | - $this->repository = $repository; | |
| 50 | - $this->primary_term = $primary_term; | |
| 51 | - $this->meta = $meta; | |
| 59 | + $this->repository = $repository; | |
| 60 | + $this->indexable_helper = $indexable_helper; | |
| 61 | + $this->primary_term = $primary_term; | |
| 62 | + $this->meta = $meta; | |
| 52 | 63 | } |
| 53 | 64 | |
| 54 | 65 | /** |
| 55 | 66 | * Formats and saves the primary terms for the post with the given post id. |
| @@ -74,23 +85,23 @@ | ||
| 74 | 85 | */ |
| 75 | 86 | protected function save_primary_term( $post_id, $taxonomy ) { |
| 76 | 87 | $term_id = $this->meta->get_value( 'primary_' . $taxonomy, $post_id ); |
| 77 | 88 | |
| 78 | - $term_selected = ! empty( $term_id ); | |
| 79 | - $primary_term = $this->repository->find_by_post_id_and_taxonomy( $post_id, $taxonomy, $term_selected ); | |
| 89 | + $term_selected = ! empty( $term_id ); | |
| 90 | + $primary_term_indexable = $this->repository->find_by_post_id_and_taxonomy( $post_id, $taxonomy, $term_selected ); | |
| 80 | 91 | |
| 81 | 92 | // Removes the indexable when no term found. |
| 82 | 93 | if ( ! $term_selected ) { |
| 83 | - if ( $primary_term ) { | |
| 84 | - $primary_term->delete(); | |
| 94 | + if ( $primary_term_indexable ) { | |
| 95 | + $primary_term_indexable->delete(); | |
| 85 | 96 | } |
| 86 | 97 | |
| 87 | 98 | return; |
| 88 | 99 | } |
| 89 | 100 | |
| 90 | - $primary_term->term_id = $term_id; | |
| 91 | - $primary_term->post_id = $post_id; | |
| 92 | - $primary_term->taxonomy = $taxonomy; | |
| 93 | - $primary_term->blog_id = \get_current_blog_id(); | |
| 94 | - $primary_term->save(); | |
| 101 | + $primary_term_indexable->term_id = $term_id; | |
| 102 | + $primary_term_indexable->post_id = $post_id; | |
| 103 | + $primary_term_indexable->taxonomy = $taxonomy; | |
| 104 | + $primary_term_indexable->blog_id = \get_current_blog_id(); | |
| 105 | + $this->indexable_helper->save_indexable( $primary_term_indexable ); | |
| 95 | 106 | } |
| 96 | 107 | } |