Skip to content

Commit

Permalink
[Workflows] Schema (#623)
Browse files Browse the repository at this point in the history
* add some workflow tweaks

* fix: unit tests

* fix: param descriptions
  • Loading branch information
lukmzig authored Dec 9, 2024
1 parent 5bbacda commit 8e9ab51
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
20 changes: 12 additions & 8 deletions src/Workflow/Schema/SubmitAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ public function __construct(
example: WorkflowActionTypes::TRANSITION_ACTION
)]
private string $actionType,
#[Property(description: 'id of the element', type: 'integer', example: 50)]
#[Property(description: 'Id of the element', type: 'integer', example: 50)]
private int $elementId,
#[Property(description: 'type of the element', type: 'string', example: ElementTypes::TYPE_OBJECT)]
#[Property(description: 'Type of the element', type: 'string', example: ElementTypes::TYPE_DATA_OBJECT)]
private string $elementType,
#[Property(description: 'name of the workflow', type: 'string', example: 'my_first_workflow')]
private string $workflowName,
#[Property(description: 'transition', type: 'string', example: 'start_workflow')]
private string $transition,
#[Property(description: 'Id of the workflow', type: 'string', example: 'my_first_workflow')]
private string $workflowId,
#[Property(description: 'Id of the transition', type: 'string', example: 'start_workflow')]
private string $transitionId,
#[Property(
description: 'workflowOptions',
type: 'object',
Expand Down Expand Up @@ -79,12 +79,16 @@ public function getElementId(): int

public function getElementType(): string
{
if ($this->elementType === ElementTypes::TYPE_DATA_OBJECT) {
return ElementTypes::TYPE_OBJECT;
}

return $this->elementType;
}

public function getWorkflowName(): string
{
return $this->workflowName;
return $this->workflowId;
}

public function getWorkflowOptions(): array
Expand All @@ -94,6 +98,6 @@ public function getWorkflowOptions(): array

public function getTransition(): string
{
return $this->transition;
return $this->transitionId;
}
}
7 changes: 6 additions & 1 deletion src/Workflow/Service/WorkflowDetailsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Pimcore\Model\Element\ElementInterface;
use Pimcore\Model\UserInterface;
use Pimcore\Workflow\Manager;
use Symfony\Component\ExpressionLanguage\SyntaxError;
use Symfony\Component\Workflow\WorkflowInterface;
use function count;

Expand Down Expand Up @@ -87,7 +88,11 @@ public function hasElementWorkflowsById(int $elementId, string $elementType, Use

public function hasElementWorkflows(ElementInterface $element): bool
{
return count($this->workflowManager->getAllWorkflowsForSubject($element)) > 0;
try {
return count($this->workflowManager->getAllWorkflowsForSubject($element)) > 0;
} catch (SyntaxError) {
return false;
}
}

/**
Expand Down
12 changes: 6 additions & 6 deletions tests/Unit/Workflow/Schema/SubmitActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public function testSubmitActionException(): void
actionType: 'someUnusualType',
elementId: 1,
elementType: 'object',
workflowName: 'myWorkflow',
transition: 'myTransition',
workflowId: 'myWorkflow',
transitionId: 'myTransition',
workflowOptions: []
);
}
Expand All @@ -48,8 +48,8 @@ public function testSubmitActionElementException(): void
actionType: 'global',
elementId: 1,
elementType: 'someUnusualElementType',
workflowName: 'myWorkflow',
transition: 'myTransition',
workflowId: 'myWorkflow',
transitionId: 'myTransition',
workflowOptions: []
);
}
Expand All @@ -60,8 +60,8 @@ public function testSubmitActionParameters(): void
actionType: 'transition',
elementId: 1,
elementType: 'asset',
workflowName: 'myWorkflow',
transition: 'myTransition',
workflowId: 'myWorkflow',
transitionId: 'myTransition',
workflowOptions: []
);

Expand Down

0 comments on commit 8e9ab51

Please sign in to comment.