From b483b51a60e932d03b268615531d9b7aff6e0e48 Mon Sep 17 00:00:00 2001 From: Malcolm Young Date: Mon, 25 Mar 2024 10:09:19 +0000 Subject: [PATCH] Drush commands for workspaces - #5933 --- src/Commands/core/WorkspacesCommands.php | 70 ++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/Commands/core/WorkspacesCommands.php diff --git a/src/Commands/core/WorkspacesCommands.php b/src/Commands/core/WorkspacesCommands.php new file mode 100644 index 0000000000..0042fcee91 --- /dev/null +++ b/src/Commands/core/WorkspacesCommands.php @@ -0,0 +1,70 @@ +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(); + $this->logger()->success(dt('Workspace %source_label published.', $args)); + } + +}