From e977788110cde2f3a0a6f3704f15b5d5c821d773 Mon Sep 17 00:00:00 2001 From: kodinkat Date: Mon, 11 May 2026 14:25:43 +0100 Subject: [PATCH] Add activity log support to migration settings and import process - Introduced a new setting to include activity logs during export and import operations. - Updated the admin interface to allow users to enable or disable activity log inclusion. - Enhanced the import process to handle activity log rows, ensuring they are imported correctly when the setting is enabled. - Refactored related classes and methods to accommodate the new functionality, including adjustments to the REST API responses to include activity log counts. - Updated version number to 1.1 to reflect the addition of this feature. --- admin/admin-menu-and-tabs.php | 3 +- admin/class-dt-migration-import-ajax.php | 24 ++++ admin/class-dt-migration-tab-import.php | 115 +++++++++++++++++- admin/class-dt-migration-tab-settings.php | 16 +++ includes/class-dt-migration-export-file.php | 80 ++++++++++-- includes/class-dt-migration-import-engine.php | 111 +++++++++++++++-- rest-api/rest-api.php | 86 +++++++++++-- 7 files changed, 409 insertions(+), 26 deletions(-) diff --git a/admin/admin-menu-and-tabs.php b/admin/admin-menu-and-tabs.php index 7554b40..eaa028a 100644 --- a/admin/admin-menu-and-tabs.php +++ b/admin/admin-menu-and-tabs.php @@ -136,7 +136,8 @@ public static function get_post_type_label( string $post_type ): string { */ public static function get_settings(): array { $defaults = [ - 'enabled' => false, + 'enabled' => false, + 'include_activity_log' => false, // Legacy option; UI no longer exposes a single "mode". Capabilities API reports both channels. 'mode' => 'api', 'allowed_items' => [ diff --git a/admin/class-dt-migration-import-ajax.php b/admin/class-dt-migration-import-ajax.php index 4e910ba..d71d1ef 100644 --- a/admin/class-dt-migration-import-ajax.php +++ b/admin/class-dt-migration-import-ajax.php @@ -304,6 +304,18 @@ public function handle_import_batch() : void { $batch_result['errors'] = array_merge( $batch_result['errors'] ?? [], $pum_result['errors'] ); } + if ( ! empty( $settings['include_activity_log'] ) ) { + $activity_rows = $rbody['activity_log'] ?? []; + $act_result = Disciple_Tools_Migration_Import_Engine::import_activity_log_for_posts( + is_array( $activity_rows ) ? $activity_rows : [], + $batch_post_ids, + $post_type + ); + if ( ! empty( $act_result['errors'] ) ) { + $batch_result['errors'] = array_merge( $batch_result['errors'] ?? [], $act_result['errors'] ); + } + } + wp_send_json_success( [ 'done' => ! $has_more, 'phase' => 'records', @@ -486,6 +498,18 @@ private function handle_file_mode_batch( string $step, array $settings ) : void $batch_result['errors'] = array_merge( $batch_result['errors'] ?? [], $pum_result['errors'] ); } + if ( ! empty( $settings['include_activity_log'] ) ) { + $activity_rows = $payload['activity_log'][ $post_type ] ?? []; + $act_result = Disciple_Tools_Migration_Import_Engine::import_activity_log_for_posts( + is_array( $activity_rows ) ? $activity_rows : [], + $slice_post_ids, + $post_type + ); + if ( ! empty( $act_result['errors'] ) ) { + $batch_result['errors'] = array_merge( $batch_result['errors'] ?? [], $act_result['errors'] ); + } + } + wp_send_json_success( [ 'done' => ! $has_more, 'phase' => 'records', diff --git a/admin/class-dt-migration-tab-import.php b/admin/class-dt-migration-tab-import.php index edd6505..0a18c78 100644 --- a/admin/class-dt-migration-tab-import.php +++ b/admin/class-dt-migration-tab-import.php @@ -49,6 +49,13 @@ class Disciple_Tools_Migration_Tab_Import { */ private $import_preview_user_count = 0; + /** + * Whether the previewed export includes activity log rows (source package / Server A). + * + * @var bool + */ + private $import_preview_export_include_activity_log = false; + /** * Which import UI produced the current preview: 'api' or 'file'. * @@ -322,6 +329,7 @@ class="dt-migration-setting-checkbox" + render_import_preview_activity_settings_row(); ?> @@ -336,6 +344,7 @@ class="dt-migration-setting-checkbox" + @@ -360,12 +369,27 @@ class="dt-migration-record-checkbox" + + import_preview_export_include_activity_log ) { + $ac = isset( $record_data['activity_log_count'] ) ? (int) $record_data['activity_log_count'] : 0; + echo esc_html( number_format_i18n( $ac ) ); + } else { + echo ''; + } + ?> + + import_preview_export_include_activity_log && empty( $settings['include_activity_log'] ) ) : ?> +

+ +

+