Skip to content

Commit

Permalink
Merge pull request #8 from newfold-labs/PRESS0-1202
Browse files Browse the repository at this point in the history
Press0 1202
  • Loading branch information
ramyakrishnai authored Apr 29, 2024
2 parents 7f97af5 + 74ca663 commit 13790e3
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
30 changes: 30 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, 1 );
add_action( 'pre_update_option_instawp_last_migration_details', array( $this, 'on_update_instawp_last_migration_details' ), 10, 1 );
}

Expand All @@ -63,6 +66,33 @@ public function on_update_nfd_migrate_site() {
$response = $this->insta_service->install_instawp_connect();
}

/**
* Updates showMigrationSteps option based on instawp_last_migration_details
*
* @param string $file path of plugin installed
*/
public function delete_plugin( $file ) {
$migrationDetails = (array) get_option( 'instawp_last_migration_details', array() );
$isMigrationCompleted = $migrationDetails['status'];
if ( 'instawp-connect/instawp-connect.php' === $file ) {
if ( 'completed' === $isMigrationCompleted ) {
$event = array(
'category' => 'wonder_start',
'action' => 'migration_completed',
'data' => array(),
);
EventService::send( $event );
} else {
$event = array(
'category' => 'wonder_start',
'action' => 'migration_failed',
'data' => array(),
);
EventService::send( $event );
}
}
}

/**
* Updates showMigrationSteps option based on instawp_last_migration_details
*
Expand Down
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\Migration\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;
}
}
1 change: 0 additions & 1 deletion includes/Services/InstaMigrateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public function install_instawp_connect() {
);
}
}

// Ready to start the migration
if ( function_exists( 'instawp' ) ) {
// Check if there is a connect ID
Expand Down

0 comments on commit 13790e3

Please sign in to comment.