Revision
extends Model
in package
Content revision entity.
Represents a single saved snapshot of a page or post at a point in time, including who made the change and what kind of change it was.
Attributes
- #[Table]
- 'content_revisions'
Table of Contents
Constants
- ACTION_CREATED : mixed = 'created'
- ACTION_RESTORED : mixed = 'restored'
- ACTION_UPDATED : mixed = 'updated'
- TYPE_PAGE : mixed = 'page'
- TYPE_POST : mixed = 'post'
Properties
- $_loadedRelations : array<string|int, mixed>
- Loaded relations cache
- $_pdo : PDO|null
- Database connection
- $_relationCache : array<string|int, mixed>
- Relation metadata cache
- $_action : string
- $_contentId : int
- $_contentType : string
- $_createdAt : DateTimeImmutable|null
- $_editedBy : int|null
- $_editedByName : string|null
- $_id : int|null
- $_snapshot : string
- $_status : string
- $_title : string
Methods
- __construct() : mixed
- __get() : mixed
- Magic method to access relations.
- all() : array<string|int, mixed>
- Get all models.
- beginTransaction() : bool
- Begin a database transaction.
- commit() : bool
- Commit the current transaction.
- create() : static
- Create a new model and save it to the database.
- delete() : bool
- Delete the model without handling dependents (simple delete).
- destroy() : bool
- Delete the model from the database with dependent cascade.
- destroyMany() : int
- Delete one or more models by ID.
- exists() : bool
- Check if the model exists in the database.
- fill() : self
- Fill the model with an array of attributes.
- find() : static|null
- Find a model by primary key.
- fromArray() : static
- Create a Revision from array data.
- getAction() : string
- getAttribute() : mixed
- Get an attribute value from the model.
- getContentId() : int
- getContentType() : string
- getCreatedAt() : DateTimeImmutable|null
- getEditedBy() : int|null
- getEditedByName() : string|null
- getEditorLabel() : string
- Human-friendly label for who made the change.
- getId() : int|null
- getPrimaryKey() : string
- Get the primary key column name.
- getSnapshot() : string
- Get the raw JSON snapshot string.
- getSnapshotData() : array<string|int, mixed>
- Get the decoded snapshot data.
- getStatus() : string
- getTableName() : string
- Get the table name for this model from the Table attribute.
- getTitle() : string
- inTransaction() : bool
- Check if currently inside a transaction.
- limit() : QueryBuilder
- Set result limit.
- loadRelations() : void
- Eager load relations.
- offset() : QueryBuilder
- Set result offset.
- orderBy() : QueryBuilder
- Add an order by clause.
- query() : QueryBuilder
- Create a new query builder for this model.
- relation() : BelongsToRelation|HasManyRelation|HasOneRelation|BelongsToManyRelation
- Get a relation instance (for calling sync/attach/detach methods).
- rollBack() : bool
- Roll back the current transaction.
- save() : bool
- Save the model to the database (insert or update).
- setAction() : self
- setAttribute() : void
- Set an attribute value on the model.
- setContentId() : self
- setContentType() : self
- setCreatedAt() : self
- setEditedBy() : self
- setEditedByName() : self
- setId() : self
- setLoadedRelation() : void
- Set a loaded relation (used by eager loading).
- setPdo() : void
- Set the PDO connection for all models.
- setSnapshot() : self
- Set the snapshot from a raw JSON string.
- setSnapshotArray() : self
- Set the snapshot from an array (encoded to JSON).
- setStatus() : self
- setTitle() : self
- toArray() : array<string|int, mixed>
- Convert the revision to an array of database columns.
- transaction() : mixed
- Execute a closure within a database transaction.
- update() : bool
- Update the model's attributes and save to database.
- where() : QueryBuilder
- Start a query with a where clause.
- whereIn() : QueryBuilder
- Start a query with a where in clause.
- with() : QueryBuilder
- Eager load relations.
- createRelation() : BelongsToRelation|HasManyRelation|HasOneRelation|BelongsToManyRelation
- Create a relation instance.
- getForeignKeyName() : string
- Get the foreign key name for this model.
- getPdo() : PDO
- Get the PDO connection.
- getPivotTableName() : string
- Get the pivot table name for a many-to-many relationship.
- getRelatedForeignKeyName() : string
- Get the foreign key name for a related model.
- getRelationMetadata() : array<string|int, mixed>|null
- Get relation metadata for a property.
- handleDependentRelations() : void
- Handle dependent relations before destroying the model.
- performInsert() : bool
- Perform an insert operation.
- performUpdate() : bool
- Perform an update operation.
- propertyToColumn() : string
- Convert property name to database column name.
Constants
ACTION_CREATED
public
mixed
ACTION_CREATED
= 'created'
ACTION_RESTORED
public
mixed
ACTION_RESTORED
= 'restored'
ACTION_UPDATED
public
mixed
ACTION_UPDATED
= 'updated'
TYPE_PAGE
public
mixed
TYPE_PAGE
= 'page'
TYPE_POST
public
mixed
TYPE_POST
= 'post'
Properties
$_loadedRelations
Loaded relations cache
protected
array<string|int, mixed>
$_loadedRelations
= []
$_pdo
Database connection
protected
static PDO|null
$_pdo
= null
$_relationCache
Relation metadata cache
protected
static array<string|int, mixed>
$_relationCache
= []
$_action
private
string
$_action
= self::ACTION_UPDATED
$_contentId
private
int
$_contentId
= 0
$_contentType
private
string
$_contentType
= ''
$_createdAt
private
DateTimeImmutable|null
$_createdAt
= null
$_editedBy
private
int|null
$_editedBy
= null
$_editedByName
private
string|null
$_editedByName
= null
$_id
private
int|null
$_id
= null
$_snapshot
private
string
$_snapshot
= '{}'
$_status
private
string
$_status
= 'draft'
$_title
private
string
$_title
= ''
Methods
__construct()
public
__construct() : mixed
__get()
Magic method to access relations.
public
__get(string $name) : mixed
Parameters
- $name : string
Tags
all()
Get all models.
public
static all() : array<string|int, mixed>
Return values
array<string|int, mixed>beginTransaction()
Begin a database transaction.
public
static beginTransaction() : bool
Tags
Return values
bool —True on success
commit()
Commit the current transaction.
public
static commit() : bool
Tags
Return values
bool —True on success
create()
Create a new model and save it to the database.
public
static create(array<string|int, mixed> $attributes) : static
Parameters
- $attributes : array<string|int, mixed>
Tags
Return values
staticdelete()
Delete the model without handling dependents (simple delete).
public
delete() : bool
Tags
Return values
booldestroy()
Delete the model from the database with dependent cascade.
public
destroy() : bool
Tags
Return values
booldestroyMany()
Delete one or more models by ID.
public
static destroyMany(int|array<string|int, mixed> $ids) : int
Parameters
- $ids : int|array<string|int, mixed>
Tags
Return values
int —Number of records deleted
exists()
Check if the model exists in the database.
public
exists() : bool
Return values
boolfill()
Fill the model with an array of attributes.
public
fill(array<string|int, mixed> $attributes) : self
Parameters
- $attributes : array<string|int, mixed>
Return values
selffind()
Find a model by primary key.
public
static find(int $id) : static|null
Parameters
- $id : int
Return values
static|nullfromArray()
Create a Revision from array data.
public
static fromArray(array<string|int, mixed> $data) : static
Parameters
- $data : array<string|int, mixed>
Return values
staticgetAction()
public
getAction() : string
Return values
stringgetAttribute()
Get an attribute value from the model.
public
getAttribute(string $key) : mixed
Parameters
- $key : string
getContentId()
public
getContentId() : int
Return values
intgetContentType()
public
getContentType() : string
Return values
stringgetCreatedAt()
public
getCreatedAt() : DateTimeImmutable|null
Return values
DateTimeImmutable|nullgetEditedBy()
public
getEditedBy() : int|null
Return values
int|nullgetEditedByName()
public
getEditedByName() : string|null
Return values
string|nullgetEditorLabel()
Human-friendly label for who made the change.
public
getEditorLabel() : string
Return values
stringgetId()
public
getId() : int|null
Return values
int|nullgetPrimaryKey()
Get the primary key column name.
public
static getPrimaryKey() : string
Return values
stringgetSnapshot()
Get the raw JSON snapshot string.
public
getSnapshot() : string
Return values
stringgetSnapshotData()
Get the decoded snapshot data.
public
getSnapshotData() : array<string|int, mixed>
Return values
array<string|int, mixed>getStatus()
public
getStatus() : string
Return values
stringgetTableName()
Get the table name for this model from the Table attribute.
public
static getTableName() : string
Tags
Return values
stringgetTitle()
public
getTitle() : string
Return values
stringinTransaction()
Check if currently inside a transaction.
public
static inTransaction() : bool
Tags
Return values
bool —True if inside a transaction
limit()
Set result limit.
public
static limit(int $limit) : QueryBuilder
Parameters
- $limit : int
Return values
QueryBuilderloadRelations()
Eager load relations.
public
static loadRelations(array<string|int, mixed> $relations, array<string|int, mixed> $models) : void
Parameters
- $relations : array<string|int, mixed>
-
Relation names to load
- $models : array<string|int, mixed>
-
Array of models to load relations for
offset()
Set result offset.
public
static offset(int $offset) : QueryBuilder
Parameters
- $offset : int
Return values
QueryBuilderorderBy()
Add an order by clause.
public
static orderBy(string $column[, string $direction = 'ASC' ]) : QueryBuilder
Parameters
- $column : string
- $direction : string = 'ASC'
Return values
QueryBuilderquery()
Create a new query builder for this model.
public
static query() : QueryBuilder
Return values
QueryBuilderrelation()
Get a relation instance (for calling sync/attach/detach methods).
public
relation(string $name) : BelongsToRelation|HasManyRelation|HasOneRelation|BelongsToManyRelation
Parameters
- $name : string
-
Relation name
Tags
Return values
BelongsToRelation|HasManyRelation|HasOneRelation|BelongsToManyRelationrollBack()
Roll back the current transaction.
public
static rollBack() : bool
Tags
Return values
bool —True on success
save()
Save the model to the database (insert or update).
public
save() : bool
Tags
Return values
boolsetAction()
public
setAction(string $action) : self
Parameters
- $action : string
Return values
selfsetAttribute()
Set an attribute value on the model.
public
setAttribute(string $key, mixed $value) : void
Parameters
- $key : string
- $value : mixed
setContentId()
public
setContentId(int $contentId) : self
Parameters
- $contentId : int
Return values
selfsetContentType()
public
setContentType(string $contentType) : self
Parameters
- $contentType : string
Return values
selfsetCreatedAt()
public
setCreatedAt(DateTimeImmutable $createdAt) : self
Parameters
- $createdAt : DateTimeImmutable
Return values
selfsetEditedBy()
public
setEditedBy(int|null $editedBy) : self
Parameters
- $editedBy : int|null
Return values
selfsetEditedByName()
public
setEditedByName(string|null $editedByName) : self
Parameters
- $editedByName : string|null
Return values
selfsetId()
public
setId(int $id) : self
Parameters
- $id : int
Return values
selfsetLoadedRelation()
Set a loaded relation (used by eager loading).
public
setLoadedRelation(string $name, mixed $value) : void
Parameters
- $name : string
- $value : mixed
setPdo()
Set the PDO connection for all models.
public
static setPdo(PDO $pdo) : void
Parameters
- $pdo : PDO
setSnapshot()
Set the snapshot from a raw JSON string.
public
setSnapshot(string $snapshot) : self
Parameters
- $snapshot : string
Return values
selfsetSnapshotArray()
Set the snapshot from an array (encoded to JSON).
public
setSnapshotArray(array<string|int, mixed> $data) : self
Parameters
- $data : array<string|int, mixed>
Tags
Return values
selfsetStatus()
public
setStatus(string $status) : self
Parameters
- $status : string
Return values
selfsetTitle()
public
setTitle(string $title) : self
Parameters
- $title : string
Return values
selftoArray()
Convert the revision to an array of database columns.
public
toArray() : array<string|int, mixed>
Return values
array<string|int, mixed>transaction()
Execute a closure within a database transaction.
public
static transaction(callable $callback) : mixed
If the closure executes successfully, the transaction is committed. If an exception is thrown, the transaction is rolled back and the exception is re-thrown.
Parameters
- $callback : callable
-
Function to execute within transaction
Tags
Return values
mixed —The return value of the callback
update()
Update the model's attributes and save to database.
public
update(array<string|int, mixed> $attributes) : bool
Parameters
- $attributes : array<string|int, mixed>
Tags
Return values
boolwhere()
Start a query with a where clause.
public
static where(string $column, mixed $operator[, mixed|null $value = null ]) : QueryBuilder
Parameters
- $column : string
- $operator : mixed
- $value : mixed|null = null
Return values
QueryBuilderwhereIn()
Start a query with a where in clause.
public
static whereIn(string $column, array<string|int, mixed> $values) : QueryBuilder
Parameters
- $column : string
- $values : array<string|int, mixed>
Return values
QueryBuilderwith()
Eager load relations.
public
static with(array<string|int, mixed>|string $relations) : QueryBuilder
Parameters
- $relations : array<string|int, mixed>|string
Return values
QueryBuildercreateRelation()
Create a relation instance.
protected
createRelation(string $propertyName, array<string|int, mixed> $metadata) : BelongsToRelation|HasManyRelation|HasOneRelation|BelongsToManyRelation
Parameters
- $propertyName : string
- $metadata : array<string|int, mixed>
Tags
Return values
BelongsToRelation|HasManyRelation|HasOneRelation|BelongsToManyRelationgetForeignKeyName()
Get the foreign key name for this model.
protected
getForeignKeyName() : string
Return values
stringgetPdo()
Get the PDO connection.
protected
static getPdo() : PDO
Tags
Return values
PDOgetPivotTableName()
Get the pivot table name for a many-to-many relationship.
protected
getPivotTableName(string $relatedModel) : string
Parameters
- $relatedModel : string
Return values
stringgetRelatedForeignKeyName()
Get the foreign key name for a related model.
protected
getRelatedForeignKeyName(string $relatedModel) : string
Parameters
- $relatedModel : string
Return values
stringgetRelationMetadata()
Get relation metadata for a property.
protected
getRelationMetadata(string $propertyName) : array<string|int, mixed>|null
Parameters
- $propertyName : string
Return values
array<string|int, mixed>|nullhandleDependentRelations()
Handle dependent relations before destroying the model.
protected
handleDependentRelations() : void
Tags
performInsert()
Perform an insert operation.
protected
performInsert() : bool
Tags
Return values
boolperformUpdate()
Perform an update operation.
protected
performUpdate() : bool
Tags
Return values
boolpropertyToColumn()
Convert property name to database column name.
protected
propertyToColumn(string $propertyName) : string
Parameters
- $propertyName : string