I'd suggest having a look at this extension for Doctrine 2 -> EntityAudit (there's an explanation on how to install it in Symfony2).
As you can read in the documentation,
This extension for Doctrine 2 is inspired by Hibernate Envers and
allows full versioning of entities and their associations.
The usage is pretty simple. You could do the following once you have it installed:
- Specify the entities that you want to audit. Let's start by Product:
app/config/config.yml
simple_things_entity_audit:
audited_entities:
- MyBundle\Entity\Product
- Launch an update on your DB to create the necessary tables:
./app/console doctrine:schema:update --force
And then from your controller:
class DefaultController extends Controller {
public function indexAction() {
....
$auditReader = $this->container->get("simplethings_entityaudit.reader");
foreach( $orderLine as $product ) {// Let's assume for simplicity that this makes sense.
$productAudit = $auditReader->find(
'SimpleThings\EntityAudit\Tests\ProductAudit',
$id = $product->getId(),
$rev = 10 // Number of the revision you're interested in.
);
// Do whatever you please with the estate of the entity at revision 10!
}
....
}
}
Hope it helps.
Kind regards and happy new year.