I need to save profile changes in the database history. With the exception of profile data, I have to save timestamp and user_id. The request to create a new history record is simple:
INSERT INTO history_profile
SELECT NULL, CURRENT_TIMESTAMP(), p.* FROM profile p WHERE p.profile_id=?
Where is this request? I can not use triggers. I have some ideas:
in the controller in the action called in the form of sending
$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();
but this request is executed each, even if updates are not updated.
essentially as an event listener for preUpdate
class Profile {
public function onPrePersist()
{
}
}
but I do not know how to get the doctrine compound object
edit - trial version of EntityAudit
This package looks promising, but I cannot configure it. I installed it correctly and add it to config.yml:
simple_things_entity_audit:
audited_entities:
- AldenXyzBundle\Entity\Profile
and looked at requests after
php ./app/console doctrine:schema:update
but there was only SQL to create table editions:
CREATE TABLE revisions (id INT AUTO_INCREMENT NOT NULL,
timestamp DATETIME NOT NULL, username VARCHAR(255) NOT NULL,
PRIMARY KEY(id)) ENGINE = InnoDB
koral source