diff --git a/src/Commands/core/WorkspacesCommands.php b/src/Commands/core/WorkspacesCommands.php new file mode 100644 index 0000000000..b3ac8ae189 --- /dev/null +++ b/src/Commands/core/WorkspacesCommands.php @@ -0,0 +1,67 @@ +has('plugin.manager.migration')) { + $this->workspacesOperationFactory = $container->get('workspaces.operation_factory'); + } + } + + /** + * Publish a workspace. + */ + #[CLI\Command(name: self::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)); + } +} diff --git a/tests/integration/WorkspacesTest.php b/tests/integration/WorkspacesTest.php new file mode 100644 index 0000000000..9b4c07c97e --- /dev/null +++ b/tests/integration/WorkspacesTest.php @@ -0,0 +1,44 @@ +drush('pm:install', ['workspaces', 'node']); + + // $this->workspaceManager = \Drupal::service('workspaces.manager'); + } + + public function testWorkspaces(): void + { + $this->drush(PhpCommands::SCRIPT, ['workspaces'], ['script-path' => __DIR__ . '/resources']); + } + + /** + * {@inheritdoc} + */ + protected function tearDown(): void + { + // Cleanup any created content. + $this->drush('entity:delete', ['node']); + + // Uninstall test modules. + // $this->drush('pm:uninstall', ['workspaces', 'node']); + + parent::tearDown(); + } +} diff --git a/tests/integration/resources/workspaces.php b/tests/integration/resources/workspaces.php new file mode 100644 index 0000000000..f53bd1d349 --- /dev/null +++ b/tests/integration/resources/workspaces.php @@ -0,0 +1,4 @@ +setActiveWorkspace($workspace);