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

Install and activate a list of plugins during migrations #2745

Merged
merged 16 commits into from
Jun 13, 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
2 changes: 1 addition & 1 deletion classes/class-wc-connect-service-settings-store.php
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ public function get_package_lookup() {

return $lookup;
}

public function is_eligible_for_migration() {
return false;
}
Expand Down
62 changes: 59 additions & 3 deletions client/components/migration/feature-announcement.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useState } from '@wordpress/element';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { localize } from 'i18n-calypso';
import { getNonce, getBaseURL } from 'api/request'; // client/api/request.js

/**
* Internal dependencies
Expand All @@ -30,9 +31,64 @@ const FeatureAnnouncement = ({ translate, isEligable }) => {
};

const update = () => {
// Todo: implement update
setIsUpdating(true);
setTimeout(() => setIsUpdating(false), 2000);
const plugins = 'woocommerce-shipping,woocommerce-tax'; //this needs to be a CSV string.
const headers = {
"Content-Type": "application/json",
'X-WP-Nonce': getNonce()
};

const installPluginAPICall = () =>
fetch( getBaseURL() + 'wc-admin/plugins/install', {
method: 'POST',
headers,
body: JSON.stringify({
plugins
})
} );

const activatePluginAPICall = () =>
fetch( getBaseURL() + 'wc-admin/plugins/activate', {
method: 'POST',
headers,
body: JSON.stringify({
plugins
})
} );

const deactivateWCSTPluginAPICall = () =>
fetch( getBaseURL() + 'wp/v2/plugins/woocommerce-services/woocommerce-services', {
method: 'POST',
headers,
body: JSON.stringify({
status: 'inactive'
})
} );


const installAndActivatePlugins = async() => {
const tasks = [installPluginAPICall, activatePluginAPICall, deactivateWCSTPluginAPICall];

try {
setIsUpdating(true);

for (const task of tasks) {
const apiResponse = await task();
const apiJSONResponse = await apiResponse.json();
if (task.status >= 400) {
throw new Error(apiJSONResponse.message || translate("Failed to setup WooCommerce Shipping. Please try again."));
}
}

window.location = global.wcsPluginData.adminPluginPath;
} catch (e) {
//TODO: error handling.
// console.log('Failed to install or activate.', e);
} finally {
setIsUpdating(false);
}
};

installAndActivatePlugins();
};

return <>{isOpen && (<Modal
Expand Down
1 change: 1 addition & 0 deletions woocommerce-services.php
Original file line number Diff line number Diff line change
Expand Up @@ -1475,6 +1475,7 @@ public function admin_enqueue_scripts() {
'wcsPluginData',
array(
'assetPath' => self::get_wc_connect_base_url(),
'adminPluginPath' => admin_url('plugins.php'),
)
);
}
Expand Down
Loading