loadProcessInstanceEventEntity()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Jabe\Impl\History\Handler;
4
5
use Jabe\{
6
    ProcessEngineException,
7
    ProcessEngineConfiguration
8
};
9
use Jabe\Batch\BatchInterface;
10
use Jabe\Delegate\{
11
    DelegateExecutionInterface,
12
    DelegateTaskInterface,
13
    VariableScopeInterface
14
};
15
use Jabe\ExternalTask\ExternalTaskInterface;
16
use Jabe\History\{
17
    ExternalTaskStateImpl,
18
    ExternalTaskStateInterface,
19
    HistoricProcessInstanceInterface,
20
    IncidentStateImpl,
21
    JobStateImpl
22
};
23
use Jabe\Impl\ProcessEngineLogger;
24
use Jabe\Impl\Batch\BatchEntity;
25
use Jabe\Impl\Batch\History\HistoricBatchEntity;
26
use Jabe\Impl\Cfg\{
27
    ConfigurationLogger,
28
    IdGenerator
29
};
30
use Jabe\Impl\Context\Context;
31
use Jabe\Impl\History\DefaultHistoryRemovalTimeProvider;
32
use Jabe\Impl\History\Event\{
33
    HistoricActivityInstanceEventEntity,
34
    HistoricExternalTaskLogEntity,
35
    HistoricFormPropertyEventEntity,
36
    HistoricIdentityLinkLogEventEntity,
37
    HistoricIncidentEventEntity,
38
    HistoricProcessInstanceEventEntity,
39
    HistoricTaskInstanceEventEntity,
40
    HistoricVariableUpdateEventEntity,
41
    HistoryEvent,
42
    HistoryEventTypeInterface,
43
    HistoryEventTypes,
44
    UserOperationLogEntryEventEntity
45
};
46
use Jabe\Impl\JobExecutor\HistoryCleanup\HistoryCleanupJobHandler;
47
use Jabe\Impl\Migration\Instance\MigratingActivityInstance;
48
use Jabe\Impl\OpLog\{
49
    UserOperationLogContext,
50
    UserOperationLogContextEntry
51
};
52
use Jabe\Impl\Persistence\Entity\{
53
    ByteArrayEntity,
54
    ExecutionEntity,
55
    ExternalTaskEntity,
56
    HistoricJobLogEventEntity,
57
    IncidentEntity,
58
    JobEntity,
59
    ProcessDefinitionEntity,
60
    PropertyChange,
61
    TaskEntity,
62
    VariableInstanceEntity
63
};
64
use Jabe\Impl\Pvm\PvmScopeInterface;
65
use Jabe\Impl\Pvm\Runtime\CompensationBehavior;
66
use Jabe\Impl\Util\{
67
    ClockUtil,
68
    ExceptionUtil,
69
    ParseUtil,
70
    StringUtil
71
};
72
use Jabe\Repository\{
73
    ProcessDefinitionInterface,
74
    ResourceTypes
75
};
76
use Jabe\Runtime\{
77
    IncidentInterface,
78
    JobInterface
79
};
80
use Jabe\Task\IdentityLinkInterface;
81
82
class DefaultHistoryEventProducer implements HistoryEventProducerInterface
83
{
84
    //protected final static ConfigurationLogger LOG = ProcessEngineLogger.CONFIG_LOGGER;
85
86
    protected function initActivityInstanceEvent(
87
        HistoricActivityInstanceEventEntity $evt,
88
        ExecutionEntity $instance,
89
        HistoryEventTypeInterface $eventType
90
    ): void {
91
        $eventSource = $instance->getActivity();
92
        if ($eventSource == null) {
93
            $eventSource = $instance->getEventSource();
94
        }
95
        $activityInstanceId = $instance->getActivityInstanceId();
96
97
        $parentActivityInstanceId = null;
98
        $parentExecution = $instance->getParent();
99
100
        if ($parentExecution !== null && CompensationBehavior::isCompensationThrowing($parentExecution) && $instance->getActivity() !== null) {
101
            $parentActivityInstanceId = CompensationBehavior::getParentActivityInstanceId($instance);
102
        } else {
103
            $parentActivityInstanceId = $instance->getParentActivityInstanceId();
104
        }
105
106
        $this->initActivityInstanceEventWithIds(
107
            $evt,
108
            $instance,
109
            $eventSource,
110
            $activityInstanceId,
0 ignored issues
show
Bug introduced by
It seems like $activityInstanceId can also be of type null; however, parameter $activityInstanceId of Jabe\Impl\History\Handle...yInstanceEventWithIds() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

110
            /** @scrutinizer ignore-type */ $activityInstanceId,
Loading history...
111
            $parentActivityInstanceId,
0 ignored issues
show
Bug introduced by
It seems like $parentActivityInstanceId can also be of type null; however, parameter $parentActivityInstanceId of Jabe\Impl\History\Handle...yInstanceEventWithIds() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

111
            /** @scrutinizer ignore-type */ $parentActivityInstanceId,
Loading history...
112
            $eventType
113
        );
114
    }
115
116
    protected function initActivityInstanceEventWithMigration(
117
        HistoricActivityInstanceEventEntity $evt,
118
        MigratingActivityInstance $migratingActivityInstance,
119
        HistoryEventTypeInterface $eventType
120
    ): void {
121
        $eventSource = $migratingActivityInstance->getTargetScope();
122
        $activityInstanceId = $migratingActivityInstance->getActivityInstanceId();
123
124
        $parentInstance = $migratingActivityInstance->getParent();
125
        $parentActivityInstanceId = null;
126
        if ($parentInstance !== null) {
127
            $parentActivityInstanceId = $parentInstance->getActivityInstanceId();
128
        }
129
130
        $execution = $migratingActivityInstance->resolveRepresentativeExecution();
131
132
        $this->initActivityInstanceEventWithIds(
133
            $evt,
134
            $execution,
135
            $eventSource,
136
            $activityInstanceId,
137
            $parentActivityInstanceId,
138
            $eventType
139
        );
140
    }
141
142
    protected function initActivityInstanceEventWithIds(
143
        HistoricActivityInstanceEventEntity $evt,
144
        ExecutionEntity $execution,
145
        PvmScopeInterface $eventSource,
146
        string $activityInstanceId,
147
        string $parentActivityInstanceId,
148
        HistoryEventTypeInterface $eventType
149
    ): void {
150
151
        $evt->setId($activityInstanceId);
152
        $evt->setEventType($eventType->getEventName());
153
        $evt->setActivityInstanceId($activityInstanceId);
154
        $evt->setParentActivityInstanceId($parentActivityInstanceId);
155
        $evt->setProcessDefinitionId($execution->getProcessDefinitionId());
156
        $evt->setProcessInstanceId($execution->getProcessInstanceId());
157
        $evt->setExecutionId($execution->getId());
158
        $evt->setTenantId($execution->getTenantId());
159
        $evt->setRootProcessInstanceId($execution->getRootProcessInstanceId());
160
161
        if ($this->isHistoryRemovalTimeStrategyStart()) {
162
            $this->provideRemovalTime($evt);
163
        }
164
165
        $definition = $execution->getProcessDefinition();
166
        if ($definition !== null) {
167
            $evt->setProcessDefinitionKey($definition->getKey());
168
        }
169
170
        $evt->setActivityId($eventSource->getId());
171
        $evt->setActivityName($eventSource->getProperty("name"));
172
        $evt->setActivityType($eventSource->getProperty("type"));
173
174
        // update sub process reference
175
        $subProcessInstance = $execution->getSubProcessInstance();
176
        if ($subProcessInstance !== null) {
177
            $evt->setCalledProcessInstanceId($subProcessInstance->getId());
178
        }
179
180
        // update sub case reference
181
        /*CaseExecutionEntity subCaseInstance = $execution->getSubCaseInstance();
182
        if (subCaseInstance !== null) {
183
            $evt->setCalledCaseInstanceId(subCaseInstance->getId());
184
        }*/
185
    }
186
187
    protected function initProcessInstanceEvent(
188
        HistoricProcessInstanceEventEntity $evt,
189
        ExecutionEntity $execution,
190
        HistoryEventTypeInterface $eventType
191
    ): void {
192
        $processDefinitionId = $execution->getProcessDefinitionId();
193
        $processInstanceId = $execution->getProcessInstanceId();
194
        $executionId = $execution->getId();
195
        // the given execution is the process instance!
196
        //String caseInstanceId = $execution->getCaseInstanceId();
197
        $tenantId = $execution->getTenantId();
198
199
        $definition = $execution->getProcessDefinition();
200
        $processDefinitionKey = null;
201
        if ($definition !== null) {
202
            $processDefinitionKey = $definition->getKey();
203
        }
204
205
        $evt->setId($processInstanceId);
206
        $evt->setEventType($eventType->getEventName());
207
        $evt->setProcessDefinitionKey($processDefinitionKey);
0 ignored issues
show
Bug introduced by
It seems like $processDefinitionKey can also be of type null; however, parameter $processDefinitionKey of Jabe\Impl\History\Event\...tProcessDefinitionKey() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

207
        $evt->setProcessDefinitionKey(/** @scrutinizer ignore-type */ $processDefinitionKey);
Loading history...
208
        $evt->setProcessDefinitionId($processDefinitionId);
209
        $evt->setProcessInstanceId($processInstanceId);
210
        $evt->setExecutionId($executionId);
211
        $evt->setBusinessKey($execution->getProcessBusinessKey());
0 ignored issues
show
Bug introduced by
It seems like $execution->getProcessBusinessKey() can also be of type null; however, parameter $businessKey of Jabe\Impl\History\Event\...ntity::setBusinessKey() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

211
        $evt->setBusinessKey(/** @scrutinizer ignore-type */ $execution->getProcessBusinessKey());
Loading history...
212
        //$evt->setCaseInstanceId(caseInstanceId);
213
        $evt->setTenantId($tenantId);
214
        $evt->setRootProcessInstanceId($execution->getRootProcessInstanceId());
215
216
        /*if ($execution->getSuperCaseExecution() !== null) {
217
            $evt->setSuperCaseInstanceId($execution->getSuperCaseExecution()->getCaseInstanceId());
218
        }*/
219
        if ($execution->getSuperExecution() !== null) {
220
            $evt->setSuperProcessInstanceId($execution->getSuperExecution()->getProcessInstanceId());
221
        }
222
    }
223
224
    protected function initTaskInstanceEvent(
225
        HistoricTaskInstanceEventEntity $evt,
226
        TaskEntity $taskEntity,
227
        HistoryEventTypeInterface $eventType
228
    ): void {
229
        $processDefinitionKey = null;
230
        $definition = $taskEntity->getProcessDefinition();
231
        if ($definition !== null) {
232
            $processDefinitionKey = $definition->getKey();
233
        }
234
235
        $processDefinitionId = $taskEntity->getProcessDefinitionId();
236
        $processInstanceId = $taskEntity->getProcessInstanceId();
237
        $executionId = $taskEntity->getExecutionId();
238
239
        /*String caseDefinitionKey = null;
240
        CaseDefinitionEntity caseDefinition = $taskEntity->getCaseDefinition();
241
        if (caseDefinition !== null) {
242
            caseDefinitionKey = caseDefinition->getKey();
243
        }
244
245
        String caseDefinitionId = $taskEntity->getCaseDefinitionId();
246
        String caseExecutionId = $taskEntity->getCaseExecutionId();
247
        String caseInstanceId = $taskEntity->getCaseInstanceId();*/
248
        $tenantId = $taskEntity->getTenantId();
249
250
        $evt->setId($taskEntity->getId());
0 ignored issues
show
Bug introduced by
It seems like $taskEntity->getId() can also be of type null; however, parameter $id of Jabe\Impl\History\Event\HistoryEvent::setId() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

250
        $evt->setId(/** @scrutinizer ignore-type */ $taskEntity->getId());
Loading history...
251
        $evt->setEventType($eventType->getEventName());
252
        $evt->setTaskId($taskEntity->getId());
0 ignored issues
show
Bug introduced by
It seems like $taskEntity->getId() can also be of type null; however, parameter $taskId of Jabe\Impl\History\Event\...ventEntity::setTaskId() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

252
        $evt->setTaskId(/** @scrutinizer ignore-type */ $taskEntity->getId());
Loading history...
253
254
        $evt->setProcessDefinitionKey($processDefinitionKey);
0 ignored issues
show
Bug introduced by
It seems like $processDefinitionKey can also be of type null; however, parameter $processDefinitionKey of Jabe\Impl\History\Event\...tProcessDefinitionKey() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

254
        $evt->setProcessDefinitionKey(/** @scrutinizer ignore-type */ $processDefinitionKey);
Loading history...
255
        $evt->setProcessDefinitionId($processDefinitionId);
256
        $evt->setProcessInstanceId($processInstanceId);
257
        $evt->setExecutionId($executionId);
258
259
        /*$evt->setCaseDefinitionKey(caseDefinitionKey);
260
        $evt->setCaseDefinitionId(caseDefinitionId);
261
        $evt->setCaseExecutionId(caseExecutionId);
262
        $evt->setCaseInstanceId(caseInstanceId);*/
263
264
        $evt->setAssignee($taskEntity->getAssignee());
265
        $evt->setDescription($taskEntity->getDescription());
266
        $evt->setDueDate($taskEntity->getDueDate());
267
        $evt->setFollowUpDate($taskEntity->getFollowUpDate());
268
        $evt->setName($taskEntity->getName());
269
        $evt->setOwner($taskEntity->getOwner());
270
        $evt->setParentTaskId($taskEntity->getParentTaskId());
0 ignored issues
show
Bug introduced by
It seems like $taskEntity->getParentTaskId() can also be of type null; however, parameter $parentTaskId of Jabe\Impl\History\Event\...tity::setParentTaskId() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

270
        $evt->setParentTaskId(/** @scrutinizer ignore-type */ $taskEntity->getParentTaskId());
Loading history...
271
        $evt->setPriority($taskEntity->getPriority());
272
        $evt->setTaskDefinitionKey($taskEntity->getTaskDefinitionKey());
273
        $evt->setTenantId($tenantId);
274
275
        $execution = $taskEntity->getExecution();
276
        if ($execution !== null) {
277
            $evt->setActivityInstanceId($execution->getActivityInstanceId());
0 ignored issues
show
Bug introduced by
It seems like $execution->getActivityInstanceId() can also be of type null; however, parameter $activityInstanceId of Jabe\Impl\History\Event\...setActivityInstanceId() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

277
            $evt->setActivityInstanceId(/** @scrutinizer ignore-type */ $execution->getActivityInstanceId());
Loading history...
278
            $evt->setRootProcessInstanceId($execution->getRootProcessInstanceId());
279
280
            if ($this->isHistoryRemovalTimeStrategyStart()) {
281
                $this->provideRemovalTime($evt);
282
            }
283
        }
284
    }
285
286
    protected function initHistoricVariableUpdateEvt(
287
        HistoricVariableUpdateEventEntity $evt,
288
        VariableInstanceEntity $variableInstance,
289
        HistoryEventTypeInterface $eventType
290
    ): void {
291
292
        // init properties
293
        $evt->setEventType($eventType->getEventName());
294
        $evt->setTimestamp(ClockUtil::getCurrentTime()->format('c'));
295
        $evt->setVariableInstanceId($variableInstance->getId());
0 ignored issues
show
Bug introduced by
It seems like $variableInstance->getId() can also be of type null; however, parameter $variableInstanceId of Jabe\Impl\History\Event\...setVariableInstanceId() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

295
        $evt->setVariableInstanceId(/** @scrutinizer ignore-type */ $variableInstance->getId());
Loading history...
296
        $evt->setProcessInstanceId($variableInstance->getProcessInstanceId());
297
        $evt->setExecutionId($variableInstance->getExecutionId());
298
        //$evt->setCaseInstanceId($variableInstance->getCaseInstanceId());
299
        //$evt->setCaseExecutionId($variableInstance->getCaseExecutionId());
300
        $evt->setTaskId($variableInstance->getTaskId());
301
        $evt->setRevision($variableInstance->getRevision());
302
        $evt->setVariableName($variableInstance->getName());
303
        $evt->setSerializerName($variableInstance->getSerializerName());
304
        $evt->setTenantId($variableInstance->getTenantId());
305
        $evt->setUserOperationId(Context::getCommandContext()->getOperationId());
0 ignored issues
show
Bug introduced by
It seems like Jabe\Impl\Context\Contex...ext()->getOperationId() can also be of type null; however, parameter $userOperationId of Jabe\Impl\History\Event\...y::setUserOperationId() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

305
        $evt->setUserOperationId(/** @scrutinizer ignore-type */ Context::getCommandContext()->getOperationId());
Loading history...
306
307
        $execution = $variableInstance->getExecution();
308
        if ($execution !== null) {
309
            $definition = $execution->getProcessDefinition();
310
            if ($definition !== null) {
311
                $evt->setProcessDefinitionId($definition->getId());
312
                $evt->setProcessDefinitionKey($definition->getKey());
313
            }
314
            $evt->setRootProcessInstanceId($execution->getRootProcessInstanceId());
315
316
            if ($this->isHistoryRemovalTimeStrategyStart()) {
317
                $this->provideRemovalTime($evt);
318
            }
319
        }
320
321
        /*CaseExecutionEntity caseExecution = variableInstance->getCaseExecution();
322
        if (caseExecution !== null) {
323
            CaseDefinitionEntity definition = (CaseDefinitionEntity) caseExecution->getCaseDefinition();
324
            if (definition !== null) {
325
            $evt->setCaseDefinitionId(definition->getId());
326
            $evt->setCaseDefinitionKey(definition->getKey());
327
            }
328
        }*/
329
330
        // copy value
331
        $evt->setTextValue($variableInstance->getTextValue());
332
        $evt->setTextValue2($variableInstance->getTextValue2());
333
        $evt->setDoubleValue($variableInstance->getDoubleValue());
334
        $evt->setLongValue($variableInstance->getLongValue());
335
        if ($variableInstance->getByteArrayValueId() !== null) {
0 ignored issues
show
introduced by
The condition $variableInstance->getByteArrayValueId() !== null is always true.
Loading history...
336
            $evt->setByteValue($variableInstance->getByteArrayValue());
337
        }
338
    }
339
340
    protected function initUserOperationLogEvent(
341
        UserOperationLogEntryEventEntity $evt,
342
        UserOperationLogContext $context,
343
        UserOperationLogContextEntry $contextEntry,
344
        PropertyChange $propertyChange
345
    ): void {
346
        // init properties
347
        $evt->setDeploymentId($contextEntry->getDeploymentId());
348
        $evt->setEntityType($contextEntry->getEntityType());
349
        $evt->setOperationType($contextEntry->getOperationType());
350
        $evt->setOperationId($context->getOperationId());
351
        $evt->setUserId($context->getUserId());
352
        $evt->setProcessDefinitionId($contextEntry->getProcessDefinitionId());
353
        $evt->setProcessDefinitionKey($contextEntry->getProcessDefinitionKey());
354
        $evt->setProcessInstanceId($contextEntry->getProcessInstanceId());
355
        $evt->setExecutionId($contextEntry->getExecutionId());
356
        $evt->setCaseDefinitionId($contextEntry->getCaseDefinitionId());
0 ignored issues
show
Bug introduced by
The method getCaseDefinitionId() does not exist on Jabe\Impl\OpLog\UserOperationLogContextEntry. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

356
        $evt->setCaseDefinitionId($contextEntry->/** @scrutinizer ignore-call */ getCaseDefinitionId());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method setCaseDefinitionId() does not exist on Jabe\Impl\History\Event\...tionLogEntryEventEntity. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

356
        $evt->/** @scrutinizer ignore-call */ 
357
              setCaseDefinitionId($contextEntry->getCaseDefinitionId());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
357
        //$evt->setCaseInstanceId($contextEntry->getCaseInstanceId());
358
        $evt->setCaseExecutionId($contextEntry->getCaseExecutionId());
0 ignored issues
show
Bug introduced by
The method setCaseExecutionId() does not exist on Jabe\Impl\History\Event\...tionLogEntryEventEntity. Did you maybe mean setExecutionId()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

358
        $evt->/** @scrutinizer ignore-call */ 
359
              setCaseExecutionId($contextEntry->getCaseExecutionId());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method getCaseExecutionId() does not exist on Jabe\Impl\OpLog\UserOperationLogContextEntry. Did you maybe mean getExecutionId()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

358
        $evt->setCaseExecutionId($contextEntry->/** @scrutinizer ignore-call */ getCaseExecutionId());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
359
        $evt->setTaskId($contextEntry->getTaskId());
360
        $evt->setJobId($contextEntry->getJobId());
361
        $evt->setJobDefinitionId($contextEntry->getJobDefinitionId());
362
        $evt->setBatchId($contextEntry->getBatchId());
363
        $evt->setCategory($contextEntry->getCategory());
364
        $evt->setTimestamp(ClockUtil::getCurrentTime()->format('c'));
365
        $evt->setRootProcessInstanceId($contextEntry->getRootProcessInstanceId());
366
        $evt->setExternalTaskId($contextEntry->getExternalTaskId());
367
        $evt->setAnnotation($contextEntry->getAnnotation());
368
369
        if ($this->isHistoryRemovalTimeStrategyStart()) {
370
            $this->provideRemovalTime($evt);
371
        }
372
373
        // init property value
374
        $evt->setProperty($propertyChange->getPropertyName());
0 ignored issues
show
Bug introduced by
It seems like $propertyChange->getPropertyName() can also be of type null; however, parameter $property of Jabe\Impl\History\Event\...ntEntity::setProperty() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

374
        $evt->setProperty(/** @scrutinizer ignore-type */ $propertyChange->getPropertyName());
Loading history...
375
        $evt->setOrgValue($propertyChange->getOrgValueString());
0 ignored issues
show
Bug introduced by
It seems like $propertyChange->getOrgValueString() can also be of type null; however, parameter $orgValue of Jabe\Impl\History\Event\...ntEntity::setOrgValue() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

375
        $evt->setOrgValue(/** @scrutinizer ignore-type */ $propertyChange->getOrgValueString());
Loading history...
376
        $evt->setNewValue($propertyChange->getNewValueString());
0 ignored issues
show
Bug introduced by
It seems like $propertyChange->getNewValueString() can also be of type null; however, parameter $newValue of Jabe\Impl\History\Event\...ntEntity::setNewValue() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

376
        $evt->setNewValue(/** @scrutinizer ignore-type */ $propertyChange->getNewValueString());
Loading history...
377
    }
378
379
    protected function initHistoricIncidentEvent(
380
        HistoricIncidentEventEntity $evt,
381
        IncidentInterface $incident,
382
        HistoryEventTypeInterface $eventType
383
    ): void {
384
        // init properties
385
        $evt->setId($incident->getId());
386
        $evt->setProcessDefinitionId($incident->getProcessDefinitionId());
387
        $evt->setProcessInstanceId($incident->getProcessInstanceId());
388
        $evt->setExecutionId($incident->getExecutionId());
389
        $evt->setCreateTime($incident->getIncidentTimestamp());
390
        $evt->setIncidentType($incident->getIncidentType());
391
        $evt->setActivityId($incident->getActivityId());
392
        $evt->setCauseIncidentId($incident->getCauseIncidentId());
393
        $evt->setRootCauseIncidentId($incident->getRootCauseIncidentId());
394
        $evt->setConfiguration($incident->getConfiguration());
395
        $evt->setIncidentMessage($incident->getIncidentMessage());
396
        $evt->setTenantId($incident->getTenantId());
397
        $evt->setJobDefinitionId($incident->getJobDefinitionId());
398
        $evt->setHistoryConfiguration($incident->getHistoryConfiguration());
399
        $evt->setFailedActivityId($incident->getFailedActivityId());
0 ignored issues
show
Bug introduced by
It seems like $incident->getFailedActivityId() can also be of type null; however, parameter $failedActivityId of Jabe\Impl\History\Event\...::setFailedActivityId() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

399
        $evt->setFailedActivityId(/** @scrutinizer ignore-type */ $incident->getFailedActivityId());
Loading history...
400
        $evt->setAnnotation($incident->getAnnotation());
401
402
        $jobId = $incident->getConfiguration();
403
        if ($jobId !== null && $this->isHistoryRemovalTimeStrategyStart()) {
404
            $historicBatch = $this->getHistoricBatchByJobId($jobId);
405
            if ($historicBatch !== null) {
406
                $evt->setRemovalTime($historicBatch->getRemovalTime());
407
            }
408
        }
409
410
        $incidentEntity = $incident;
411
        $definition = $incidentEntity->getProcessDefinition();
0 ignored issues
show
Bug introduced by
The method getProcessDefinition() does not exist on Jabe\Runtime\IncidentInterface. Did you maybe mean getProcessDefinitionId()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

411
        /** @scrutinizer ignore-call */ 
412
        $definition = $incidentEntity->getProcessDefinition();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
412
        if ($definition !== null) {
413
            $evt->setProcessDefinitionKey($definition->getKey());
414
        }
415
416
        $execution = $incidentEntity->getExecution();
0 ignored issues
show
Bug introduced by
The method getExecution() does not exist on Jabe\Runtime\IncidentInterface. Did you maybe mean getExecutionId()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

416
        /** @scrutinizer ignore-call */ 
417
        $execution = $incidentEntity->getExecution();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
417
        if ($execution !== null) {
418
            $evt->setRootProcessInstanceId($execution->getRootProcessInstanceId());
419
420
            if ($this->isHistoryRemovalTimeStrategyStart()) {
421
                $this->provideRemovalTime($evt);
422
            }
423
        }
424
425
        // init event type
426
        $evt->setEventType($eventType->getEventName());
427
428
        // init state
429
        $incidentState = IncidentStateImpl::default();
430
        if (HistoryEventTypes::incidentDelete()->equals($eventType)) {
0 ignored issues
show
Bug introduced by
The method equals() does not exist on Jabe\Impl\History\Event\HistoryEventTypeInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Jabe\Impl\History\Event\HistoryEventTypeInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

430
        if (HistoryEventTypes::incidentDelete()->/** @scrutinizer ignore-call */ equals($eventType)) {
Loading history...
431
            $incidentState = IncidentStateImpl::deleted();
432
        } elseif (HistoryEventTypes::incidentResolve()->equals($eventType)) {
433
            $incidentState = IncidentStateImpl::resolved();
434
        }
435
        $evt->setIncidentState($incidentState->getStateCode());
436
    }
437
438
    protected function createHistoricVariableEvent(
439
        VariableInstanceEntity $variableInstance,
440
        VariableScopeInterface $sourceVariableScope,
441
        HistoryEventTypeInterface $eventType
442
    ): HistoryEvent {
443
        $scopeActivityInstanceId = null;
444
        $sourceActivityInstanceId = null;
445
446
        if ($variableInstance->getExecutionId() !== null) {
0 ignored issues
show
introduced by
The condition $variableInstance->getExecutionId() !== null is always true.
Loading history...
447
            $scopeExecution = Context::getCommandContext()
448
            ->getDbEntityManager()
449
            ->selectById(ExecutionEntity::class, $variableInstance->getExecutionId());
450
451
            if (
452
                $variableInstance->getTaskId() == null
453
                && !$variableInstance->isConcurrentLocal()
454
            ) {
455
                $scopeActivityInstanceId = $scopeExecution->getParentActivityInstanceId();
0 ignored issues
show
Bug introduced by
The method getParentActivityInstanceId() does not exist on Jabe\Impl\Db\DbEntityInterface. It seems like you code against a sub-type of Jabe\Impl\Db\DbEntityInterface such as Jabe\Impl\Persistence\Entity\ExecutionEntity or Jabe\Impl\History\Event\...vityInstanceEventEntity. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

455
                /** @scrutinizer ignore-call */ 
456
                $scopeActivityInstanceId = $scopeExecution->getParentActivityInstanceId();
Loading history...
456
            } else {
457
                $scopeActivityInstanceId = $scopeExecution->getActivityInstanceId();
0 ignored issues
show
Bug introduced by
The method getActivityInstanceId() does not exist on Jabe\Impl\Db\DbEntityInterface. It seems like you code against a sub-type of Jabe\Impl\Db\DbEntityInterface such as Jabe\Impl\Persistence\En...cVariableInstanceEntity or Jabe\Impl\Persistence\En...\VariableInstanceEntity or Jabe\Impl\Persistence\Entity\ExecutionEntity or Jabe\Impl\Persistence\Entity\ExternalTaskEntity or Jabe\Impl\History\Event\...icExternalTaskLogEntity or Jabe\Impl\History\Event\HistoricDetailEventEntity or Jabe\Impl\History\Event\...TaskInstanceEventEntity or Jabe\Impl\History\Event\...vityInstanceEventEntity. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

457
                /** @scrutinizer ignore-call */ 
458
                $scopeActivityInstanceId = $scopeExecution->getActivityInstanceId();
Loading history...
458
            }
459
        } elseif ($variableInstance->getCaseExecutionId() !== null) {
460
            $scopeActivityInstanceId = $variableInstance->getCaseExecutionId();
461
        }
462
463
        $sourceExecution = null;
464
        //CaseExecutionEntity sourceCaseExecution = null;
465
        if ($sourceVariableScope instanceof ExecutionEntity) {
466
            $sourceExecution = $sourceVariableScope;
467
            $sourceActivityInstanceId = $sourceExecution->getActivityInstanceId();
468
        } elseif ($sourceVariableScope instanceof TaskEntity) {
469
            $sourceExecution = $sourceVariableScope->getExecution();
470
            if ($sourceExecution !== null) {
471
                $sourceActivityInstanceId = $sourceExecution->getActivityInstanceId();
472
            }/* else {
473
                sourceCaseExecution = ((TaskEntity) sourceVariableScope)->getCaseExecution();
474
                if (sourceCaseExecution !== null) {
475
                    sourceActivityInstanceId = sourceCaseExecution->getId();
476
                }
477
            }*/
478
        } /*elseif (sourceVariableScopeInterface $instanceof CaseExecutionEntity) {
479
            sourceCaseExecution = (CaseExecutionEntity) sourceVariableScope;
480
            sourceActivityInstanceId = sourceCaseExecution->getId();
481
        }*/
482
483
        // create event
484
        $evt = $this->newVariableUpdateEventEntity($sourceExecution);
0 ignored issues
show
Bug introduced by
It seems like $sourceExecution can also be of type null; however, parameter $execution of Jabe\Impl\History\Handle...ableUpdateEventEntity() does only seem to accept Jabe\Impl\Persistence\Entity\ExecutionEntity, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

484
        $evt = $this->newVariableUpdateEventEntity(/** @scrutinizer ignore-type */ $sourceExecution);
Loading history...
485
        // initialize
486
        $this->initHistoricVariableUpdateEvt($evt, $variableInstance, $eventType);
487
        // initialize sequence counter
488
        $this->initSequenceCounter($variableInstance, $evt);
489
490
        // set scope activity instance id
491
        $evt->setScopeActivityInstanceId($scopeActivityInstanceId);
492
493
        // set source activity instance id
494
        $evt->setActivityInstanceId($sourceActivityInstanceId);
0 ignored issues
show
Bug introduced by
It seems like $sourceActivityInstanceId can also be of type null; however, parameter $activityInstanceId of Jabe\Impl\History\Event\...setActivityInstanceId() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

494
        $evt->setActivityInstanceId(/** @scrutinizer ignore-type */ $sourceActivityInstanceId);
Loading history...
495
496
        // mark initial variables on process start
497
        if (
498
            $sourceExecution !== null
499
            && $sourceExecution->isProcessInstanceStarting()
500
            && HistoryEventTypes::variabelInstanceCreate()->equals($eventType)
0 ignored issues
show
Bug introduced by
The method variabelInstanceCreate() does not exist on Jabe\Impl\History\Event\HistoryEventTypes. Did you maybe mean variableInstanceCreate()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

500
            && HistoryEventTypes::/** @scrutinizer ignore-call */ variabelInstanceCreate()->equals($eventType)

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
501
        ) {
502
            if ($variableInstance->getSequenceCounter() == 1) {
503
                $evt->setInitial(true);
504
            }
505
506
            if ($sourceActivityInstanceId == null && $sourceExecution->getActivity() !== null && $sourceExecution->getTransition() == null) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $sourceActivityInstanceId of type null|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
507
                $evt->setActivityInstanceId($sourceExecution->getProcessInstanceId());
508
            }
509
        }
510
511
        return $evt;
512
    }
513
514
    // event instance factory ////////////////////////
515
516
    protected function newProcessInstanceEventEntity(ExecutionEntity $execution): HistoricProcessInstanceEventEntity
0 ignored issues
show
Unused Code introduced by
The parameter $execution is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

516
    protected function newProcessInstanceEventEntity(/** @scrutinizer ignore-unused */ ExecutionEntity $execution): HistoricProcessInstanceEventEntity

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
517
    {
518
        return new HistoricProcessInstanceEventEntity();
519
    }
520
521
    protected function newActivityInstanceEventEntity(ExecutionEntity $execution): HistoricActivityInstanceEventEntity
0 ignored issues
show
Unused Code introduced by
The parameter $execution is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

521
    protected function newActivityInstanceEventEntity(/** @scrutinizer ignore-unused */ ExecutionEntity $execution): HistoricActivityInstanceEventEntity

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
522
    {
523
        return new HistoricActivityInstanceEventEntity();
524
    }
525
526
    protected function newTaskInstanceEventEntity(DelegateTaskInterface $task): HistoricTaskInstanceEventEntity
0 ignored issues
show
Unused Code introduced by
The parameter $task is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

526
    protected function newTaskInstanceEventEntity(/** @scrutinizer ignore-unused */ DelegateTaskInterface $task): HistoricTaskInstanceEventEntity

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
527
    {
528
        return new HistoricTaskInstanceEventEntity();
529
    }
530
531
    protected function newVariableUpdateEventEntity(ExecutionEntity $execution): HistoricVariableUpdateEventEntity
0 ignored issues
show
Unused Code introduced by
The parameter $execution is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

531
    protected function newVariableUpdateEventEntity(/** @scrutinizer ignore-unused */ ExecutionEntity $execution): HistoricVariableUpdateEventEntity

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
532
    {
533
        return new HistoricVariableUpdateEventEntity();
534
    }
535
536
    protected function newHistoricFormPropertyEvent(): HistoricFormPropertyEventEntity
537
    {
538
        return new HistoricFormPropertyEventEntity();
539
    }
540
541
    protected function newIncidentEventEntity(IncidentInterface $incident): HistoricIncidentEventEntity
0 ignored issues
show
Unused Code introduced by
The parameter $incident is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

541
    protected function newIncidentEventEntity(/** @scrutinizer ignore-unused */ IncidentInterface $incident): HistoricIncidentEventEntity

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
542
    {
543
        return new HistoricIncidentEventEntity();
544
    }
545
546
    protected function newHistoricJobLogEntity(JobInterface $job): HistoricJobLogEventEntity
0 ignored issues
show
Unused Code introduced by
The parameter $job is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

546
    protected function newHistoricJobLogEntity(/** @scrutinizer ignore-unused */ JobInterface $job): HistoricJobLogEventEntity

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
547
    {
548
        return new HistoricJobLogEventEntity();
549
    }
550
551
    protected function newBatchEventEntity(BatchEntity $batch): HistoricBatchEntity
0 ignored issues
show
Unused Code introduced by
The parameter $batch is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

551
    protected function newBatchEventEntity(/** @scrutinizer ignore-unused */ BatchEntity $batch): HistoricBatchEntity

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
552
    {
553
        return new HistoricBatchEntity();
554
    }
555
556
    protected function loadProcessInstanceEventEntity(ExecutionEntity $execution): HistoricProcessInstanceEventEntity
557
    {
558
        return $this->newProcessInstanceEventEntity($execution);
559
    }
560
561
    protected function loadActivityInstanceEventEntity(ExecutionEntity $execution): HistoricActivityInstanceEventEntity
562
    {
563
        return $this->newActivityInstanceEventEntity($execution);
564
    }
565
566
    protected function loadTaskInstanceEvent(DelegateTaskInterface $task): HistoricTaskInstanceEventEntity
567
    {
568
        return newTaskInstanceEventEntity($task);
0 ignored issues
show
Bug introduced by
The function newTaskInstanceEventEntity was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

568
        return /** @scrutinizer ignore-call */ newTaskInstanceEventEntity($task);
Loading history...
569
    }
570
571
    protected function loadIncidentEvent(IncidentInterface $incident): HistoricIncidentEventEntity
572
    {
573
        return $this->newIncidentEventEntity($incident);
574
    }
575
576
    protected function loadBatchEntity(BatchEntity $batch): HistoricBatchEntity
577
    {
578
        return newBatchEventEntity($batch);
0 ignored issues
show
Bug introduced by
The function newBatchEventEntity was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

578
        return /** @scrutinizer ignore-call */ newBatchEventEntity($batch);
Loading history...
579
    }
580
581
    // Implementation ////////////////////////////////
582
583
    public function createProcessInstanceStartEvt(DelegateExecutionInterface $execution): HistoryEvent
584
    {
585
        $executionEntity = $execution;
586
587
        // create event instance
588
        $evt = $this->newProcessInstanceEventEntity($executionEntity);
589
590
        // initialize event
591
        $this->initProcessInstanceEvent($evt, $executionEntity, HistoryEventTypes::processInstanceStart());
592
593
        $evt->setStartActivityId($executionEntity->getActivityId());
0 ignored issues
show
Bug introduced by
The method getActivityId() does not exist on Jabe\Delegate\DelegateExecutionInterface. Did you maybe mean getActivityInstanceId()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

593
        $evt->setStartActivityId($executionEntity->/** @scrutinizer ignore-call */ getActivityId());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
594
        $evt->setStartTime(ClockUtil::getCurrentTime()->format('c'));
595
596
        // set super process instance id
597
        $superExecution = $executionEntity->getSuperExecution();
598
        if ($superExecution !== null) {
599
            $evt->setSuperProcessInstanceId($superExecution->getProcessInstanceId());
600
        }
601
602
        //state
603
        $evt->setState(HistoricProcessInstanceInterface::STATE_ACTIVE);
604
605
        // set start user Id
606
        $evt->setStartUserId(Context::getCommandContext()->getAuthenticatedUserId());
0 ignored issues
show
Bug introduced by
It seems like Jabe\Impl\Context\Contex...etAuthenticatedUserId() can also be of type null; however, parameter $startUserId of Jabe\Impl\History\Event\...ntity::setStartUserId() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

606
        $evt->setStartUserId(/** @scrutinizer ignore-type */ Context::getCommandContext()->getAuthenticatedUserId());
Loading history...
607
608
        if ($this->isHistoryRemovalTimeStrategyStart()) {
609
            if ($this->isRootProcessInstance($evt)) {
610
                $removalTime = $this->calculateRemovalTime($evt);
611
                $evt->setRemovalTime($removalTime);
0 ignored issues
show
Bug introduced by
It seems like $removalTime can also be of type null; however, parameter $removalTime of Jabe\Impl\History\Event\...Event::setRemovalTime() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

611
                $evt->setRemovalTime(/** @scrutinizer ignore-type */ $removalTime);
Loading history...
612
            } else {
613
                $this->provideRemovalTime($evt);
614
            }
615
        }
616
617
        return $evt;
618
    }
619
620
    public function createProcessInstanceUpdateEvt(DelegateExecutionInterface $execution): HistoryEvent
621
    {
622
        $executionEntity = $execution;
623
624
        // create event instance
625
        $evt = $this->loadProcessInstanceEventEntity($executionEntity);
626
627
        // initialize event
628
        $this->initProcessInstanceEvent($evt, $executionEntity, HistoryEventTypes::processInstanceUpdate());
629
630
        if ($executionEntity->isSuspended()) {
0 ignored issues
show
Bug introduced by
The method isSuspended() does not exist on Jabe\Delegate\DelegateExecutionInterface. It seems like you code against a sub-type of Jabe\Delegate\DelegateExecutionInterface such as Jabe\Impl\Persistence\Entity\ExecutionEntity. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

630
        if ($executionEntity->/** @scrutinizer ignore-call */ isSuspended()) {
Loading history...
631
            $evt->setState(HistoricProcessInstanceInterface::STATE_SUSPENDED);
632
        } else {
633
            $evt->setState(HistoricProcessInstanceInterface::STATE_ACTIVE);
634
        }
635
636
        return $evt;
637
    }
638
639
    public function createProcessInstanceMigrateEvt(DelegateExecutionInterface $execution): HistoryEvent
640
    {
641
        $executionEntity = $execution;
642
643
        // create event instance
644
        $evt = $this->newProcessInstanceEventEntity($executionEntity);
645
646
        // initialize event
647
        $this->initProcessInstanceEvent($evt, $executionEntity, HistoryEventTypes::processInstanceMigrate());
648
649
        if ($executionEntity->isSuspended()) {
650
            $evt->setState(HistoricProcessInstanceInterface::STATE_SUSPENDED);
651
        } else {
652
            $evt->setState(HistoricProcessInstanceInterface::STATE_ACTIVE);
653
        }
654
655
        return $evt;
656
    }
657
658
    public function createProcessInstanceEndEvt(DelegateExecutionInterface $execution): HistoryEvent
659
    {
660
        $executionEntity = $execution;
661
662
        // create event instance
663
        $evt = $this->loadProcessInstanceEventEntity($executionEntity);
664
665
        // initialize event
666
        $this->initProcessInstanceEvent($evt, $executionEntity, HistoryEventTypes::processInstanceEnd());
667
668
        $this->determineEndState($executionEntity, $evt);
669
670
        // set end activity id
671
        $evt->setEndActivityId($executionEntity->getActivityId());
672
        $evt->setEndTime(ClockUtil::getCurrentTime()->format('c'));
673
674
        if ($evt->getStartTime() !== null) {
0 ignored issues
show
introduced by
The condition $evt->getStartTime() !== null is always true.
Loading history...
675
            $et = new \DateTime($evt->getEndTime());
676
            $endTimeUt = $et->getTimestamp();
677
678
            $st = new \DateTime($evt->getStartTime());
679
            $startTimeUt = $st->getTimestamp();
680
681
            $evt->setDurationInMillis($endTimeUt * 1000 - $startTimeUt * 1000);
682
        }
683
684
        if ($this->isRootProcessInstance($evt) && $this->isHistoryRemovalTimeStrategyEnd()) {
685
            $removalTime = $this->calculateRemovalTime($evt);
686
687
            if ($removalTime !== null) {
688
                $this->addRemovalTimeToHistoricProcessInstances($evt->getRootProcessInstanceId(), $removalTime);
689
                /*if ($this->isDmnEnabled()) {
690
                    $this->addRemovalTimeToHistoricDecisions($evt->getRootProcessInstanceId(), $removalTime);
691
                }*/
692
            }
693
        }
694
695
        // set delete reason (if applicable).
696
        if ($executionEntity->getDeleteReason() !== null) {
0 ignored issues
show
Bug introduced by
The method getDeleteReason() does not exist on Jabe\Delegate\DelegateExecutionInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Jabe\Impl\Pvm\Delegate\ActivityExecutionInterface. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

696
        if ($executionEntity->/** @scrutinizer ignore-call */ getDeleteReason() !== null) {
Loading history...
697
            $evt->setDeleteReason($executionEntity->getDeleteReason());
698
        }
699
700
        return $evt;
701
    }
702
703
    protected function addRemovalTimeToHistoricDecisions(string $rootProcessInstanceId, string $removalTime): void
704
    {
705
        Context::getCommandContext()
706
            ->getHistoricDecisionInstanceManager()
0 ignored issues
show
Bug introduced by
The method getHistoricDecisionInstanceManager() does not exist on Jabe\Impl\Interceptor\CommandContext. Did you maybe mean getHistoricProcessInstanceManager()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

706
            ->/** @scrutinizer ignore-call */ getHistoricDecisionInstanceManager()

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
707
            ->addRemovalTimeToDecisionsByRootProcessInstanceId($rootProcessInstanceId, $removalTime);
708
    }
709
710
    protected function addRemovalTimeToHistoricProcessInstances(string $rootProcessInstanceId, string $removalTime): void
711
    {
712
        Context::getCommandContext()
713
            ->getHistoricProcessInstanceManager()
714
            ->addRemovalTimeToProcessInstancesByRootProcessInstanceId($rootProcessInstanceId, $removalTime);
715
    }
716
717
    /*protected boolean isDmnEnabled() {
718
        return Context::getCommandContext()
719
            ->getProcessEngineConfiguration()
720
            ->isDmnEnabled();
721
    }*/
722
723
    protected function determineEndState(ExecutionEntity $executionEntity, HistoricProcessInstanceEventEntity $evt): void
724
    {
725
        //determine state
726
        if ($executionEntity->getActivity() !== null) {
727
            $evt->setState(HistoricProcessInstanceInterface::STATE_COMPLETED);
728
        } else {
729
            if ($executionEntity->isExternallyTerminated()) {
730
                $evt->setState(HistoricProcessInstanceInterface::STATE_EXTERNALLY_TERMINATED);
731
            } elseif (!$executionEntity->isExternallyTerminated()) {
732
                $evt->setState(HistoricProcessInstanceInterface::STATE_INTERNALLY_TERMINATED);
733
            }
734
        }
735
    }
736
737
    public function createActivityInstanceStartEvt(DelegateExecutionInterface $execution): HistoryEvent
738
    {
739
        $executionEntity = $execution;
740
741
        // create event instance
742
        $evt = $this->newActivityInstanceEventEntity($executionEntity);
743
744
        // initialize event
745
        $this->initActivityInstanceEvent($evt, $executionEntity, HistoryEventTypes::activityInstanceStart());
746
747
        // initialize sequence counter
748
        $this->initSequenceCounter($executionEntity, $evt);
749
750
        $evt->setStartTime(ClockUtil::getCurrentTime()->format('c'));
751
752
        return $evt;
753
    }
754
755
    public function createActivityInstanceUpdateEvt(DelegateExecutionInterface $execution, ?DelegateTaskInterface $task = null): HistoryEvent
756
    {
757
        $executionEntity = $execution;
758
759
        // create event instance
760
        $evt = $this->loadActivityInstanceEventEntity($executionEntity);
761
762
        // initialize event
763
        $this->initActivityInstanceEvent($evt, $executionEntity, HistoryEventTypes::activityInstanceUpdate());
764
765
        // update task assignment
766
        if ($task !== null) {
767
            $evt->setTaskId($task->getId());
768
            $evt->setTaskAssignee($task->getAssignee());
769
        }
770
771
        return $evt;
772
    }
773
774
    public function createActivityInstanceMigrateEvt(MigratingActivityInstance $actInstance): HistoryEvent
775
    {
776
777
        // create event instance
778
        $evt = $this->loadActivityInstanceEventEntity($actInstance->resolveRepresentativeExecution());
779
780
        // initialize event
781
        $this->initActivityInstanceEvent($evt, $actInstance, HistoryEventTypes::activityInstanceMigrate());
782
783
        return $evt;
784
    }
785
786
    public function createActivityInstanceEndEvt(DelegateExecutionInterface $execution): HistoryEvent
787
    {
788
        $executionEntity = $execution;
789
790
        // create event instance
791
        $evt = $this->loadActivityInstanceEventEntity($executionEntity);
792
        $evt->setActivityInstanceState($executionEntity->getActivityInstanceState());
0 ignored issues
show
Bug introduced by
The method getActivityInstanceState() does not exist on Jabe\Delegate\DelegateExecutionInterface. Did you maybe mean getActivityInstanceId()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

792
        $evt->setActivityInstanceState($executionEntity->/** @scrutinizer ignore-call */ getActivityInstanceState());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
793
794
        // initialize event
795
        $this->initActivityInstanceEvent($evt, $execution, HistoryEventTypes::activityInstanceEnd());
796
797
        $evt->setEndTime(ClockUtil::getCurrentTime()->format('c'));
798
        if ($evt->getStartTime() !== null) {
0 ignored issues
show
introduced by
The condition $evt->getStartTime() !== null is always true.
Loading history...
799
            $evt->setDurationInMillis((new \DateTime($evt->getEndTime()))->getTimestamp() * 1000 - (new \DateTime($evt->getStartTime()))->getTimestamp() * 1000);
800
        }
801
802
        return $evt;
803
    }
804
805
    public function createTaskInstanceCreateEvt(DelegateTaskInterface $task): HistoryEvent
806
    {
807
808
        // create event instance
809
        $evt = newTaskInstanceEventEntity($task);
0 ignored issues
show
Bug introduced by
The function newTaskInstanceEventEntity was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

809
        $evt = /** @scrutinizer ignore-call */ newTaskInstanceEventEntity($task);
Loading history...
810
811
        // initialize event
812
        $this->initTaskInstanceEvent($evt, $task, HistoryEventTypes::taskInstanceCreate());
813
814
        $evt->setStartTime(ClockUtil::getCurrentTime()->format('c'));
815
816
        return $evt;
817
    }
818
819
    public function createTaskInstanceUpdateEvt(DelegateTaskInterface $task): HistoryEvent
820
    {
821
822
        // create event instance
823
        $evt = $this->loadTaskInstanceEvent($task);
824
825
        // initialize event
826
        $this->initTaskInstanceEvent($evt, $task, HistoryEventTypes::taskInstanceUpdate());
827
828
        return $evt;
829
    }
830
831
    public function createTaskInstanceMigrateEvt(DelegateTaskInterface $task): HistoryEvent
832
    {
833
        // create event instance
834
        $evt = $this->loadTaskInstanceEvent($task);
835
836
        // initialize event
837
        $this->initTaskInstanceEvent($evt, $task, HistoryEventTypes::taskInstanceMigrate());
838
839
        return $evt;
840
    }
841
842
    public function createTaskInstanceCompleteEvt(DelegateTaskInterface $task, string $deleteReason): HistoryEvent
843
    {
844
        // create event instance
845
        $evt = $this->loadTaskInstanceEvent($task);
846
847
        // initialize event
848
        $this->initTaskInstanceEvent($evt, $task, HistoryEventTypes::taskInstanceComplete());
849
850
        // set end time
851
        $evt->setEndTime(ClockUtil::getCurrentTime()->format('c'));
852
        if ($evt->getStartTime() !== null) {
0 ignored issues
show
introduced by
The condition $evt->getStartTime() !== null is always true.
Loading history...
853
            $evt->setDurationInMillis((new \DateTime($evt->getEndTime()))->getTimestamp() * 1000 - (new \DateTime($evt->getStartTime()))->getTimestamp() * 1000);
854
        }
855
856
        // set delete reason
857
        $evt->setDeleteReason($deleteReason);
858
859
        return $evt;
860
    }
861
862
    // User Operation Logs ///////////////////////////
863
864
    public function createUserOperationLogEvents(UserOperationLogContext $context): array
865
    {
866
        $historyEvents = [];
867
868
        $operationId = Context::getCommandContext()->getOperationId();
869
        $context->setOperationId($operationId);
0 ignored issues
show
Bug introduced by
It seems like $operationId can also be of type null; however, parameter $operationId of Jabe\Impl\OpLog\UserOper...ntext::setOperationId() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

869
        $context->setOperationId(/** @scrutinizer ignore-type */ $operationId);
Loading history...
870
871
        foreach ($context->getEntries() as $entry) {
872
            foreach ($entry->getPropertyChanges() as $propertyChange) {
873
                $evt = new UserOperationLogEntryEventEntity();
874
875
                $this->initUserOperationLogEvent($evt, $context, $entry, $propertyChange);
876
877
                $historyEvents[] = $evt;
878
            }
879
        }
880
881
        return $historyEvents;
882
    }
883
884
    // variables /////////////////////////////////
885
886
    public function createHistoricVariableCreateEvt(VariableInstanceEntity $variableInstance, VariableScopeInterface $sourceVariableScope): HistoryEvent
887
    {
888
        return $this->createHistoricVariableEvent($variableInstance, $sourceVariableScope, HistoryEventTypes::variableInstanceCreate());
889
    }
890
891
    public function createHistoricVariableDeleteEvt(VariableInstanceEntity $variableInstance, VariableScopeInterface $sourceVariableScope): HistoryEvent
892
    {
893
        return $this->createHistoricVariableEvent($variableInstance, $sourceVariableScope, HistoryEventTypes::variableInstanceDelete());
894
    }
895
896
    public function createHistoricVariableUpdateEvt(VariableInstanceEntity $variableInstance, VariableScopeInterface $sourceVariableScope): HistoryEvent
897
    {
898
        return $this->createHistoricVariableEvent($variableInstance, $sourceVariableScope, HistoryEventTypes::variableInstanceUpdate());
899
    }
900
901
    public function createHistoricVariableMigrateEvt(VariableInstanceEntity $variableInstance): HistoryEvent
902
    {
903
        return $this->createHistoricVariableEvent($variableInstance, null, HistoryEventTypes::variableInstanceMigrate());
0 ignored issues
show
Bug introduced by
null of type null is incompatible with the type Jabe\Delegate\VariableScopeInterface expected by parameter $sourceVariableScope of Jabe\Impl\History\Handle...HistoricVariableEvent(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

903
        return $this->createHistoricVariableEvent($variableInstance, /** @scrutinizer ignore-type */ null, HistoryEventTypes::variableInstanceMigrate());
Loading history...
904
    }
905
906
    // form Properties ///////////////////////////
907
908
    public function createFormPropertyUpdateEvt(ExecutionEntity $execution, string $propertyId, string $propertyValue, string $taskId): HistoryEvent
909
    {
910
        $idGenerator = Context::getProcessEngineConfiguration()->getIdGenerator();
0 ignored issues
show
Bug introduced by
The method getIdGenerator() does not exist on Jabe\Impl\Cfg\ProcessEngineConfigurationImpl. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

910
        $idGenerator = Context::getProcessEngineConfiguration()->/** @scrutinizer ignore-call */ getIdGenerator();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
911
912
        $historicFormPropertyEntity = newHistoricFormPropertyEvent();
0 ignored issues
show
Bug introduced by
The function newHistoricFormPropertyEvent was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

912
        $historicFormPropertyEntity = /** @scrutinizer ignore-call */ newHistoricFormPropertyEvent();
Loading history...
913
914
        $historicFormPropertyEntity->setId($idGenerator->getNextId());
915
        $historicFormPropertyEntity->setEventType(HistoryEventTypes::formPropertyUpdate()->getEventName());
916
        $historicFormPropertyEntity->setTimestamp(ClockUtil::getCurrentTime()->format('c'));
917
        $historicFormPropertyEntity->setExecutionId($execution->getId());
918
        $historicFormPropertyEntity->setProcessDefinitionId($execution->getProcessDefinitionId());
919
        $historicFormPropertyEntity->setProcessInstanceId($execution->getProcessInstanceId());
920
        $historicFormPropertyEntity->setPropertyId($propertyId);
921
        $historicFormPropertyEntity->setPropertyValue($propertyValue);
922
        $historicFormPropertyEntity->setTaskId($taskId);
923
        $historicFormPropertyEntity->setTenantId($execution->getTenantId());
924
        $historicFormPropertyEntity->setUserOperationId(Context::getCommandContext()->getOperationId());
925
        $historicFormPropertyEntity->setRootProcessInstanceId($execution->getRootProcessInstanceId());
926
927
        if ($this->isHistoryRemovalTimeStrategyStart()) {
928
            $this->provideRemovalTime($historicFormPropertyEntity);
929
        }
930
931
        $definition = $execution->getProcessDefinition();
932
        if ($definition !== null) {
933
            $historicFormPropertyEntity->setProcessDefinitionKey($definition->getKey());
934
        }
935
936
        // initialize sequence counter
937
        $this->initSequenceCounter($execution, $historicFormPropertyEntity);
938
939
        if ($execution->isProcessInstanceStarting()) {
940
            // instantiate activity instance id as process instance id when starting a process instance
941
            // via a form
942
            $historicFormPropertyEntity->setActivityInstanceId($execution->getProcessInstanceId());
943
        } else {
944
            $historicFormPropertyEntity->setActivityInstanceId($execution->getActivityInstanceId());
945
        }
946
947
        return $historicFormPropertyEntity;
948
    }
949
950
    // Incidents //////////////////////////////////
951
952
    public function createHistoricIncidentCreateEvt(IncidentInterface $incident): HistoryEvent
953
    {
954
        return $this->createHistoricIncidentEvt($incident, HistoryEventTypes::incidentCreate());
955
    }
956
957
    public function createHistoricIncidentUpdateEvt(IncidentInterface $incident): HistoryEvent
958
    {
959
        return $this->createHistoricIncidentEvt($incident, HistoryEventTypes::incidentUpdate());
960
    }
961
962
    public function createHistoricIncidentResolveEvt(IncidentInterface $incident): HistoryEvent
963
    {
964
        return $this->createHistoricIncidentEvt($incident, HistoryEventTypes::incidentResolve());
965
    }
966
967
    public function createHistoricIncidentDeleteEvt(IncidentInterface $incident): HistoryEvent
968
    {
969
        return $this->createHistoricIncidentEvt($incident, HistoryEventTypes::incidentDelete());
970
    }
971
972
    public function createHistoricIncidentMigrateEvt(IncidentInterface $incident): HistoryEvent
973
    {
974
        return $this->createHistoricIncidentEvt($incident, HistoryEventTypes::incidentMigrate());
975
    }
976
977
    protected function createHistoricIncidentEvt(IncidentInterface $incident, HistoryEventTypes $eventType): HistoryEvent
978
    {
979
        // create event
980
        $evt = $this->loadIncidentEvent($incident);
981
        // initialize
982
        $this->initHistoricIncidentEvent($evt, $incident, $eventType);
983
984
        if (HistoryEventTypes::incidentResolve()->equals($eventType) || HistoryEventTypes::incidentDelete()->equals($eventType)) {
985
            $evt->setEndTime(ClockUtil::getCurrentTime()->format('c'));
986
        }
987
988
        return $evt;
989
    }
990
991
    public function createHistoricIdentityLinkAddEvent(IdentityLinkInterface $identityLink): HistoryEvent
992
    {
993
        return $this->createHistoricIdentityLinkEvt($identityLink, HistoryEventTypes::identityLinkAdd());
994
    }
995
996
    public function createHistoricIdentityLinkDeleteEvent(IdentityLinkInterface $identityLink): HistoryEvent
997
    {
998
        return $this->createHistoricIdentityLinkEvt($identityLink, HistoryEventTypes::identityLinkDelete());
999
    }
1000
1001
    protected function createHistoricIdentityLinkEvt(IdentityLinkInterface $identityLink, HistoryEventTypes $eventType): HistoryEvent
1002
    {
1003
        // create historic identity link event
1004
        $evt = newIdentityLinkEventEntity();
0 ignored issues
show
Bug introduced by
The function newIdentityLinkEventEntity was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1004
        $evt = /** @scrutinizer ignore-call */ newIdentityLinkEventEntity();
Loading history...
1005
        // Mapping all the values of identity link to HistoricIdentityLinkEvent
1006
        $this->initHistoricIdentityLinkEvent($evt, $identityLink, $eventType);
1007
        return $evt;
1008
    }
1009
1010
    protected function newIdentityLinkEventEntity(): HistoricIdentityLinkLogEventEntity
1011
    {
1012
        return new HistoricIdentityLinkLogEventEntity();
1013
    }
1014
1015
    protected function initHistoricIdentityLinkEvent(HistoricIdentityLinkLogEventEntity $evt, IdentityLinkInterface $identityLink, HistoryEventTypeInterface $eventType): void
1016
    {
1017
        if ($identityLink->getTaskId() !== null) {
0 ignored issues
show
introduced by
The condition $identityLink->getTaskId() !== null is always true.
Loading history...
1018
            $task = Context::getCommandContext()
1019
                ->getTaskManager()
1020
                ->findTaskById($identityLink->getTaskId());
1021
1022
            $evt->setProcessDefinitionId($task->getProcessDefinitionId());
1023
1024
            if ($task->getProcessDefinition() !== null) {
1025
                $evt->setProcessDefinitionKey($task->getProcessDefinition()->getKey());
1026
            }
1027
1028
            $execution = $task->getExecution();
1029
            if ($execution !== null) {
1030
                $evt->setRootProcessInstanceId($execution->getRootProcessInstanceId());
1031
1032
                if ($this->isHistoryRemovalTimeStrategyStart()) {
1033
                    $this->provideRemovalTime($evt);
1034
                }
1035
            }
1036
        }
1037
1038
        if ($identityLink->getProcessDefId() !== null) {
0 ignored issues
show
introduced by
The condition $identityLink->getProcessDefId() !== null is always true.
Loading history...
1039
            $evt->setProcessDefinitionId($identityLink->getProcessDefId());
1040
1041
            $definition = Context::getProcessEngineConfiguration()
1042
                ->getDeploymentCache()
0 ignored issues
show
Bug introduced by
The method getDeploymentCache() does not exist on Jabe\Impl\Cfg\ProcessEngineConfigurationImpl. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1042
                ->/** @scrutinizer ignore-call */ getDeploymentCache()

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1043
                ->findProcessDefinitionFromCache($identityLink->getProcessDefId());
1044
            $evt->setProcessDefinitionKey($definition->getKey());
1045
        }
1046
1047
        $evt->setTime(ClockUtil::getCurrentTime()->format('c'));
1048
        $evt->setType($identityLink->getType());
1049
        $evt->setUserId($identityLink->getUserId());
1050
        $evt->setGroupId($identityLink->getGroupId());
1051
        $evt->setTaskId($identityLink->getTaskId());
1052
        $evt->setTenantId($identityLink->getTenantId());
1053
        // There is a conflict in HistoryEventTypes for 'delete' keyword,
1054
        // So HistoryEventTypes.IDENTITY_LINK_ADD /
1055
        // HistoryEventTypes.IDENTITY_LINK_DELETE is provided with the event name
1056
        // 'add-identity-link' /'delete-identity-link'
1057
        // and changed to 'add'/'delete' (While inserting it into the database) on
1058
        // Historic identity link add / delete event
1059
        $operationType = "add";
1060
        if ($eventType->getEventName() == HistoryEventTypes::identityLinkDelete()->getEventName()) {
1061
            $operationType = "delete";
1062
        }
1063
1064
        $evt->setOperationType($operationType);
1065
        $evt->setEventType($eventType->getEventName());
1066
        $evt->setAssignerId(Context::getCommandContext()->getAuthenticatedUserId());
0 ignored issues
show
Bug introduced by
It seems like Jabe\Impl\Context\Contex...etAuthenticatedUserId() can also be of type null; however, parameter $assignerId of Jabe\Impl\History\Event\...Entity::setAssignerId() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1066
        $evt->setAssignerId(/** @scrutinizer ignore-type */ Context::getCommandContext()->getAuthenticatedUserId());
Loading history...
1067
    }
1068
    // Batch
1069
1070
    public function createBatchStartEvent(BatchInterface $batch): HistoryEvent
1071
    {
1072
        $historicBatch = $this->createBatchEvent($batch, HistoryEventTypes::batchStart());
1073
1074
        if ($this->isHistoryRemovalTimeStrategyStart()) {
1075
            $this->provideRemovalTime($historicBatch);
1076
        }
1077
1078
        return $historicBatch;
1079
    }
1080
1081
    public function createBatchEndEvent(BatchInterface $batch): HistoryEvent
1082
    {
1083
        $historicBatch = $this->createBatchEvent($batch, HistoryEventTypes::batchEnd());
1084
1085
        if ($this->isHistoryRemovalTimeStrategyEnd()) {
1086
            $this->provideRemovalTime($historicBatch);
1087
1088
            $this->addRemovalTimeToHistoricJobLog($historicBatch);
1089
            $this->addRemovalTimeToHistoricIncidents($historicBatch);
1090
        }
1091
1092
        return $historicBatch;
1093
    }
1094
1095
    protected function createBatchEvent(BatchEntity $batch, HistoryEventTypes $eventType): HistoryEvent
1096
    {
1097
        $event = $this->loadBatchEntity($batch);
1098
1099
        $event->setId($batch->getId());
1100
        $event->setType($batch->getType());
1101
        $event->setTotalJobs($batch->getTotalJobs());
1102
        $event->setBatchJobsPerSeed($batch->getBatchJobsPerSeed());
1103
        $event->setInvocationsPerBatchJob($batch->getInvocationsPerBatchJob());
1104
        $event->setSeedJobDefinitionId($batch->getSeedJobDefinitionId());
1105
        $event->setMonitorJobDefinitionId($batch->getMonitorJobDefinitionId());
1106
        $event->setBatchJobDefinitionId($batch->getBatchJobDefinitionId());
1107
        $event->setTenantId($batch->getTenantId());
1108
        $event->setEventType($eventType->getEventName());
1109
1110
        if (HistoryEventTypes::batchStart()->equals($eventType)) {
1111
            $event->setStartTime(ClockUtil::getCurrentTime()->format('c'));
1112
            $event->setCreateUserId(Context::getCommandContext()->getAuthenticatedUserId());
0 ignored issues
show
Bug introduced by
It seems like Jabe\Impl\Context\Contex...etAuthenticatedUserId() can also be of type null; however, parameter $createUserId of Jabe\Impl\Batch\History\...tity::setCreateUserId() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1112
            $event->setCreateUserId(/** @scrutinizer ignore-type */ Context::getCommandContext()->getAuthenticatedUserId());
Loading history...
1113
        }
1114
1115
        if (HistoryEventTypes::batchEnd()->equals($eventType)) {
1116
            $event->setEndTime(ClockUtil::getCurrentTime()->format('c'));
1117
        }
1118
1119
        return $event;
1120
    }
1121
1122
    // Job Log
1123
1124
    public function createHistoricJobLogCreateEvt(JobInterface $job): HistoryEvent
1125
    {
1126
        return $this->createHistoricJobLogEvt($job, HistoryEventTypes::jobCreate());
1127
    }
1128
1129
    public function createHistoricJobLogFailedEvt(JobInterface $job, ?\Throwable $exception = null): HistoryEvent
1130
    {
1131
        $event = $this->createHistoricJobLogEvt($job, HistoryEventTypes::jobFail());
1132
1133
        if ($exception !== null) {
1134
            // exception message
1135
            $event->setJobExceptionMessage($exception->getMessage());
0 ignored issues
show
Bug introduced by
The method setJobExceptionMessage() does not exist on Jabe\Impl\History\Event\HistoryEvent. It seems like you code against a sub-type of Jabe\Impl\History\Event\HistoryEvent such as Jabe\Impl\History\Event\HistoricJobLogEvent. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1135
            $event->/** @scrutinizer ignore-call */ 
1136
                    setJobExceptionMessage($exception->getMessage());
Loading history...
1136
1137
            // stacktrace
1138
            $exceptionStacktrace = ExceptionUtil::getExceptionStacktrace($exception);
1139
            $exceptionBytes = StringUtil::toByteArray($exceptionStacktrace);
1140
1141
            $byteArray = ExceptionUtil::createJobExceptionByteArray($exceptionBytes, ResourceTypes::history());
1142
            $byteArray->setRootProcessInstanceId($event->getRootProcessInstanceId());
1143
1144
            if ($this->isHistoryRemovalTimeStrategyStart()) {
1145
                $byteArray->setRemovalTime($event->getRemovalTime());
1146
            }
1147
1148
            $event->setExceptionByteArrayId($byteArray->getId());
0 ignored issues
show
Bug introduced by
The method setExceptionByteArrayId() does not exist on Jabe\Impl\History\Event\HistoryEvent. It seems like you code against a sub-type of Jabe\Impl\History\Event\HistoryEvent such as Jabe\Impl\History\Event\HistoricJobLogEvent. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1148
            $event->/** @scrutinizer ignore-call */ 
1149
                    setExceptionByteArrayId($byteArray->getId());
Loading history...
1149
        }
1150
1151
        return $event;
1152
    }
1153
1154
    public function createHistoricJobLogSuccessfulEvt(JobInterface $job): HistoryEvent
1155
    {
1156
        return $this->createHistoricJobLogEvt($job, HistoryEventTypes::jobSuccess());
1157
    }
1158
1159
    public function createHistoricJobLogDeleteEvt(JobInterface $job): HistoryEvent
1160
    {
1161
        return $this->createHistoricJobLogEvt($job, HistoryEventTypes::jobDelete());
1162
    }
1163
1164
    protected function createHistoricJobLogEvt(JobInterface $job, HistoryEventTypeInterface $eventType): HistoryEvent
1165
    {
1166
        $event = newHistoricJobLogEntity($job);
0 ignored issues
show
Bug introduced by
The function newHistoricJobLogEntity was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1166
        $event = /** @scrutinizer ignore-call */ newHistoricJobLogEntity($job);
Loading history...
1167
        $this->initHistoricJobLogEvent($event, $job, $eventType);
1168
        return $event;
1169
    }
1170
1171
    protected function initHistoricJobLogEvent(HistoricJobLogEventEntity $evt, JobInterface $job, HistoryEventTypeInterface $eventType): void
1172
    {
1173
        $currentTime = ClockUtil::getCurrentTime()->format('c');
1174
        $evt->setTimestamp($currentTime);
1175
1176
        $jobEntity = $job;
1177
        $evt->setJobId($jobEntity->getId());
0 ignored issues
show
Bug introduced by
It seems like $jobEntity->getId() can also be of type null; however, parameter $jobId of Jabe\Impl\History\Event\...JobLogEvent::setJobId() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1177
        $evt->setJobId(/** @scrutinizer ignore-type */ $jobEntity->getId());
Loading history...
1178
        $evt->setJobDueDate($jobEntity->getDuedate());
1179
        $evt->setJobRetries($jobEntity->getRetries());
1180
        $evt->setJobPriority($jobEntity->getPriority());
0 ignored issues
show
Bug introduced by
$jobEntity->getPriority() of type double is incompatible with the type integer expected by parameter $jobPriority of Jabe\Impl\History\Event\...Event::setJobPriority(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1180
        $evt->setJobPriority(/** @scrutinizer ignore-type */ $jobEntity->getPriority());
Loading history...
1181
1182
        $hostName = Context::getCommandContext()->getProcessEngineConfiguration()->getHostname();
0 ignored issues
show
Bug introduced by
The method getHostname() does not exist on Jabe\Impl\Cfg\ProcessEngineConfigurationImpl. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1182
        $hostName = Context::getCommandContext()->getProcessEngineConfiguration()->/** @scrutinizer ignore-call */ getHostname();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1183
        $evt->setHostname($hostName);
1184
1185
        if (HistoryCleanupJobHandler::TYPE == $jobEntity->getJobHandlerType()) {
0 ignored issues
show
Bug introduced by
The method getJobHandlerType() does not exist on Jabe\Runtime\JobInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Jabe\Runtime\JobInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1185
        if (HistoryCleanupJobHandler::TYPE == $jobEntity->/** @scrutinizer ignore-call */ getJobHandlerType()) {
Loading history...
1186
            $timeToLive = Context::getProcessEngineConfiguration()->getHistoryCleanupJobLogTimeToLive();
0 ignored issues
show
Bug introduced by
The method getHistoryCleanupJobLogTimeToLive() does not exist on Jabe\Impl\Cfg\ProcessEngineConfigurationImpl. Did you maybe mean getHistory()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1186
            $timeToLive = Context::getProcessEngineConfiguration()->/** @scrutinizer ignore-call */ getHistoryCleanupJobLogTimeToLive();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1187
            if ($timeToLive !== null) {
1188
                try {
1189
                    $timeToLiveDays = ParseUtil::parseHistoryTimeToLive($timeToLive);
1190
                    $removalTime = DefaultHistoryRemovalTimeProvider::determineRemovalTime($currentTime, $timeToLiveDays);
0 ignored issues
show
Bug introduced by
It seems like $timeToLiveDays can also be of type null; however, parameter $timeToLive of Jabe\Impl\History\Defaul...:determineRemovalTime() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1190
                    $removalTime = DefaultHistoryRemovalTimeProvider::determineRemovalTime($currentTime, /** @scrutinizer ignore-type */ $timeToLiveDays);
Loading history...
1191
                    $evt->setRemovalTime($removalTime);
1192
                } catch (ProcessEngineException $e) {
1193
                    //$wrappedException = LOG.invalidPropertyValue("historyCleanupJobLogTimeToLive", timeToLive, e);
1194
                    //LOG.invalidPropertyValue(wrappedException);
1195
                    throw $e;
1196
                }
1197
            }
1198
        }
1199
1200
        $jobDefinition = $jobEntity->getJobDefinition();
0 ignored issues
show
Bug introduced by
The method getJobDefinition() does not exist on Jabe\Runtime\JobInterface. Did you maybe mean getJobDefinitionId()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1200
        /** @scrutinizer ignore-call */ 
1201
        $jobDefinition = $jobEntity->getJobDefinition();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1201
        if ($jobDefinition !== null) {
1202
            $evt->setJobDefinitionId($jobDefinition->getId());
1203
            $evt->setJobDefinitionType($jobDefinition->getJobType());
1204
            $evt->setJobDefinitionConfiguration($jobDefinition->getJobConfiguration());
1205
1206
            $historicBatchId = $jobDefinition->getJobConfiguration();
1207
            if ($historicBatchId !== null && $this->isHistoryRemovalTimeStrategyStart()) {
1208
                $historicBatch = $this->getHistoricBatchById($historicBatchId);
1209
                if ($historicBatch !== null) {
1210
                    $evt->setRemovalTime($historicBatch->getRemovalTime());
1211
                }
1212
            }
1213
        } else {
1214
            // in case of async signal there does not exist a job definition
1215
            // but we use the jobHandlerType as jobDefinitionType
1216
            $evt->setJobDefinitionType($jobEntity->getJobHandlerType());
1217
        }
1218
1219
        $evt->setActivityId($jobEntity->getActivityId());
0 ignored issues
show
Bug introduced by
The method getActivityId() does not exist on Jabe\Runtime\JobInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Jabe\Runtime\JobInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1219
        $evt->setActivityId($jobEntity->/** @scrutinizer ignore-call */ getActivityId());
Loading history...
1220
        $evt->setFailedActivityId($jobEntity->getFailedActivityId());
0 ignored issues
show
Bug introduced by
It seems like $jobEntity->getFailedActivityId() can also be of type null; however, parameter $failedActivityId of Jabe\Impl\History\Event\...::setFailedActivityId() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1220
        $evt->setFailedActivityId(/** @scrutinizer ignore-type */ $jobEntity->getFailedActivityId());
Loading history...
1221
        $evt->setExecutionId($jobEntity->getExecutionId());
1222
        $evt->setProcessInstanceId($jobEntity->getProcessInstanceId());
1223
        $evt->setProcessDefinitionId($jobEntity->getProcessDefinitionId());
1224
        $evt->setProcessDefinitionKey($jobEntity->getProcessDefinitionKey());
1225
        $evt->setDeploymentId($jobEntity->getDeploymentId());
0 ignored issues
show
Bug introduced by
It seems like $jobEntity->getDeploymentId() can also be of type null; however, parameter $deploymentId of Jabe\Impl\History\Event\...vent::setDeploymentId() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1225
        $evt->setDeploymentId(/** @scrutinizer ignore-type */ $jobEntity->getDeploymentId());
Loading history...
1226
        $evt->setTenantId($jobEntity->getTenantId());
1227
1228
        $execution = $jobEntity->getExecution();
0 ignored issues
show
Bug introduced by
The method getExecution() does not exist on Jabe\Runtime\JobInterface. Did you maybe mean getExecutionId()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1228
        /** @scrutinizer ignore-call */ 
1229
        $execution = $jobEntity->getExecution();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1229
        if ($execution !== null) {
1230
            $evt->setRootProcessInstanceId($execution->getRootProcessInstanceId());
1231
1232
            if ($this->isHistoryRemovalTimeStrategyStart()) {
1233
                $this->provideRemovalTime($evt);
1234
            }
1235
        }
1236
1237
        // initialize sequence counter
1238
        $this->initSequenceCounter($jobEntity, $evt);
1239
1240
        $state = null;
1241
        if (HistoryEventTypes::jobCreate()->equals($eventType)) {
1242
            $state = JobStateImpl::created();
1243
        } elseif (HistoryEventTypes::jobFail()->equals($eventType)) {
1244
            $state = JobStateImpl::failed();
1245
        } elseif (HistoryEventTypes::jobSuccess()->equals($eventType)) {
1246
            $state = JobStateImpl::successful();
1247
        } elseif (HistoryEventTypes::jobDelete()->equals($eventType)) {
1248
            $state = JobStateImpl::deleted();
1249
        }
1250
        $evt->setState($state->getStateCode());
1251
    }
1252
1253
    public function createHistoricExternalTaskLogCreatedEvt(ExternalTaskInterface $task): HistoryEvent
1254
    {
1255
        return initHistoricExternalTaskLog($task, ExternalTaskStateImpl::created());
0 ignored issues
show
Bug introduced by
The function initHistoricExternalTaskLog was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1255
        return /** @scrutinizer ignore-call */ initHistoricExternalTaskLog($task, ExternalTaskStateImpl::created());
Loading history...
1256
    }
1257
1258
    public function createHistoricExternalTaskLogFailedEvt(ExternalTaskInterface $task): HistoryEvent
1259
    {
1260
        $event = $this->initHistoricExternalTaskLog($task, ExternalTaskStateImpl::failed());
1261
        $event->setErrorMessage($task->getErrorMessage());
1262
        $errorDetails = $task->getErrorDetails();
0 ignored issues
show
Bug introduced by
The method getErrorDetails() does not exist on Jabe\ExternalTask\ExternalTaskInterface. Did you maybe mean getErrorMessage()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1262
        /** @scrutinizer ignore-call */ 
1263
        $errorDetails = $task->getErrorDetails();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1263
        if ($errorDetails !== null) {
1264
            $event->setErrorDetails($errorDetails);
1265
        }
1266
        return $event;
1267
    }
1268
1269
    public function createHistoricExternalTaskLogSuccessfulEvt(ExternalTaskInterface $task): HistoryEvent
1270
    {
1271
        return $this->initHistoricExternalTaskLog($task, ExternalTaskStateImpl::successful());
1272
    }
1273
1274
    public function createHistoricExternalTaskLogDeletedEvt(ExternalTaskInterface $task): HistoryEvent
1275
    {
1276
        return $this->initHistoricExternalTaskLog($task, ExternalTaskStateImpl::deleted());
1277
    }
1278
1279
    protected function initHistoricExternalTaskLog(ExternalTaskEntity $entity, ExternalTaskStateInterface $state): HistoricExternalTaskLogEntity
1280
    {
1281
        $event = new HistoricExternalTaskLogEntity();
1282
        $event->setTimestamp(ClockUtil::getCurrentTime()->format('c'));
1283
        $event->setExternalTaskId($entity->getId());
0 ignored issues
show
Bug introduced by
It seems like $entity->getId() can also be of type null; however, parameter $externalTaskId of Jabe\Impl\History\Event\...ty::setExternalTaskId() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1283
        $event->setExternalTaskId(/** @scrutinizer ignore-type */ $entity->getId());
Loading history...
1284
        $event->setTopicName($entity->getTopicName());
1285
        $event->setWorkerId($entity->getWorkerId());
1286
1287
        $event->setPriority($entity->getPriority());
1288
        $event->setRetries($entity->getRetries());
1289
1290
        $event->setActivityId($entity->getActivityId());
1291
        $event->setActivityInstanceId($entity->getActivityInstanceId());
1292
        $event->setExecutionId($entity->getExecutionId());
1293
1294
        $event->setProcessInstanceId($entity->getProcessInstanceId());
1295
        $event->setProcessDefinitionId($entity->getProcessDefinitionId());
1296
        $event->setProcessDefinitionKey($entity->getProcessDefinitionKey());
1297
        $event->setTenantId($entity->getTenantId());
1298
        $event->setState($state->getStateCode());
0 ignored issues
show
Bug introduced by
The method getStateCode() does not exist on Jabe\History\ExternalTaskStateInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Jabe\History\ExternalTaskStateInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1298
        $event->setState($state->/** @scrutinizer ignore-call */ getStateCode());
Loading history...
1299
1300
        $execution = $entity->getExecution();
1301
        if ($execution !== null) {
1302
            $event->setRootProcessInstanceId($execution->getRootProcessInstanceId());
1303
1304
            if ($this->isHistoryRemovalTimeStrategyStart()) {
1305
                $this->provideRemovalTime($event);
1306
            }
1307
        }
1308
1309
        return $event;
1310
    }
1311
1312
    protected function isRootProcessInstance(HistoricProcessInstanceEventEntity $evt): bool
1313
    {
1314
        return $evt->getProcessInstanceId() == $evt->getRootProcessInstanceId();
1315
    }
1316
1317
    protected function isHistoryRemovalTimeStrategyStart(): bool
1318
    {
1319
        return ProcessEngineConfiguration::HISTORY_REMOVAL_TIME_STRATEGY_START == $this->getHistoryRemovalTimeStrategy();
1320
    }
1321
1322
    protected function isHistoryRemovalTimeStrategyEnd(): bool
1323
    {
1324
        return ProcessEngineConfiguration::HISTORY_REMOVAL_TIME_STRATEGY_END == $this->getHistoryRemovalTimeStrategy();
1325
    }
1326
1327
    protected function getHistoryRemovalTimeStrategy(): string
1328
    {
1329
        return Context::getProcessEngineConfiguration()
1330
            ->getHistoryRemovalTimeStrategy();
0 ignored issues
show
Bug introduced by
The method getHistoryRemovalTimeStrategy() does not exist on Jabe\Impl\Cfg\ProcessEngineConfigurationImpl. Did you maybe mean getHistory()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1330
            ->/** @scrutinizer ignore-call */ getHistoryRemovalTimeStrategy();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1331
    }
1332
1333
    protected function calculateRemovalTime($event): ?string
1334
    {
1335
        if ($event instanceof HistoryEvent) {
1336
            $processDefinitionId = $event->getProcessDefinitionId();
1337
            $processDefinition = findProcessDefinitionById($processDefinitionId);
0 ignored issues
show
Bug introduced by
The function findProcessDefinitionById was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1337
            $processDefinition = /** @scrutinizer ignore-call */ findProcessDefinitionById($processDefinitionId);
Loading history...
1338
1339
            return Context::getProcessEngineConfiguration()
1340
                ->getHistoryRemovalTimeProvider()
0 ignored issues
show
Bug introduced by
The method getHistoryRemovalTimeProvider() does not exist on Jabe\Impl\Cfg\ProcessEngineConfigurationImpl. Did you maybe mean getHistory()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1340
                ->/** @scrutinizer ignore-call */ getHistoryRemovalTimeProvider()

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1341
                ->calculateRemovalTime($event, $processDefinition);
1342
        } elseif ($event instanceof HistoricBatchEntity) {
1343
            return Context::getProcessEngineConfiguration()
1344
            ->getHistoryRemovalTimeProvider()
1345
            ->calculateRemovalTime($event);
1346
        }
1347
        return null;
1348
    }
1349
1350
    protected function provideRemovalTime($event): void
1351
    {
1352
        if ($event instanceof HistoryEvent) {
1353
            $rootProcessInstanceId = $event->getRootProcessInstanceId();
1354
            if ($rootProcessInstanceId !== null) {
0 ignored issues
show
introduced by
The condition $rootProcessInstanceId !== null is always true.
Loading history...
1355
                $historicRootProcessInstance = $this->getHistoricRootProcessInstance($rootProcessInstanceId);
1356
1357
                if ($historicRootProcessInstance !== null) {
1358
                    $removalTime = $historicRootProcessInstance->getRemovalTime();
1359
                    $event->setRemovalTime($removalTime);
1360
                }
1361
            }
1362
        } elseif ($event instanceof HistoricBatchEntity) {
1363
            $removalTime = $this->calculateRemovalTime($event);
1364
            if ($removalTime !== null) {
1365
                $event->setRemovalTime($removalTime);
1366
            }
1367
        }
1368
    }
1369
1370
    protected function getHistoricRootProcessInstance(string $rootProcessInstanceId): ?HistoricProcessInstanceEventEntity
1371
    {
1372
        return Context::getCommandContext()
1373
            ->getDbEntityManager()
1374
            ->selectById(HistoricProcessInstanceEventEntity::class, $rootProcessInstanceId);
1375
    }
1376
1377
    protected function findProcessDefinitionById(string $processDefinitionId): ?ProcessDefinitionInterface
1378
    {
1379
        return Context::getCommandContext()
1380
            ->getProcessEngineConfiguration()
1381
            ->getDeploymentCache()
1382
            ->findDeployedProcessDefinitionById($processDefinitionId);
1383
    }
1384
1385
    protected function getHistoricBatchById(string $batchId): ?HistoricBatchEntity
1386
    {
1387
        return Context::getCommandContext()
1388
            ->getHistoricBatchManager()
1389
            ->findHistoricBatchById($batchId);
1390
    }
1391
1392
    protected function getHistoricBatchByJobId(string $jobId): ?HistoricBatchEntity
1393
    {
1394
        return Context::getCommandContext()
1395
            ->getHistoricBatchManager()
1396
            ->findHistoricBatchByJobId($jobId);
1397
    }
1398
1399
    protected function addRemovalTimeToHistoricJobLog(HistoricBatchEntity $historicBatch): void
1400
    {
1401
        $removalTime = $historicBatch->getRemovalTime();
1402
        if ($removalTime !== null) {
0 ignored issues
show
introduced by
The condition $removalTime !== null is always true.
Loading history...
1403
            Context::getCommandContext()
1404
            ->getHistoricJobLogManager()
1405
            ->addRemovalTimeToJobLogByBatchId($historicBatch->getId(), $removalTime);
1406
        }
1407
    }
1408
1409
    protected function addRemovalTimeToHistoricIncidents(HistoricBatchEntity $historicBatch): void
1410
    {
1411
        $removalTime = $historicBatch->getRemovalTime();
1412
        if ($removalTime !== null) {
0 ignored issues
show
introduced by
The condition $removalTime !== null is always true.
Loading history...
1413
            Context::getCommandContext()
1414
            ->getHistoricIncidentManager()
1415
            ->addRemovalTimeToHistoricIncidentsByBatchId($historicBatch->getId(), $removalTime);
1416
        }
1417
    }
1418
1419
    // sequence counter //////////////////////////////////////////////////////
1420
1421
    protected function initSequenceCounter($obj, HistoryEvent $event): void
1422
    {
1423
        if (is_int($obj)) {
1424
            $event->setSequenceCounter($obj);
1425
        } elseif (method_exists($obj, 'getSequenceCounter')) {
1426
            $this->initSequenceCounter($obj->getSequenceCounter(), $event);
1427
        }
1428
    }
1429
}
1430