← All changes
|
src/actions/indexing/indexable-term-indexation-action.php
+25
-17
18.2
→
trunk
View file →
| @@ -10,10 +10,8 @@ | ||
| 10 | 10 | use Yoast\WP\SEO\Values\Indexables\Indexable_Builder_Versions; |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | 13 | * Reindexing action for term indexables. |
| 14 | - * | |
| 15 | - * @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded | |
| 16 | 14 | */ |
| 17 | 15 | class Indexable_Term_Indexation_Action extends Abstract_Indexing_Action { |
| 18 | 16 | |
| 19 | 17 | /** |
| @@ -18,9 +16,9 @@ | ||
| 18 | 16 | |
| 19 | 17 | /** |
| 20 | 18 | * The transient cache key. |
| 21 | 19 | */ |
| 22 | - const UNINDEXED_COUNT_TRANSIENT = 'wpseo_total_unindexed_terms'; | |
| 20 | + public const UNINDEXED_COUNT_TRANSIENT = 'wpseo_total_unindexed_terms'; | |
| 23 | 21 | |
| 24 | 22 | /** |
| 25 | 23 | * The transient cache key for limited counts. |
| 26 | 24 | * |
| @@ -25,9 +23,9 @@ | ||
| 25 | 23 | * The transient cache key for limited counts. |
| 26 | 24 | * |
| 27 | 25 | * @var string |
| 28 | 26 | */ |
| 29 | - const UNINDEXED_LIMITED_COUNT_TRANSIENT = self::UNINDEXED_COUNT_TRANSIENT . '_limited'; | |
| 27 | + public const UNINDEXED_LIMITED_COUNT_TRANSIENT = self::UNINDEXED_COUNT_TRANSIENT . '_limited'; | |
| 30 | 28 | |
| 31 | 29 | /** |
| 32 | 30 | * The post type helper. |
| 33 | 31 | * |
| @@ -84,14 +82,14 @@ | ||
| 84 | 82 | public function index() { |
| 85 | 83 | $query = $this->get_select_query( $this->get_limit() ); |
| 86 | 84 | |
| 87 | 85 | // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Function get_select_query returns a prepared query. |
| 88 | - $term_ids = $this->wpdb->get_col( $query ); | |
| 86 | + $term_ids = ( $query === '' ) ? [] : $this->wpdb->get_col( $query ); | |
| 89 | 87 | |
| 90 | - $indexables = []; | |
| 91 | - foreach ( $term_ids as $term_id ) { | |
| 92 | - $indexables[] = $this->repository->find_by_id_and_type( (int) $term_id, 'term' ); | |
| 93 | - } | |
| 88 | + $indexables = $this->repository->find_by_multiple_ids_and_type( | |
| 89 | + \array_map( 'intval', $term_ids ), | |
| 90 | + 'term', | |
| 91 | + ); | |
| 94 | 92 | |
| 95 | 93 | if ( \count( $indexables ) > 0 ) { |
| 96 | 94 | \delete_transient( static::UNINDEXED_COUNT_TRANSIENT ); |
| 97 | 95 | \delete_transient( static::UNINDEXED_LIMITED_COUNT_TRANSIENT ); |
| @@ -108,9 +106,9 @@ | ||
| 108 | 106 | public function get_limit() { |
| 109 | 107 | /** |
| 110 | 108 | * Filter 'wpseo_term_indexation_limit' - Allow filtering the number of terms indexed during each indexing pass. |
| 111 | 109 | * |
| 112 | - * @api int The maximum number of terms indexed. | |
| 110 | + * @param int $limit The maximum number of terms indexed. | |
| 113 | 111 | */ |
| 114 | 112 | $limit = \apply_filters( 'wpseo_term_indexation_limit', 25 ); |
| 115 | 113 | |
| 116 | 114 | if ( ! \is_int( $limit ) || $limit < 1 ) { |
| @@ -125,11 +123,16 @@ | ||
| 125 | 123 | * |
| 126 | 124 | * @return string The prepared query string. |
| 127 | 125 | */ |
| 128 | 126 | protected function get_count_query() { |
| 129 | - $indexable_table = Model::get_table_name( 'Indexable' ); | |
| 130 | - $taxonomy_table = $this->wpdb->term_taxonomy; | |
| 131 | - $public_taxonomies = \array_keys( $this->taxonomy->get_public_taxonomies() ); | |
| 127 | + $indexable_table = Model::get_table_name( 'Indexable' ); | |
| 128 | + $taxonomy_table = $this->wpdb->term_taxonomy; | |
| 129 | + $public_taxonomies = $this->taxonomy->get_indexable_taxonomies(); | |
| 130 | + | |
| 131 | + if ( empty( $public_taxonomies ) ) { | |
| 132 | + return ''; | |
| 133 | + } | |
| 134 | + | |
| 132 | 135 | $taxonomies_placeholders = \implode( ', ', \array_fill( 0, \count( $public_taxonomies ), '%s' ) ); |
| 133 | 136 | |
| 134 | 137 | $replacements = [ $this->version ]; |
| 135 | 138 | \array_push( $replacements, ...$public_taxonomies ); |
| @@ -144,9 +147,9 @@ | ||
| 144 | 147 | AND I.object_type = 'term' |
| 145 | 148 | AND I.version = %d |
| 146 | 149 | WHERE I.object_id IS NULL |
| 147 | 150 | AND taxonomy IN ($taxonomies_placeholders)", |
| 148 | - $replacements | |
| 151 | + $replacements, | |
| 149 | 152 | ); |
| 150 | 153 | } |
| 151 | 154 | |
| 152 | 155 | /** |
| @@ -158,11 +161,16 @@ | ||
| 158 | 161 | */ |
| 159 | 162 | protected function get_select_query( $limit = false ) { |
| 160 | 163 | $indexable_table = Model::get_table_name( 'Indexable' ); |
| 161 | 164 | $taxonomy_table = $this->wpdb->term_taxonomy; |
| 162 | - $public_taxonomies = \array_keys( $this->taxonomy->get_public_taxonomies() ); | |
| 163 | - $placeholders = \implode( ', ', \array_fill( 0, \count( $public_taxonomies ), '%s' ) ); | |
| 165 | + $public_taxonomies = $this->taxonomy->get_indexable_taxonomies(); | |
| 164 | 166 | |
| 167 | + if ( empty( $public_taxonomies ) ) { | |
| 168 | + return ''; | |
| 169 | + } | |
| 170 | + | |
| 171 | + $placeholders = \implode( ', ', \array_fill( 0, \count( $public_taxonomies ), '%s' ) ); | |
| 172 | + | |
| 165 | 173 | $replacements = [ $this->version ]; |
| 166 | 174 | \array_push( $replacements, ...$public_taxonomies ); |
| 167 | 175 | |
| 168 | 176 | $limit_query = ''; |
| @@ -182,8 +190,8 @@ | ||
| 182 | 190 | AND I.version = %d |
| 183 | 191 | WHERE I.object_id IS NULL |
| 184 | 192 | AND taxonomy IN ($placeholders) |
| 185 | 193 | $limit_query", |
| 186 | - $replacements | |
| 194 | + $replacements, | |
| 187 | 195 | ); |
| 188 | 196 | } |
| 189 | 197 | } |