Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a DB Error when BP Blogs component is active on a regular WP #501

Merged
merged 2 commits into from
Apr 18, 2024

Conversation

imath
Copy link
Contributor

@imath imath commented Apr 16, 2024

Steps to reproduce the DB error:

  • Use a regular WP config (not Multisite)
  • Activate Activity component if not already active
  • Activate the Blogs component if not already active
  • Publish a new post (it should generate a new_blog_post activity
  • Go to buddypress/v1/activity?_embed=1

You should get the DB Error, I believe you can also get it trying to get the root blog using the corresponding endpoint.

I believe it’s only impacting the BP REST plugin as the Blogs REST Controller is only loaded when Multisite is active and a stable BuddyPress release is used. See https://github.com/buddypress/buddypress/blob/ef9fde9191b87a2f6a4027f2ecc75cfc1c616090/src/bp-blogs/classes/class-bp-blogs-component.php#L508

Request to achieve `buddypress/v1/activity?_embed=1` to reproduce the issue
@renatonascalves
Copy link
Member

🤔 I can't replicate this, btw. Tested on a fresh install with BP 12.4.0.

What's the DB error you see?

@renatonascalves
Copy link
Member

Actually, I forgot to add the _embed param. I see the right response, but also a rest_no_route error.

"No route was found matching the URL and request method."

@imath
Copy link
Contributor Author

imath commented Apr 16, 2024

Interesting 🧐.

First, if you use the 12.4.0 BP stable version, I'm not sure the BP REST plugin is used even if activated, I believe it's using the built REST endpoints of BuddyPress.

The fact a regular endpoint ends up having no route is very weird, have you customized the activity component ID?

If I've found the issue with the activity endpoint, I think you can more easily get it trying to reach any Blogs component endpoint making sure the component is active and BuddyPress is activated on a NON Multisite config. A regular WP.

This endpoint's goal is to list blogs, it shouldn't be loaded in regular configs because there's only one blog. The BP REST plugin unlike BuddyPress is loading it... The failing unit tests are proving it.

@renatonascalves
Copy link
Member

Give me a minute to test it again. I was not using the BP REST plugin.

@imath
Copy link
Contributor Author

imath commented Apr 16, 2024

Here's the error I get:

[16-Apr-2024 17:15:44 UTC] WordPress database error Table 'develop_buddypress.wp_blogs' doesn't exist for query 
			SELECT b.blog_id, b.user_id as admin_user_id, u.user_email as admin_user_email, wb.domain, wb.path, bm.meta_value as last_activity, bm_name.meta_value as name
			FROM
			  wp_bp_user_blogs b
			  LEFT JOIN wp_bp_user_blogs_blogmeta bm ON (b.blog_id = bm.blog_id)
			  LEFT JOIN wp_bp_user_blogs_blogmeta bm_name ON (b.blog_id = bm_name.blog_id)
			  LEFT JOIN wp_bp_user_blogs_blogmeta bm_description ON (b.blog_id = bm_description.blog_id)
			  LEFT JOIN wp_blogs wb ON (b.blog_id = wb.blog_id)
			  LEFT JOIN wp_users u ON (b.user_id = u.ID)
			WHERE
			  wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 
			  AND bm.meta_key = 'last_activity' AND bm_name.meta_key = 'name' AND bm_description.meta_key = 'description'
			     AND b.blog_id IN (1) 
			GROUP BY b.blog_id ORDER BY bm.meta_value DESC  LIMIT 0, 20
		 made by require_once('wp-admin/admin-header.php'), do_action('admin_enqueue_scripts'), WP_Hook->do_action, WP_Hook->apply_filters, bp_admin_enqueue_scripts, do_action('bp_admin_enqueue_scripts'), WP_Hook->do_action, WP_Hook->apply_filters, bp_activity_admin_enqueue_assets, array_reduce, rest_preload_api_request, WP_REST_Server->response_to_data, WP_REST_Server->embed_links, WP_REST_Server->dispatch, WP_REST_Server->respond_to_request, BP_REST_Blogs_Endpoint->get_item, BP_REST_Blogs_Endpoint->get_blog_object, bp_blogs_get_blogs, BP_Blogs_Blog::get

Copy link
Member

@renatonascalves renatonascalves left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed! Makes sense. We are trying to get a blog without having any available.

Fix looks good!

@imath imath merged commit 7297884 into buddypress:master Apr 18, 2024
8 checks passed
@imath imath deleted the fix/blogs-endpoint-db-error branch April 18, 2024 06:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants