Skip to content

Commit

Permalink
Merge pull request #47 from Automattic/add/cli-rebuild
Browse files Browse the repository at this point in the history
feat: wp-cli command to reset db tables
  • Loading branch information
Jefferson Rabb authored May 26, 2020
2 parents 304ac52 + 21cd825 commit 53ea09a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
3 changes: 3 additions & 0 deletions dependency-includer-script.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@
require_once dirname( __FILE__ ) . '/lib/content-patcher/elementManipulators/class-htmlelementmanipulator.php';
require_once dirname( __FILE__ ) . '/lib/content-patcher/elementManipulators/class-squarebracketselementmanipulator.php';
require_once dirname( __FILE__ ) . '/lib/content-patcher/elementManipulators/class-wpblockmanipulator.php';
if ( defined( 'WP_CLI' ) && WP_CLI ) {
require_once dirname( __FILE__ ) . '/lib/class-cli.php';
}
42 changes: 42 additions & 0 deletions lib/class-cli.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* WP-CLI integration.
*
* @package Newspack
*/

namespace NewspackContentConverter;

/**
* Class Config
*
* @package NewspackContentConverter
*/
class CLI {

/**
* Singleton instance.
*
* @var Config
*/
private static $instance;

/**
* Config constructor.
*/
public function __construct() {
\WP_CLI::add_command( 'newspack-content-converter reset', [ $this, 'cli_reset' ] );
}

/**
* Reset the Newspack Content Converter tables. This action is equivalent to uninstalling, deleting, and reinstaalling the plugin.
*/
public static function cli_reset() {
\NewspackContentConverter\Installer::uninstall_plugin( true );
\WP_CLI::line( __( 'Uninstallation complete.', 'newspack-content-converter' ) );
\NewspackContentConverter\Installer::install_plugin( true );
\WP_CLI::line( __( 'Installation complete.', 'newspack-content-converter' ) );
\WP_CLI::success( 'Reset complete.' );
}
}
new \NewspackContentConverter\CLI();
4 changes: 2 additions & 2 deletions lib/class-installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public static function install_plugin() {
* Plugin uninstallation.
* Drops the plugin table, deleted plugin options.
*/
public static function uninstall_plugin() {
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
public static function uninstall_plugin( $override = false ) {
if ( ! $override && ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit();
}

Expand Down

0 comments on commit 53ea09a

Please sign in to comment.