Skip to:
Content

BuddyPress.org

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#5749 closed defect (bug) (fixed)

bp_blogs_record_existing_blogs() improvements

Reported by: johnjamesjacoby Owned by:
Milestone: 2.1 Priority: normal
Severity: normal Version:
Component: Blogs Keywords:
Cc:

Description (last modified by johnjamesjacoby)

A few separate issues I see here:

  • No limitations on the number of sites being recorded
  • bp_user_blogs is emptied, but not truncated, meaning auto-increment is never reset
  • We should probably truncate bp_user_blogmeta also, to ensure accurate data is populated
  • We delete all rows in the bp_user_blogs table and then potentially return before repopulating them

Change History (18)

#1 @johnjamesjacoby
5 years ago

  • Description modified (diff)
  • Summary changed from Blogmeta not removed when running bp_blogs_record_existing_blogs() to bp_blogs_record_existing_blogs() improvements

#2 @johnjamesjacoby
5 years ago

In 8584:

Check for wp_is_large_network() before looping through all blogs in the network, to prevent looping through thousands of sites on large networks. If you have this many sites, you should manage this in a queue or job system. See #5749.

#3 @johnjamesjacoby
5 years ago

  • Description modified (diff)

#4 @johnjamesjacoby
5 years ago

In 8585:

In bp_blogs_record_existing_blogs(), switch to using TRUNCATE rather than DELETE to reset the auto-increment value.

  • Move this truncation to after the empty( $blog_ids ) check, to avoid leaving the tables in a misaligned state.
  • Also truncate bp_user_blogmeta to ensure accurate data is recorded.

See #5749.

#5 @johnjamesjacoby
5 years ago

In 8586:

In bp_blogs_record_existing_blogs(), use $wpdb->blogid rather than hardcoded 1 as there is no guarantee what the current blog ID actually is, even on single-site installations. See #5749.

#6 @johnjamesjacoby
5 years ago

In 8587:

Clean-up some logic in bp_blogs_record_existing_blogs() for recording the user-to-blog relationship. See #5749.

#7 @johnjamesjacoby
5 years ago

In 8588:

Cast $users as array in bp_blogs_record_existing_blogs() to stay consistent with $blog_ids casting in the same function. See #5749.

#8 @johnjamesjacoby
5 years ago

In 8589:

Add return values to bp_blogs_record_existing_blogs() add use them in a new blog meta data recording repair tool. See #5749.

#9 @johnjamesjacoby
5 years ago

In 8592:

bp_blogs_record_existing_blogs() is too taxing of a routine to be called from inside bp_core_activation_notice() (which is responsible for notices beyond just activation) so remove it for now (and refactor a bit of the preceding logic too.)

We'll relocate this function call to a more appropriate location soon. See #5749.

#10 @boonebgorges
5 years ago

In 8594:

Ensure that blog paths are unique during blogs unit tests

WP's UnitTest_Generator_Sequence() tool is not working correctly here for some
reason.

See #5749

#11 @boonebgorges
5 years ago

In 8595:

Delete blogmeta cache after truncating blogmeta table in bp_blogs_record_existing_blog()

This ensures that no stale data is left in the persistent cache after being
removed manually from the database.

See #5749

#12 @johnjamesjacoby
5 years ago

In 8598:

Clean up bp_blogs_add_user_to_blog():

  • Compare user roles against get_editable_roles() so dynamic roles cannot be accidentally used.
  • Use array_shift() rather than array_search() to speed up comparison.
  • Add brackets and inline doc.

See #5749.

#13 @johnjamesjacoby
5 years ago

In 8599:

More clean up in bp_blogs_record_existing_blogs():

  • Do not touch the $bp global directly.
  • Remove user/subscriber intersection and use bp_blogs_add_user_to_blog() instead of bp_blogs_record_blog(). This reduces complexity and leans on a function purpose-built for doing this comparison rather than duplicating part of that logic.

See #5749.

#14 @johnjamesjacoby
5 years ago

In 8600:

In bp_blogs_add_user_to_blog0 call switch_to_blog() before running role comparisons to ensure roles for that blog are reinitialized correctly. See #5749.

#15 @johnjamesjacoby
5 years ago

In 8601:

Revert r8600 for now, likely until roles and caps get themselves a nice overhaul. See #5749.

#16 @DJPaul
5 years ago

r8598 is causing fatal errors when you register a new user account through /register when the blogs component is enabled (tested on non-ms):

Fatal error: Call to undefined function get_editable_roles() in /buddypress/src/bp-blogs/bp-blogs-functions.php on line 791

#17 @DJPaul
5 years ago

  • Resolution set to fixed
  • Status changed from new to closed

Fixed in r8741

#18 @johnjamesjacoby
5 years ago

In 8942:

Improvements to Blogs & capabilities:

  • Introduce bp_blogs_get_allowed_roles() to act as a blog-role whitelist
  • Introduce bp_get_current_blog_roles() to avoid including an admin-only file theme-side
  • Use these functions to clean-up the add_user_to_blog process in several ways:

More accurately match the member-to-blog relationship specification
No-subscriber users remains functionality intact
Allow extending of existing user-to-blog behavior

See #5749, #5819.

Note: See TracTickets for help on using tickets.