Skip to:
Content

Opened 22 months ago

Closed 5 months ago

Last modified 5 months ago

#1889 closed enhancement (fixed)

Option to delete imported users when performing 'Reset Forum'

Reported by: netweb Owned by: johnjamesjacoby
Milestone: 2.5 Priority: normal
Severity: normal Version: 2.0
Component: Importers Keywords: dev-feedback needs-testing
Cc: jared@…

Description

When you perform a 'Reset Forums' all forums/topics/replies are removed as is the importers conversion table (bbprc4_bbp_converter_translator), this leaves all imported users as standard WordPress users with all bbPress metadata removed from the user.

Because the conversion table is now gone you have no way to delete the imported users as there is no longer a record of what users were imported.

Thus when performing a 'Reset Forums' should there also be an option to also delete these users during this process to remove them whilst bbPress still knows something about these users?

I don't think this behavior should be forced as default as there would be use cases where you do want to actually keep all the users as standard WordPress users if you were to longer use bbPress for example but still wanted the users user/pass to stay in the system.

Attachments (2)

1889.diff (3.0 KB) - added by netweb 6 months ago.
1889.png (26.1 KB) - added by netweb 6 months ago.

Download all attachments as: .zip

Change History (20)

comment:1 netweb22 months ago

  • Type changed from defect to enhancement

comment:2 netweb22 months ago

  • Summary changed from Option to delete imported users when performing 'Rest Forum' to Option to delete imported users when performing 'Reset Forum'

comment:3 johnjamesjacoby22 months ago

  • Milestone changed from Awaiting Review to 2.2

comment:4 follow-up: jaredatch19 months ago

  • Cc jared@… added

This sounds pretty easy, is there some user meta data that can be used to only delete users that were imported (and not users that were created outside the importer)?

comment:5 in reply to: ↑ 4 johnjamesjacoby18 months ago

Replying to jaredatch:

This sounds pretty easy, is there some user meta data that can be used to only delete users that were imported (and not users that were created outside the importer)?

Could look for '_bbp_user_id' in usermeta.

comment:6 jaredatch17 months ago

Does anyone have an export I can use for testing so I don't have to manually add the usermeta?

comment:7 netweb17 months ago

Jared,

How about a SQL database of BuddyPress with Group Forums with some sample data?

That way you can re-run the import as often as you need to import users etc

comment:8 jaredatch16 months ago

Sure, I think that may work :)

comment:9 johnjamesjacoby16 months ago

  • Milestone changed from 2.3 to 2.4

Moving to 2.4 so we can focus on importers then. If an urgent/compelling patch comes in, we can sneak this in to 2.3.

comment:10 johnjamesjacoby11 months ago

  • Milestone changed from 2.4 to 2.5

No time. Moving to 2.5.

comment:11 netweb6 months ago

_bbp_user_id is wp_usermeta only exists if the user was imported and the code already exists in the importer when selecting 'Purge Previous Import' it 'should' remove imported users.
(I say should but for some reason it isn't at the moment, will create a ticket for this shortly)

http://bbpress.trac.wordpress.org/browser/trunk/includes/admin/converter.php#L1083

netweb6 months ago

netweb6 months ago

comment:12 netweb6 months ago

  • Keywords dev-feedback needs-testing added

In 1889.diff an option to delete imported users has been added to 'Reset Forums' (see 1889.png)

If the option IS checked any imported user with a wp_usermeta entry _bbp_user_id will be deleted from wp_users & wp_usermeta and cannot be undone.

If the option is NOT checked only bbPress meta properties (%_bbp_%) for that user will be removed from wp_usermeta

Optionally we could leave (or copy/rename the key) _bbp_user_id assigned to the user_id and this would allow 'Reset Forums' to be run subsequent times to delete imported users. Typically if an import fails and you want to start from scratch you would always delete the imported users. A use case for only resetting the forums without deleting the imported users I cannot think of off the top of my head.

comment:13 netweb5 months ago

If BuddyPress is activated user data in wp_bp_xprofile_data is not deleted as we delete users directly from _users & _usermeta using SQL DELETE FROM statements in 1889.diff.

Maybe include some if exists checks for BuddyPress after _usermeta is deleted:

$exists_bp_xprofile_data = $wpdb->prefix . 'wp_bp_xprofile_data';
if ( $wpdb->get_var( "SHOW TABLES LIKE '{$exists_bp_xprofile_data }'" ) === $exists_bp_xprofile_data ) {
 $sql_delete = "DELETE FROM `{$wpdb->wp_bp_xprofile_data}` WHERE `user_id` IN ('{$sql_meta}');";
 $result     = is_wp_error( $wpdb->query( $sql_delete ) ) ? $failed : $success;
 $messages[] = sprintf( $statement, $result );
}

comment:14 johnjamesjacoby5 months ago

That's an interesting problem with us doing direct queries. It's probably something BuddyPress should have built into itself eventually, and I'm fine not including BuddyPress specific direct queries in bbPress until then.

comment:15 netweb5 months ago

I have a PHP error in 1889.diff and I am not sure what or why

On line 1187 of the patch $sql_meta[] = $key; breaks the patch and I know it is something I am doing wrong, just what it is I do not know.

At this stage using the attached patch, if you check the box to delete the imported users it fails, click back in your browser and submit again and it works and deletes the imported users. :P

comment:16 johnjamesjacoby5 months ago

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

In 5173:

When resetting the forums back to pre-import status, allow admins to delete imported users. This handles the clean up of a potentially botched import, while also helping revert a site back to a pre-bbPress configuration. Fixes #1889. Props netweb.

comment:17 johnjamesjacoby5 months ago

In 5174:

If not deleting users, delete the imported user meta-data instead. See #1889. Props netweb.

comment:18 johnjamesjacoby5 months ago

In 5175:

Mass hysteria. See #1889.

Note: See TracTickets for help on using tickets.