udx / wp-stateless

WP-Stateless is a WordPress plugin that uploads and serves your WordPress media from Google Cloud Storage.
https://stateless.udx.io
MIT License
260 stars 64 forks source link

YOAST indexable-link-builder compatibility #574

Open donbowman opened 3 years ago

donbowman commented 3 years ago

You can see the below stack trace I get when updating a page w/ both wp-stateless and yoast (wordpress-seo) installed.

212#212: *238 FastCGI sent in stderr: "PHP message: PHP Warning:  filesize(): stat failed for gs://BUCKET/path/file.svg in /app/wp-content/plugins/wordpress-seo/src/builders/indexable-link-builder.php on line 287
PHP message: PHP Stack trace:PHP message: PHP   1. {main}() /app/index.php:0
PHP message: PHP   2. require() /app/index.php:17
PHP message: PHP   3. wp() /app/wp-blog-header.php:16
PHP message: PHP   4. WP->main() /app/wp-includes/functions.php:1285
PHP message: PHP   5. WP->parse_request() /app/wp-includes/class-wp.php:745
PHP message: PHP   6. do_action_ref_array() /app/wp-includes/class-wp.php:388
PHP message: PHP   7. WP_Hook->do_action() /app/wp-includes/plugin.php:544
PHP message: PHP   8. WP_Hook->apply_filters() /app/wp-includes/class-wp-hook.php:311
PHP message: PHP   9. rest_api_loaded() /app/wp-includes/class-wp-hook.php:287
PHP message: PHP  10. WP_REST_Server->serve_request() /app/wp-includes/rest-api.php:339
PHP message: PHP  11. WP_REST_Server->dispatch() /app/wp-includes/rest-api/class-wp-rest-server.php:376
PHP message: PHP  12. WP_REST_Posts_Controller->update_item() /app/wp-includes/rest-api/class-wp-rest-server.php:1050
PHP message: PHP  13. wp_update_post() /app/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:761
PHP message: PHP  14. wp_insert_post() /app/wp-includes/post.php:4354
PHP message: PHP  15. do_action() /app/wp-includes/post.php:4271
PHP message: PHP  16. WP_Hook->do_action() /app/wp-includes/plugin.php:478
PHP message: PHP  17. WP_Hook->apply_filters() /app/wp-includes/class-wp-hook.php:311
PHP message: PHP  18. YoastWPSEOIntegrationsWatchersIndexable_Post_Watcher->build_indexable() /app/wp-includes/class-wp-hook.php:289
PHP message: PHP  19. YoastWPSEOBuildersIndexable_Builder->build_for_id_and_type() /app/wp-content/plugins/wordpress-seo/src/integrations/watchers/indexable-post-watcher.php:216
PHP message: PHP  20. YoastWPSEOBuildersIndexable_Builder->save_indexable() /app/wp-content/plugins/wordpress-seo/src/builders/indexable-builder.php:193
PHP message: PHP  21. do_action() /app/wp-content/plugins/wordpress-seo/src/builders/indexable-builder.php:314
PHP message: PHP  22. WP_Hook->do_action() /app/wp-includes/plugin.php:478
PHP message: PHP  23. WP_Hook->apply_filters() /app/wp-includes/class-wp-hook.php:311
PHP message: PHP  24. YoastWPSEOIntegrationsWatchersIndexable_Post_Watcher->updated_indexable() /app/wp-includes/class-wp-hook.php:287
PHP message: PHP  25. YoastWPSEOBuildersIndexable_Link_Builder->build() /app/wp-content/plugins/wordpress-seo/src/integrations/watchers/indexable-post-watcher.php:170
PHP message: PHP  26. YoastWPSEOBuildersIndexable_Link_Builder->create_links() /app/wp-content/plugins/wordpress-seo/src/builders/indexable-link-builder.php:101
PHP message: PHP  27. array_map() /app/wp-content/plugins/wordpress-seo/src/builders/indexable-link-builder.php:209
PHP message: PHP  28. YoastWPSEOBuildersIndexable_Link_Builder->YoastWPSEOBuilders{closure:/app/wp-content/plugins/wordpress-seo/src/builders/indexable-link-builder.php:206-208}() /app/wp-content/plugins/wordpress-seo/src/builders/indexable-link-builder.php:209
PHP message: PHP  29. YoastWPSEOBuildersIndexable_Link_Builder->create_internal_link() /app/wp-content/plugins/wordpress-seo/src/builders/indexable-link-builder.php:207
PHP message: PHP  30. filesize() /app/wp-content/plugins/wordpress-seo/src/builders/indexable-link-builder.php:287" while reading response header from upstream, client: 10.16.3.4, server: _, request: "POST /wp-json/wp/v2/pages/117?_locale=user HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.4-fpm.sock:", host: "www.MYSITE.com", referrer: "https://www.MYSITE.com/" 

the affected code in yoast:

   285      protected function update_related_indexables( $indexable, $links ) {
   286          $updated_indexable_ids = [];
   287          $old_links             = $this->seo_links_repository->find_all_by_indexable_id( $indexable->id );
   288          $this->seo_links_repository->delete_all_by_indexable_id( $indexable->id );

   289          // Old links were only stored by post id, so remove this as well. This can be removed if we ever fully clear all seo links.
   290          if ( $indexable->object_type === 'post' ) {
   291              $this->seo_links_repository->delete_all_by_post_id( $indexable->object_id );
   292          }
ewsopp commented 3 years ago

@donbowman can you provide more detail here? What am I looking at above? What do you want it to do?

donbowman commented 3 years ago

Hi. sure.

I use wp-stateless, github. I talk about the why here https://www.agilicus.com/cloud-native-wordpress/ but the tldr:

I run my wordpress in kubernetes. I don't have shared storage. wp-stateless allows me to save all media to google cloud storage (GCS). Thus i can run >1 copy of wordpress simultaneously, load balanced.

I've been doing this for some time, it works quite well.

I also use YOAST (for obvious reasons!). Recently (not sure exactly when) it started giving this error.

The root of the error stat failed for gs://BUCKET/path/file.svg implies that yoast is assuming the file exists locally on the filesystem, it does not. So thus stat() does not work.

From there i'm not really sure. wp-stateless has a few compatibility things in it, i suppose I could look there as to what is missing. but it seems there is an assumption on the stat() here which is not true.