auditor-bundle 8.0.0
auditor-bundle 8.0 turns audit logs into histories people can read: a viewer rewritten around actions told as
phrases, the history of a business object across the entities attached to it, a Twig component to show that
history in your own pages, and a streaming export. It ships with auditor 5.0 and auditor-doctrine-provider
2.0, released together, and their new audit table format (schema v2).
⚠️ Breaking changes / upgrading
The full procedure is in UPGRADE-8.0.md
and the upgrade guide. In short:
Requirements
| Requirement | 7.x | 8.0 |
|---|---|---|
| PHP | >= 8.4 | >= 8.4 |
| Symfony | >= 8.1 | >= 8.1 |
| Doctrine DBAL | >= 4.3 | >= 4.6 (via the provider) |
| Doctrine ORM | >= 3.2 | >= 3.7 (via the provider) |
damienharper/auditor
| 4.x | 5.0 |
damienharper/auditor-doctrine-provider
| 1.x | 2.0 |
auditor 5.0 and auditor-doctrine-provider 2.0 are released together with this version; composer require damienharper/auditor-bundle:^8.0 pulls both.
Migrate the audit tables to schema v2
auditor-doctrine-provider 2.0 writes a new audit format (ULID transaction_id, blame JSON column, unified diffs
envelope). Existing audit tables must be migrated, and the migration cannot be undone:
- back up the audit tables, and rehearse on a copy of your data to size the maintenance window;
- stop writing audits (maintenance mode, Messenger workers, scheduled tasks);
- update the packages, without letting
doctrine:schema:updateor a generated Doctrine migration touch the audit
tables; - migrate, then apply the rest of the schema:
composer require damienharper/auditor-bundle:^8.0
bin/console cache:clear
bin/console audit:schema:migrate --force --convert-all
bin/console audit:schema:update --forceAudit tables created by Doctrine Migrations need a replayable migration and a deployment order: see
Audit tables managed by Doctrine Migrations.
Raw SQL written against the 7.x columns (transaction_hash, blame_user, ip…) must be rewritten.
Redo your viewer template overrides
The viewer templates were rewritten around actions: templates overridden from 7.x under
templates/bundles/DHAuditorBundle/ no longer receive the same variables and must be rewritten from the new ones.
- Every Tailwind class of the templates now carries the
dh:prefix and colors come from design tokens
(dh:bg-dh-cardinstead ofbg-white dark:bg-slate-900). The precompiledapp.cssonly holds the prefixed
classes of the bundle: 7.x classes (slate-*,indigo-*…) or unprefixed ones lose their styles. - Each page of
Audit/wraps its content in<div data-dh-auditor-viewer>: keep it in an overridden page, the
reset of the viewer only applies under it. Audit/entry.html.twigis removed; the history of an object is nowAudit/object_history.html.twig.- A layout that does not extend the bundle's one must load
bundles/dhauditor/viewer.js(inline scripts are gone).
Other changes to check
- History of an object (
/audit/{entity}/{id}): route names are unchanged, but the query parameters are new:
type→what,user→who,date_from/date_to→when(last 7, 30 or 90 days),page→ theafter
cursor. Links built withAuditViewerUrlGenerator/dh_auditor_entity_url()gettypeandusertranslated;
hand-written 7.x links lose their filters. page_sizecounts actions (transactions), no longer entries.- Impersonation: the built-in
UserProviderno longer appends[impersonator <name>]to the username; the
impersonator is recorded apart.user_fqdnis now the class of the user: custom user providers pass it as the
third argument ofUser. Entry:$entry->transactionHashis removed, use$entry->transactionId.- Attributes: the deprecated
DH\Auditor\Provider\Doctrine\Auditing\Attribute\*aliases are removed, import them
fromDH\Auditor\Attribute. - Behavior: YAML entity
ignored_columnsnow apply to#[Auditable]entities too; an audit entry that cannot be
written now fails the flush (it used to be lost silently);extra_data_provideris called once per flush.
7.x now only receives bug and security fixes.
✨ What's new
A viewer that tells what happened
The viewer is rewritten around actions (one database transaction each), told as phrases, such as alice changed
Status: Draft → Published and added to Tags: symfony and audit, with their technical details one click away (#679,
#677). The objects a phrase names link to their own history, and are marked (deleted) when they no longer exist.
- Overview (
/audit): the recent activity across the entities you may view, and the audited entities with their
number of actions and latest activity, sortable by name, number of actions or latest activity
(?sort=count_desc) (#631). - History of an object (
/audit/{entity}/{id}): the object and the entities attached to it, grouped by day,
with who/what/field/origin/period filters, Show older actions through a cursor, and the fields changed last. - Action page, actions of a user (
/audit/user/{id}, #634), and comparison of two revisions of an object,
field by field (/audit/{entity}/{id}/compare, #635). - Entity stream filters by changed field (#633) and date range (#632).
- Lists are paginated by actions: every page but the last holds
page_sizewhole actions, and every header,
count and activity bar counts actions the same way (#709, #710, #711). - Origin badges (Web, Command line, Messenger, System), blame context and impersonator next to the author.
- Works on narrow screens and under a strict Content Security Policy (
script-src 'self'; style-src 'self'): no
inline script norstyleattribute any more (#673).
/audit/App-Entity-Post/42?who=12&what=update&field=status
/audit/App-Entity-Post/42?origin=console&when=30&attached=0
A shadcn-style theme that stays out of your application's way
The viewer follows the conventions of shadcn/ui without depending on it: every color is a
--dh-* design token, with light and dark values, actions are colored by meaning and links in the teal of the logo
(#704, #707). Redefine a token to restyle it:
:root { --dh-primary: #4f46e5; --dh-brand: #4f46e5; }
.dark { --dh-primary: #a5b4fc; --dh-brand: #a5b4fc; }Its styles are isolated from an application that uses Tailwind too: every class carries the dh: prefix, the
theme variables are --dh-*, and the reset only reaches the content of the viewer, so the order of the stylesheets
no longer matters and your page keeps its own reset and font (#725). An application can also compile the viewer with
its own Tailwind 4 by importing viewer.css.
Histories of business objects
#[AuditRoot('path')] or the roots entity option attach the audit entries of an entity to the history of another
one: a property listing with its features, publications and visits (#675).
dh_auditor:
providers:
doctrine:
entities:
App\Entity\Property: ~
App\Entity\PropertyFeature:
roots: [property]audit:roots:rebuild indexes the existing entries, Reader::createRootQuery() reads the history with cursor
pagination, and root_resolver, entity_label_resolver and read_scope take service IDs. Field labels come from
the dh_auditor_fields translation domain, and Twig functions tell who changed a field last:
{% set change = dh_auditor_last_change(property, 'price') %}
{% if change %}
{{ dh_auditor_field_label(property, 'price') }}: {{ change.value('price') }},
changed by {{ change.entry.username ?? 'system' }} {{ change.entry.createdAt|time_ago }}
{% endif %}The |dh_auditor_phrase, |dh_auditor_phrase_text and |dh_auditor_author filters tell an action as a phrase,
shipped in the 9 languages of the viewer and customizable through the dh_auditor_history translation domain,
#[AsChangeDescriber] services and ObjectUrlResolverInterface (#677).
<twig:DhAuditor:History>: the history in your own pages
A Twig component shows the history of an object next to its form, for instance, with the actions on the entities
attached to it and, mixed in by date, elements of your application that are not audited (comments, notes, emails)
through HistoryElementInterface (#682). It needs symfony/ux-twig-component.
<twig:DhAuditor:History :subject="post" :with="post.comments" details="ROLE_ADMIN">
<twig:block name="element">
<strong>{{ element.author }}</strong> · {{ element.createdAt|date }}
<p>{{ element.body }}</p>
</twig:block>
</twig:DhAuditor:History>Link to the viewer from your pages
The autowirable AuditViewerUrlGenerator and its Twig functions hide the route names, parameters and entity
encoding of the viewer; they return null when the viewer cannot show the page (#669).
{% set history_url = dh_auditor_entity_url(post) %}
{% if history_url and dh_auditor_is_viewable(post) %}
<a href="{{ history_url }}">History</a>
{% endif %}
<a href="{{ dh_auditor_transaction_url(entry.transactionId) }}">Transaction</a>
<a href="{{ dh_auditor_user_url(entry.userId) }}">User activity</a>Streaming export
/audit/export streams audit entries as NDJSON, JSON or CSV, filtered by entity, object, period or user, optionally
anonymized, and restricted to the entities the user can view (#616).
/audit/export?entity=App-Entity-User&format=csv&from=2026-01-01
Blame context and impersonation
Audit entries record how a change was made, in the via key of the blame JSON (#670): every console command
runs in a console context, the opt-in dh_auditor.messenger.blame_context_middleware blames the changes of a
worker on the user who dispatched the message, and your code pushes its own contexts through the autowirable
BlameContextStack. The viewer shows the context next to the author, and exports carry it as blame_via.
$this->blameContextStack->run(
new BlameContext('import', 'Import batch #'.$batch->id),
fn () => $this->importer->import($batch),
);When a user is impersonated (switch user), the impersonated user is blamed with their real class and the
impersonator is recorded apart: an impersonated by badge in the viewer, blame_impersonator* fields in exports
(#722).
Masked fields
#[Mask] records that a property changed without storing its values: ***, or an HMAC-SHA256 keyed with the new
mask_secret option, so that the entries of one value can be found without storing it (#715).
#[Mask(strategy: MaskStrategy::KeyedHash)]
private string $email = '';dh_auditor:
providers:
doctrine:
mask_secret: '%env(AUDIT_MASK_SECRET)%'Scheduled retention
Audit entries can be pruned on a schedule with Symfony Scheduler, per entity (retention.max_age /
retention.max_entries, or #[Auditable(maxAge: …, maxEntries: …)]), with an optional default_max_age. Disabled
by default (#644, #645).
dh_auditor:
providers:
doctrine:
entities:
App\Entity\Payment:
retention:
max_age: 'P7Y'
retention:
schedule: '0 3 * * *'Initial snapshot
audit:snapshot writes an insert entry flagged as a snapshot for every existing entity, so that the history of
data that existed before auditing was enabled starts with its state at that time (#667).
bin/console audit:snapshot --all --dry-run
bin/console audit:snapshot --allMore control over what is audited
entities.*.audited_columnsaudits only the listed properties, andignored_columns_resolverdecides per object
(#668).- The provider options of auditor-doctrine-provider 2.0:
batch_size(multi-row inserts),compression(MariaDB),
skip_disabled_entities,full_snapshot_on_remove(#659, #662, #671). - Readable values in the diffs with
#[DiffLabel]resolvers, wired by their FQCN as service ID (#609). - Custom providers are registered with the
dh_auditor.providertag (#608), and the console user provider can be
decorated throughConsoleUserProviderInterface(#615). - Failures that cannot be thrown are logged on the application logger (#655).
What's Changed
Features
- feat: native custom provider support via dh_auditor.provider tag by @DamienHarper in #608
- feat: wire DiffLabel resolver locator + add docs for human-readable diff labels by @DamienHarper in #609
- feat: update viewer and docs for audit table schema v2 by @DamienHarper in #613
- feat: introduce ConsoleUserProviderInterface to allow decoration by @DamienHarper in #615
- feat: add streaming audit export HTTP endpoint by @DamienHarper in #616
- feat(viewer): add sorting to the audited entities overview by @Gumbraise in #631
- feat(viewer): add date range filtering to the audit entity stream by @Gumbraise in #632
- feat(viewer): add a global activity timeline per user by @Gumbraise in #634
- feat(viewer): add changed field filter by @Gumbraise in #633
- feat(viewer): compare two revisions of an audited object by @Gumbraise in #635
- feat(config): add a per-entity retention option for the Doctrine provider by @DamienHarper in #644
- feat(retention): add opt-in scheduled pruning of audit logs by @DamienHarper in #645
- feat(config): inject the logger into the Doctrine provider by @DamienHarper in #655
- feat: document and pass the DoctrineProvider "compression" option by @DamienHarper in #659
- feat(snapshot): register audit:snapshot and flag snapshot entries in the viewer by @DamienHarper in #667
- feat(config): audited_columns and ignored_columns_resolver options by @DamienHarper in #668
- feat(viewer): add a viewer URL generator and its Twig functions by @DamienHarper in #669
- feat(blame): blame context service, console and Messenger contexts, viewer badge by @DamienHarper in #670
- feat: histories across entities (roots, field labels, last change of a field) by @DamienHarper in #675
- feat: tell history items as readable phrases with links by @DamienHarper in #677
- feat(viewer): rewrite the viewer around readable actions by @DamienHarper in #679
- feat(viewer):
<twig:DhAuditor:History>component for the host app by @DamienHarper in #682 - feat(viewer): style the viewer with shadcn-style design tokens by @DamienHarper in #704
- feat(viewer): color actions by meaning and links in teal by @DamienHarper in #707
- feat(viewer): paginate the lists of actions by actions by @DamienHarper in #709
- feat(config): document mask_secret for #[Mask] fields by @oleg-andreyev in #715
- feat(blame): keep the impersonator apart from the blamed user by @DamienHarper in #722
Performance
- perf(viewer): read the user filter options from the blame_id index by @DamienHarper in #661
- perf(viewer): no whole-database introspection, cached counts, cheaper type filter by @DamienHarper in #674
Bug fixes
- fix(viewer): don't link to non-viewable entities in association diffs by @Gumbraise in #629
- fix(viewer): identify the source of association diffs by its primary key name by @DamienHarper in #642
- fix(viewer): tell JSON deep diffs apart from field diffs by @DamienHarper in #646
- fix(viewer): render audit dates in the auditor timezone by @DamienHarper in #653
- fix(viewer): mobile layout, paginated transaction view, strict CSP, stable user timeline by @DamienHarper in #673
- fix(viewer): prefix the viewer classes and bound its reset to the viewer content by @DamienHarper in #725
Polish of the new viewer
- fix(viewer): show the label of an association in the details of a creation or removal by @DamienHarper in #693
- fix(viewer): one Change column for the action details, lined up and readable by @DamienHarper in #694
- fix(viewer): compare punctuation apart from the words of a text change by @DamienHarper in #695
- fix(viewer): give the raw details of an action fixed columns by @DamienHarper in #696
- fix(history): do not tell twice an element the action creates or deletes by @DamienHarper in #697
- fix(viewer): stack the changes of the action details on a narrow screen by @DamienHarper in #698
- fix(history): do not mark as deleted the object a deletion phrase names by @DamienHarper in #699
- fix(viewer): polish the action rows, the values of the details, the filters and the header by @DamienHarper in #701
- fix(viewer): never cut an action in the lists of actions by @DamienHarper in #702
- fix(history): name the objects of an action that changes several of them by @DamienHarper in #703
- fix(viewer): ship theme.css in the package archives by @DamienHarper in #705
- fix(viewer): polish the viewer controls and the entity stream by @DamienHarper in #706
- fix(viewer): put the target of a link under new or old, labels in the normal font by @DamienHarper in #708
- fix(viewer): count, paginate and name actions consistently by @DamienHarper in #710
- fix(viewer): count the actions of the overview and the graph as the stream does by @DamienHarper in #711
- refactor(viewer): remove the unused entry count of the activity graph provider by @DamienHarper in #713
- fix(viewer): sort the overview by number of actions, not events by @DamienHarper in #714
- fix(viewer): return no URL for an entry without user or transaction id by @DamienHarper in #726
Compatibility and packaging
- chore: support auditor 5.x and auditor-doctrine-provider 2.x by @DamienHarper in #610
- chore: install damienharper packages from source, tighten the archive by @DamienHarper in #720
Documentation
- docs: state that the previous major only receives bug and security fixes by @DamienHarper in #658
- docs: document the DoctrineProvider skip_disabled_entities option by @DamienHarper in #662
- docs(upgrade): migrate the audit tables before audit:schema:update in the 8.0 guide by @DamienHarper in #665
- docs: new features of 8.0, export, revision comparison and provider options by @DamienHarper in #671
- docs: link to the console commands section without the emoji variation selector by @DamienHarper in #672
- docs: add UPGRADE-8.0.md and bring the 8.0 docs in line with the code by @DamienHarper in #683
- docs: align the documentation with the code by @DamienHarper in #692
- docs(viewer): describe the action count of the overview as the stream counts it by @DamienHarper in #712
- docs(upgrade): link the Doctrine Migrations recipe, lazy listener workarounds by @DamienHarper in #724
Also released in 7.x
These changes are part of 8.0 and were backported to the 7.x line:
- fix: anonymous access bypasses entity-level security restrictions by @Gumbraise in #630 (7.2.2)
- fix: remove always-true instanceof check in RoleChecker by @DamienHarper in #637 (7.2.2)
- fix(event-dispatcher): declare AuditEventSubscriber in the container by @DamienHarper in #660 (7.3.0)
- fix(doctrine): audit the flushes made before the provider is built by @DamienHarper in #678 (7.3.0)
- docs(attributes): YAML enabled: false and roles apply to #[Auditable] entities by @DamienHarper in #685 (7.3.0)
- fix(console): restore the user provider set before a command when it ends by @DamienHarper in #687 (7.3.1)
- fix(viewer): keep viewer routes out of routing.controllers by @DamienHarper in #719 (7.3.1, GHSA-cqq8-4jc5-5p42)
New Contributors
- @Gumbraise made their first contribution in #630
References
- UPGRADE-8.0.md
- Upgrade guide
- auditor 5.0.0 release notes
- auditor-doctrine-provider 2.0.0 release notes
- Official documentation
Full Changelog: 7.3.1...8.0.0