Skip to content

AJAX Runtime Environment Setup/Cleanup #86

@jjgrainger

Description

@jjgrainger

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.

Metadata

Metadata

Assignees

Labels

WP AdminIssues for the WP Admin screen[Type] EnhancementA suggestion for improvement of an existing feature

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions