kor*_*ral 3 symfony doctrine-orm
我需要保留Profile的更改的数据库历史记录.除了配置文件数据,我必须保存时间戳和user_id.查询以创建新的历史记录很简单:
INSERT INTO history_profile
SELECT NULL, CURRENT_TIMESTAMP(), p.* FROM profile p WHERE p.profile_id=?
Run Code Online (Sandbox Code Playgroud)
放这个查询的地方?我不能使用触发器.我有几个想法:
在提交表单中调用的控制器中
$em = $this->getEntityManager();
$conn = $em->getConnection();
if (!is_null($profile->getProfileId()))
{
$conn->executeQuery('INSERT INTO history_profile SELECT NULL, CURRENT_TIMESTAMP(), p.* FROM profile p WHERE p.profile_id=?', array($profile->getProfileId()));
}
$em->persist($profile);
$em->flush();
Run Code Online (Sandbox Code Playgroud)
但即使没有对配置文件的更新,也会在每次提交时执行此查询.
在实体中,作为preUpdate的事件监听器
class Profile {
/**
* @ORM\preUpdate
* @ORM\prePersist
*/
public function onPrePersist()
{
}
}
Run Code Online (Sandbox Code Playgroud)
但我不知道如何获得教条的连接对象
编辑 - EntityAudit试用版
这个捆绑看起来很有希望,但我无法配置它.我正确安装它,当我添加到config.yml时:
simple_things_entity_audit:
audited_entities:
- AldenXyzBundle\Entity\Profile
Run Code Online (Sandbox Code Playgroud)
然后看了一下查询
php ./app/console doctrine:schema:update --dump-sql
Run Code Online (Sandbox Code Playgroud)
但是只有SQL用于创建表修订:
CREATE TABLE revisions (id INT AUTO_INCREMENT NOT NULL,
timestamp DATETIME NOT NULL, username VARCHAR(255) NOT NULL,
PRIMARY KEY(id)) ENGINE = InnoDB
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7779 次 |
最近记录: |