Skip to content

Commit 46e1025

Browse files
Alexandre Blondfranmomu
authored andcommitted
[Fix] Tree PathHash field implementation in the Xml Driver of Tree
1 parent 7744700 commit 46e1025

File tree

6 files changed

+14
-0
lines changed

6 files changed

+14
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ a release.
2020

2121
## [Unreleased]
2222
### Fixed
23+
- Tree: Missing support for `tree-path-hash` fields in XML mapping.
2324
- Tree: Check for affected rows at `ClosureTreeRepository::cleanUpClosure()` and `Closure::updateNode()`.
2425
- `Gedmo\Mapping\Driver\Xml::_loadMappingFile()` behavior in scenarios where `libxml_disable_entity_loader(true)` was previously
2526
called.

schemas/orm/doctrine-extensions-mapping-2-2.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<xs:element name="tree-parent" type="gedmo:emptyType"/>
4444
<xs:element name="tree-path-source" type="gedmo:emptyType"/>
4545
<xs:element name="tree-lock-time" type="gedmo:emptyType"/>
46+
<xs:element name="tree-path-hash" type="gedmo:emptyType"/>
4647
<xs:element name="sortable-group" type="gedmo:emptyType"/>
4748
<xs:element name="sortable-position" type="gedmo:emptyType"/>
4849
<xs:element name="uploadable-file-mime-type" type="gedmo:emptyType"/>

src/Tree/Mapping/Driver/Xml.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ public function readExtendedMetadata($meta, array &$config)
139139
throw new InvalidMappingException("Tree PathSource field - [{$field}] type is not valid. It can be any of the integer variants, double, float or string in class - {$meta->name}");
140140
}
141141
$config['path_source'] = $field;
142+
} elseif (isset($mapping->{'tree-path-hash'})) {
143+
if (!$validator->isValidFieldForPathSource($meta, $field)) {
144+
throw new InvalidMappingException("Tree PathHash field - [{$field}] type is not valid and must be 'string' in class - {$meta->name}");
145+
}
146+
$config['path_hash'] = $field;
142147
} elseif (isset($mapping->{'tree-lock-time'})) {
143148
if (!$validator->isValidFieldForLockTime($meta, $field)) {
144149
throw new InvalidMappingException("Tree LockTime field - [{$field}] type is not valid. It must be \"date\" in class - {$meta->name}");

tests/Gedmo/Mapping/Driver/Xml/Gedmo.Tests.Mapping.Fixture.Xml.MaterializedPathTree.dcm.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
<field name="lockTime" type="datetime">
2020
<gedmo:tree-lock-time/>
2121
</field>
22+
<field name="pathHash" type="string" nullable="true">
23+
<gedmo:tree-path-hash/>
24+
</field>
2225
<many-to-one field="parent" target-entity="MaterializedPathTree">
2326
<join-column name="parent_id" referenced-column-name="id" on-delete="CASCADE"/>
2427
<gedmo:tree-parent/>

tests/Gedmo/Mapping/Fixture/Xml/MaterializedPathTree.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class MaterializedPathTree
1212

1313
private $lockTime;
1414

15+
private $pathHash;
16+
1517
private $parent;
1618

1719
private $level;

tests/Gedmo/Mapping/Xml/MaterializedPathTreeMappingTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,7 @@ public function testTreeMetadata()
7777
static::assertEquals('path', $config['path']);
7878
static::assertArrayHasKey('lock_time', $config);
7979
static::assertEquals('lockTime', $config['lock_time']);
80+
static::assertArrayHasKey('path_hash', $config);
81+
static::assertEquals('pathHash', $config['path_hash']);
8082
}
8183
}

0 commit comments

Comments
 (0)