Symfony2 und Doctrine2 - Historie der änderungen aufzeichnen

Ich brauche, um in der Datenbank der Geschichte der Veränderungen des Profils. Mit Ausnahme von Profil-Daten, die ich speichern muss, Zeitstempel und Benutzerkennung. Abfrage zur Erstellung einer neuen Historie-Datensatz ist einfach:

INSERT INTO history_profile 
SELECT NULL, CURRENT_TIMESTAMP(), p.* FROM profile p WHERE p.profile_id=?

Wo setzen Sie diese Abfrage? Ich kann nicht mit löst. Ich habe mehrere Ideen:

  1. controller in Aktion genannt, die auf " submit form

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

    aber diese Abfrage ausgeführt wird jeder Einreichen, auch wenn es keine updates zu Profilieren.

  2. in Person, als Ereignis-listener, um preUpdate

    class Profile {
        /**
         * @ORM\preUpdate
         * @ORM\prePersist
         */
        public function onPrePersist()
        {
        }
    }

    aber ich weiß nicht, wie man Lehre connection-Objekt

Bearbeiten - EntityAudit Studie

Diesem Set sieht vielversprechend aus, aber ich kann nicht konfigurieren. Ich installierte es richtig und wenn ich auf config.yml:

simple_things_entity_audit:
    audited_entities:
        - AldenXyzBundle\Entity\Profile

angeschaut und fragt nach

php ./app/console doctrine:schema:update --dump-sql

aber es war nur für SQL create table-Revisionen:

CREATE TABLE revisions (id INT AUTO_INCREMENT NOT NULL, 
timestamp DATETIME NOT NULL, username VARCHAR(255) NOT NULL, 
PRIMARY KEY(id)) ENGINE = InnoDB
InformationsquelleAutor koral | 2012-05-20
Schreibe einen Kommentar