5

I have got logging working on my entity so that when I make a change to a product field with the @Gedmo\Versioned annotation a new version is created. However the only problem is that the username field remains NULL. There is an authenticated user as the update is performed in Sonata Admin backend.

<?php

namespace MyApp\CmsBundle\Entity\Log;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Loggable\Entity\MappedSuperclass\AbstractLogEntry;
use Gedmo\Loggable\Entity\Repository\LogEntryRepository;

/**
 * @ORM\Entity(repositoryClass="Gedmo\Loggable\Entity\Repository\LogEntryRepository", readOnly=true)
 * @ORM\Table(
 *      name="log_product",
 *      indexes={
 *          @ORM\Index(name="log_class_lookup_idx", columns={"object_class"}),
 *          @ORM\Index(name="log_date_lookup_idx", columns={"logged_at"}),
 *          @ORM\Index(name="log_user_lookup_idx", columns={"username"}),
 *      }
 * )
 */
class ProductLog extends AbstractLogEntry
{

}

So it would appear the log_user_lookup_idx isn't working correctly, is there a particular bit of config I require for this?

diggersworld
  • 12,770
  • 24
  • 84
  • 119
  • Did you configure the `username` filed to be logged? – A.L Sep 17 '15 at 15:22
  • There's no `username` attribute on Product. It picks up the user object via the lookup. – diggersworld Sep 17 '15 at 18:08
  • I only see indexes in your code, this creates indexes in your database table but that doesn't configure how fields are logged, see the [documentation](https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/loggable.md#loggable-entity-example). – A.L Sep 17 '15 at 18:11

1 Answers1

6

It appears I was missing a bit of config, adding the following to the main app/config/config.yml file did the trick.

stof_doctrine_extensions:
    default_locale: en
    orm:
        default:
            loggable: true

I did originally have this in my bundles' services.yml config:

gedmo.listener.loggable:
    class: Gedmo\Loggable\LoggableListener
    tags:
        - { name: doctrine.event_subscriber, connection: default }
    calls:
        - [ setAnnotationReader, [ "@annotation_reader" ] ]

This managed to track the entity being modified but not the user, I have since removed this config and the logging remains to work with just the stof_doctrine_extensions config setting.

If you have both in your code base then everything will be logged twice I found.

diggersworld
  • 12,770
  • 24
  • 84
  • 119