From c28a9e45d4f43a9cafc04d37fd5649e133bf684d Mon Sep 17 00:00:00 2001 From: Mirco Babini Date: Fri, 24 Sep 2021 12:59:51 +0200 Subject: [PATCH] 1.3.4 add reinstall-core and reinstall-plugins --- command.php | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/command.php b/command.php index bc9455f..6e4a452 100644 --- a/command.php +++ b/command.php @@ -4,7 +4,7 @@ class Swim_WP_CLI extends WP_CLI_Command { // todo move the version to the "package meta" docblock - const VERSION = '1.3.3'; + const VERSION = '1.3.4'; /** * A test which always gives success and the current version. @@ -21,6 +21,62 @@ public function test( array $args = [], array $assoc_args = [] ) { WP_CLI::success( "Success. Installed version $current_version." ); } + /** + * Clean the core install and reinstall + * - known limits: will update everything + * + * ## EXAMPLES + * + * wp swim reinstall-core + * + * @subcommand reinstall-core + */ + public function reinstall_core( array $args = [], array $assoc_args = [] ) { + // subcommand options + $options = array( + 'return' => true, // Return 'STDOUT'; use 'all' for full object. + 'parse' => 'json', // Parse captured STDOUT to JSON array. + 'launch' => false, // Reuse the current process. + 'exit_error' => true, // Halt script execution on error. + ); + + // rm core folders + WP_CLI::debug( "rm -rf wp-includes wp-admin" ); + exec( "rm -rf wp-includes wp-admin" ); + + // core download force + WP_CLI::debug( "wp core download --force --skip-content" ); + WP_CLI::runcommand( "wp core download --force --skip-content", $options ); + + // verify checksums + WP_CLI::debug( "wp core verify-checksums" ); + WP_CLI::runcommand( "wp core verify-checksums", $options ); + } + + /** + * Reinstall plugins + * - known limits: can't delete infected files... maybe? + * + * ## EXAMPLES + * + * wp swim reinstall-plugins + * + * @subcommand reinstall-plugins + */ + public function reinstall_plugins( array $args = [], array $assoc_args = [] ) { + // subcommand options + $options = array( + 'return' => true, // Return 'STDOUT'; use 'all' for full object. + 'parse' => 'json', // Parse captured STDOUT to JSON array. + 'launch' => false, // Reuse the current process. + 'exit_error' => true, // Halt script execution on error. + ); + + // db dump + WP_CLI::debug( "wp plugin install $(wp plugin list --field=name) --force" ); + WP_CLI::runcommand( "wp plugin install $(wp plugin list --field=name) --force", $options ); + } + /** * Create a zip archive for the site, including a sql dump *