Skip to content

CLI Runtime Environment Setup/Cleanup #87

@jjgrainger

Description

@jjgrainger

This issue will implement the runtime environment setup and cleanup for CLI 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.

Acceptance Criteria

  • Add a new before_wp_load hook with WP_CLI::add_hook() to implement the object-cache.php drop-in file.
    • The hook will manually (not using the WP filesystem) add the object-cache.php drop-in file to the wp-content folder.
  • Create a cli.php file in the plugin root.
    • This file will be used to setup the Plugin_Check_Command both early and late in the WordPress load process.
    • The file will first check if the Plugin_Check_Command class exists.
      • If it does not this file is running before WordPress has loaded and the command will need to be setup manually.
        • This is done by loading the plugin autoload file so the class is available.
        • A new Plugin_Context for the plugin checker is created and passed to the Plugin_Check_Command constructor.
        • The Plugin_Check_Command is then registered to the WordPress CLI.
      • If the Plugin_Check_Command class does exist.
        • A check is made to see if the $context variable exists, which will be set in the Plugin_Main::add_hooks() method.
        • A new instance of the Plugin_Check_Command is created passing the $context to the constructor.
        • The Plugin_Check_Command is then registered to the WordPress CLI.
  • Update the Plugin_Main::add_hooks() method to require_once the cli.php file, instead of adding the command directly to WP_CLI.
  • Update the wp plugin check to run the Runtime_Environment_Setup::setup() method at the start of the commands run process if any runtime check is to be performed. This is to setup the database tables required for runtime checks.
  • Update the wp plugin check to run the Runtime_Environment_Setup::cleanup() method at the end of the commands run process. This will remove the database tables and object-cache.php drop-in file if they exists.
  • When running the wp plugin check command the --require flag can be used to include the cli.php file early to create the object-cache.php file and register the command.

Metadata

Metadata

Assignees

Labels

WP-CLIIssues related to WP-CLI[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