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

Add extra fields and indices to audit tables, based on configuration (see: #61) #187

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

wouter-toppy
Copy link

An extend and finalized version of #61

Closes:

This pull request allows users to create extra columns in their audit tables. This is useful when You need to group audit events with an external parameter for easy retrieval later on.

Adds the options "extra_fields" and "extra_indices" to the Configuration object:

new Configuration([
    'table_prefix' => '',
    'table_suffix' => '_audit',
    'ignored_columns' => [],
    'entities' => [
       'App\Entity\Demo' => [
           'extra_fields' => ['extra_column'],
           'extra_indices' => ['extra_column'],
       ],
    ],
    'viewer' => true,
    'extra_fields' => [
        'extra_column' => [
            'type' => 'string',
            'options' => ['notnull' => true]
        ]
    ],
    'extra_indices' => ['extra_column' => null]
]);

Adds the ability to query the audit table on the configured extra_indices via filters, eg.

$query->addFilter(new SimpleFilter('extra_column', '123abc'));

The field is automaticly detected by using the Symfony Property Accessor

In this case, the App\Entity\Demo needs to have a property called extra_column, and the bundle will automaticly pick it up (doesn't need to be a doctrine property, just an object property) (see: src/Provider/Doctrine/Auditing/Transaction/AuditTrait.php:132)

class App\Entity\Demo
{
    private ?string $extraColumn = null;

    public function getExtraColumn(): ?string
    {
        return $this->extraColumn;
    }

    public function setExtraColumn(?string $extraColumn): void
    {
        $this->extraColumn = $extraColumn;
    }
}

@wouter-toppy
Copy link
Author

image

@wouter-toppy
Copy link
Author

image

@FluffyDiscord
Copy link

Any chance to merge this?

@yskolnick
Copy link

Is this being implemented? Is there another way to do this?

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

Successfully merging this pull request may close these issues.

3 participants