Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions inc/CLI/ProjectCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,62 @@ 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|url>
* : 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.
*/
public function unlock( array $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() ) );
}
}