Comments (4)
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.
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.
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.
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)
- List of administrators HOT 1
- Add a page to display information about a user
- Provide a simplified interface to create tickets (API?)
- Link a finished contract to a ticket
- Assign tickets and unaccounted time spent when creating or renewing a contract
- Allow to filter/search into the list of organizations
- List "on-call" times
- Associate email domains with an organization
- Define a default user role HOT 1
- Automatically assign a ticket to a team/agent
- Detect and block spam
- Automatically close a resolved ticket after a certain amount of time HOT 1
- Allow users to reset their password
- Redesign the popup menu on mobile
- Put all the "new" buttons on the right
- Update to PHP-IMAP 5.6 (when released)
- Fix Foundry changing the Symfony error handler
- Bileto a ticket manager with Agile Scrum to manage project and tickets HOT 3
- Allow to import teams' agents
- Allow to import organizations' observers
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bileto.