Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions ProcessMaker/Nayra/Managers/WorkflowManagerDefault.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
use ProcessMaker\Nayra\Contracts\Bpmn\ThrowEventInterface;
use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface;
use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface;
use ProcessMaker\Repositories\DefinitionsRepository;

class WorkflowManagerDefault implements WorkflowManagerInterface
{
Expand Down Expand Up @@ -265,12 +264,28 @@ public function throwSignalEventDefinition(EventDefinitionInterface $sourceEvent
}

$excludeProcesses = [$token->getInstance()->getModel()->process_id];
$excludeRequests = [];
$instances = $token->getInstance()->getProcess()->getEngine()->getExecutionInstances();

$excludeRequests = $this->getCollaboratingInstanceIds($token->getInstance());
ThrowSignalEvent::dispatch($signalRef, $data, $excludeProcesses, $excludeRequests)->onQueue('bpmn');
}

/**
* Retrieves IDs of all instances collaborating with the given instance.
*
* This function compiles a list of IDs from execution instances associated
* with the same process as the input instance, including the instance itself.
*
* @param ProcessRequest $instance The instance to find collaborators for.
* @return int[] Array of collaborating instance IDs.
*/
protected function getCollaboratingInstanceIds($instance)
{
$ids = [];
$instances = $instance->getProcess()->getEngine()->getExecutionInstances();
foreach ($instances as $instance) {
$excludeRequests[] = $instance->getId();
$ids[] = $instance->getId();
}
ThrowSignalEvent::dispatch($signalRef, $data, $excludeProcesses, $excludeRequests)->onQueue('bpmn');
return $ids;
}

/**
Expand Down
18 changes: 18 additions & 0 deletions ProcessMaker/Nayra/Managers/WorkflowManagerRabbitMq.php
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,24 @@ public function throwSignalEventRequest(ProcessRequest $request, $signalRef, arr
]);
}

/**
* Retrieves IDs of all instances collaborating with the given instance.
*
* This function compiles a list of IDs from execution instances associated
* with the same process as the input instance, including the instance itself.
*
* @param ProcessRequest $instance The instance to find collaborators for.
* @return int[] Array of collaborating instance IDs.
*/
protected function getCollaboratingInstanceIds($instance)
{
$ids = ProcessRequest::
where('process_collaboration_id', $instance->process_collaboration_id)
->pluck('id')
->toArray();
return $ids;
}

/**
* Build a state object.
*
Expand Down
3 changes: 3 additions & 0 deletions ProcessMaker/Nayra/Repositories/PersistenceHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ public function save(array $transaction)
case 'start_event_triggered':
$this->persistStartEventTriggered($transaction);
break;
case 'throw_global_signal_event':
$this->throwGlobalSignalEvent($transaction);
break;
case 'event_based_gateway_activated':
$this->persistEventBasedGatewayActivated($transaction);
break;
Expand Down
9 changes: 9 additions & 0 deletions ProcessMaker/Nayra/Repositories/PersistenceTokenTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace ProcessMaker\Nayra\Repositories;

use Illuminate\Support\Facades\Cache;
use ProcessMaker\Facades\WorkflowManager;
use ProcessMaker\Listeners\BpmnSubscriber;
use ProcessMaker\Listeners\CommentsSubscriber;
use ProcessMaker\Nayra\Bpmn\Events\ActivityActivatedEvent;
Expand Down Expand Up @@ -298,4 +299,12 @@ public function persistAbout(array $aboutInfo)
error_log("Microservice $name version $version is running.");
Cache::put(self::$aboutCacheKey, $aboutInfo, 60);
}

public function throwGlobalSignalEvent(array $transaction)
{
$throwElement = $this->deserializer->unserializeEntity($transaction['throw_element']);
$token = $transaction['token'] ? $this->deserializer->unserializeToken($transaction['token']) : null;
$eventDefinition = $throwElement->getEventDefinitions()->item(0);
WorkflowManager::throwSignalEventDefinition($eventDefinition, $token);
}
}