Skip to content

Commit

Permalink
Merge pull request doctrine-extensions#1791 from JCID/patch-1
Browse files Browse the repository at this point in the history
[Loggable] Allow for Embedded documents to also have child documents
  • Loading branch information
l3pp4rd authored May 29, 2017
2 parents 4d64048 + d8a2344 commit f65c02e
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 7 deletions.
7 changes: 6 additions & 1 deletion lib/Gedmo/Loggable/Mapping/Driver/Annotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,12 @@ private function inspectEmbeddedForVersioned($field, array &$config, \Doctrine\O
foreach ($сlass->getProperties() as $property) {
// versioned property
if ($this->reader->getPropertyAnnotation($property, self::VERSIONED)) {
$config['versioned'][] = $field . '.' . $property->getName();
$embeddedField = $field . '.' . $property->getName();
$config['versioned'][] = $embeddedField;

if (isset($meta->embeddedClasses[$embeddedField])) {
$this->inspectEmbeddedForVersioned($embeddedField, $config, $meta);
}
}
}
}
Expand Down
32 changes: 29 additions & 3 deletions tests/Gedmo/Loggable/Fixture/Entity/Geo.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,25 @@ class Geo
*/
protected $longitude;

/**
* @var GeoLocation $geoLocation
* @ORM\Embedded(class="Loggable\Fixture\Entity\GeoLocation")
* @Gedmo\Versioned()
*/
protected $geoLocation;

/**
* Geo constructor.
* @param string $latitude
* @param string $longitude
*
* @param string $latitude
* @param string $longitude
* @param GeoLocation $geoLocation
*/
public function __construct($latitude, $longitude)
public function __construct($latitude, $longitude, GeoLocation $geoLocation)
{
$this->latitude = $latitude;
$this->longitude = $longitude;
$this->geoLocation = $geoLocation;
}

/**
Expand Down Expand Up @@ -70,4 +80,20 @@ public function setLongitude($longitude)
{
$this->longitude = $longitude;
}

/**
* @return GeoLocation
*/
public function getGeoLocation()
{
return $this->geoLocation;
}

/**
* @param GeoLocation $geoLocation
*/
public function setGeoLocation($geoLocation)
{
$this->geoLocation = $geoLocation;
}
}
48 changes: 48 additions & 0 deletions tests/Gedmo/Loggable/Fixture/Entity/GeoLocation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Loggable\Fixture\Entity;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;

/**
* Class GeoLocation
* @package Loggable\Fixture
* @author Fabian Sabau <[email protected]>
*
* @ORM\Embeddable()
*/
class GeoLocation
{
/**
* @var string $latitude
* @ORM\Column(type="string")
* @Gedmo\Versioned()
*/
protected $location;

/**
* Geo constructor.
* @param string $location
*/
public function __construct($location)
{
$this->location = $location;
}

/**
* @return string
*/
public function getLocation()
{
return $this->location;
}

/**
* @param string $location
*/
public function setLocation($location)
{
$this->location = $location;
}
}
10 changes: 7 additions & 3 deletions tests/Gedmo/Loggable/LoggableEntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Gedmo\Loggable;

use Loggable\Fixture\Entity\GeoLocation;
use Tool\BaseTestCaseORM;
use Doctrine\Common\EventManager;
use Loggable\Fixture\Entity\Address;
Expand Down Expand Up @@ -144,7 +145,10 @@ public function testLogEmbedded()
$logEntries = $logRepo->getLogEntries($address);

$this->assertCount(4, $logEntries);

$this->assertCount(1, $logEntries[0]->getData());
$this->assertCount(2, $logEntries[1]->getData());
$this->assertCount(3, $logEntries[2]->getData());
$this->assertCount(5, $logEntries[3]->getData());
}

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

$geo = new Geo(1.0000, 1.0000);
$geo = new Geo(1.0000, 1.0000, new GeoLocation('Online'));

$address->setGeo($geo);

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

$geo2 = new Geo(2.0000, 2.0000);
$geo2 = new Geo(2.0000, 2.0000, new GeoLocation('Offline'));
$address->setGeo($geo2);

$this->em->persist($address);
Expand Down

0 comments on commit f65c02e

Please sign in to comment.