Summary
The current WP-CLI implementation in classes/class-wpcom-liveblog-wp-cli.php uses legacy patterns and needs modernisation to align with our plugin standards.
Current State
The class contains two commands:
-
readme_for_github - Converts readme.txt to markdown for GitHub README. This is obsolete since we now maintain README.md directly.
-
fix-archive - Repairs wp_commentmeta for archived liveblogs where edited entries have incorrect replaces meta values. This appears to be a legitimate repair tool for edge cases.
Issues
- Old-style multi-method class extending
WP_CLI_Command
- Business logic mixed with CLI output concerns
- No dependency injection
- No tests (behat or unit)
readme_for_github is obsolete
Proposed Changes
1. Delete readme_for_github command
This command is no longer needed. We maintain README.md directly.
2. Evaluate fix-archive necessity
Before refactoring, determine if this command is still needed:
- When was it last used?
- Is the underlying bug that causes corrupted data still present?
- Could the root cause be fixed instead?
3. If fix-archive is still needed, refactor to modern standards
Create command class classes/CLI/Fix_Archive_Command.php:
class Fix_Archive_Command {
private Archive_Repair_Service $service;
public function __construct( Archive_Repair_Service $service ) {
$this->service = $service;
}
public function __invoke( array $args, array $assoc_args ): void {
$dry_run = isset( $assoc_args['dry-run'] );
// Delegate to service, handle CLI output
}
}
Create service class classes/Services/Archive_Repair_Service.php:
class Archive_Repair_Service {
public function get_liveblogs(): array { }
public function get_edited_entries( int $post_id ): array { }
public function repair_entry( int $entry_id, int $correct_id ): void { }
}
Register command in main plugin file:
if ( defined( 'WP_CLI' ) && WP_CLI ) {
WP_CLI::add_command( 'liveblog fix-archive', new Fix_Archive_Command( new Archive_Repair_Service() ) );
}
4. Add behat tests
Create features/cli-fix-archive.feature to test:
- Dry run mode
- Actual repair execution
- Edge cases (no liveblogs, no edits, already correct)
Acceptance Criteria
References
- Current implementation:
classes/class-wpcom-liveblog-wp-cli.php
Summary
The current WP-CLI implementation in
classes/class-wpcom-liveblog-wp-cli.phpuses legacy patterns and needs modernisation to align with our plugin standards.Current State
The class contains two commands:
readme_for_github- Convertsreadme.txtto markdown for GitHub README. This is obsolete since we now maintainREADME.mddirectly.fix-archive- Repairswp_commentmetafor archived liveblogs where edited entries have incorrectreplacesmeta values. This appears to be a legitimate repair tool for edge cases.Issues
WP_CLI_Commandreadme_for_githubis obsoleteProposed Changes
1. Delete
readme_for_githubcommandThis command is no longer needed. We maintain
README.mddirectly.2. Evaluate
fix-archivenecessityBefore refactoring, determine if this command is still needed:
3. If
fix-archiveis still needed, refactor to modern standardsCreate command class
classes/CLI/Fix_Archive_Command.php:Create service class
classes/Services/Archive_Repair_Service.php:Register command in main plugin file:
4. Add behat tests
Create
features/cli-fix-archive.featureto test:Acceptance Criteria
readme_for_githubcommand removedfix-archiveis still neededfix-archiverefactored to one-class-per-command patternclass-wpcom-liveblog-wp-cli.phpfile deletedReferences
classes/class-wpcom-liveblog-wp-cli.php