| @@ -15,8 +15,9 @@ | ||
| 15 | 15 | use Yoast\WP\SEO\Actions\Indexing\Indexing_Prepare_Action; |
| 16 | 16 | use Yoast\WP\SEO\Actions\Indexing\Post_Link_Indexing_Action; |
| 17 | 17 | use Yoast\WP\SEO\Actions\Indexing\Term_Link_Indexing_Action; |
| 18 | 18 | use Yoast\WP\SEO\Conditionals\No_Conditionals; |
| 19 | +use Yoast\WP\SEO\Exceptions\Indexable\Indexing_Failed_Exception; | |
| 19 | 20 | use Yoast\WP\SEO\Helpers\Indexing_Helper; |
| 20 | 21 | use Yoast\WP\SEO\Helpers\Options_Helper; |
| 21 | 22 | use Yoast\WP\SEO\Main; |
| 22 | 23 | |
| @@ -33,9 +34,9 @@ | ||
| 33 | 34 | * The indexing complete route constant. |
| 34 | 35 | * |
| 35 | 36 | * @var string |
| 36 | 37 | */ |
| 37 | - const COMPLETE_ROUTE = 'indexing/complete'; | |
| 38 | + public const COMPLETE_ROUTE = 'indexing/complete'; | |
| 38 | 39 | |
| 39 | 40 | /** |
| 40 | 41 | * The full indexing complete route constant. |
| 41 | 42 | * |
| @@ -40,9 +41,9 @@ | ||
| 40 | 41 | * The full indexing complete route constant. |
| 41 | 42 | * |
| 42 | 43 | * @var string |
| 43 | 44 | */ |
| 44 | - const FULL_COMPLETE_ROUTE = Main::API_V1_NAMESPACE . '/' . self::COMPLETE_ROUTE; | |
| 45 | + public const FULL_COMPLETE_ROUTE = Main::API_V1_NAMESPACE . '/' . self::COMPLETE_ROUTE; | |
| 45 | 46 | |
| 46 | 47 | /** |
| 47 | 48 | * The indexables complete route constant. |
| 48 | 49 | * |
| @@ -47,9 +48,9 @@ | ||
| 47 | 48 | * The indexables complete route constant. |
| 48 | 49 | * |
| 49 | 50 | * @var string |
| 50 | 51 | */ |
| 51 | - const INDEXABLES_COMPLETE_ROUTE = 'indexing/indexables-complete'; | |
| 52 | + public const INDEXABLES_COMPLETE_ROUTE = 'indexing/indexables-complete'; | |
| 52 | 53 | |
| 53 | 54 | /** |
| 54 | 55 | * The full indexing complete route constant. |
| 55 | 56 | * |
| @@ -54,9 +55,9 @@ | ||
| 54 | 55 | * The full indexing complete route constant. |
| 55 | 56 | * |
| 56 | 57 | * @var string |
| 57 | 58 | */ |
| 58 | - const FULL_INDEXABLES_COMPLETE_ROUTE = Main::API_V1_NAMESPACE . '/' . self::INDEXABLES_COMPLETE_ROUTE; | |
| 59 | + public const FULL_INDEXABLES_COMPLETE_ROUTE = Main::API_V1_NAMESPACE . '/' . self::INDEXABLES_COMPLETE_ROUTE; | |
| 59 | 60 | |
| 60 | 61 | /** |
| 61 | 62 | * The indexing prepare route constant. |
| 62 | 63 | * |
| @@ -61,9 +62,9 @@ | ||
| 61 | 62 | * The indexing prepare route constant. |
| 62 | 63 | * |
| 63 | 64 | * @var string |
| 64 | 65 | */ |
| 65 | - const PREPARE_ROUTE = 'indexing/prepare'; | |
| 66 | + public const PREPARE_ROUTE = 'indexing/prepare'; | |
| 66 | 67 | |
| 67 | 68 | /** |
| 68 | 69 | * The full indexing prepare route constant. |
| 69 | 70 | * |
| @@ -68,9 +69,9 @@ | ||
| 68 | 69 | * The full indexing prepare route constant. |
| 69 | 70 | * |
| 70 | 71 | * @var string |
| 71 | 72 | */ |
| 72 | - const FULL_PREPARE_ROUTE = Main::API_V1_NAMESPACE . '/' . self::PREPARE_ROUTE; | |
| 73 | + public const FULL_PREPARE_ROUTE = Main::API_V1_NAMESPACE . '/' . self::PREPARE_ROUTE; | |
| 73 | 74 | |
| 74 | 75 | /** |
| 75 | 76 | * The posts route constant. |
| 76 | 77 | * |
| @@ -75,9 +76,9 @@ | ||
| 75 | 76 | * The posts route constant. |
| 76 | 77 | * |
| 77 | 78 | * @var string |
| 78 | 79 | */ |
| 79 | - const POSTS_ROUTE = 'indexing/posts'; | |
| 80 | + public const POSTS_ROUTE = 'indexing/posts'; | |
| 80 | 81 | |
| 81 | 82 | /** |
| 82 | 83 | * The full posts route constant. |
| 83 | 84 | * |
| @@ -82,9 +83,9 @@ | ||
| 82 | 83 | * The full posts route constant. |
| 83 | 84 | * |
| 84 | 85 | * @var string |
| 85 | 86 | */ |
| 86 | - const FULL_POSTS_ROUTE = Main::API_V1_NAMESPACE . '/' . self::POSTS_ROUTE; | |
| 87 | + public const FULL_POSTS_ROUTE = Main::API_V1_NAMESPACE . '/' . self::POSTS_ROUTE; | |
| 87 | 88 | |
| 88 | 89 | /** |
| 89 | 90 | * The terms route constant. |
| 90 | 91 | * |
| @@ -89,9 +90,9 @@ | ||
| 89 | 90 | * The terms route constant. |
| 90 | 91 | * |
| 91 | 92 | * @var string |
| 92 | 93 | */ |
| 93 | - const TERMS_ROUTE = 'indexing/terms'; | |
| 94 | + public const TERMS_ROUTE = 'indexing/terms'; | |
| 94 | 95 | |
| 95 | 96 | /** |
| 96 | 97 | * The full terms route constant. |
| 97 | 98 | * |
| @@ -96,9 +97,9 @@ | ||
| 96 | 97 | * The full terms route constant. |
| 97 | 98 | * |
| 98 | 99 | * @var string |
| 99 | 100 | */ |
| 100 | - const FULL_TERMS_ROUTE = Main::API_V1_NAMESPACE . '/' . self::TERMS_ROUTE; | |
| 101 | + public const FULL_TERMS_ROUTE = Main::API_V1_NAMESPACE . '/' . self::TERMS_ROUTE; | |
| 101 | 102 | |
| 102 | 103 | /** |
| 103 | 104 | * The terms route constant. |
| 104 | 105 | * |
| @@ -103,9 +104,9 @@ | ||
| 103 | 104 | * The terms route constant. |
| 104 | 105 | * |
| 105 | 106 | * @var string |
| 106 | 107 | */ |
| 107 | - const POST_TYPE_ARCHIVES_ROUTE = 'indexing/post-type-archives'; | |
| 108 | + public const POST_TYPE_ARCHIVES_ROUTE = 'indexing/post-type-archives'; | |
| 108 | 109 | |
| 109 | 110 | /** |
| 110 | 111 | * The full terms route constant. |
| 111 | 112 | * |
| @@ -110,9 +111,9 @@ | ||
| 110 | 111 | * The full terms route constant. |
| 111 | 112 | * |
| 112 | 113 | * @var string |
| 113 | 114 | */ |
| 114 | - const FULL_POST_TYPE_ARCHIVES_ROUTE = Main::API_V1_NAMESPACE . '/' . self::POST_TYPE_ARCHIVES_ROUTE; | |
| 115 | + public const FULL_POST_TYPE_ARCHIVES_ROUTE = Main::API_V1_NAMESPACE . '/' . self::POST_TYPE_ARCHIVES_ROUTE; | |
| 115 | 116 | |
| 116 | 117 | /** |
| 117 | 118 | * The general route constant. |
| 118 | 119 | * |
| @@ -117,9 +118,9 @@ | ||
| 117 | 118 | * The general route constant. |
| 118 | 119 | * |
| 119 | 120 | * @var string |
| 120 | 121 | */ |
| 121 | - const GENERAL_ROUTE = 'indexing/general'; | |
| 122 | + public const GENERAL_ROUTE = 'indexing/general'; | |
| 122 | 123 | |
| 123 | 124 | /** |
| 124 | 125 | * The full general route constant. |
| 125 | 126 | * |
| @@ -124,9 +125,9 @@ | ||
| 124 | 125 | * The full general route constant. |
| 125 | 126 | * |
| 126 | 127 | * @var string |
| 127 | 128 | */ |
| 128 | - const FULL_GENERAL_ROUTE = Main::API_V1_NAMESPACE . '/' . self::GENERAL_ROUTE; | |
| 129 | + public const FULL_GENERAL_ROUTE = Main::API_V1_NAMESPACE . '/' . self::GENERAL_ROUTE; | |
| 129 | 130 | |
| 130 | 131 | /** |
| 131 | 132 | * The posts route constant. |
| 132 | 133 | * |
| @@ -131,9 +132,9 @@ | ||
| 131 | 132 | * The posts route constant. |
| 132 | 133 | * |
| 133 | 134 | * @var string |
| 134 | 135 | */ |
| 135 | - const POST_LINKS_INDEXING_ROUTE = 'link-indexing/posts'; | |
| 136 | + public const POST_LINKS_INDEXING_ROUTE = 'link-indexing/posts'; | |
| 136 | 137 | |
| 137 | 138 | /** |
| 138 | 139 | * The full posts route constant. |
| 139 | 140 | * |
| @@ -138,9 +139,9 @@ | ||
| 138 | 139 | * The full posts route constant. |
| 139 | 140 | * |
| 140 | 141 | * @var string |
| 141 | 142 | */ |
| 142 | - const FULL_POST_LINKS_INDEXING_ROUTE = Main::API_V1_NAMESPACE . '/' . self::POST_LINKS_INDEXING_ROUTE; | |
| 143 | + public const FULL_POST_LINKS_INDEXING_ROUTE = Main::API_V1_NAMESPACE . '/' . self::POST_LINKS_INDEXING_ROUTE; | |
| 143 | 144 | |
| 144 | 145 | /** |
| 145 | 146 | * The terms route constant. |
| 146 | 147 | * |
| @@ -145,9 +146,9 @@ | ||
| 145 | 146 | * The terms route constant. |
| 146 | 147 | * |
| 147 | 148 | * @var string |
| 148 | 149 | */ |
| 149 | - const TERM_LINKS_INDEXING_ROUTE = 'link-indexing/terms'; | |
| 150 | + public const TERM_LINKS_INDEXING_ROUTE = 'link-indexing/terms'; | |
| 150 | 151 | |
| 151 | 152 | /** |
| 152 | 153 | * The full terms route constant. |
| 153 | 154 | * |
| @@ -152,9 +153,9 @@ | ||
| 152 | 153 | * The full terms route constant. |
| 153 | 154 | * |
| 154 | 155 | * @var string |
| 155 | 156 | */ |
| 156 | - const FULL_TERM_LINKS_INDEXING_ROUTE = Main::API_V1_NAMESPACE . '/' . self::TERM_LINKS_INDEXING_ROUTE; | |
| 157 | + public const FULL_TERM_LINKS_INDEXING_ROUTE = Main::API_V1_NAMESPACE . '/' . self::TERM_LINKS_INDEXING_ROUTE; | |
| 157 | 158 | |
| 158 | 159 | /** |
| 159 | 160 | * The post indexing action. |
| 160 | 161 | * |
| @@ -266,10 +267,8 @@ | ||
| 266 | 267 | $this->general_indexation_action = $general_indexation_action; |
| 267 | 268 | $this->indexable_indexing_complete_action = $indexable_indexing_complete_action; |
| 268 | 269 | $this->indexing_complete_action = $indexing_complete_action; |
| 269 | 270 | $this->prepare_indexing_action = $prepare_indexing_action; |
| 270 | - $this->post_link_indexing_action = $post_link_indexing_action; | |
| 271 | - $this->term_link_indexing_action = $term_link_indexing_action; | |
| 272 | 271 | $this->options_helper = $options_helper; |
| 273 | 272 | $this->post_link_indexing_action = $post_link_indexing_action; |
| 274 | 273 | $this->term_link_indexing_action = $term_link_indexing_action; |
| 275 | 274 | $this->indexing_helper = $indexing_helper; |
| @@ -276,8 +275,10 @@ | ||
| 276 | 275 | } |
| 277 | 276 | |
| 278 | 277 | /** |
| 279 | 278 | * Registers the routes used to index indexables. |
| 279 | + * | |
| 280 | + * @return void | |
| 280 | 281 | */ |
| 281 | 282 | public function register_routes() { |
| 282 | 283 | $route_args = [ |
| 283 | 284 | 'methods' => 'POST', |
| @@ -417,8 +418,22 @@ | ||
| 417 | 418 | */ |
| 418 | 419 | protected function run_indexation_action( Indexation_Action_Interface $indexation_action, $url ) { |
| 419 | 420 | try { |
| 420 | 421 | return parent::run_indexation_action( $indexation_action, $url ); |
| 422 | + } catch ( Indexing_Failed_Exception $exception ) { | |
| 423 | + $this->indexing_helper->indexing_failed(); | |
| 424 | + | |
| 425 | + $previous = $exception->getPrevious(); | |
| 426 | + | |
| 427 | + return new WP_Error( | |
| 428 | + 'wpseo_error_indexing', | |
| 429 | + $exception->getMessage(), | |
| 430 | + [ | |
| 431 | + 'stackTrace' => ( $previous !== null ) ? $previous->getTraceAsString() : $exception->getTraceAsString(), | |
| 432 | + 'object_id' => $exception->get_object_id(), | |
| 433 | + 'object_type' => $exception->get_object_type(), | |
| 434 | + ], | |
| 435 | + ); | |
| 421 | 436 | } catch ( Exception $exception ) { |
| 422 | 437 | $this->indexing_helper->indexing_failed(); |
| 423 | 438 | |
| 424 | 439 | return new WP_Error( |
| @@ -423,9 +438,9 @@ | ||
| 423 | 438 | |
| 424 | 439 | return new WP_Error( |
| 425 | 440 | 'wpseo_error_indexing', |
| 426 | 441 | $exception->getMessage(), |
| 427 | - [ 'stackTrace' => $exception->getTraceAsString() ] | |
| 442 | + [ 'stackTrace' => $exception->getTraceAsString() ], | |
| 428 | 443 | ); |
| 429 | 444 | } |
| 430 | 445 | } |
| 431 | 446 | } |