bp_document_admin_repair_document()

Repair BuddyBoss document.

Description

Source

File: bp-document/bp-document-filters.php

function bp_document_admin_repair_document() {
	global $wpdb;
	$offset 	= isset( $_POST['offset'] ) ? (int) ( $_POST['offset'] ) : 0;
	$bp 		= buddypress();

	$document_query = "SELECT id, activity_id FROM {$bp->document->table_name} WHERE activity_id != 0 LIMIT 50 OFFSET $offset ";
	$documents 	= $wpdb->get_results( $document_query );

	if ( ! empty( $documents ) ) {
		foreach ( $documents as $document ) {
			if ( ! empty( $document->id ) && ! empty( $document->activity_id ) ) {
				$activity = new BP_Activity_Activity( $document->activity_id );
				if ( ! empty( $activity->id ) ) {
					if ( 'activity_comment' === $activity->type ) {
						$activity = new BP_Activity_Activity( $activity->item_id );
					}
					if ( bp_is_active( 'groups' ) && buddypress()->groups->id === $activity->component ) {
						$update_query = "UPDATE {$bp->document->table_name} SET group_id=" . $activity->item_id . ", privacy='grouponly' WHERE id=" . $document->id . " ";
						$wpdb->query( $update_query );
					}
					if ( 'document' === $activity->privacy ) {
						if ( ! empty( $activity->secondary_item_id ) ) {
							$document_activity = new BP_Activity_Activity( $activity->secondary_item_id );
							if ( ! empty( $document_activity->id ) ) {
								if ( 'activity_comment' === $document_activity->type ) {
									$document_activity = new BP_Activity_Activity( $document_activity->item_id );
								}
								if ( bp_is_active( 'groups' ) && buddypress()->groups->id === $document_activity->component ) {
									$update_query = "UPDATE {$bp->document->table_name} SET group_id=" . $document_activity->item_id . ", privacy='grouponly' WHERE id=" . $document->id . " ";
									$wpdb->query( $update_query );
									$activity->item_id   = $document_activity->item_id;
									$activity->component = buddypress()->groups->id;
								}
							}
						}

						$activity->hide_sitewide = true;
						$activity->save();
					}
				}
			}
			$offset ++;
		}
		$records_updated = sprintf( __( '%s document updated successfully.', 'buddyboss' ), number_format_i18n( $offset ) );

		return array(
				'status'  => 'running',
				'offset'  => $offset,
				'records' => $records_updated,
		);
	} else {
		return array(
				'status'  => 1,
				'message' => __( 'document update complete!', 'buddyboss' ),
		);
	}
}

Changelog

Changelog
Version Description
BuddyBoss 1.4.4 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.