Skip to content
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

Open
wants to merge 3 commits into
base: 13.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
63 changes: 63 additions & 0 deletions src/Commands/core/WorkspacesCommands.php
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) {

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'])]


$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();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this fails with wse enabled, because \Drupal\wse_preview\Negotiator\CookieWorkspaceNegotiator::unsetActiveWorkspace tries to get the user session

Choose a reason for hiding this comment

The 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));
}

}