SilverStripe\Versioned\Versioned
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.
Note: This extension relies on the object also having the extension applied.
Synopsis
class Versioned
extends DataExtension
implements
TemplateGlobalProvider,Resettable
{
- // constants
- const DEFAULT_MODE = 'Stage.Live';
- const STAGEDVERSIONED = 'StagedVersioned';
- const VERSIONED = 'Versioned';
- const LIVE = 'Live';
- const DRAFT = 'Stage';
- const MIGRATING_VERSION = 'MigratingVersion';
- const NEXT_WRITE_WITHOUT_VERSIONED = 'NextWriteWithoutVersioned';
- const DELETE_WRITES_VERSION_DISABLED = 'DeleteWritesVersionDisabled';
- // members
- protected $mode;
- protected static $cache_versionnumber;
- protected static bool|null $is_draft_site_secured = NULL;
- private static bool $draft_site_secured = true;
- protected array $versionModifiedCache = ;
- protected static $reading_mode = NULL;
- protected static null $default_reading_mode = self::DEFAULT_MODE;
- private static array $non_virtual_fields = ;
- private static array $db_for_versions_table = ;
- private static array $casting = ;
- private static array $db = ;
- private static boolean $prepopulate_versionnumber_cache = true;
- private static bool $use_conditions_over_inner_joins = false;
- private static array $indexes_for_versions_table = ;
- private static array $versionableExtensions = ;
- private static array $non_live_permissions = ;
- private static bool $use_session = false;
- // methods
- public static void reset()
- public void augmentDataQueryCreation()
- public void __construct()
- public Versioned|DataObject getAtVersion()
- protected string getLastEditedForVersion()
- protected array getLastEditedAndStageForVersion()
- public void updateInheritableQueryParams()
- public void augmentSQL()
- protected void augmentSQLStage()
- protected void augmentSQLStageUnique()
- protected void augmentSQLVersioned()
- protected SQLSelect prepareMaxVersionSubSelect()
- protected void shouldApplySubSelectAsCondition()
- protected void augmentSQLVersionedArchive()
- protected void augmentSQLVersionedLatestSingle()
- protected void augmentSQLVersionedLatest()
- protected void augmentSQLVersionedVersion()
- protected void augmentSQLVersionedAll()
- protected bool isTableVersioned()
- public void augmentLoadLazyFields()
- public void augmentDatabase()
- protected void cleanupVersionedOrphans()
- private array uniqueToIndex()
- protected void augmentWriteVersioned()
- protected void augmentWriteStaged()
- protected void createDeletedVersion()
- public void augmentWrite()
- public int writeWithoutVersion()
- public void onAfterWrite()
- public bool getNextWriteWithoutVersion()
- public DataObject setNextWriteWithoutVersion()
- public bool getDeleteWritesVersion()
- public DataObject setDeleteWritesVersion()
- protected mixed suppressDeletedVersion()
- public void onAfterSkippedWrite()
- public bool canPublish()
- public mixed canUnpublish()
- public bool canArchive()
- public bool canRevertToLive()
- public bool canRestoreToDraft()
- public bool|null canView()
- public bool canViewVersioned()
- public bool canViewStage()
- public boolean canBeVersioned()
- public boolean hasVersionField()
- public string extendWithSuffix()
- public bool latestPublished()
- public void doPublish()
- public bool publishSingle()
- public bool doArchive()
- public bool doUnpublish()
- public void onAfterDelete()
- public bool hasPublishedOwners()
- public bool doRevertToLive()
- public void onAfterRevertToLive()
- public void publish()
- public void copyVersionToStage()
- public int|null getMigratingVersion()
- public void migrateVersion()
- public DataObject setMigratingVersion()
- public bool stagesDiffer()
- public ArrayList Versions()
- public DataList VersionsList()
- public ArrayList allVersions()
- public DataObject compareVersions()
- protected string baseTable()
- public string stageTable()
- public static bool can_choose_site_stage()
- public static void choose_site_stage()
- public static void set_reading_mode()
- public static string get_reading_mode()
- public static string get_stage()
- public static string current_archived_date()
- public static string current_archived_stage()
- public static void set_stage()
- public static void set_default_reading_mode()
- public static string get_default_reading_mode()
- public static bool get_draft_site_secured()
- public static void set_draft_site_secured()
- public static void reading_archived_date()
- public static DataObject get_one_by_stage()
- public static int|null get_versionnumber_by_stage()
- private static int|null determineVersionNumberByStage()
- public void onPrepopulateTreeDataCache()
- public static void prepopulate_versionnumber_cache()
- public static DataList get_by_stage()
- public void deleteFromStage()
- public int writeToStage()
- public void doRollbackTo()
- public void onAfterRollback()
- public DataObject|Versioned rollbackRecursive()
- public void rollbackSingle()
- public static DataObject get_latest_version()
- public boolean isLatestVersion()
- public bool isLiveVersion()
- public bool isLatestDraftVersion()
- public bool isPublished()
- public bool isArchived()
- public bool isOnDraft()
- public bool isOnLiveOnly()
- public bool isOnDraftOnly()
- public bool isModifiedOnDraft()
- public static DataList get_including_deleted()
- public static DataObject get_version()
- public static DataList get_all_versions()
- public void updateFieldLabels()
- public void updateCMSFields()
- public void onBeforeDuplicate()
- public void flushCache()
- public string cacheKeyComponent()
- public array getVersionedStages()
- public static void get_template_global_variables()
- public bool hasStages()
- public static mixed withVersionedMode()
- public Member|null Author()
- public Member|null Publisher()
Hierarchy
Extends
- SilverStripe\ORM\DataExtension
Implements
- SilverStripe\View\TemplateGlobalProvider
- SilverStripe\Core\Resettable
Tasks
Line | Task |
---|---|
2775+ | Performance - could do this directly via SQL. |
Constants
Name | Value |
---|---|
DEFAULT_MODE | 'Stage.Live' |
STAGEDVERSIONED | 'StagedVersioned' |
VERSIONED | 'Versioned' |
LIVE | 'Live' |
DRAFT | 'Stage' |
MIGRATING_VERSION | 'MigratingVersion' |
NEXT_WRITE_WITHOUT_VERSIONED | 'NextWriteWithoutVersioned' |
DELETE_WRITES_VERSION_DISABLED | 'DeleteWritesVersionDisabled' |
Members
private
- $casting
—
array
Ensure versioned records cast extra fields properly - $db — array
- $db_for_versions_table
—
array
Additional database columns for the new "_Versions" table. Used in {@link augmentDatabase()} and all Versioned calls extending or creating SELECT statements. - $draft_site_secured
—
SilverStripe\Versioned\bool
Default config for $is_draft_site_secured - $indexes_for_versions_table
—
array
Additional database indexes for the new "_Versions" table. Used in {@link augmentDatabase()}. - $non_live_permissions
—
array
Permissions necessary to view records outside of the live stage (e.g. archive / draft stage). - $non_virtual_fields
—
array
Ensure versioned page doesn't attempt to virtualise these non-db fields - $prepopulate_versionnumber_cache
—
boolean
Used to enable or disable the prepopulation of the version number cache. - $use_conditions_over_inner_joins
—
SilverStripe\Versioned\bool
Indicates whether augmentSQL operations should add subselects as WHERE conditions instead of INNER JOIN intersections. Performance of the INNER JOIN scales on the size of _Versions tables where as the condition scales on the number of records being returned from the base query. - $use_session
—
SilverStripe\Versioned\bool
Use PHP's session storage for the "reading mode" and "unsecuredDraftSite", instead of explicitly relying on the "stage" query parameter. - $versionableExtensions
—
array
An array of DataObject extensions that may require versioning for extra tables The array value is a set of suffixes to form these table names, assuming a preceding '_'.
protected
- $cache_versionnumber
—
array
A cache used by get_versionnumber_by_stage(). - $default_reading_mode
—
null
Default reading mode, if none set. - $is_draft_site_secured
—
SilverStripe\Versioned\bool|null
Set if draft site is secured or not. Fails over to $draft_site_secured if unset - $mode
—
string
Versioning mode for this object. - $reading_mode
—
string
Current reading mode. Supports stage / archive modes. - $versionModifiedCache
—
array
Cache of version to modified dates for this object
Methods
private
- determineVersionNumberByStage()
- uniqueToIndex() — Helper for augmentDatabase() to find unique indexes and convert them to non-unique
protected
- augmentSQLStage() — Reading a specific stage (Stage or Live)
- augmentSQLStageUnique() — Reading a specific stage, but only return items that aren't in any other stage
- augmentSQLVersioned() — Augment SQL to select from `_Versions` table instead.
- augmentSQLVersionedAll() — If all versions are requested, ensure that records are sorted by this field
- augmentSQLVersionedArchive() — Filter the versioned history by a specific date and archive stage
- augmentSQLVersionedLatest() — Return latest version instances, regardless of whether they are on a particular stage.
- augmentSQLVersionedLatestSingle() — Return latest version instance, regardless of whether it is on a particular stage.
- augmentSQLVersionedVersion() — If selecting a specific version, filter it here
- augmentWriteStaged() — Rewrite the given manipulation to update the selected (non-default) stage
- augmentWriteVersioned() — Generates a ($table)_version DB manipulation and injects it into the current $manipulation
- baseTable() — Return the base table - the class that directly extends DataObject.
- cleanupVersionedOrphans() — Cleanup orphaned records in the _Versions table
- createDeletedVersion() — Adds a WasDeleted=1 version entry for this record, and records any stages the deletion applies to
- getLastEditedAndStageForVersion() — Get modified date and stage for the given version
- getLastEditedForVersion() — Get modified date for the given version
- isTableVersioned() — Determine if the given versioned table is a part of the sub-tree of the current dataobject This helps prevent rewriting of other tables that get joined in, in particular, many_many tables
- prepareMaxVersionSubSelect() — Prepare a sub-select for determining latest versions of records on the base table. This is used as either an inner join or sub-select on the base query
- shouldApplySubSelectAsCondition() — Indicates if a subquery filtering versioned records should apply as a condition instead of an inner join
- suppressDeletedVersion() — Helper method to safely suppress delete callback
public
- __construct() — Construct a new Versioned object.
- Author() — Get author of this record.
- Publisher() — Get publisher of this record.
- Versions()
- VersionsList() — NOTE: Versions() will be replaced with this method in SilverStripe 5.0
- allVersions() — Return a list of all the versions available.
- augmentDataQueryCreation() — Amend freshly created DataQuery objects with versioned-specific information.
- augmentDatabase()
- augmentLoadLazyFields() — For lazy loaded fields requiring extra sql manipulation, ie versioning.
- augmentSQL() — Augment the the SQLSelect that is created by the DataQuery
- augmentWrite()
- cacheKeyComponent() — Return a piece of text to keep DataObject cache keys appropriately specific.
- canArchive() — Check if the current user is allowed to archive this record.
- canBeVersioned() — Determine if a class is supporting the Versioned extensions (e.g.
- canPublish() — This function should return true if the current user can publish this record.
- canRestoreToDraft() — Check if the user can restore this record to draft
- canRevertToLive() — Check if the user can revert this record to live
- canUnpublish() — Check if the current user can delete this record from live
- canView() — Extend permissions to include additional security for objects that are not published to live.
- canViewStage() — Determines canView permissions for the latest version of this object on a specific stage.
- canViewVersioned() — Determine if there are any additional restrictions on this object for the given reading version.
- can_choose_site_stage() — Determine if the current user is able to set the given site stage / archive
- choose_site_stage() — Choose the stage the site is currently on.
- compareVersions() — Compare two version, and return the diff between them.
- copyVersionToStage() — Move a database record from one stage to the other.
- current_archived_date() — Get the current archive date.
- current_archived_stage() — Get the current archive stage.
- deleteFromStage() — Delete this record from the given stage
- doArchive() — Removes the record from both live and stage
- doPublish()
- doRevertToLive() — Revert the draft changes: replace the draft content with the content on live
- doRollbackTo() — Roll the draft version of this record to match the published record.
- doUnpublish() — Removes this record from the live site
- extendWithSuffix()
- flushCache()
- getAtVersion() — Get this record at a specific version
- getDeleteWritesVersion() — Check if delete() should write _Version rows or not
- getMigratingVersion() — Get version migrated to
- getNextWriteWithoutVersion() — Check if next write is without version
- getVersionedStages() — Returns an array of possible stages.
- get_all_versions() — Return a list of all versions for a given id.
- get_by_stage() — Get a set of class instances by the given stage.
- get_default_reading_mode() — Get default reading mode
- get_draft_site_secured() — Check if draft site should be secured.
- get_including_deleted() — Return the equivalent of a DataList::create() call, querying the latest version of each record stored in the (class)_Versions tables.
- get_latest_version() — Return the latest version of the given record.
- get_one_by_stage() — Get a singleton instance of a class in the given stage.
- get_reading_mode() — Get the current reading mode.
- get_stage() — Get the current reading stage.
- get_template_global_variables()
- get_version() — Return the specific version of the given id.
- get_versionnumber_by_stage() — Gets the current version number of a specific record.
- hasPublishedOwners() — Determine if this object is published, and has any published owners.
- hasStages() — Check if this object has stages
- hasVersionField() — Check if a certain table has the 'Version' field.
- isArchived() — Check if page doesn't exist on any stage, but used to be
- isLatestDraftVersion() — Returns whether the current record's version is the current draft/modified version
- isLatestVersion() — Returns whether the current record is the latest one.
- isLiveVersion() — Returns whether the current record's version is the current live/published version
- isModifiedOnDraft() — Compares current draft with live version, and returns true if these versions differ, meaning there have been unpublished changes to the draft site.
- isOnDraft() — Check if this record exists on the draft stage.
- isOnDraftOnly() — Compares current draft with live version, and returns true if no live version exists, meaning the page was never published.
- isOnLiveOnly() — Compares current draft with live version, and returns true if no draft version of this page exists but the page is still published (eg, after triggering "Delete from draft site" in the CMS).
- isPublished() — Check if this record exists on live On objects with only 1 stage, check if the record exists on that stage.
- latestPublished() — Determines if the current draft version is the same as live or rather, that there are no outstanding draft changes
- migrateVersion()
- onAfterDelete()
- onAfterRevertToLive()
- onAfterRollback()
- 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.
- onAfterWrite()
- onBeforeDuplicate() — Ensure version ID is reset to 0 on duplicate
- onPrepopulateTreeDataCache() — Hook into {@link Hierarchy::prepopulateTreeDataCache}.
- prepopulate_versionnumber_cache() — Pre-populate 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 record will be pre-cached.
- publish()
- publishSingle() — Publishes this object to Live, but doesn't publish owned objects.
- reading_archived_date() — Set the reading archive date.
- reset() — Reset static configuration variables to their default values.
- rollbackRecursive() — Recursively rollback draft to the given version. This will also rollback any owned objects at that point in time to the same date. Objects which didn't exist (or weren't attached) to the record at the target point in time will be "unlinked", which dis-associates the record without requiring a hard deletion.
- rollbackSingle() — Rollback draft to a given version
- setDeleteWritesVersion() — Set if delete() should write _Version rows
- setMigratingVersion() — Set the migrating version.
- setNextWriteWithoutVersion() — Set if next write should be without version or not
- set_default_reading_mode() — Replace default mode.
- set_draft_site_secured() — Set if the draft site should be secured or not
- set_reading_mode() — Set the current reading mode.
- set_stage() — Set the reading stage.
- stageTable() — Given a table and stage determine the table name.
- stagesDiffer() — Compare two stages to see if they're different.
- updateCMSFields()
- updateFieldLabels()
- updateInheritableQueryParams() — Updates query parameters of relations attached to versioned dataobjects
- withVersionedMode() — Invoke a callback which may modify reading mode, but ensures this mode is restored after completion, without modifying global state.
- writeToStage() — Write the given record to the given stage.
- writeWithoutVersion() — Perform a write without affecting the version table.