From 262ca7203926ad8cfd84303f3515fb4004834044 Mon Sep 17 00:00:00 2001 From: Bernhard Kau Date: Wed, 9 Nov 2022 19:39:46 +0100 Subject: [PATCH 1/2] Add a CLI command to unlock a project --- inc/CLI/ProjectCommand.php | 59 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/inc/CLI/ProjectCommand.php b/inc/CLI/ProjectCommand.php index 5da100d..88a3cbb 100644 --- a/inc/CLI/ProjectCommand.php +++ b/inc/CLI/ProjectCommand.php @@ -206,4 +206,63 @@ public function update( array $args, array $assoc_args ): void { WP_CLI::warning( sprintf( 'Could not update translations for project (ID: %d)!', $project->get_id() ) ); } + /** + * Unlocks a project. + * + * Finds the project and removes the lock. + * + * ## OPTIONS + * + * + * : Project path / ID or source code repository URL, e.g. https://github.com/wearerequired/required-valencia + * + * ## EXAMPLES + * + * # Unlock project with repository URL. + * $ wp traduttore project unlock https://github.com/wearerequired/required-valencia + * Success: Project unlocked (ID: 123)! + * + * # Unlock project with project path. + * $ wp traduttore project unlock wearerequired/required-valencia + * Success: Project unlocked (ID: 123)! + * + * # Unlock project with project ID. + * $ wp traduttore project unlock 123 + * Success: Project unlocked (ID: 123)! + * + * @param string[] $args Command args. + * @param string[] $assoc_args Associative args. + */ + public function unlock( array $args, array $assoc_args ): void { + + $locator = new ProjectLocator( $args[0] ); + $project = $locator->get_project(); + + if ( ! $project ) { + WP_CLI::error( 'Project not found' ); + } + + $repository = ( new RepositoryFactory() )->get_repository( $project ); + + if ( ! $repository ) { + WP_CLI::error( 'Invalid project type' ); + } + + $loader = ( new LoaderFactory() )->get_loader( $repository ); + + if ( ! $loader ) { + WP_CLI::error( 'Invalid project type' ); + } + + $updater = new Updater( $project ); + + if ( ! $updater->has_lock() ) { + WP_CLI::error( sprintf( 'Project was not locked (ID: %d)!', $project->get_id() ) ); + } + + $updater->remove_lock(); + + WP_CLI::success( sprintf( 'Project unlocked (ID: %d)!', $project->get_id() ) ); + } + } From 92431e9184f0ab812c1b3c9791b1340273305168 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Fri, 17 May 2024 09:52:58 +0200 Subject: [PATCH 2/2] Remove unused parameter --- inc/CLI/ProjectCommand.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/inc/CLI/ProjectCommand.php b/inc/CLI/ProjectCommand.php index f5d4f78..c3e7932 100644 --- a/inc/CLI/ProjectCommand.php +++ b/inc/CLI/ProjectCommand.php @@ -230,10 +230,9 @@ public function update( array $args, array $assoc_args ): void { * $ wp traduttore project unlock 123 * Success: Project unlocked (ID: 123)! * - * @param string[] $args Command args. - * @param string[] $assoc_args Associative args. + * @param string[] $args Command args. */ - public function unlock( array $args, array $assoc_args ): void { + public function unlock( array $args ): void { $locator = new ProjectLocator( $args[0] ); $project = $locator->get_project();