Add beta tester tool to force the coming soon landing pages to display on the front-end (#49341)
* Add tool to force the coming soon landing pages to display on the front-end * Add changelog * Revert line change * Add doc comments and remove unnecessary check * Invalidate caches * Fix tools invalid json errors * Set default value * Call wc_beta_tester_override_coming_soon_options out of init
This commit is contained in:
parent
b8fcc56e43
commit
8d23ac11a9
|
@ -53,12 +53,13 @@ require 'tools/delete-all-products.php';
|
|||
require 'tools/disable-wc-email.php';
|
||||
require 'tools/trigger-update-callbacks.php';
|
||||
require 'tools/reset-cys.php';
|
||||
require 'tools/set-block-template-logging-threshold.php';
|
||||
require 'tools/set-coming-soon-mode.php';
|
||||
require 'tracks/class-tracks-debug-log.php';
|
||||
require 'features/features.php';
|
||||
require 'rest-api-filters/class-wca-test-helper-rest-api-filters.php';
|
||||
require 'rest-api-filters/hook.php';
|
||||
require 'live-branches/manifest.php';
|
||||
require 'live-branches/install.php';
|
||||
require 'tools/set-block-template-logging-threshold.php';
|
||||
require 'remote-spec-validator/class-wca-test-helper-remote-spec-validator.php';
|
||||
require 'remote-inbox-notifications/class-wca-test-helper-remote-inbox-notifications.php';
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
use Automattic\WooCommerce\Internal\ComingSoon\ComingSoonCacheInvalidator;
|
||||
|
||||
register_woocommerce_admin_test_helper_rest_route(
|
||||
'/tools/update-coming-soon-mode/v1',
|
||||
'tools_set_coming_soon_mode',
|
||||
array(
|
||||
'methods' => 'POST',
|
||||
'args' => array(
|
||||
'mode' => array(
|
||||
'description' => 'Coming soon mode',
|
||||
'type' => 'enum',
|
||||
'enum' => array( 'site', 'store', 'disabled' ),
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
register_woocommerce_admin_test_helper_rest_route(
|
||||
'/tools/get-force-coming-soon-mode/v1',
|
||||
'tools_get_coming_soon_mode',
|
||||
array(
|
||||
'methods' => 'GET',
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* A tool to set the coming soon mode.
|
||||
*
|
||||
* @param WP_REST_Request $request Request object.
|
||||
*/
|
||||
function tools_set_coming_soon_mode( $request ) {
|
||||
$mode = $request->get_param( 'mode' );
|
||||
|
||||
update_option( 'wc_admin_test_helper_force_coming_soon_mode', $mode );
|
||||
|
||||
wc_get_container()->get( ComingSoonCacheInvalidator::class )->invalidate_caches();
|
||||
|
||||
return new WP_REST_Response( $mode, 200 );
|
||||
}
|
||||
|
||||
/**
|
||||
* A tool to get the coming soon mode.
|
||||
*/
|
||||
function tools_get_coming_soon_mode() {
|
||||
$mode = get_option( 'wc_admin_test_helper_force_coming_soon_mode', 'disabled' );
|
||||
|
||||
return new WP_REST_Response( $mode, 200 );
|
||||
}
|
|
@ -48,7 +48,7 @@ function trigger_selected_update_callbacks( $request ) {
|
|||
$update_callbacks = $db_updates[ $version ];
|
||||
|
||||
foreach ( $update_callbacks as $update_callback ) {
|
||||
call_user_func( $update_callback );
|
||||
\WC_Install::run_update_callback( $update_callback );
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
Significance: minor
|
||||
Type: add
|
||||
|
||||
Add tool to force the coming soon landing pages to display on the front-end
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
/**
|
||||
* Override the coming soon options.
|
||||
|
||||
* @package WC_Beta_Tester
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* WC_Beta_Tester Override Coming Soon Options Class.
|
||||
*/
|
||||
class WC_Beta_Tester_Override_Coming_Soon_Options {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->wc_beta_tester_override_coming_soon_options();
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the coming soon options.
|
||||
*/
|
||||
public function wc_beta_tester_override_coming_soon_options() {
|
||||
$mode = get_option( 'wc_admin_test_helper_force_coming_soon_mode', 'disabled' );
|
||||
|
||||
if ( 'disabled' === $mode ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$is_request_frontend = ( ! is_admin() || defined( 'DOING_AJAX' ) )
|
||||
&& ! defined( 'DOING_CRON' ) && ! WC()->is_rest_api_request();
|
||||
if ( ! $is_request_frontend ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->override_woocommerce_coming_soon_option( $mode );
|
||||
$this->override_woocommerce_store_pages_only_option( $mode );
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the woocommerce_coming_soon option.
|
||||
*
|
||||
* @param string $mode The coming soon mode.
|
||||
*/
|
||||
private function override_woocommerce_coming_soon_option( $mode ) {
|
||||
add_filter(
|
||||
'option_woocommerce_coming_soon',
|
||||
function ( $value ) use ( $mode ) {
|
||||
if ( 'site' === $mode || 'store' === $mode ) {
|
||||
return 'yes';
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the woocommerce_store_pages_only option.
|
||||
*
|
||||
* @param string $mode The coming soon mode.
|
||||
*/
|
||||
private function override_woocommerce_store_pages_only_option( $mode ) {
|
||||
add_filter(
|
||||
'option_woocommerce_store_pages_only',
|
||||
function ( $value ) use ( $mode ) {
|
||||
if ( 'store' === $mode ) {
|
||||
return 'yes';
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
new WC_Beta_Tester_Override_Coming_Soon_Options();
|
|
@ -26,3 +26,4 @@ add_filter( 'woocommerce_admin_get_feature_config', function( $feature_config )
|
|||
}
|
||||
return $feature_config;
|
||||
} );
|
||||
|
||||
|
|
|
@ -11,6 +11,10 @@ import {
|
|||
TriggerUpdateCallbacks,
|
||||
TRIGGER_UPDATE_CALLBACKS_ACTION_NAME,
|
||||
} from './trigger-update-callbacks';
|
||||
import {
|
||||
SetComingSoonMode,
|
||||
UPDATE_COMING_SOON_MODE_ACTION_NAME,
|
||||
} from './set-coming-soon-mode';
|
||||
|
||||
export default [
|
||||
{
|
||||
|
@ -78,4 +82,9 @@ export default [
|
|||
description: <UpdateBlockTemplateLoggingThreshold />,
|
||||
action: UPDATE_BLOCK_TEMPLATE_LOGGING_THRESHOLD_ACTION_NAME,
|
||||
},
|
||||
{
|
||||
command: 'Force coming soon page to show',
|
||||
description: <SetComingSoonMode />,
|
||||
action: UPDATE_COMING_SOON_MODE_ACTION_NAME,
|
||||
},
|
||||
];
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
import { SelectControl } from '@wordpress/components';
|
||||
import { useDispatch, useSelect } from '@wordpress/data';
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import { STORE_KEY } from '../data/constants';
|
||||
|
||||
export const UPDATE_COMING_SOON_MODE_ACTION_NAME = 'updateComingSoonMode';
|
||||
|
||||
const OPTIONS = [
|
||||
{ label: 'Whole Site', value: 'site' },
|
||||
{ label: 'Store Only', value: 'store' },
|
||||
{ label: 'Disabled', value: 'disabled' },
|
||||
];
|
||||
|
||||
export const SetComingSoonMode = () => {
|
||||
const comingSoonMode = useSelect(
|
||||
( select ) => select( STORE_KEY ).getComingSoonMode(),
|
||||
[]
|
||||
);
|
||||
const { updateCommandParams } = useDispatch( STORE_KEY );
|
||||
|
||||
function onChange( mode ) {
|
||||
updateCommandParams( UPDATE_COMING_SOON_MODE_ACTION_NAME, {
|
||||
mode,
|
||||
} );
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="select-description">
|
||||
{ ! comingSoonMode ? (
|
||||
<p>Loading ...</p>
|
||||
) : (
|
||||
<SelectControl
|
||||
label="Mode"
|
||||
labelPosition="side"
|
||||
value={ comingSoonMode }
|
||||
onChange={ onChange }
|
||||
options={ OPTIONS }
|
||||
/>
|
||||
) }
|
||||
</div>
|
||||
);
|
||||
};
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
import { SelectControl } from '@wordpress/components';
|
||||
import { useDispatch, useSelect } from '@wordpress/data';
|
||||
import { useMemo } from '@wordpress/element';
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
|
@ -13,26 +14,33 @@ export const TRIGGER_UPDATE_CALLBACKS_ACTION_NAME =
|
|||
'runSelectedUpdateCallbacks';
|
||||
|
||||
export const TriggerUpdateCallbacks = () => {
|
||||
const { dbUpdateVersions } = useSelect( ( select ) => {
|
||||
const { getDBUpdateVersions } = select( STORE_KEY );
|
||||
return {
|
||||
dbUpdateVersions: getDBUpdateVersions(),
|
||||
};
|
||||
} );
|
||||
|
||||
const dbUpdateVersions = useSelect(
|
||||
( select ) => select( STORE_KEY ).getDBUpdateVersions(),
|
||||
[]
|
||||
);
|
||||
const selectedVersion = useSelect(
|
||||
( select ) =>
|
||||
select( STORE_KEY ).getCommandParams(
|
||||
TRIGGER_UPDATE_CALLBACKS_ACTION_NAME
|
||||
).runSelectedUpdateCallbacks.version,
|
||||
[]
|
||||
);
|
||||
const { updateCommandParams } = useDispatch( STORE_KEY );
|
||||
|
||||
function onCronChange( version ) {
|
||||
function onChange( version ) {
|
||||
updateCommandParams( TRIGGER_UPDATE_CALLBACKS_ACTION_NAME, {
|
||||
version,
|
||||
} );
|
||||
}
|
||||
|
||||
function getOptions() {
|
||||
return dbUpdateVersions.map( ( version ) => {
|
||||
return { label: version, value: version };
|
||||
} );
|
||||
}
|
||||
const options = useMemo(
|
||||
() =>
|
||||
dbUpdateVersions.map( ( version ) => ( {
|
||||
label: version,
|
||||
value: version,
|
||||
} ) ),
|
||||
[ dbUpdateVersions ]
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="select-description">
|
||||
|
@ -41,9 +49,10 @@ export const TriggerUpdateCallbacks = () => {
|
|||
) : (
|
||||
<SelectControl
|
||||
label="Select a version to run"
|
||||
onChange={ onCronChange }
|
||||
onChange={ onChange }
|
||||
labelPosition="side"
|
||||
options={ getOptions().reverse() }
|
||||
options={ options }
|
||||
value={ selectedVersion }
|
||||
/>
|
||||
) }
|
||||
</div>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
*/
|
||||
|
||||
import { SelectControl } from '@wordpress/components';
|
||||
import { useEffect, useState } from '@wordpress/element';
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore no types
|
||||
// eslint-disable-next-line @woocommerce/dependency-group
|
||||
|
@ -35,7 +34,6 @@ export const UpdateBlockTemplateLoggingThreshold = () => {
|
|||
|
||||
const retrievedLoggingLevels = getLoggingLevels();
|
||||
const retrievedThreshold = getBlockTemplateLoggingThreshold();
|
||||
|
||||
return {
|
||||
loggingLevels: retrievedLoggingLevels,
|
||||
threshold: retrievedThreshold,
|
||||
|
@ -44,12 +42,9 @@ export const UpdateBlockTemplateLoggingThreshold = () => {
|
|||
}
|
||||
);
|
||||
|
||||
const [ newThreshold, setNewThreshold ] = useState( threshold );
|
||||
|
||||
const { updateCommandParams } = useDispatch( STORE_KEY );
|
||||
|
||||
function onThresholdChange( selectedThreshold: string ) {
|
||||
setNewThreshold( selectedThreshold );
|
||||
updateCommandParams(
|
||||
UPDATE_BLOCK_TEMPLATE_LOGGING_THRESHOLD_ACTION_NAME,
|
||||
{
|
||||
|
@ -67,10 +62,6 @@ export const UpdateBlockTemplateLoggingThreshold = () => {
|
|||
} );
|
||||
}
|
||||
|
||||
useEffect( () => {
|
||||
setNewThreshold( threshold );
|
||||
}, [ threshold ] );
|
||||
|
||||
return (
|
||||
<div className="select-description">
|
||||
{ isLoading ? (
|
||||
|
@ -83,7 +74,7 @@ export const UpdateBlockTemplateLoggingThreshold = () => {
|
|||
// @ts-ignore labelPosition prop exists
|
||||
labelPosition="side"
|
||||
options={ getOptions() }
|
||||
value={ newThreshold }
|
||||
value={ threshold }
|
||||
/>
|
||||
) }
|
||||
</div>
|
||||
|
|
|
@ -9,10 +9,9 @@ const TYPES = {
|
|||
IS_EMAIL_DISABLED: 'IS_EMAIL_DISABLED',
|
||||
SET_DB_UPDATE_VERSIONS: 'SET_DB_UPDATE_VERSIONS',
|
||||
SET_LOGGING_LEVELS: 'SET_LOGGING_LEVELS',
|
||||
SET_BLOCK_TEMPLATE_LOGGING_THRESHOLD:
|
||||
'SET_BLOCK_TEMPLATE_LOGGING_THRESHOLD',
|
||||
UPDATE_BLOCK_TEMPLATE_LOGGING_THRESHOLD:
|
||||
'UPDATE_BLOCK_TEMPLATE_LOGGING_THRESHOLD',
|
||||
UPDATE_COMING_SOON_MODE: 'UPDATE_COMING_SOON_MODE',
|
||||
};
|
||||
|
||||
export default TYPES;
|
||||
|
|
|
@ -262,3 +262,13 @@ export function* updateBlockTemplateLoggingThreshold( params ) {
|
|||
} );
|
||||
} );
|
||||
}
|
||||
|
||||
export function* updateComingSoonMode( params ) {
|
||||
yield runCommand( 'Update coming soon mode', function* () {
|
||||
yield apiFetch( {
|
||||
path: API_NAMESPACE + '/tools/update-coming-soon-mode/v1',
|
||||
method: 'POST',
|
||||
data: params,
|
||||
} );
|
||||
} );
|
||||
}
|
||||
|
|
|
@ -9,11 +9,14 @@ const DEFAULT_STATE = {
|
|||
cronJobs: false,
|
||||
isEmailDisabled: '',
|
||||
messages: {},
|
||||
params: [],
|
||||
params: {
|
||||
updateComingSoonMode: {},
|
||||
updateBlockTemplateLoggingThreshold: {},
|
||||
runSelectedUpdateCallbacks: {},
|
||||
},
|
||||
status: '',
|
||||
dbUpdateVersions: [],
|
||||
loggingLevels: null,
|
||||
blockTemplateLoggingThreshold: null,
|
||||
};
|
||||
|
||||
const reducer = ( state = DEFAULT_STATE, action ) => {
|
||||
|
@ -48,7 +51,7 @@ const reducer = ( state = DEFAULT_STATE, action ) => {
|
|||
return {
|
||||
...state,
|
||||
currentlyRunning: {
|
||||
...state,
|
||||
...state.currentlyRunning,
|
||||
[ action.command ]: true,
|
||||
},
|
||||
};
|
||||
|
@ -56,7 +59,7 @@ const reducer = ( state = DEFAULT_STATE, action ) => {
|
|||
return {
|
||||
...state,
|
||||
currentlyRunning: {
|
||||
...state,
|
||||
...state.currentlyRunning,
|
||||
[ action.command ]: false,
|
||||
},
|
||||
};
|
||||
|
@ -74,6 +77,7 @@ const reducer = ( state = DEFAULT_STATE, action ) => {
|
|||
return {
|
||||
...state,
|
||||
params: {
|
||||
...state.params,
|
||||
[ action.source ]: action.params,
|
||||
},
|
||||
};
|
||||
|
@ -87,12 +91,6 @@ const reducer = ( state = DEFAULT_STATE, action ) => {
|
|||
...state,
|
||||
loggingLevels: action.loggingLevels,
|
||||
};
|
||||
case TYPES.SET_BLOCK_TEMPLATE_LOGGING_THRESHOLD:
|
||||
return {
|
||||
...state,
|
||||
blockTemplateLoggingThreshold:
|
||||
action.blockTemplateLoggingThreshold,
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
|
@ -8,12 +8,15 @@ import { apiFetch } from '@wordpress/data-controls';
|
|||
*/
|
||||
import { API_NAMESPACE } from './constants';
|
||||
import {
|
||||
setBlockTemplateLoggingThreshold,
|
||||
setCronJobs,
|
||||
setDBUpdateVersions,
|
||||
setIsEmailDisabled,
|
||||
setLoggingLevels,
|
||||
updateCommandParams,
|
||||
} from './actions';
|
||||
import { UPDATE_BLOCK_TEMPLATE_LOGGING_THRESHOLD_ACTION_NAME } from '../commands/update-block-template-logging-threshold';
|
||||
import { UPDATE_COMING_SOON_MODE_ACTION_NAME } from '../commands/set-coming-soon-mode';
|
||||
import { TRIGGER_UPDATE_CALLBACKS_ACTION_NAME } from '../commands/trigger-update-callbacks';
|
||||
|
||||
export function* getCronJobs() {
|
||||
const path = `${ API_NAMESPACE }/tools/get-cron-list/v1`;
|
||||
|
@ -33,11 +36,19 @@ export function* getDBUpdateVersions() {
|
|||
const path = `${ API_NAMESPACE }/tools/get-update-versions/v1`;
|
||||
|
||||
try {
|
||||
const response = yield apiFetch( {
|
||||
const dbUpdateVersions = yield apiFetch( {
|
||||
path,
|
||||
method: 'GET',
|
||||
} );
|
||||
yield setDBUpdateVersions( response );
|
||||
|
||||
dbUpdateVersions.reverse();
|
||||
yield setDBUpdateVersions( dbUpdateVersions );
|
||||
yield updateCommandParams( TRIGGER_UPDATE_CALLBACKS_ACTION_NAME, {
|
||||
version:
|
||||
Array.isArray( dbUpdateVersions ) && dbUpdateVersions.length > 0
|
||||
? dbUpdateVersions[ 0 ]
|
||||
: null,
|
||||
} );
|
||||
} catch ( error ) {
|
||||
throw new Error( error );
|
||||
}
|
||||
|
@ -76,11 +87,32 @@ export function* getBlockTemplateLoggingThreshold() {
|
|||
const path = `${ API_NAMESPACE }/tools/get-block-template-logging-threshold/v1`;
|
||||
|
||||
try {
|
||||
const response = yield apiFetch( {
|
||||
const threshold = yield apiFetch( {
|
||||
path,
|
||||
method: 'GET',
|
||||
} );
|
||||
yield setBlockTemplateLoggingThreshold( response );
|
||||
yield updateCommandParams(
|
||||
UPDATE_BLOCK_TEMPLATE_LOGGING_THRESHOLD_ACTION_NAME,
|
||||
{
|
||||
threshold,
|
||||
}
|
||||
);
|
||||
} catch ( error ) {
|
||||
throw new Error( error );
|
||||
}
|
||||
}
|
||||
|
||||
export function* getComingSoonMode() {
|
||||
const path = `${ API_NAMESPACE }/tools/get-force-coming-soon-mode/v1`;
|
||||
|
||||
try {
|
||||
const mode = yield apiFetch( {
|
||||
path,
|
||||
method: 'GET',
|
||||
} );
|
||||
yield updateCommandParams( UPDATE_COMING_SOON_MODE_ACTION_NAME, {
|
||||
mode: mode || 'disabled',
|
||||
} );
|
||||
} catch ( error ) {
|
||||
throw new Error( error );
|
||||
}
|
||||
|
|
|
@ -31,5 +31,9 @@ export function getLoggingLevels( state ) {
|
|||
}
|
||||
|
||||
export function getBlockTemplateLoggingThreshold( state ) {
|
||||
return state.blockTemplateLoggingThreshold;
|
||||
return state.params.updateBlockTemplateLoggingThreshold.threshold;
|
||||
}
|
||||
|
||||
export function getComingSoonMode( state ) {
|
||||
return state.params.updateComingSoonMode.mode;
|
||||
}
|
||||
|
|
|
@ -77,9 +77,8 @@ function Tools( {
|
|||
|
||||
export default compose(
|
||||
withSelect( ( select ) => {
|
||||
const { getCurrentlyRunning, getMessages, getCommandParams } = select(
|
||||
STORE_KEY
|
||||
);
|
||||
const { getCurrentlyRunning, getMessages, getCommandParams } =
|
||||
select( STORE_KEY );
|
||||
return {
|
||||
currentlyRunningCommands: getCurrentlyRunning(),
|
||||
messages: getMessages(),
|
||||
|
|
|
@ -63,6 +63,7 @@ function _wc_beta_tester_bootstrap() {
|
|||
new WC_Beta_Tester_Import_Export();
|
||||
// Tools.
|
||||
include dirname( __FILE__ ) . '/includes/class-wc-beta-tester-version-picker.php';
|
||||
include dirname( __FILE__ ) . '/includes/class-wc-beta-tester-override-coming-soon-options.php';
|
||||
|
||||
register_activation_hook( __FILE__, array( 'WC_Beta_Tester', 'activate' ) );
|
||||
|
||||
|
|
Loading…
Reference in New Issue