Skip to content

Commit

Permalink
Set workflow place only on draft dimension
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasnatter committed May 15, 2020
1 parent ac74df7 commit 5a468fd
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,38 @@ public function map(
*/
private function setWorkflowData(WorkflowInterface $object, array $data): void
{
$this->setInitialPlaceToDraftDimension($object, $data);
$this->setPublishedToLiveDimension($object, $data);
}

/**
* @param mixed[] $data
*/
private function setInitialPlaceToDraftDimension(WorkflowInterface $object, array $data): void
{
// we want to set the initial place only to the draft dimension, the live dimension should not have a place
// after the place was set by this mapper initially, the place should only be changed by the ContentWorkflow
// see: https://github.com/sulu/SuluContentBundle/issues/92

if (!$object instanceof DimensionContentInterface
|| DimensionInterface::STAGE_DRAFT !== $object->getDimension()->getStage()) {
return;
}

if (!$object->getWorkflowPlace()) {
// TODO: get public workflow registry and set initial place based on $object::getWorkflowName()
$object->setWorkflowPlace(WorkflowInterface::WORKFLOW_PLACE_UNPUBLISHED);
}
}

/**
* @param mixed[] $data
*/
private function setPublishedToLiveDimension(WorkflowInterface $object, array $data): void
{
// the published property of the draft dimension should only be changed by a ContentWorkflow subscriber
// therefore we only want to copy the published property from the draft to the live dimension

if (!$object instanceof DimensionContentInterface
|| DimensionInterface::STAGE_LIVE !== $object->getDimension()->getStage()) {
return;
Expand Down
2 changes: 1 addition & 1 deletion Content/Application/ContentWorkflow/ContentWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function __construct(
$this->dimensionContentRepository = $dimensionContentRepository;
$this->viewFactory = $viewFactory;
$this->eventDispatcher = $eventDispatcher ?: new EventDispatcher();
// TODO get workflow from outside
// TODO: get public workflow registry from outside
$this->workflowRegistry = $workflowRegistry ?: new Registry();
$this->workflowRegistry->addWorkflow(
$this->getWorkflow(),
Expand Down
4 changes: 2 additions & 2 deletions Content/Domain/Model/WorkflowInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ interface WorkflowInterface

public static function getWorkflowName(): string;

public function getWorkflowPlace(): string;
public function getWorkflowPlace(): ?string;

public function setWorkflowPlace(string $workflowPlace): void;
public function setWorkflowPlace(?string $workflowPlace): void;

public function getWorkflowPublished(): ?\DateTimeImmutable;

Expand Down
8 changes: 4 additions & 4 deletions Content/Domain/Model/WorkflowTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
trait WorkflowTrait
{
/**
* @var string
* @var string|null
*/
protected $workflowPlace = WorkflowInterface::WORKFLOW_PLACE_UNPUBLISHED;
protected $workflowPlace;

/**
* @var \DateTimeImmutable|null
Expand All @@ -30,12 +30,12 @@ public static function getWorkflowName(): string
return WorkflowInterface::WORKFLOW_DEFAULT_NAME;
}

public function getWorkflowPlace(): string
public function getWorkflowPlace(): ?string
{
return $this->workflowPlace;
}

public function setWorkflowPlace(string $workflowPlace): void
public function setWorkflowPlace(?string $workflowPlace): void
{
$this->workflowPlace = $workflowPlace;
}
Expand Down
2 changes: 1 addition & 1 deletion Content/Infrastructure/Doctrine/MetadataLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $event): void
}

if ($reflection->implementsInterface(WorkflowInterface::class)) {
$this->addField($metadata, 'workflowPlace', 'string', ['length' => 32, 'nullable' => false, 'default' => WorkflowInterface::WORKFLOW_PLACE_UNPUBLISHED]);
$this->addField($metadata, 'workflowPlace', 'string', ['length' => 32, 'nullable' => true]);
$this->addField($metadata, 'workflowPublished', 'datetime_immutable', ['nullable' => true]);
}
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/Unit/Mocks/WorkflowMockWrapperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public static function getWorkflowName(): string
return 'mock-workflow-name';
}

public function getWorkflowPlace(): string
public function getWorkflowPlace(): ?string
{
return $this->instance->getWorkflowPlace();
}

public function setWorkflowPlace(string $workflowPlace): void
public function setWorkflowPlace(?string $workflowPlace): void
{
$this->instance->setWorkflowPlace($workflowPlace);
}
Expand Down

0 comments on commit 5a468fd

Please sign in to comment.