Skip to content

Commit

Permalink
Add debug mode to ease development (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethitter authored Nov 27, 2024
1 parent b4e0802 commit 033016a
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions classes/class-init.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use Throwable;
use WP_CLI;

use function WP_CLI\Utils\get_flag_value;

/**
* Class Init.
*/
Expand All @@ -34,29 +36,62 @@ final class Init extends PMC_WP_CLI {
/**
* Prepare production database for use in local-development environment.
*
* ## OPTIONS
*
* [--debug-mode]
* : Skip deletion step and retain table holding found IDs.
*
* ## EXAMPLES
* wp pmc-local-data start
* wp pmc-local-data start --debug-mode
*
* @subcommand start
*
* @param array $args Positional arguments.
* @param array $assoc_args Associative arguments.
* @return void
*/
public function start(): void {
public function start( array $args, array $assoc_args ): void {
try {
$debug_mode = get_flag_value(
$assoc_args,
'debug-mode',
false
);

WP_CLI::line( 'Starting local-data process.' );

if ( $debug_mode ) {
WP_CLI::warning(
'Debug mode active: `Clean_DB` class will be skipped and IDs table will be retained.'
);
}

do_action( 'pmc_wp_cli_local_data_before_processing' );

$this->_drop_table();
$this->_create_table();

$this->_query_for_ids_to_keep();

new Clean_DB();
if ( $debug_mode ) {
WP_CLI::warning( 'Debug mode active: skipping `Clean_DB` class.' );
} else {
new Clean_DB();
}

do_action( 'pmc_wp_cli_local_data_after_processing' );

$this->_drop_table();
if ( $debug_mode ) {
WP_CLI::warning(
sprintf(
'Debug mode active: retaining `%1$s` table.',
self::TABLE_NAME
)
);
} else {
$this->_drop_table();
}

WP_CLI::line( 'Process complete.' );
} catch ( Throwable $throwable ) {
Expand Down

0 comments on commit 033016a

Please sign in to comment.