Skip to content

Commit

Permalink
Merge pull request #62 from newfold-labs/add/PRESS0-1877
Browse files Browse the repository at this point in the history
Add/press0 1877
  • Loading branch information
ramyakrishnai authored Aug 20, 2024
2 parents 6cca658 + 48c90ef commit 853d4fa
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 6 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/brand-plugin-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Cypress Tests for Module Updates in Brand Plugin

on:
pull_request:
types: [opened, reopened, ready_for_review, synchronize]
branches:
- main
- trunk
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
cancel-in-progress: true

jobs:
setup:
name: Setup
runs-on: ubuntu-latest
outputs:
branch: ${{ steps.extract_branch.outputs.branch }}
steps:
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch

bluehost:
name: Bluehost Build and Test
needs: setup
uses: newfold-labs/workflows/.github/workflows/module-plugin-test.yml@main
with:
only-module-tests: true
module-repo: ${{ github.repository }}
module-branch: ${{ needs.setup.outputs.branch }}
plugin-repo: 'bluehost/bluehost-wordpress-plugin'
secrets: inherit

hostgator:
name: HostGator Build and Test
needs: setup
uses: newfold-labs/workflows/.github/workflows/module-plugin-test.yml@main
with:
only-module-tests: true
module-repo: ${{ github.repository }}
module-branch: ${{ needs.setup.outputs.branch }}
plugin-repo: 'newfold-labs/wp-plugin-hostgator'
secrets: inherit

