Skip to content

Commit f65c02e

Browse files
authored
Merge pull request #1791 from JCID/patch-1
[Loggable] Allow for Embedded documents to also have child documents
2 parents 4d64048 + d8a2344 commit f65c02e

File tree

4 files changed

+90
-7
lines changed

4 files changed

+90
-7
lines changed

lib/Gedmo/Loggable/Mapping/Driver/Annotation.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,12 @@ private function inspectEmbeddedForVersioned($field, array &$config, \Doctrine\O
128128
foreach ($сlass->getProperties() as $property) {
129129
// versioned property
130130
if ($this->reader->getPropertyAnnotation($property, self::VERSIONED)) {
131-
$config['versioned'][] = $field . '.' . $property->getName();
131+
$embeddedField = $field . '.' . $property->getName();
132+
$config['versioned'][] = $embeddedField;
133+
134+
if (isset($meta->embeddedClasses[$embeddedField])) {
135+
$this->inspectEmbeddedForVersioned($embeddedField, $config, $meta);
136+
}
132137
}
133138
}
134139
}

tests/Gedmo/Loggable/Fixture/Entity/Geo.php

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,25 @@ class Geo
2828
*/
2929
protected $longitude;
3030

31+
/**
32+
* @var GeoLocation $geoLocation
33+
* @ORM\Embedded(class="Loggable\Fixture\Entity\GeoLocation")
34+
* @Gedmo\Versioned()
35+
*/
36+
protected $geoLocation;
37+
3138
/**
3239
* Geo constructor.
33-
* @param string $latitude
34-
* @param string $longitude
40+
*
41+
* @param string $latitude
42+
* @param string $longitude
43+
* @param GeoLocation $geoLocation
3544
*/
36-
public function __construct($latitude, $longitude)
45+
public function __construct($latitude, $longitude, GeoLocation $geoLocation)
3746
{
3847
$this->latitude = $latitude;
3948
$this->longitude = $longitude;
49+
$this->geoLocation = $geoLocation;
4050
}
4151

4252
/**
@@ -70,4 +80,20 @@ public function setLongitude($longitude)
7080
{
7181
$this->longitude = $longitude;
7282
}
83+
84+
/**
85+
* @return GeoLocation
86+
*/
87+
public function getGeoLocation()
88+
{
89+
return $this->geoLocation;
90+
}
91+
92+
/**
93+
* @param GeoLocation $geoLocation
94+
*/
95+
public function setGeoLocation($geoLocation)
96+
{
97+
$this->geoLocation = $geoLocation;
98+
}
7399
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace Loggable\Fixture\Entity;
4+
5+
use Doctrine\ORM\Mapping as ORM;
6+
use Gedmo\Mapping\Annotation as Gedmo;
7+
8+
/**
9+
* Class GeoLocation
10+
* @package Loggable\Fixture
11+
* @author Fabian Sabau <[email protected]>
12+
*
13+
* @ORM\Embeddable()
14+
*/
15+
class GeoLocation
16+
{
17+
/**
18+
* @var string $latitude
19+
* @ORM\Column(type="string")
20+
* @Gedmo\Versioned()
21+
*/
22+
protected $location;
23+
24+
/**
25+
* Geo constructor.
26+
* @param string $location
27+
*/
28+
public function __construct($location)
29+
{
30+
$this->location = $location;
31+
}
32+
33+
/**
34+
* @return string
35+
*/
36+
public function getLocation()
37+
{
38+
return $this->location;
39+
}
40+
41+
/**
42+
* @param string $location
43+
*/
44+
public function setLocation($location)
45+
{
46+
$this->location = $location;
47+
}
48+
}

tests/Gedmo/Loggable/LoggableEntityTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Gedmo\Loggable;
44

5+
use Loggable\Fixture\Entity\GeoLocation;
56
use Tool\BaseTestCaseORM;
67
use Doctrine\Common\EventManager;
78
use Loggable\Fixture\Entity\Address;
@@ -144,7 +145,10 @@ public function testLogEmbedded()
144145
$logEntries = $logRepo->getLogEntries($address);
145146

146147
$this->assertCount(4, $logEntries);
147-
148+
$this->assertCount(1, $logEntries[0]->getData());
149+
$this->assertCount(2, $logEntries[1]->getData());
150+
$this->assertCount(3, $logEntries[2]->getData());
151+
$this->assertCount(5, $logEntries[3]->getData());
148152
}
149153

150154
protected function getUsedEntityFixtures()
@@ -166,14 +170,14 @@ private function populateEmbedded()
166170
$address->setCity('city-v1');
167171
$address->setStreet('street-v1');
168172

169-
$geo = new Geo(1.0000, 1.0000);
173+
$geo = new Geo(1.0000, 1.0000, new GeoLocation('Online'));
170174

171175
$address->setGeo($geo);
172176

173177
$this->em->persist($address);
174178
$this->em->flush();
175179

176-
$geo2 = new Geo(2.0000, 2.0000);
180+
$geo2 = new Geo(2.0000, 2.0000, new GeoLocation('Offline'));
177181
$address->setGeo($geo2);
178182

179183
$this->em->persist($address);

0 commit comments

Comments
 (0)