2017 © Pedro PelĂĄez
 

library entity-logger

Allows to automatically log entities modification

image

meyfarth/entity-logger

Allows to automatically log entities modification

  • Saturday, October 18, 2014
  • by Meyfarth
  • Repository
  • 1 Watchers
  • 0 Stars
  • 24 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

entity-logger

By Sébastien Garcia, (*1)

This bundle allows you to log every modification made to your entities, just by implementing the EntityLoggerInterface interface., (*2)

Installation

Using Composer:, (*3)

php composer.phar require meyfarth/entity-logger dev-master

Enable the bundle in your kernel :, (*4)

// app/AppKernel.php

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new \Meyfarth\EntityLoggerBundle\MeyfarthEntityLoggerBundle(),
        );

        ...

        return $bundles;
    }

Update your database :, (*5)

php app/console doctrine:schema:update --force

This will create a meyfarth_entity_log table. You can dump your database first using --dump-sql option if you want to know the table structure., (*6)

Usage

To log an entity, implement the EntityLoggerInterface interface in the entities you want to log :, (*7)

<?php

namespace MyApp\MyBundle\Entity;

use Meyfarth\EntityLoggerBundle\Entity\EntityLoggerInterface;

/**
 * MyEntity
 */
class MyEntity implements EntityLoggerInterface
{
  // Your code
}

Configuration

# app/config/config.yml
meyfarth_entity_logger:
    enable: true # default false. If not enabled, nothing will be logged
    log:
        create: true  # log on new entities
        update: true  # log on updates, new entities will not be considered as updates
        delete: true  # log on deletion
    user_class: false # log the current user (see below for explainations)
    nb_logs_by_page: 50 # number of logs by page on listing page, default is 50

If you use the security component with your own user entity (managed by Doctrine in your database), you can automatically log the current user by specifying the user_class parameter:, (*8)

# app/config/config.yml
meyfarth_entity_logger:
    user_class: MyApp\MyBundle\Entity\MyUser

Interfaces

You can now list all the logs. Simply add to your routing :, (*9)

# app/config.routing.yml
#...
meyfarth_entity_log:
    resource: "@MeyfarthEntityLoggerBundle/Resources/config/routing.yml"
    prefix:   /entity-log

You can now access the log list by going to yourserver/entity-log/list/{page} and see the ugliest table you'll ever see. Note that the {page} token is by default 1., (*10)

To override the default template, add your own template named list.html.twig in app/Resouces/MeyfarthEntityLoggerBundle/views/Log/list.html.twig., (*11)

The controller pass those parameters to the view :, (*12)

'logs' # the database result of the current page.
'page' # the current page
'nbByPage' # the number of elements by page
'nbPages' # the total number of pages

To access the EntityLog data in twig :, (*13)

log.id      {# the EntityLog id #}
log.dateLog {# DateTime of the log #}
log.typeLog {# type of log. Possibles values are defined in EntityLoggerService #}
log.data    {# the data : an array of array #}

Note : to compare the values in log.typeLog, you can use the following class constants : * Meyfarth\EntityLoggerBundle\Service\EntityLoggerService::TYPE_INSERT * Meyfarth\EntityLoggerBundle\Service\EntityLoggerService::TYPE_UPDATE * Meyfarth\EntityLoggerBundle\Service\EntityLoggerService::TYPE_DELETE, (*14)

The log.data is defined as following :, (*15)


/* Note that only the fields modified will be in the data. It means that if you only modify the "string" field of your entity, only the "string" field will be present in the log.data */ array( '[FIELDNAME]' => array( 0 => previousData, 1 => currentData, ), '[FIELDNAME2]' => array( 0 => previousData, 1 => currentData, ), );

The Versions

18/10 2014

dev-master

9999999-dev https://github.com/Meyfarth/entity-logger

Allows to automatically log entities modification

  Sources   Download

MIT

The Requires

 

by Sébastien GARCIA

log entity

12/10 2014

v1.0.0

1.0.0.0 https://github.com/Meyfarth/entity-logger

Allows to automatically log entities modification

  Sources   Download

MIT

The Requires

 

by Sébastien GARCIA

log entity

09/09 2014

dev-dev

dev-dev

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

by Avatar Meyfarth