Skip to content

Commit d735c2c

Browse files
authored
Merge pull request #45 from daniellienert/bugfix/fake-nodes
BUGFIX: Ensure that fake nodes are not persisted to the database
2 parents f1e0fef + 5aff189 commit d735c2c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Classes/Domain/Service/FakeNodeDataFactory.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Neos\ContentRepository\Domain\Service\NodeTypeManager;
2020
use Neos\ContentRepository\Exception\NodeTypeNotFoundException;
2121
use Neos\Flow\Annotations as Flow;
22+
use Neos\Flow\Persistence\Doctrine\PersistenceManager;
2223

2324
/**
2425
* @Flow\Scope("singleton")
@@ -37,14 +38,20 @@ class FakeNodeDataFactory
3738
*/
3839
protected $nodeTypeManager;
3940

41+
/**
42+
* @var PersistenceManager
43+
* @Flow\Inject
44+
*/
45+
protected $persistenceManager;
46+
4047
/**
4148
* This creates a "fake" removed NodeData instance from the given payload
4249
*
4350
* @param array $payload
4451
* @return NodeData
4552
* @throws Exception
4653
*/
47-
public function createFromPayload(array $payload)
54+
public function createFromPayload(array $payload): NodeData
4855
{
4956
if (!isset($payload['workspace']) || empty($payload['workspace'])) {
5057
throw new Exception('Unable to create fake node data, missing workspace value', 1508448007);
@@ -76,6 +83,11 @@ public function createFromPayload(array $payload)
7683

7784
$nodeData->setRemoved(true);
7885

86+
// Ensure, the fake-node is not persisted
87+
if ($this->persistenceManager->isNewObject($nodeData)) {
88+
$this->persistenceManager->remove($nodeData);
89+
}
90+
7991
return $nodeData;
8092
}
8193
}

0 commit comments

Comments
 (0)