From 247f742433a03ac58baf3809888d31f033bcc902 Mon Sep 17 00:00:00 2001 From: Rebecca Scott Date: Wed, 19 May 2021 15:43:07 +1000 Subject: [PATCH] Add tool to delete all products --- api/api.php | 1 + api/tools/delete-all-products.php | 16 ++++++++++++++++ src/tools/commands.js | 5 +++++ src/tools/data/actions.js | 13 +++++++++++++ 4 files changed, 35 insertions(+) create mode 100644 api/tools/delete-all-products.php diff --git a/api/api.php b/api/api.php index a1115cf41c3..02544cb790a 100644 --- a/api/api.php +++ b/api/api.php @@ -31,3 +31,4 @@ require( 'admin-notes/add-note.php' ); require( 'tools/trigger-wca-install.php' ); require( 'tools/run-wc-admin-daily.php' ); require( 'options/rest-api.php' ); +require( 'tools/delete-all-products.php'); diff --git a/api/tools/delete-all-products.php b/api/tools/delete-all-products.php new file mode 100644 index 00000000000..953f7e11e3b --- /dev/null +++ b/api/tools/delete-all-products.php @@ -0,0 +1,16 @@ +get_products(); + + foreach ( $products as $product ) { + $product->delete( true ); + } + + return true; +} diff --git a/src/tools/commands.js b/src/tools/commands.js index dca28d59b8e..221b74abcc8 100644 --- a/src/tools/commands.js +++ b/src/tools/commands.js @@ -34,4 +34,9 @@ export default [ description: 'Run wc_admin_daily job', action: 'runWcAdminDailyJob', }, + { + command: 'Delete all products', + description: 'Delete all products', + action: 'deleteAllProducts', + }, ]; diff --git a/src/tools/data/actions.js b/src/tools/data/actions.js index 90243321cf7..46c1e4a0faf 100644 --- a/src/tools/data/actions.js +++ b/src/tools/data/actions.js @@ -138,3 +138,16 @@ export function* runWcAdminDailyJob() { } ); } ); } + +export function* deleteAllProducts() { + if ( ! confirm( 'Are you sure you want to delete all of the products?' ) ) { + return; + } + + yield runCommand( 'Delete all products', function* () { + yield apiFetch( { + path: `${ API_NAMESPACE }/tools/delete-all-products/v1`, + method: 'POST', + } ); + } ); +}