2021-11-17 22:08:52 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Automattic\WooCommerce\Admin\API\Reports\Cache;
|
|
|
|
|
|
|
|
register_woocommerce_admin_test_helper_rest_route(
|
|
|
|
'/tools/get-update-versions/v1',
|
|
|
|
'tools_get_wc_admin_versions',
|
|
|
|
array(
|
|
|
|
'methods' => 'GET',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
register_woocommerce_admin_test_helper_rest_route(
|
|
|
|
'/tools/trigger-selected-update-callbacks/v1',
|
|
|
|
'trigger_selected_update_callbacks',
|
|
|
|
array(
|
|
|
|
'methods' => 'POST',
|
|
|
|
'args' => array(
|
|
|
|
'version' => array(
|
|
|
|
'description' => 'Name of the update version',
|
|
|
|
'type' => 'string',
|
|
|
|
'sanitize_callback' => 'sanitize_text_field',
|
|
|
|
)
|
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
function tools_get_wc_admin_versions() {
|
2022-05-27 13:17:55 +00:00
|
|
|
$db_updates = \WC_Install::get_db_update_callbacks();
|
2021-11-17 22:08:52 +00:00
|
|
|
|
|
|
|
return new WP_REST_Response( array_keys( $db_updates ), 200 );
|
|
|
|
}
|
|
|
|
|
|
|
|
function trigger_selected_update_callbacks( $request ) {
|
|
|
|
$version = $request->get_param( 'version' );
|
|
|
|
if ( ! isset( $version ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-27 13:17:55 +00:00
|
|
|
$db_updates = \WC_Install::get_db_update_callbacks();
|
2021-11-17 22:08:52 +00:00
|
|
|
$update_callbacks = $db_updates[ $version ];
|
|
|
|
|
|
|
|
foreach ( $update_callbacks as $update_callback ) {
|
|
|
|
call_user_func( $update_callback );
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|