diff --git a/src/Commands/core/WorkspacesCommands.php b/src/Commands/core/WorkspacesCommands.php new file mode 100644 index 0000000000..a844c2fa9a --- /dev/null +++ b/src/Commands/core/WorkspacesCommands.php @@ -0,0 +1,64 @@ +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')] + #[CLI\ValidateModulesEnabled(modules: ['workspaces'])] + 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)); + } + +}