-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7160 from Automattic/add/progress-validation-cli
Add progress validation command
- Loading branch information
Showing
11 changed files
with
942 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
/** | ||
* Sensei_Validate_Progress_Command class file. | ||
* | ||
* @package sensei | ||
*/ | ||
|
||
use Sensei\Internal\Migration\Validations\Progress_Validation; | ||
|
||
if ( ! defined( 'ABSPATH' ) ) { | ||
exit; // Exit if accessed directly. | ||
} | ||
|
||
/** | ||
* WP-CLI command that validates the progress data. | ||
* | ||
* @since $$next-version$$ | ||
*/ | ||
class Sensei_Validate_Progress_Command { | ||
/** | ||
* Seed the database. | ||
* | ||
* @since $$next-version$$ | ||
* | ||
* @param array $args Command arguments. | ||
* @param array $assoc_args Command arguments with names. | ||
*/ | ||
public function __invoke( array $args = [], array $assoc_args = [] ) { | ||
$progress_validation = new Progress_Validation(); | ||
|
||
$progress_validation->run(); | ||
|
||
if ( ! $progress_validation->has_errors() ) { | ||
WP_CLI::success( 'Progress data is valid.' ); | ||
return; | ||
} | ||
|
||
$this->output_validation_errors( $progress_validation ); | ||
|
||
WP_CLI::error( 'Progress data is not valid.' ); | ||
} | ||
|
||
/** | ||
* Output the validation errors. | ||
* | ||
* @since $$next-version$$ | ||
* | ||
* @param Progress_Validation $progress_validation Progress validation. | ||
*/ | ||
private function output_validation_errors( Progress_Validation $progress_validation ) { | ||
foreach ( $progress_validation->get_errors() as $error ) { | ||
WP_CLI::warning( $error->get_message() ); | ||
|
||
if ( $error->has_data() ) { | ||
$error_data = $error->get_data(); | ||
$error_data = is_array( $error_data[0] ) ? $error_data : [ $error_data ]; | ||
|
||
WP_CLI\Utils\format_items( | ||
'table', | ||
$error_data, | ||
array_keys( $error_data[0] ) | ||
); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.