From 9465eaa5c79b128ca87ea35ed61d63c8644e4f31 Mon Sep 17 00:00:00 2001 From: manikantakailasa Date: Wed, 24 Apr 2024 17:20:27 +0530 Subject: [PATCH 1/2] migration events --- includes/Migration.php | 27 ++++++++++++++++++++ includes/Services/EventService.php | 30 +++++++++++++++++++++++ includes/Services/InstaMigrateService.php | 11 ++++++++- 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 includes/Services/EventService.php diff --git a/includes/Migration.php b/includes/Migration.php index dfe0caa..6312023 100644 --- a/includes/Migration.php +++ b/includes/Migration.php @@ -3,6 +3,8 @@ use NewfoldLabs\WP\ModuleLoader\Container; use NewfoldLabs\WP\Module\Migration\Services\InstaMigrateService; +use NewfoldLabs\WP\Module\Migration\Services\EventService; + /** * Class Migration * @@ -43,6 +45,7 @@ public function __construct( Container $container ) { add_action( 'rest_api_init', array( $this, 'register_routes' ) ); add_action( 'pre_update_option_nfd_migrate_site', array( $this, 'on_update_nfd_migrate_site' ) ); + add_action( 'deleted_plugin', array( $this, 'delete_plugin' ), 10, 2 ); } /** @@ -61,4 +64,28 @@ public function register_routes() { public function on_update_nfd_migrate_site() { $response = $this->insta_service->install_instawp_connect(); } + + public function delete_plugin( $file, $deleted ) { + $migrationDetails = (array) get_option( 'instawp_last_migration_details', array() ); + $isMigrationCompleted = $migrationDetails['status']; + if ( 'instawp-connect/instawp-connect.php' === $file ) { + if ( $isMigrationCompleted === 'completed') + { + $event = [ + "category" => "wonder_start", + "action" => "migration_completed", + "data" => [] + ]; + EventService::send( $event ); + } else { + $event = [ + "category" => "wonder_start", + "action" => "migration_failed", + "data" => [] + ]; + EventService::send( $event ); + } + + } + } } diff --git a/includes/Services/EventService.php b/includes/Services/EventService.php new file mode 100644 index 0000000..5c46e22 --- /dev/null +++ b/includes/Services/EventService.php @@ -0,0 +1,30 @@ +set_body_params( $event ); + + $response = rest_do_request( $event_data_request ); + if ( $response->is_error() ) { + return $response->as_error(); + } + + return $response; + } +} diff --git a/includes/Services/InstaMigrateService.php b/includes/Services/InstaMigrateService.php index 694ddff..b46a3a2 100644 --- a/includes/Services/InstaMigrateService.php +++ b/includes/Services/InstaMigrateService.php @@ -3,6 +3,7 @@ use InstaWP\Connect\Helpers\Helper; use InstaWP\Connect\Helpers\Installer; +use NewfoldLabs\WP\Module\Migration\Services\EventService; /** * Class InstaMigrateService @@ -56,7 +57,15 @@ public function install_instawp_connect() { ); } } - + $currentURL = $_SERVER['REQUEST_URI']; + $event = [ + "category" => "wonder_start", + "action" => "migration_initiated", + "data" => [ + "page"=> $currentURL + ] + ]; + EventService::send( $event ); // Ready to start the migration if ( function_exists( 'instawp' ) ) { // Check if there is a connect ID From e1fb8fc3710342e6da6b5c777b2ef235fee20023 Mon Sep 17 00:00:00 2001 From: manikantakailasa Date: Mon, 29 Apr 2024 12:26:13 +0530 Subject: [PATCH 2/2] event update --- includes/Services/InstaMigrateService.php | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/includes/Services/InstaMigrateService.php b/includes/Services/InstaMigrateService.php index b46a3a2..b60dcf1 100644 --- a/includes/Services/InstaMigrateService.php +++ b/includes/Services/InstaMigrateService.php @@ -3,7 +3,6 @@ use InstaWP\Connect\Helpers\Helper; use InstaWP\Connect\Helpers\Installer; -use NewfoldLabs\WP\Module\Migration\Services\EventService; /** * Class InstaMigrateService @@ -57,15 +56,7 @@ public function install_instawp_connect() { ); } } - $currentURL = $_SERVER['REQUEST_URI']; - $event = [ - "category" => "wonder_start", - "action" => "migration_initiated", - "data" => [ - "page"=> $currentURL - ] - ]; - EventService::send( $event ); + // Ready to start the migration if ( function_exists( 'instawp' ) ) { // Check if there is a connect ID