Skip to content

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

Open
herman-aka-wouter wants to merge 2 commits intoDamienHarper:masterfrom
herman-aka-wouter:master
Open

Add extra fields and indices to audit tables, based on configuration (see: #61)#187
herman-aka-wouter wants to merge 2 commits intoDamienHarper:masterfrom
herman-aka-wouter:master

Conversation

@herman-aka-wouter
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;
    }
}

@herman-aka-wouter
Copy link
Author

image

@herman-aka-wouter
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?

@manuakasam
Copy link

@DamienHarper i wouldn't understand how annoying continuous requests might be, but feedback would be greatly appreciated.
For large scale systems, additional fields would be insanely helpful (i.d. to flag an entry with a customerId that's used across all entities) to be able to "find all entries for customer FOO from all entities". As it stands now, we'd have to first query for potential IDs across all entities and then run the queries against the changelog table using those IDs, that's a lot of effort.

Seeing as this issue has ultimately been open for 4 years or so, I doubt it would make it into the system, though potentially having a final word, or outlook on the current issues, on this would be great.

@dmitryuk
Copy link
Contributor

@wouter-toppy please resolve conflicts
@DamienHarper please review

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.

5 participants