Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Press0 1202 #8

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading