Giter Club home page Giter Club logo

Comments (4)

marien-probesys avatar marien-probesys commented on August 26, 2024

I need to track activity of all Entities: insert, update and delete. This can be done pretty easily with a Doctrine Lifecycle Subscriber.

For updates, I have to track the changes. Changes can be retrieved via the unit of work:

public function postUpdate(LifecycleEventArgs $args): void
{
    $entity = $args->getObject();
    /** @var \Doctrine\ORM\EntityManager $entityManager */
    $entityManager = $args->getObjectManager();
    $unitOfWork = $entityManager->getUnitOfWork();
    $entityChanges = $unitOfWork->getEntityChangeSet($entity);

    // do something with $entityChanges
}

The activity can be saved in a table / entity EntityEvent with the following fields:

  • id
  • uid
  • createdAt
  • createdBy
  • type (insert, update or delete)
  • entity (polymorphic relation? entity_type, entity_id)
  • changes (a JSON object with the list of old and new values per affected fields, e.g. {'title': ['Old title', 'New title']}, {} for insert and delete)

The $entityChanges needs to be processed before serializing it in JSON because of possible relations. For instance, ticket.organization cannot be serialized. In this case, we need to retrieve the relation id (ticket.organization.id). An exception should be raised for other unserializable changes.

from bileto.

marien-probesys avatar marien-probesys commented on August 26, 2024

Note that the changes should be visually grouped as much as possible. For instance, one single action could trigger multiple changes. Visually, it could be great to identify this action, and allow to open the details of what changed.

from bileto.

marien-probesys avatar marien-probesys commented on August 26, 2024

Remaining questions:

  • should we clean the EntityEvent table? (e.g. after a certain time, or when the entity pointed by entity_id is deleted)
  • what about personal data of users? (don't log events of the User entity?)

from bileto.

marien-probesys avatar marien-probesys commented on August 26, 2024

Fetching ticket events:

$events = $entityEventRepository->findBy([
    'entity_type' => $ticket::class,
    'entity_id' => $ticket->getId(),
]);

// merge messages and events in a unique array ordered by `createdAt`
$timeline = Timeline::build($messages, $events);

Display timeline:

{% for timelineItem in timeline %}
    {% if class(timelineItem) == 'Message' %}
        {% include('tickets/_show_message', { message: timelineItem }) %}
    {% elseif class(timelineItem) == 'EntityEvent' %}
        {% include('tickets/_show_event', { event: timelineItem }) %}
    {% endif %}
{% endfor %}

from bileto.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.