| @@ -4,8 +4,9 @@ | ||
| 4 | 4 | |
| 5 | 5 | use Yoast\WP\Lib\Model; |
| 6 | 6 | use Yoast\WP\Lib\ORM; |
| 7 | 7 | use Yoast\WP\SEO\Builders\Indexable_Hierarchy_Builder; |
| 8 | +use Yoast\WP\SEO\Helpers\Indexable_Helper; | |
| 8 | 9 | use Yoast\WP\SEO\Models\Indexable; |
| 9 | 10 | |
| 10 | 11 | /** |
| 11 | 12 | * Class Indexable_Hierarchy_Repository. |
| @@ -19,13 +20,22 @@ | ||
| 19 | 20 | */ |
| 20 | 21 | protected $builder; |
| 21 | 22 | |
| 22 | 23 | /** |
| 24 | + * Represents the indexable helper. | |
| 25 | + * | |
| 26 | + * @var Indexable_Helper | |
| 27 | + */ | |
| 28 | + protected $indexable_helper; | |
| 29 | + | |
| 30 | + /** | |
| 23 | 31 | * Sets the hierarchy builder. |
| 24 | 32 | * |
| 25 | 33 | * @required |
| 26 | 34 | * |
| 27 | 35 | * @param Indexable_Hierarchy_Builder $builder The indexable hierarchy builder. |
| 36 | + * | |
| 37 | + * @return void | |
| 28 | 38 | */ |
| 29 | 39 | public function set_builder( Indexable_Hierarchy_Builder $builder ) { |
| 30 | 40 | $this->builder = $builder; |
| 31 | 41 | } |
| @@ -30,8 +40,21 @@ | ||
| 30 | 40 | $this->builder = $builder; |
| 31 | 41 | } |
| 32 | 42 | |
| 33 | 43 | /** |
| 44 | + * Sets the indexable helper. | |
| 45 | + * | |
| 46 | + * @required | |
| 47 | + * | |
| 48 | + * @param Indexable_Helper $indexable_helper The indexable helper. | |
| 49 | + * | |
| 50 | + * @return void | |
| 51 | + */ | |
| 52 | + public function set_helper( Indexable_Helper $indexable_helper ) { | |
| 53 | + $this->indexable_helper = $indexable_helper; | |
| 54 | + } | |
| 55 | + | |
| 56 | + /** | |
| 34 | 57 | * Removes all ancestors for an indexable. |
| 35 | 58 | * |
| 36 | 59 | * @param int $indexable_id The indexable id. |
| 37 | 60 | * |
| @@ -50,8 +73,12 @@ | ||
| 50 | 73 | * |
| 51 | 74 | * @return bool Whether or not the ancestor was added successfully. |
| 52 | 75 | */ |
| 53 | 76 | public function add_ancestor( $indexable_id, $ancestor_id, $depth ) { |
| 77 | + if ( ! $this->indexable_helper->should_index_indexables() ) { | |
| 78 | + return false; | |
| 79 | + } | |
| 80 | + | |
| 54 | 81 | $hierarchy = $this->query()->create( |
| 55 | 82 | [ |
| 56 | 83 | 'indexable_id' => $indexable_id, |
| 57 | 84 | 'ancestor_id' => $ancestor_id, |
| @@ -56,9 +83,9 @@ | ||
| 56 | 83 | 'indexable_id' => $indexable_id, |
| 57 | 84 | 'ancestor_id' => $ancestor_id, |
| 58 | 85 | 'depth' => $depth, |
| 59 | 86 | 'blog_id' => \get_current_blog_id(), |
| 60 | - ] | |
| 87 | + ], | |
| 61 | 88 | ); |
| 62 | 89 | |
| 63 | 90 | return $hierarchy->save(); |
| 64 | 91 | } |