Skip to content

Commit

Permalink
migration events
Browse files Browse the repository at this point in the history
  • Loading branch information
manikantakailasa committed Apr 24, 2024
1 parent 99437ce commit 9465eaa
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
27 changes: 27 additions & 0 deletions includes/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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 );
}

/**
Expand All @@ -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 );
}

}
}
}
30 changes: 30 additions & 0 deletions includes/Services/EventService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace NewfoldLabs\WP\Module\Onboarding\Services;

/**
* Class for handling analytics events.
*/
class EventService {

/**
* Sends a Hiive Event to the data module API.
*
* @param array $event The event to send.
* @return WP_REST_Response|WP_Error
*/
public static function send( $event ) {
$event_data_request = new \WP_REST_Request(
\WP_REST_Server::CREATABLE,
NFD_MODULE_DATA_EVENTS_API
);
$event_data_request->set_body_params( $event );

$response = rest_do_request( $event_data_request );
if ( $response->is_error() ) {
return $response->as_error();
}

return $response;
}
}
11 changes: 10 additions & 1 deletion includes/Services/InstaMigrateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use InstaWP\Connect\Helpers\Helper;
use InstaWP\Connect\Helpers\Installer;
use NewfoldLabs\WP\Module\Migration\Services\EventService;

/**
* Class InstaMigrateService
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9465eaa

Please sign in to comment.