Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Loggable] Incomplete documentation on how to use custom LogEntry entity #2751

Open
Tetragramat opened this issue Feb 1, 2024 · 1 comment

Comments

@Tetragramat
Copy link

Documentation https://github.com/doctrine-extensions/DoctrineExtensions/blob/main/doc/loggable.md

Contains how custom LogEntry entity should look, but what should be configured for it to work is completely missing.

I'm really struggling here. I though I figured it out, but ended with getting logged one change twice with the same version number.

Using with stof/doctrine-extensions-bundle, but it should be documented here too.

@Tetragramat
Copy link
Author

Tetragramat commented Feb 5, 2024

Found out the issue.

To have custom LogEntry entity used as default one you must create custom entity as defined in https://github.com/doctrine-extensions/DoctrineExtensions/blob/main/doc/loggable.md#custom-logentry-class and then extend \Gedmo\Loggable\LoggableListener.

class LoggableListener extends \Gedmo\Loggable\LoggableListener
{
	protected function getLogEntryClass(LoggableAdapter $ea, $class)
	{
		return self::$configurations[$this->name][$class]['logEntryClass'] ?? CustomLogEntry::class;
	}

	protected function prePersistLogEntry($logEntry, $object)
	{
		// set up additional fields in CustomLogEntry
	}
}

If you use stof/doctrine-extensions-bundle.

stof_doctrine_extensions:
    orm:
        default:
            loggable: true
    class:
        loggable: 'App\EventListener\LoggableListener' # your extended listener
        
services:
    # register extended listener as alias to make sure your autoconfiguration does not register it twice
    stof_doctrine_extensions.listener.loggable: '@App\EventListener\LoggableListener'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant