Loggable拡張機能を使用すると、次のように実行できます。
$repo = $em->getRepository('Gedmo\Loggable\Entity\LogEntry');
// your Product entity
$product = $em->find('Entity\Product', $id);
// find revisions for given product
$logs = $repo->getLogEntries($product);
if (count($logs) > 0) {
// as it is sorted descending by version
$currentVersion = $repo->getLogEntries($product)[0]->getVersion();
}
EntityAudit拡張機能もお勧めします: https://github.com/simplethings/EntityAudit
あなたの場合、それは次のようになります:
$auditReader = $this->container->get("simplethings_entityaudit.reader");
$revision = $auditReader->getCurrentRevision(
'YourBundle\Entity\Product',
$id
);
// current version number
$revision->getRev();
あなたもすることができます:
- 特定のリビジョンでエンティティの状態を見つける
- 特定のリビジョンで変更されたエンティティを見つける
- 監査対象エンティティの改訂履歴を見つける