VOOZH about

URL: https://deepwiki.com/mathsgod/light/4.3.5-revisioncontroller

⇱ RevisionController | mathsgod/light | DeepWiki


Loading...
Last indexed: 31 January 2026 (cf9511)
Menu

RevisionController

This page documents the RevisionController, which provides GraphQL operations for querying and restoring historical changes tracked by the automatic audit system. The controller enables clients to retrieve complete revision history for any model instance and selectively restore previous field values.

For information about how the audit system automatically logs changes, see Auto-Auditing and Lifecycle Hooks. For the EventLog table structure and revision tracking implementation, see Revision System.

Sources: src/Controller/RevisionController.php1-44


Overview

The RevisionController provides GraphQL operations for querying and restoring historical changes tracked by the automatic audit system. It allows clients to retrieve revision history for any model instance and selectively restore previous field values.

Sources: src/Controller/RevisionController.php1-44


Core Architecture

The revision system consists of three primary components that work together to provide comprehensive audit trail functionality:


The RevisionController exposes two GraphQL operations that wrap the Revision type, which in turn reads from the EventLog table. All models extending Light\Model automatically write to EventLog on every insert, update, and delete operation.

Sources: src/Controller/RevisionController.php12-43 src/Type/Revision.php12-119 src/Model.php120-238


Query Operations

getRevisionsByModel

Retrieves all revision history for a specific model instance, sorted by creation time in descending order (most recent first).


GraphQL Schema:


Parameters:

ParameterTypeDescription
model_classstringFully qualified class name (e.g., "Light\\Model\\User")
model_idintPrimary key value of the model instance

Authorization:

  • Requires revision.read permission
  • User must be authenticated (@Logged annotation)

Implementation Details:

The query filters EventLog entries by both class and id, then sorts by created_time in descending order src/Controller/RevisionController.php35-37 Each EventLog entry is wrapped in a Revision type for GraphQL exposure src/Controller/RevisionController.php39-41

Sources: src/Controller/RevisionController.php29-42


Mutation Operations

restoreRevision

Restores specific fields from a historical revision to the current model instance. This allows selective rollback without reverting the entire record.


GraphQL Schema:


Parameters:

ParameterTypeDescription
revision_idintThe EventLog ID to restore from
fieldsstring[]Array of field names to restore

Authorization:

  • Requires revision.restore permission
  • User must be authenticated (@Logged annotation)

Behavior:

  1. Fetches the EventLog entry by revision_id src/Controller/RevisionController.php23
  2. Creates a Revision wrapper src/Controller/RevisionController.php24
  3. Calls retoreFields() with the specified fields src/Controller/RevisionController.php24
  4. For each field, validates it exists in the model schema src/Type/Revision.php35
  5. Retrieves the field value from the revision's source data src/Type/Revision.php36
  6. Assigns the value to the current model instance src/Type/Revision.php36
  7. Saves the model, which creates a new audit log entry src/Type/Revision.php39

Sources: src/Controller/RevisionController.php15-25 src/Type/Revision.php27-43


Revision Views

The Revision type provides three different perspectives on change history, each optimized for different use cases:

Content View

Returns the complete snapshot of the model's state at the time of the revision.


Field: content

Returns: Mixed (object) - Complete field-value pairs sorted by key

Use Case: Viewing the full state of a model at a specific point in time

Implementation: Retrieves the source field from the EventLog entry, which contains the pre-change state src/Type/Revision.php66 and sorts fields alphabetically for consistent output src/Type/Revision.php68

Sources: src/Type/Revision.php63-70


Delta View

Returns only the fields that changed, showing their new values after the change.


Field: delta

Returns: Mixed (object) - Only changed field-value pairs

Use Case: Efficiently viewing what changed in an update operation

Implementation: Compares source and target objects field-by-field src/Type/Revision.php79-82 building a delta object containing only fields where values differ. Both objects are sanitized before comparison src/Type/Revision.php75-76

Sources: src/Type/Revision.php72-87


Diff View

Returns human-readable unified diff format showing before/after changes for each field.


Field: diff

Returns: Mixed (object) - Field names mapped to unified diff strings

Use Case: Displaying changes in a code-review style format for complex fields

Implementation: Uses sebastian/diff library to generate unified diff output src/Type/Revision.php97-106 for each changed field. Handles both scalar values and JSON-encoded arrays src/Type/Revision.php110-114

Sources: src/Type/Revision.php89-118


Integration with Audit System

The revision system is automatically populated by the base Light\Model class. Every model extending this class generates EventLog entries without any explicit instrumentation.

Audit Log Generation


Automatic Tracking:

OperationSourceTargetTimestamps Updated
InsertnullNew record JSONcreated_time, created_by
UpdateOriginal record JSONModified record JSONupdated_time, updated_by
DeletenullDeleted record JSONNone

User Attribution:

The system automatically captures the current user ID from the Auth\Service container src/Model.php126-129 and associates it with the audit log entry src/Model.php137 src/Model.php233

Blob Field Filtering:

To prevent storing large binary data in audit logs, the system filters out fields with blob data types (longblob, mediumblob, tinyblob) before JSON encoding src/Model.php179-185 src/Model.php204-209

Sources: src/Model.php120-238


Metadata and Attribution

The Revision type provides metadata about each change:


Fields:

FieldTypeDescription
revision_idInt!The EventLog primary key identifier
createdTimeString!ISO 8601 timestamp when the change occurred
revisionByStringDisplay name of the user who made the change (null if system)

User Resolution:

The revisionBy field performs a join to the User table to resolve the user ID to a display name src/Type/Revision.php54-58 Returns null if the user_id is not set or the user no longer exists.

Sources: src/Type/Revision.php45-61


Security Model

Both operations in the RevisionController enforce security through GraphQLite annotations:


Permission Requirements:

OperationPermissionScope
getRevisionsByModelrevision.readRead access to revision history
restoreRevisionrevision.restoreWrite access to restore changes

Authentication:

Both operations require authentication via the @Logged annotation src/Controller/RevisionController.php16 src/Controller/RevisionController.php29 which validates the JWT token before execution.

Authorization:

The @Right annotation enforces permission checks through the RBAC system src/Controller/RevisionController.php20 src/Controller/RevisionController.php31 For more details on permission configuration, see Role Hierarchy and Permissions.

Sources: src/Controller/RevisionController.php15-32


GraphQL Type Definition

The complete GraphQL schema for the Revision type:


Note: The Mixed type represents arbitrary JSON data. The content, delta, and diff fields return objects with field names as keys and values matching the field types of the underlying model.

Sources: src/Type/Revision.php12-119


Example Usage Scenarios

Viewing Revision History


Returns a chronological list of changes to User #42, showing only what changed in each revision.


Restoring a Field


Restores the email and status fields from revision 1234 to the current model instance, leaving other fields unchanged.


Comparing Versions


Returns full snapshots and diffs for all changes to Config #5, useful for detailed audit review.

Sources: src/Controller/RevisionController.php1-44 src/Type/Revision.php1-119