DamienHarper / auditor

auditor, the missing audit log library
MIT License
164 stars 53 forks source link

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

Open wouter-toppy opened 12 months ago

wouter-toppy commented 12 months ago

An extend and finalized version of DamienHarper/auditor#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 commented 12 months ago

image

wouter-toppy commented 12 months ago

image

FluffyDiscord commented 9 months ago

Any chance to merge this?

yskolnick commented 1 month ago

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