-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathProcessingErrorHandler.php
More file actions
116 lines (96 loc) · 3.68 KB
/
ProcessingErrorHandler.php
File metadata and controls
116 lines (96 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
namespace Flowpack\NodeTemplates\Domain\ErrorHandling;
use Neos\ContentRepository\Core\NodeType\NodeType;
use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Log\ThrowableStorageInterface;
use Neos\Flow\Log\Utility\LogEnvironment;
use Neos\Neos\Ui\Domain\Model\Feedback\Messages\Error;
use Neos\Neos\Ui\Domain\Model\Feedback\Messages\Warning;
use Neos\Neos\Ui\Domain\Model\FeedbackCollection;
use Psr\Log\LoggerInterface;
class ProcessingErrorHandler
{
/**
* @var FeedbackCollection
* @Flow\Inject(lazy=false)
*/
protected $feedbackCollection;
/**
* @var LoggerInterface
* @Flow\Inject
*/
protected $logger;
/**
* @var ThrowableStorageInterface
* @Flow\Inject
*/
protected $throwableStorage;
/**
* @var ErrorHandlingConfiguration
* @Flow\Inject
*/
protected $configuration;
/**
* @return bool if to continue or abort
*/
public function handleAfterTemplateConfigurationProcessing(ProcessingErrors $processingErrors, NodeType $nodeType, NodeAggregateId $nodeAggregateId): bool
{
if (!$processingErrors->hasError()) {
return true;
}
if (!$this->configuration->shouldStopOnExceptionAfterTemplateConfigurationProcessing()) {
return true;
}
$templateNotCreatedException = new TemplateNotCreatedException(
sprintf('Template for "%s" was not applied. Only %s was created.', $nodeType->getLabel(), $nodeAggregateId->value),
1686135532992,
$processingErrors->first()->getException(),
);
$this->logProcessingErrors($processingErrors, $templateNotCreatedException);
return false;
}
/**
* @return bool if to continue or abort
*/
public function handleAfterNodeCreation(ProcessingErrors $processingErrors, NodeType $nodeType, NodeAggregateId $nodeAggregateId): bool
{
if (!$processingErrors->hasError()) {
return true;
}
$templatePartiallyCreatedException = new TemplatePartiallyCreatedException(
sprintf('Template for "%s" only partially applied. Please check the newly created nodes beneath %s.', $nodeType->getLabel(), $nodeAggregateId->value),
1686135564160,
$processingErrors->first()->getException(),
);
$this->logProcessingErrors($processingErrors, $templatePartiallyCreatedException);
// TODO add setting to abort here in case of previous processing errors
return true;
}
/**
* @param TemplateNotCreatedException|TemplatePartiallyCreatedException $templateCreationException
*/
private function logProcessingErrors(ProcessingErrors $processingErrors, \DomainException $templateCreationException): void
{
$messages = [];
foreach ($processingErrors as $index => $processingError) {
$messages[sprintf('ProcessingError (%s)', $index)] = $processingError->toMessage();
}
// log exception
$messageWithReference = $this->throwableStorage->logThrowable($templateCreationException, $messages);
$this->logger->warning($messageWithReference, LogEnvironment::fromMethodName(__METHOD__));
// neos ui logging
$nodeTemplateError = new Error();
$nodeTemplateError->setMessage($templateCreationException->getMessage());
$this->feedbackCollection->add(
$nodeTemplateError
);
foreach ($messages as $message) {
$warning = new Warning();
$warning->setMessage($message);
$this->feedbackCollection->add(
$warning
);
}
}
}