This issue will implement the runtime environment setup and cleanup for AJAX requests. This will utilise the Runtime_Environment_Setup class to setup the WP environment before checks are run, and cleanup the environment once all checks are complete.
This issue is dependent on the following:
Acceptance Criteria
Create a Runtime Setup AJAX endpoint
- In the
Admin_Ajax should create a new AJAX endpoint for the action plugin_check_setup_environment
- A new action is created for
wp_ajax_plugin_check_setup_environment that calls a setup_environment method on the Admin_Ajax class.
- A public
has_runtime_check method exists in the Abstract_Check_Runner class. This method will test the checks returned by get_checks_to_run(). If there is is at least 1 Runtime_Check it will return true, otherwise false.
- The
setup_environment method.
- This method will get an instance of the
AJAX_Runner class via the Plugin_Request_Utility::get_runner() method.
- If the
Plugin_Request_Utility::get_runner() returns null a new instance of the AJAX_Runner class should be created.
- Run the
set_check_slugs() and set_plugin_slug () methods on the AJAX_Runner instance passing in the the appropriate values taken from the request.
- The method will test if any of the checks requested are Runtime checks by calling the
AJAX_Runner has_runtime_check() method. If this returns true the Runtime_Environment_Setup class will be instantiated and it's setup() method called.
- The method will then return a JSON response for the AJAX request with the following structure
{ "success": true|false, "message": (string) success/error message }
- An error response will be returned if setup had a critical error passing
success as false and the message of the error that occured.
- If the setup was successful, a success response will be returned with
success as true and the message "runtime environment setup successful"
- If the setup did not need to run, a success response will be returned with
success as true and the message "no runtime checks, runtime environment was not setup"
- The
plugin-check-admin.js file will be updated to first send an AJAX request to the admin-ajax.php endpoint with the plugin_check_setup_environment action before any check requests are sent.
- The request will also pass the plugin and checks to be run to the endpoint in order to determine if the runtime environment needs to be setup.
- If there is an error response, a user friendly error message will be displayed on the admin page and no further AJAX requests will be sent to attempt to run checks,
Create a Runtime Cleanup AJAX endpoint
- In the
Admin_Ajax should create a new AJAX endpoint for the action plugin_check_cleanup_environment
- A new action is created for
wp_ajax_plugin_check_cleanup_environment that calls a cleanup_environment method on the Admin_Ajax class.
- The
cleanup_environment method:
- This method will test if the runtime environment had been prepared by checking if the any of the tables with the
wppc_ prefix exist.
- If the
wppc_ tables exist, the Runtime_Environment_Setup class will be instantiated and it's cleanup() method called.
- The method will then return a JSON response for the AJAX request with the following structure
{ "success": true|false, "message": (string) success/error message }
- An error response will be returned if cleanup had a critical error passing
success as false and the message of the error that occured.
- If the setup was successful, a success response will be returned with
success as true and the message "runtime environment cleanup successful"
- If the setup did not need to run, a success response will be returned with
success as true and the message "Runtime environment was not prepared, cleanup was not run."
- The
plugin-check-admin.js file will be updated to send a final AJAX request to the admin-ajax.php endpoint with the plugin_check_cleanup_environment action after all checks have been run.
- The request will also pass the plugin and checks to be run to the endpoint in order to determine if the runtime environment needs to be cleaned up.
This issue will implement the runtime environment setup and cleanup for AJAX requests. This will utilise the
Runtime_Environment_Setupclass to setup the WP environment before checks are run, and cleanup the environment once all checks are complete.This issue is dependent on the following:
Acceptance Criteria
Create a Runtime Setup AJAX endpoint
Admin_Ajaxshould create a new AJAX endpoint for the actionplugin_check_setup_environmentwp_ajax_plugin_check_setup_environmentthat calls asetup_environmentmethod on theAdmin_Ajaxclass.has_runtime_checkmethod exists in theAbstract_Check_Runnerclass. This method will test the checks returned byget_checks_to_run(). If there is is at least 1Runtime_Checkit will returntrue, otherwisefalse.setup_environmentmethod.AJAX_Runnerclass via thePlugin_Request_Utility::get_runner()method.Plugin_Request_Utility::get_runner()returnsnulla new instance of theAJAX_Runnerclass should be created.set_check_slugs()andset_plugin_slug ()methods on theAJAX_Runnerinstance passing in the the appropriate values taken from the request.AJAX_Runnerhas_runtime_check()method. If this returnstruetheRuntime_Environment_Setupclass will be instantiated and it'ssetup()method called.{ "success": true|false, "message": (string) success/error message }successasfalseand the message of the error that occured.successastrueand the message"runtime environment setup successful"successastrueand the message"no runtime checks, runtime environment was not setup"plugin-check-admin.jsfile will be updated to first send an AJAX request to theadmin-ajax.phpendpoint with theplugin_check_setup_environmentaction before any check requests are sent.Create a Runtime Cleanup AJAX endpoint
Admin_Ajaxshould create a new AJAX endpoint for the actionplugin_check_cleanup_environmentwp_ajax_plugin_check_cleanup_environmentthat calls acleanup_environmentmethod on theAdmin_Ajaxclass.cleanup_environmentmethod:wppc_prefix exist.wppc_tables exist, theRuntime_Environment_Setupclass will be instantiated and it'scleanup()method called.{ "success": true|false, "message": (string) success/error message }successasfalseand the message of the error that occured.successastrueand the message"runtime environment cleanup successful"successastrueand the message"Runtime environment was not prepared, cleanup was not run."plugin-check-admin.jsfile will be updated to send a final AJAX request to theadmin-ajax.phpendpoint with theplugin_check_cleanup_environmentaction after all checks have been run.