crazydomains:
name: Crazy Domains Build and Test
needs: setup
uses: newfold-labs/workflows/.github/workflows/module-plugin-test.yml@main
with:
only-module-tests: true
module-repo: ${{ github.repository }}
module-branch: ${{ needs.setup.outputs.branch }}
plugin-repo: 'newfold-labs/wp-plugin-crazy-domains'
secrets: inherit
4 changes: 3 additions & 1 deletion bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ function () {
'callback' => function ( Container $container ) {

if ( ! defined( 'NFD_MIGRATION_MODULE_VERSION' ) ) {
define( 'NFD_MIGRATION_MODULE_VERSION', '1.0.9' );
define( 'NFD_MIGRATION_MODULE_VERSION', '1.0.10' );
}
$brand = $container->plugin()->id;
if ( 'atomic' === getContext( 'platform' ) ) {
$brand = 'bh-cloud';
}
define( 'NFD_MIGRATION_PLUGIN_URL', $container->plugin()->url );

defined( 'NFD_PROXY_ACCESS_WORKER' ) || define( 'NFD_PROXY_ACCESS_WORKER', 'https://hiive.cloud/workers/migration-token-proxy' );
defined( 'NFD_MIGRATION_PROXY_WORKER' ) || define( 'NFD_MIGRATION_PROXY_WORKER', 'https://migrate.bluehost.com' );

Expand Down
44 changes: 44 additions & 0 deletions includes/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ function ( $listeners ) {
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( 'pre_update_option_instawp_last_migration_details', array( $this, 'on_update_instawp_last_migration_details' ), 10, 1 );
if ( $container->plugin()->id === 'bluehost' ) {
add_action( 'load-import.php', array( $this, 'register_wp_migration_tool' ) ); // Adds WordPress Migration tool to imports list
add_action( 'admin_enqueue_scripts', array( $this, 'set_import_tools' ) );
}
}

/**
Expand Down Expand Up @@ -114,4 +118,44 @@ public function register_settings() {
);
}
}

/**
* Register WordPress Migration Tool to imports.
*/
public function register_wp_migration_tool() {
register_importer(
'site_migration_wordpress_importer',
__( 'WordPress Migration Tool', 'wp-module-migration' ),
__( 'Migrate an existing WordPress site to this WordPress instance. This tool will make a copy of an existing site and automatically import it into this WordPress instance <strong>This will overwrite all the content.</strong>', 'wp-module-migration' ),
array( $this, 'wordpress_migration_tool' )
);
}

/**
* Initiates the Migration service redirects it the instawp screen
*/
public function wordpress_migration_tool() {
$this->insta_service = new InstaMigrateService();
$response = $this->insta_service->install_instawp_connect();
if ( ! is_wp_error( $response ) ) {
wp_redirect( $response['redirect_url'] );
} else {
wp_safe_redirect( admin_url( 'import.php' ) );
}
die();
}

/**
* Changes the text WordPress to WordPress content in import page
*/
public function set_import_tools() {
\wp_enqueue_script( 'nfd_migration_tool', NFD_MIGRATION_PLUGIN_URL . 'vendor/newfold-labs/wp-module-migration/includes/import-tools-changes.js', array( 'jquery' ), '1.0', true );
wp_enqueue_style( 'nfd_migration_tool', NFD_MIGRATION_PLUGIN_URL . 'vendor/newfold-labs/wp-module-migration/includes/styles.css', array(), '1.0', 'all' );
$migration_data = array(
'migration_title' => __( 'Preparing your site', 'wp-module-migration' ),
'migration_description' => __( 'Please wait a few seconds while we get your new account ready to import your existing WordPress site.', 'wp-module-migration' ),
'wordpress_title' => __( 'WordPress Content', 'wp-module-migration' ),
);
wp_localize_script( 'nfd_migration_tool', 'migration', $migration_data );
}
}
18 changes: 16 additions & 2 deletions includes/Services/InstaMigrateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ class InstaMigrateService {
* @var $insta_api_key
*/
private $insta_api_key = '';

/**
* Retry count
*
* @var $count
*/
private $count = 0;

/**
* Set required api keys for insta to initiate the migration
*/
Expand Down Expand Up @@ -57,7 +65,7 @@ public function install_instawp_connect() {
}

// Connect the website with InstaWP server
if ( empty( Helper::get_api_key() ) ) {
if ( empty( Helper::get_api_key() ) || empty( Helper::get_connect_id() ) ) {
$api_key = Helper::get_api_key( false, $this->insta_api_key );
$connect_response = Helper::instawp_generate_api_key( $api_key );

Expand All @@ -73,7 +81,13 @@ public function install_instawp_connect() {
if ( function_exists( 'instawp' ) ) {
// Check if there is a connect ID
if ( empty( Helper::get_connect_id() ) ) {
return new \WP_Error( 'Bad request', esc_html__( 'Connect plugin is installed but no connect ID.' ), array( 'status' => 400 ) );
if ( $count < 2 ) {
$count++;
delete_option( 'instawp_api_options' );
self::install_instawp_connect();
} else {
return new \WP_Error( 'Bad request', esc_html__( 'Connect plugin is installed but no connect ID.' ), array( 'status' => 400 ) );
}
}

return array(
Expand Down
76 changes: 76 additions & 0 deletions includes/import-tools-changes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//Changes the text of the wordpress to wordpress content in import
const importer_titles = document.getElementsByClassName("importer-title");
if( importer_titles ){
[...importer_titles].forEach((val, index) => {
if( val?.outerText === 'WordPress'){
document.getElementsByClassName("importer-title")[index].innerText = migration.wordpress_title
}
})
}

// designs a modal for migration tool
const node = document.createElement("div");
node.innerHTML = `<div class='migrate-screen'>
<div class='nfd-migration-loading'><span class='nfd-migration-loader'></span><h2 class='nfd-migration-title'>${migration.migration_title}</h2></div>
${migration.migration_description}
</div>`;

node.style.position = "absolute";
node.style.top = "0";
node.style.bottom = "0";
node.style.right = "0";
node.style.left = "0";
node.style.backgroundColor = "#ffffff5e";
node.style.display = "none";
node.style.alignItems = "center";
node.style.justifyContent = "center";
node.setAttribute("id", "migration-progress-modal")

document.getElementById("wpbody-content").appendChild(node)

// load a pop up when user clicks on run importer for wordpress migration tool
document.querySelector('a[href*="import=site_migration_wordpress_importer"]')?.addEventListener('click', function(e) {
e.preventDefault();
document.getElementById("migration-progress-modal").style.display = "flex";

fetch(
nfdplugin.restApiUrl + "/newfold-migration/v1/migrate/connect&_locale=user",
{
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json',
'X-WP-Nonce': nfdplugin.restApiNonce,
},
}
)
.then((response) => response.json())
.then(res => {
fetch(
nfdplugin.restApiUrl + "/newfold-data/v1/events&_locale=user",
{
credentials: 'same-origin',
method: 'post',
headers: {
'Content-Type': 'application/json',
'X-WP-Nonce': nfdplugin.restApiNonce,
},
body: JSON.stringify({
action: "migration_initiated_tools",
category: "user_action",
data: {
page: window.location.href
}})
},
)
document.getElementById("migration-progress-modal").style.display = "none";
if(res?.success){
window.open(res?.data?.redirect_url, "_self")
}
// else{
// alert("please try again in sometime. Thanks!")
// }
})
.catch(err => console.error(err))

});

48 changes: 48 additions & 0 deletions includes/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
.migrate-screen{
box-shadow: 1px 2px 8px;
font-size: 15px;
display: flex;
flex-direction: column;
background-color: #fff;
padding: 24px 32px 32px 24px;
gap: 15px;
border-radius: 4px 0px 0px 0px;
margin-top: 1%;
max-width: max-content;
}

.nfd-migration-loading{
display: flex;
gap: 16px;
align-items: center;
}
.nfd-migration-title{
display: inline-block;
font-family: Open Sans;
font-size: 20px;
font-weight: 600;
line-height: 27.24px;
text-align: left;
}

.nfd-migration-loader {
display: inline-block;
border: 4px solid #949FB1;
border-radius: 50%;
border-top: 4px solid #0060F0;
width: 29px;
height: 28px;
-webkit-animation: spin 2s linear infinite; /* Safari */
animation: spin 2s linear infinite;
}

/* Safari */
@-webkit-keyframes spin {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(360deg); }
}

@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@newfold-labs/wp-module-migration",
"version": "1.0.9",
"version": "1.0.10",
"description": "",
"main": "build/index.js",
"scripts": {
Expand Down

0 comments on commit 853d4fa

Please sign in to comment.