diff --git a/ProcessMaker/Console/Commands/OptimizeClearCommand.php b/ProcessMaker/Console/Commands/OptimizeClearCommand.php new file mode 100644 index 0000000000..9870ffa33b --- /dev/null +++ b/ProcessMaker/Console/Commands/OptimizeClearCommand.php @@ -0,0 +1,42 @@ +components->info('Clearing cached bootstrap files.'); + + collect([ + 'events' => fn () => $this->callSilent('event:clear') == 0, + 'views' => fn () => $this->callSilent('view:clear') == 0, + 'route' => fn () => $this->callSilent('route:clear') == 0, + ])->each(fn ($task, $description) => $this->components->task($description, $task)); + + $this->newLine(); + } +} diff --git a/ProcessMaker/Nayra/Managers/WorkflowManagerDefault.php b/ProcessMaker/Nayra/Managers/WorkflowManagerDefault.php index 7be0689130..4902a9ec37 100644 --- a/ProcessMaker/Nayra/Managers/WorkflowManagerDefault.php +++ b/ProcessMaker/Nayra/Managers/WorkflowManagerDefault.php @@ -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 { @@ -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; } /** diff --git a/ProcessMaker/Nayra/Managers/WorkflowManagerRabbitMq.php b/ProcessMaker/Nayra/Managers/WorkflowManagerRabbitMq.php index f942a69f92..dbd5ceb7c8 100644 --- a/ProcessMaker/Nayra/Managers/WorkflowManagerRabbitMq.php +++ b/ProcessMaker/Nayra/Managers/WorkflowManagerRabbitMq.php @@ -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. * diff --git a/ProcessMaker/Nayra/Repositories/PersistenceHandler.php b/ProcessMaker/Nayra/Repositories/PersistenceHandler.php index 8a4789b74a..17d5c662be 100644 --- a/ProcessMaker/Nayra/Repositories/PersistenceHandler.php +++ b/ProcessMaker/Nayra/Repositories/PersistenceHandler.php @@ -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; diff --git a/ProcessMaker/Nayra/Repositories/PersistenceTokenTrait.php b/ProcessMaker/Nayra/Repositories/PersistenceTokenTrait.php index 25b8cc256d..6d79d5a381 100644 --- a/ProcessMaker/Nayra/Repositories/PersistenceTokenTrait.php +++ b/ProcessMaker/Nayra/Repositories/PersistenceTokenTrait.php @@ -3,6 +3,8 @@ namespace ProcessMaker\Nayra\Repositories; use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Facades\Log; +use ProcessMaker\Facades\WorkflowManager; use ProcessMaker\Listeners\BpmnSubscriber; use ProcessMaker\Listeners\CommentsSubscriber; use ProcessMaker\Nayra\Bpmn\Events\ActivityActivatedEvent; @@ -165,9 +167,17 @@ public function persistGatewayTokenConsumed(array $transaction) public function persistGatewayTokenPassed(array $transaction) { $gateway = $this->deserializer->unserializeEntity($transaction['gateway']); - $transition = $this->deserializer->unserializeEntity($transaction['transition']); + if (!is_numeric($transaction['transition'])) { + Log::info('Invalid transition id for gateway token passed. ' . json_encode($transaction)); + return; + } + $transition = $gateway->getTransitions()[$transaction['transition']] ?? null; + if (empty($transition)) { + Log::info('Invalid transition for gateway token passed. ' . json_encode($transaction)); + return; + } $tokens = $this->deserializer->unserializeTokensCollection($transaction['tokens']); - $this->tokenRepository->persistGatewayTokenPassed($gateway, $tokens[0]); + $this->tokenRepository->persistGatewayTokenPassed($gateway, $tokens->item(0)); // Comments $subscriber = new CommentsSubscriber(); @@ -298,4 +308,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); + } } diff --git a/composer.json b/composer.json index 5af8de9678..71cb46835f 100644 --- a/composer.json +++ b/composer.json @@ -96,7 +96,7 @@ "Gmail" ], "processmaker": { - "build": "e24a3c60", + "build": "aa23ed0e", "custom": { "package-ellucian-ethos": "1.14.1", "package-plaid": "1.3.1", diff --git a/composer.lock b/composer.lock index a5a0c0eeed..75b80e7123 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "08d1c39d3fb9b2c3bd58193f03966e91", + "content-hash": "bb462c407499f96fbb57b8d1210e2e8b", "packages": [ { "name": "aws/aws-crt-php",