-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Drush commands for workspaces - #5933 #5934
base: 13.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace Drush\Commands\core; | ||
|
||
use Consolidation\OutputFormatters\StructuredData\RowsOfFields; | ||
use Drupal\Core\Entity\EntityTypeManagerInterface; | ||
use Drupal\Core\Utility\Token; | ||
use Drupal\workspaces\WorkspaceOperationFactory; | ||
use Drush\Attributes as CLI; | ||
use Drush\Commands\DrushCommands; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
final class WorkspacesCommands extends DrushCommands { | ||
|
||
/** | ||
* Constructs a WorkspacesCommands object. | ||
*/ | ||
public function __construct( | ||
private readonly WorkspaceOperationFactory $factory, | ||
private readonly EntityTypeManagerInterface $entityTypeManager, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function create(ContainerInterface $container) { | ||
return new static( | ||
$container->get('workspaces.operation_factory'), | ||
$container->get('entity_type.manager'), | ||
); | ||
} | ||
|
||
/** | ||
* Publish a workspace. | ||
*/ | ||
#[CLI\Command(name: 'workspaces:publish')] | ||
#[CLI\Argument(name: 'id', description: 'The workspace to publish.')] | ||
#[CLI\Usage(name: 'workspaces:publish stage', description: 'Publish the stage workspace')] | ||
public function commandName($id) { | ||
|
||
$workspace = $this->entityTypeManager->getStorage('workspace')->load($id); | ||
|
||
$workspace_publisher = $this->factory->getPublisher($workspace); | ||
|
||
$args = [ | ||
'%source_label' => $workspace->label(), | ||
'%target_label' => $workspace_publisher->getTargetLabel(), | ||
]; | ||
|
||
// Does this workspace have any content to publish? | ||
$diff = $workspace_publisher->getDifferringRevisionIdsOnSource(); | ||
if (empty($diff)) { | ||
$this->io()->warning(dt('There are no changes that can be published from %source_label to %target_label.', $args)); | ||
return; | ||
} | ||
|
||
$workspace->publish(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this fails with wse enabled, because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll look into this asap :) |
||
$this->logger()->success(dt('Workspace %source_label published.', $args)); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to ensure that the module is enabled:
#[CLI\ValidateModulesEnabled(modules: ['workspaces'])]