Skip to content

Handle running checks in loop and return output #84

@vishalkakadiya

Description

@vishalkakadiya

Description

Handle running checks one by one and return output.

This issue is dependent on the following:

Acceptance Criteria

  • Update the run_checks() method in the Admin_AJAX class to handle running checks and returning a response.
    • The run_checks method will first verify the request using the nonce passed and If invalid will return an error response.
    • Then the AJAX_Runner instance is gathered by calling the Plugin_Request_Utility::get_runner().
    • If the Plugin_Request_Utility::get_runner() returns null a new instance of the AJAX_Runner class should be created.
      • As part of creating the AJAX_Runner instance, the set_check_slugs() and set_plugin_slug () methods should be called passing in the appropriate values taken from the request.
    • Then the AJAX_Runners run() method is called and the Check_Results instance returned is stored in a variable.
    • If the run() method throws an exception, the error message is captured and returned in an error response to the client. The admin-plugin-check.js file will handle the error and display it on the admin page for debugging. Any further check requests will not be sent.
    • The results are then passed to the protected format_results() method in the Admin_AJAX class. This method will handle formatting all results into an array of messages, with each message being an object with the following properties.
      • message - The error or warning message.
      • type - Either error or warning.
      • standard - The standard or check name.
      • file - The filename and path
      • line_column - The line and column numbers the error/warning occurred.
    • A response is returned containing the following information
      • success - true or false as to whether the check run was successful.
      • results - The array of messages returned by format_results(). Can be an empty array.
      • check - The slug of the check that was run.
      • error - false if there were no critical errors when running checks, false if the check run was successful.
  • Update the plugin-check-admin.js to send requests to the admin-ajax.php endpoint to run checks.
    • The checks_to_run returned by the plugin_check_get_checks_to_run action will be used to send requests for each individual check.
    • The first check is removed from the array and sent in the request.
    • The AJAX request will send the following:
      • A array containing a single check slug to be run
      • The plugin name to check.
      • A valid nonce.
    • On a successful response:
      • The messages returned will be injected into the admin page using the templates setup in Show check results on the page #35
      • The next check in the checks_to_run array is removed and used in the next request. This process will repeat until the checks_to_run is empty and the last check is run.
      • When all checks have been run and the checks_to_run array is empty the runtime environment cleanup is executed by making a request to the admin-ajax.php endpoint with the plugin_check_cleanup_environment action (implemented in AJAX Runtime Environment Setup/Cleanup #86)
    • On a error response:
      • A user-friendly error message is displayed in the admin page with the error that occurred.
      • The runtime environment cleanup function will be run by making a request to the admin-ajax.php endpoint with the plugin_check_cleanup_environment action (implemented in AJAX Runtime Environment Setup/Cleanup #86)

Metadata

Metadata

Assignees

No one assigned

    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