Versioned
class Versioned extends DataExtension implements TemplateGlobalProvider
The Versioned extension allows your DataObjects to have several versions, allowing you to rollback changes and view history. An example of this is the pages used in the CMS.
Constants
DEFAULT_MODE |
The default reading mode |
LIVE |
The Public stage. |
DRAFT |
The draft (default) stage |
Config options
draft_site_secured | bool | Default config for $is_draft_site_secured | |
db | array | ||
non_live_permissions | array | Permissions necessary to view records outside of the live stage (e.g. archive / draft stage). | |
use_session | bool | Use PHP's session storage for the "reading mode" and "unsecuredDraftSite", instead of explicitly relying on the "stage" query parameter. |
Properties
$class | from Extension | ||
string | $migratingVersion | A version that a DataObject should be when it is 'migrating', that is, when it is in the process of moving from one stage to another. | |
bool | $_nextWriteWithoutVersion | Flag which is temporarily changed during the write() process to influence augmentWrite() behaviour. If set to true, no new version will be created for the following write. Needs to be public as other classes introspect this state during the write process in order to adapt to this versioning behaviour. | |
DataObject | $owner | ||
int | $RecordID | ||
int | $Version | ||
bool | $WasPublished | ||
int | $AuthorID | ||
int | $PublisherID |
Methods
Construct a new Versioned object.
Called when this extension is added to a particular class
Helper method to strip eval'ed arguments from a string thats passed to {@link DataObject::$extensions} or {@link Object::add_extension()}.
Augment the the SQLQuery that is created by the DataQuery.
Update the database schema as required by this extension.
No description
No description
Define extra database fields
This function is used to provide modifications to the form used for front end forms. {@link DataObject->getFrontEndFields()}
This is used to provide modifications to the form actions used in the CMS. {@link DataObject->getCMSActions()}.
this function is used to provide modifications to the summary fields in CMS by the extension By default, the summaryField() of its owner will merge more fields defined in the extension's $extra_fields['summary_fields']
No description
Reset static configuration variables to their default values.
Amend freshly created DataQuery objects with versioned-specific information.
For lazy loaded fields requiring extra SQL manipulation, ie versioning.
Called by {@link SapphireTest} when the database is reset.
Perform a write without affecting the version table.
If a write was skipped, then we need to ensure that we don't leave a migrateVersion() value lying around for the next write.
Determine if there are any additional restrictions on this object for the given reading version.
Determines canView permissions for the latest version of this object on a specific stage.
Determine if a table supports the Versioned extensions (e.g. $table_versions does exists).
Check if a certain table has the 'Version' field.
No description
Is the latest version of the object published?
Move a database record from one stage to the other.
Set the migrating version.
Compare two stages to see if they're different. Only checks the version numbers, not the actual content.
Get a list of versions for this object, optionally with additional SQL parameters
Get a list of versions for this object, optionally with additional SQL parameters
Compare two version, and return the differences between them.
Return the base table - the class that directly extends DataObject.
Determine if the current user is able to set the given site stage / archive
Choose the stage the site is currently on: - If $_GET['stage'] is set, then it will use that stage, and store it in the session.
Set the current reading mode.
Get the current reading mode.
Get the name of the 'live' stage.
Get the current reading stage.
Get the current archive date.
Set the reading stage.
Replace default mode.
Get default reading mode
Check if draft site should be secured.
Set if the draft site should be secured or not
Set the reading archive date.
Get a singleton instance of a class in the given stage.
Gets the current version number of a specific record.
Prepopulate the cache for Versioned::get_versionnumber_by_stage() for a list of record IDs, for more efficient database querying. If $idList is null, then every object will be pre-cached.
Get a set of class instances by the given stage.
Delete this item from the specified stage.
Write this item to the specified stage.
Roll the draft version of this object to match the published one.
Return the latest version of the given object.
Returns whether the current record is the latest one.
Return the equivalent of a DataList::create() call, querying the latest version of each object stored in the (class)_versions tables. In particular, this will query deleted records as well as active ones.
Return the specific version of the given ID.
Return a list of all versions for a given id.
Clear the cached version numbers from previous queries.
Returns a piece of text to keep DataObject cache keys appropriately specific.
Returns an array of possible stages.
No description
No description
Details
at line 217
__construct(array $stages = array('Stage', 'Live'))
Construct a new Versioned object.
in Extension at line 54
static
add_to_class(string $class, string $extensionClass, mixed $args = null)
Called when this extension is added to a particular class
in Extension at line 66
setOwner(SS_Object $owner, string $ownerBaseClass = null)
Set the owner of this extension.
in Extension at line 74
clearOwner()
in Extension at line 97
static string
get_classname_without_arguments(string $extensionStr)
Helper method to strip eval'ed arguments from a string thats passed to {@link DataObject::$extensions} or {@link Object::add_extension()}.
in DataExtension at line 10
static
get_extra_config($class, $extension, $args)
in DataExtension at line 32
static
unload_extra_statics($class, $extension)
in DataExtension at line 42
validate(ValidationResult $validationResult)
Hook for extension-specific validation.
at line 252
augmentSQL(SQLQuery $query, DataQuery $dataQuery = null)
Augment the the SQLQuery that is created by the DataQuery.
at line 442
augmentDatabase()
Update the database schema as required by this extension.
When duplicating a table's structure, remember to duplicate the create options as well. See {@link Versioned->augmentDatabase} for an example.
at line 720
augmentWrite(array $manipulation)
in DataExtension at line 70
onBeforeWrite()
at line 802
onAfterWrite()
in DataExtension at line 76
onBeforeDelete()
in DataExtension at line 79
onAfterDelete()
in DataExtension at line 82
requireDefaultRecords()
in DataExtension at line 85
populateDefaults()
in DataExtension at line 88
can($member)
in DataExtension at line 91
canEdit($member)
in DataExtension at line 94
canDelete($member)
in DataExtension at line 97
canCreate($member)
in DataExtension at line 112
array
extraStatics($class = null, $extension = null)
Define extra database fields
Return a map where the keys are db, has_one, etc, and the values are additional fields/relations to be defined.
at line 1649
updateCMSFields(FieldList $fields)
in DataExtension at line 140
updateFrontEndFields(FieldList $fields)
This function is used to provide modifications to the form used for front end forms. {@link DataObject->getFrontEndFields()}
Caution: Use {@link FieldList->push()} to add fields.
in DataExtension at line 149
updateCMSActions(FieldList $actions)
This is used to provide modifications to the form actions used in the CMS. {@link DataObject->getCMSActions()}.
in DataExtension at line 160
updateSummaryFields(array $fields)
this function is used to provide modifications to the summary fields in CMS by the extension By default, the summaryField() of its owner will merge more fields defined in the extension's $extra_fields['summary_fields']
at line 1642
updateFieldLabels(array $labels)
at line 203
static
reset()
Reset static configuration variables to their default values.
at line 235
augmentDataQueryCreation(SQLQuery $query, DataQuery $dataQuery)
Amend freshly created DataQuery objects with versioned-specific information.
at line 405
augmentLoadLazyFields(SQLQuery $query, DataQuery $dataQuery = null, DataObject $dataObject)
For lazy loaded fields requiring extra SQL manipulation, ie versioning.
at line 430
static
on_db_reset()
Called by {@link SapphireTest} when the database is reset.
at line 796
int
writeWithoutVersion()
Perform a write without affecting the version table.
at line 810
onAfterSkippedWrite()
If a write was skipped, then we need to ensure that we don't leave a migrateVersion() value lying around for the next write.
at line 820
bool|null
canView(Member $member = null)
Extend permissions to include additional security for objects that are not published to live.
at line 843
bool
canViewVersioned(Member $member = null)
Determine if there are any additional restrictions on this object for the given reading version.
Override this in a subclass to customise any additional effect that Versioned applies to canView.
This is expected to be called by canView, and thus is only responsible for denying access if the default canView would otherwise ALLOW access. Thus it should not be called in isolation as an authoritative permission check.
This has the following extension points: - canViewDraft is invoked if Mode = stage and Stage = stage - canViewArchived is invoked if Mode = archive
at line 894
bool
canViewStage(string $stage = 'Live', Member $member = null)
Determines canView permissions for the latest version of this object on a specific stage.
Usually the stage is read from {@link Versioned::current_stage()}.
This method should be invoked by user code to check if a record is visible in the given stage.
This method should not be called via ->extend('canViewStage'), but rather should be overridden in the extended class.
at line 910
bool
canBeVersioned(string $table)
Determine if a table supports the Versioned extensions (e.g. $table_versions does exists).
at line 922
bool
hasVersionField(string $table)
Check if a certain table has the 'Version' field.
at line 938
string
extendWithSuffix(string $table)
at line 960
bool
latestPublished()
Is the latest version of the object published?
at line 982
publish(string $fromStage, string $toStage, bool $createNewVersion = false)
Move a database record from one stage to the other.
at line 1042
migrateVersion(string $version)
Set the migrating version.
at line 1053
bool
stagesDiffer(string $stage1, string $stage2)
Compare two stages to see if they're different. Only checks the version numbers, not the actual content.
at line 1084
DataList
Versions(string $filter = "", string $sort = "", string $limit = "", string $join = "", string $having = "")
Get a list of versions for this object, optionally with additional SQL parameters
at line 1098
DataList
allVersions(string $filter = "", string $sort = "", string $limit = "", string $join = "", string $having = "")
Get a list of versions for this object, optionally with additional SQL parameters
at line 1150
DataObject
compareVersions(string $from, string $to)
Compare two version, and return the differences between them.
at line 1165
string
baseTable(string $stage = null)
Return the base table - the class that directly extends DataObject.
at line 1185
static bool
can_choose_site_stage(SS_HTTPRequest $request)
Determine if the current user is able to set the given site stage / archive
at line 1217
static
choose_site_stage(SS_HTTPRequest $request = null)
Choose the stage the site is currently on: - If $_GET['stage'] is set, then it will use that stage, and store it in the session.
- If $_GET['archiveDate'] is set, it will use that date, and store it in the session.
- If neither of these are set, it checks the session, otherwise the stage is set to 'Live'.
at line 1275
static
set_reading_mode(string $mode)
Set the current reading mode.
at line 1284
static string
get_reading_mode()
Get the current reading mode.
at line 1293
static string
get_live_stage()
Get the name of the 'live' stage.
at line 1302
static string
current_stage()
Get the current reading stage.
at line 1315
static string
current_archived_date()
Get the current archive date.
at line 1325
static
reading_stage(string $stage)
Set the reading stage.
at line 1336
static
set_default_reading_mode(string $mode)
Replace default mode.
An non-default mode should be specified via querystring arguments.
at line 1345
static string
get_default_reading_mode()
Get default reading mode
at line 1355
static bool
get_draft_site_secured()
Check if draft site should be secured.
Can be turned off if draft site unauthenticated
at line 1368
static
set_draft_site_secured(bool $secured)
Set if the draft site should be secured or not
at line 1377
static
reading_archived_date(string $date)
Set the reading archive date.
at line 1392
static DataObject
get_one_by_stage(string $class, string $stage, string $filter = '', bool $cache = true, string $sort = '')
Get a singleton instance of a class in the given stage.
at line 1409
static int
get_versionnumber_by_stage(string $class, string $stage, int $id, bool $cache = true)
Gets the current version number of a specific record.
at line 1445
static
prepopulate_versionnumber_cache(string $class, string $stage, array $idList = null)
Prepopulate the cache for Versioned::get_versionnumber_by_stage() for a list of record IDs, for more efficient database querying. If $idList is null, then every object will be pre-cached.
at line 1486
static DataList
get_by_stage(string $class, string $stage, string $filter = '', string $sort = '', string $join = '', string|int $limit = '', string $containerClass = 'DataList')
Get a set of class instances by the given stage.
at line 1501
deleteFromStage(string $stage)
Delete this item from the specified stage.
at line 1522
int
writeToStage(string $stage, bool $forceInsert = false)
Write this item to the specified stage.
at line 1540
doRollbackTo(string|int $version)
Roll the draft version of this object to match the published one.
Caution: Doesn't overwrite the object properties with the rolled back version.
at line 1556
static DataObject
get_latest_version(string $class, string $id)
Return the latest version of the given object.
at line 1575
bool
isLatestVersion()
Returns whether the current record is the latest one.
at line 1592
static
get_including_deleted(string $class, string $filter = "", string $sort = "")
Return the equivalent of a DataList::create() call, querying the latest version of each object stored in the (class)_versions tables. In particular, this will query deleted records as well as active ones.
at line 1612
static DataObject
get_version(string $class, int $id, int $version)
Return the specific version of the given ID.
Caution: The record is retrieved as a DataObject, but saving back modifications via write() will create a new version, rather than modifying the existing one.
at line 1630
static DataList
get_all_versions(string $class, int $id)
Return a list of all versions for a given id.
at line 1661
onBeforeDuplicate(DataObject $source, bool $doWrite)
Ensure version ID is reset to 0 on duplicate
at line 1668
flushCache()
Clear the cached version numbers from previous queries.
at line 1677
string
cacheKeyComponent()
Returns a piece of text to keep DataObject cache keys appropriately specific.
at line 1686
array
getVersionedStages()
Returns an array of possible stages.