| @@ -13,8 +13,9 @@ | ||
| 13 | 13 | use Yoast\WP\SEO\Actions\Indexing\Indexation_Action_Interface; |
| 14 | 14 | use Yoast\WP\SEO\Actions\Indexing\Indexing_Prepare_Action; |
| 15 | 15 | use Yoast\WP\SEO\Actions\Indexing\Post_Link_Indexing_Action; |
| 16 | 16 | use Yoast\WP\SEO\Actions\Indexing\Term_Link_Indexing_Action; |
| 17 | +use Yoast\WP\SEO\Exceptions\Indexable\Indexing_Failed_Exception; | |
| 17 | 18 | use Yoast\WP\SEO\Helpers\Indexable_Helper; |
| 18 | 19 | use Yoast\WP\SEO\Main; |
| 19 | 20 | |
| 20 | 21 | /** |
| @@ -162,10 +163,10 @@ | ||
| 162 | 163 | * wp yoast index |
| 163 | 164 | * |
| 164 | 165 | * @when after_wp_load |
| 165 | 166 | * |
| 166 | - * @param array|null $args The arguments. | |
| 167 | - * @param array|null $assoc_args The associative arguments. | |
| 167 | + * @param array<string>|null $args The arguments. | |
| 168 | + * @param array<string, string|bool>|null $assoc_args The associative arguments. | |
| 168 | 169 | * |
| 169 | 170 | * @return void |
| 170 | 171 | */ |
| 171 | 172 | public function index( $args = null, $assoc_args = null ) { |
| @@ -201,9 +202,9 @@ | ||
| 201 | 202 | |
| 202 | 203 | /** |
| 203 | 204 | * Runs all indexation actions. |
| 204 | 205 | * |
| 205 | - * @param array $assoc_args The associative arguments. | |
| 206 | + * @param array<string, string|bool> $assoc_args The associative arguments. | |
| 206 | 207 | * |
| 207 | 208 | * @return void |
| 208 | 209 | */ |
| 209 | 210 | protected function run_indexation_actions( $assoc_args ) { |
| @@ -257,10 +258,26 @@ | ||
| 257 | 258 | if ( $total > 0 ) { |
| 258 | 259 | $limit = $indexation_action->get_limit(); |
| 259 | 260 | $progress = Utils\make_progress_bar( 'Indexing ' . $name, $total ); |
| 260 | 261 | do { |
| 261 | - $indexables = $indexation_action->index(); | |
| 262 | - $count = \count( $indexables ); | |
| 262 | + try { | |
| 263 | + $indexables = $indexation_action->index(); | |
| 264 | + } catch ( Indexing_Failed_Exception $exception ) { | |
| 265 | + $progress->finish(); | |
| 266 | + | |
| 267 | + $previous = $exception->getPrevious(); | |
| 268 | + WP_CLI::error( | |
| 269 | + \sprintf( | |
| 270 | + 'Could not optimize %1$s while indexing %2$s: %3$s', | |
| 271 | + $exception->get_object_description(), | |
| 272 | + $name, | |
| 273 | + ( $previous !== null ) ? $previous->getMessage() : $exception->getMessage(), | |
| 274 | + ), | |
| 275 | + ); | |
| 276 | + | |
| 277 | + return; | |
| 278 | + } | |
| 279 | + $count = \count( $indexables ); | |
| 263 | 280 | $progress->tick( $count ); |
| 264 | 281 | \usleep( $interval ); |
| 265 | 282 | Utils\wp_clear_object_cache(); |
| 266 | 283 | } while ( $count >= $limit ); |