← All changes
|
src/actions/indexing/term-link-indexing-action.php
+25
-13
18.4.1
→
trunk
View file →
| @@ -6,10 +6,8 @@ | ||
| 6 | 6 | use Yoast\WP\SEO\Helpers\Taxonomy_Helper; |
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | 9 | * Reindexing action for term link indexables. |
| 10 | - * | |
| 11 | - * @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded | |
| 12 | 10 | */ |
| 13 | 11 | class Term_Link_Indexing_Action extends Abstract_Link_Indexing_Action { |
| 14 | 12 | |
| 15 | 13 | /** |
| @@ -16,9 +14,9 @@ | ||
| 16 | 14 | * The transient name. |
| 17 | 15 | * |
| 18 | 16 | * @var string |
| 19 | 17 | */ |
| 20 | - const UNINDEXED_COUNT_TRANSIENT = 'wpseo_unindexed_term_link_count'; | |
| 18 | + public const UNINDEXED_COUNT_TRANSIENT = 'wpseo_unindexed_term_link_count'; | |
| 21 | 19 | |
| 22 | 20 | /** |
| 23 | 21 | * The transient cache key for limited counts. |
| 24 | 22 | * |
| @@ -23,9 +21,9 @@ | ||
| 23 | 21 | * The transient cache key for limited counts. |
| 24 | 22 | * |
| 25 | 23 | * @var string |
| 26 | 24 | */ |
| 27 | - const UNINDEXED_LIMITED_COUNT_TRANSIENT = self::UNINDEXED_COUNT_TRANSIENT . '_limited'; | |
| 25 | + public const UNINDEXED_LIMITED_COUNT_TRANSIENT = self::UNINDEXED_COUNT_TRANSIENT . '_limited'; | |
| 28 | 26 | |
| 29 | 27 | /** |
| 30 | 28 | * The post type helper. |
| 31 | 29 | * |
| @@ -53,8 +51,12 @@ | ||
| 53 | 51 | */ |
| 54 | 52 | protected function get_objects() { |
| 55 | 53 | $query = $this->get_select_query( $this->get_limit() ); |
| 56 | 54 | |
| 55 | + if ( $query === '' ) { | |
| 56 | + return []; | |
| 57 | + } | |
| 58 | + | |
| 57 | 59 | // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Function get_select_query returns a prepared query. |
| 58 | 60 | $terms = $this->wpdb->get_results( $query ); |
| 59 | 61 | |
| 60 | 62 | return \array_map( |
| @@ -64,9 +66,9 @@ | ||
| 64 | 66 | 'type' => 'term', |
| 65 | 67 | 'content' => $term->description, |
| 66 | 68 | ]; |
| 67 | 69 | }, |
| 68 | - $terms | |
| 70 | + $terms, | |
| 69 | 71 | ); |
| 70 | 72 | } |
| 71 | 73 | |
| 72 | 74 | /** |
| @@ -74,12 +76,17 @@ | ||
| 74 | 76 | * |
| 75 | 77 | * @return string The prepared query string. |
| 76 | 78 | */ |
| 77 | 79 | protected function get_count_query() { |
| 78 | - $public_taxonomies = $this->taxonomy_helper->get_public_taxonomies(); | |
| 79 | - $placeholders = \implode( ', ', \array_fill( 0, \count( $public_taxonomies ), '%s' ) ); | |
| 80 | - $indexable_table = Model::get_table_name( 'Indexable' ); | |
| 80 | + $public_taxonomies = $this->taxonomy_helper->get_indexable_taxonomies(); | |
| 81 | 81 | |
| 82 | + if ( empty( $public_taxonomies ) ) { | |
| 83 | + return ''; | |
| 84 | + } | |
| 85 | + | |
| 86 | + $placeholders = \implode( ', ', \array_fill( 0, \count( $public_taxonomies ), '%s' ) ); | |
| 87 | + $indexable_table = Model::get_table_name( 'Indexable' ); | |
| 88 | + | |
| 82 | 89 | // Warning: If this query is changed, makes sure to update the query in get_select_query as well. |
| 83 | 90 | return $this->wpdb->prepare( |
| 84 | 91 | " |
| 85 | 92 | SELECT COUNT(T.term_id) |
| @@ -89,9 +96,9 @@ | ||
| 89 | 96 | AND I.object_type = 'term' |
| 90 | 97 | AND I.link_count IS NOT NULL |
| 91 | 98 | WHERE I.object_id IS NULL |
| 92 | 99 | AND T.taxonomy IN ($placeholders)", |
| 93 | - $public_taxonomies | |
| 100 | + $public_taxonomies, | |
| 94 | 101 | ); |
| 95 | 102 | } |
| 96 | 103 | |
| 97 | 104 | /** |
| @@ -101,12 +108,17 @@ | ||
| 101 | 108 | * |
| 102 | 109 | * @return string The prepared query string. |
| 103 | 110 | */ |
| 104 | 111 | protected function get_select_query( $limit = false ) { |
| 105 | - $public_taxonomies = $this->taxonomy_helper->get_public_taxonomies(); | |
| 106 | - $indexable_table = Model::get_table_name( 'Indexable' ); | |
| 107 | - $replacements = $public_taxonomies; | |
| 112 | + $public_taxonomies = $this->taxonomy_helper->get_indexable_taxonomies(); | |
| 108 | 113 | |
| 114 | + if ( empty( $public_taxonomies ) ) { | |
| 115 | + return ''; | |
| 116 | + } | |
| 117 | + | |
| 118 | + $indexable_table = Model::get_table_name( 'Indexable' ); | |
| 119 | + $replacements = $public_taxonomies; | |
| 120 | + | |
| 109 | 121 | $limit_query = ''; |
| 110 | 122 | if ( $limit ) { |
| 111 | 123 | $limit_query = 'LIMIT %d'; |
| 112 | 124 | $replacements[] = $limit; |
| @@ -123,8 +135,8 @@ | ||
| 123 | 135 | AND I.link_count IS NOT NULL |
| 124 | 136 | WHERE I.object_id IS NULL |
| 125 | 137 | AND T.taxonomy IN (" . \implode( ', ', \array_fill( 0, \count( $public_taxonomies ), '%s' ) ) . ") |
| 126 | 138 | $limit_query", |
| 127 | - $replacements | |
| 139 | + $replacements, | |
| 128 | 140 | ); |
| 129 | 141 | } |
| 130 | 142 | } |