Discuss your project
Partitech Sonata Extra Bundle

Sonata Extra Bundle: activity log

Overview The activity log function of the Sonata Extra Bundle is designed to monitor and record all activities within the administration site. It provides a complete view of the actions performed, the resources involved, descriptions of the activities, and...

Sonata Extra Bundle: activity log

Overview

The activity log function of the Sonata Extra Bundle is designed to monitor and record all activities within the administration site. It provides a complete view of the actions performed, the resources involved, descriptions of the activities, and the users who carried them out.

Features

  • Display of the action type: Displays the type of action performed (for example, create, update, delete).
  • Resource tracking: Identify the resource that was affected by the action.
  • Action Description: Provides a detailed description of the activity.
  • User Identification: Displays the user who performed the action.
  • Detailed view: Provides an in-depth view of the elements changed in each activity.
  • Undo: Includes a feature that allows reversing changes when possible.

Screens

  • List view:

Activity_log_index.png

  • Detailed view:

Activity_journal_detail.png

Activity Log Activation

To activate the activity log feature, the following service configuration must be added to your services file:

sonata-extra.doctrine_activity_listener:
    class: Partitech\SonataExtra\EventListener\DoctrineActivityListener
    tags:
        - { name: doctrine.event_listener, event: prePersist }
        - { name: doctrine.event_listener, event: preUpdate }
        - { name: doctrine.event_listener, event: preRemove }
        - { name: doctrine.event_listener, event: onFlush }
        - { name: kernel.event_listener, event: sonata.admin.event.batch_action.pre_batch_action, method: onPreBatchAction }

Implementation details

  • The DoctrineActivityListener class is responsible for listening to various Doctrine and Sonata administration events.
  • Events such as prePersist, preUpdate, preRemove, and onFlush are tracked to record activities related to changes in the lifecycle of entities.
  • The onPreBatchAction method handles the logging of batch actions performed in the Sonata administration.

Usage

Once activated, the Activity Log function will automatically start recording activities based on the configured events. The logs can be viewed in the administration interface, where the details of each activity are displayed clearly.

Conclusion

The activity log is a powerful feature for monitoring and controlling actions within the Sonata administration interface. It enhances transparency and accountability by providing clear and detailed logs of all activities.

Adapt the example to the installed version

The Symfony and Sonata examples remain tied to the versions indicated in the article. Symfony 4.x and Symfony 6.2 are no longer maintained: for a current project, use a maintained branch and the documentation that exactly matches your dependencies.

php bin/console about
composer show symfony/framework-bundle sonata-project/admin-bundle

Before resuming the code, check the signatures, services, routes, and templates concerned. Then add a functional test covering permissions, HTTP code, and the visible result.

Reference: maintained Symfony versions.

Share this article