I need to implement versioning for some entities.
I have an entity "Map" which has a OneToMany association with "Spot" Entities. The "Map" and also "Spot" should be versionable.
It should be possibler to show older versions of a "Map" with all the asociated "Spots" on it.
So on an old version the "Map" itself could have another backgound-image, but also the position or number of associated "Spots" can differ.
I like this approach of the AuditLog (at the end of the page): http://www.doctrine-project.org/blog/doctrine2-versionable.html
[php]
class AuditListener implements EventSubscriber
{
public function getSubscribedEvents()
{
return array(Events::onFlush);
}
public function onFlush(OnFlushEventArgs $args)
{
$em = $args->getEntityManager();
$uow = $em->getUnitOfWork();
$changeDate = new DateTime("now");
$class = $em->getClassMetadata('DoctrineExtensions\Auditable\AuditEntry');
foreach ($uow->getScheduledEntityUpdates() AS $entity) {
if ($entity instanceof Auditable) {
$changeSet = $uow->getEntityChangeSet($entity);
foreach ($changeSet AS $field => $vals) {
list($oldValue, $newValue) = $vals;
$audit = new AuditEntry(
$entity->getResourceName(),
$entity->getId(),
$oldValue,
$newValue,
$changeDate
);
$em->persist($audit);
$em->getUnitOfWork()
->computeChangeSet($class, $audit);
}
}
}
}
}
I wonder how to handle association of the versionable entity.
For Example:
When a "Map" changes, a new Map Version is saved, but what about the Association to the Spots? When a "Spot" changes, what about its parent "Map".
When buliding the new Version of "Map": - how can I figure out that it has Association? - how can I figure out that a Association is also Versionable - how do I handle the Associatons
Even if an association is not versionable, if I change an associated non-versionable entity I also change the old versions of "Map" because they are also still associated.
Does anyone has experience or ideas how to manage that with doctrine 2.1?