Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gedmo loggable working but not storing username

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?

like image 652
diggersworld Avatar asked Sep 16 '15 15:09

diggersworld


1 Answers

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.

like image 92
diggersworld Avatar answered Oct 07 '22 01:10

diggersworld