3

さまざまなエンティティの変更を追跡し、他のテーブルから特定のバージョンを参照したいと考えています。例:Orderline表で、製品の特定のバージョンを参照したいと思います。

Loggable拡張機能はこの機能を実装する最良の方法ですか、それとも手動で ProductVersion エンティティを追加する必要がありますか?

私は現時点で使用していますが、現在のバージョン番号を取得するLoggableような機能が欠けていると思います。$product->getCurrentVersion()または、ドキュメントを読み間違えていますか?

4

3 に答える 3

2

この関数をリポジトリに実装して、現在/最後のバージョンを取得できます

public function getCurrentVersion($id)
{
    $repo = $this->_em->getRepository('Gedmo\Loggable\Entity\LogEntry');
    $log = $repo->findOneBy(array('objectId' =>$id), array('version' => 'desc'));
    return $log ? $log->getVersion() : null; // or return $log for entire object
}
于 2014-12-29T15:45:34.583 に答える
2

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();

あなたもすることができます:

  • 特定のリビジョンでエンティティの状態を見つける
  • 特定のリビジョンで変更されたエンティティを見つける
  • 監査対象エンティティの改訂履歴を見つける
于 2014-12-31T10:18:35.760 に答える