Skip to content

Commit

Permalink
API Support new extend*() format for extension methods
Browse files Browse the repository at this point in the history
API Remove deprecated 5.0 methods
  • Loading branch information
Damian Mooyman authored and GuySartorelli committed Aug 26, 2022
1 parent 5eccc51 commit 9eb2aee
Showing 1 changed file with 30 additions and 96 deletions.
126 changes: 30 additions & 96 deletions src/Versioned.php
Expand Up @@ -329,17 +329,6 @@ public function augmentDataQueryCreation(SQLSelect &$query, DataQuery &$dataQuer
*/
public function __construct($mode = self::STAGEDVERSIONED)
{
// Handle deprecated behaviour
if ($mode === 'Stage' && func_num_args() === 1) {
Deprecation::notice("5.0", "Versioned now takes a mode as a single parameter");
$mode = static::VERSIONED;
} elseif (is_array($mode) || func_num_args() > 1) {
Deprecation::notice("5.0", "Versioned now takes a mode as a single parameter");
$mode = func_num_args() > 1 || count($mode ?? []) > 1
? static::STAGEDVERSIONED
: static::VERSIONED;
}

if (!in_array($mode, [static::STAGEDVERSIONED, static::VERSIONED])) {
throw new InvalidArgumentException("Invalid mode: {$mode}");
}
Expand Down Expand Up @@ -1460,11 +1449,6 @@ public function onAfterSkippedWrite()
*/
public function canPublish($member = null)
{
// Skip if invoked by extendedCan()
if (func_num_args() > 4) {
return null;
}

if (!$member) {
$member = Security::getCurrentUser();
}
Expand All @@ -1484,6 +1468,12 @@ public function canPublish($member = null)
return $owner->canEdit($member);
}

protected function extendCanPublish()
{
// prevent canPublish() from extending itself
return null;
}

/**
* Check if the current user can delete this record from live
*
Expand All @@ -1492,11 +1482,6 @@ public function canPublish($member = null)
*/
public function canUnpublish($member = null)
{
// Skip if invoked by extendedCan()
if (func_num_args() > 4) {
return null;
}

if (!$member) {
$member = Security::getCurrentUser();
}
Expand All @@ -1516,6 +1501,12 @@ public function canUnpublish($member = null)
return $owner->canPublish($member);
}

protected function extendCanUnpublish()
{
// prevent canUnpublish() extending itself
return null;
}

/**
* Check if the current user is allowed to archive this record.
* If extended, ensure that both canDelete and canUnpublish are extended also
Expand All @@ -1525,11 +1516,6 @@ public function canUnpublish($member = null)
*/
public function canArchive($member = null)
{
// Skip if invoked by extendedCan()
if (func_num_args() > 4) {
return null;
}

if (!$member) {
$member = Security::getCurrentUser();
}
Expand Down Expand Up @@ -1559,6 +1545,12 @@ public function canArchive($member = null)
return true;
}

protected function extendCanArchive()
{
// Prevent canArchive() extending itself
return null;
}

/**
* Check if the user can revert this record to live
*
Expand All @@ -1569,11 +1561,6 @@ public function canRevertToLive($member = null)
{
$owner = $this->owner;

// Skip if invoked by extendedCan()
if (func_num_args() > 4) {
return null;
}

// Can't revert if not on live
if (!$owner->isPublished()) {
return false;
Expand All @@ -1597,6 +1584,12 @@ public function canRevertToLive($member = null)
return $owner->canEdit($member);
}

protected function extendCanRevertToLive()
{
// Prevent canRevertToLive() extending itself
return null;
}

/**
* Check if the user can restore this record to draft
*
Expand All @@ -1607,11 +1600,6 @@ public function canRestoreToDraft($member = null)
{
$owner = $this->owner;

// Skip if invoked by extendedCan()
if (func_num_args() > 4) {
return null;
}

if (!$member) {
$member = Security::getCurrentUser();
}
Expand All @@ -1630,6 +1618,12 @@ public function canRestoreToDraft($member = null)
return $owner->canEdit($member);
}

protected function extendcanRestoreToDraft()
{
// Prevent canRestoreToDraft() extending itself
return null;
}

/**
* Extend permissions to include additional security for objects that are not published to live.
*
Expand Down Expand Up @@ -1815,15 +1809,6 @@ public function latestPublished()
return $draftVersion === $liveVersion;
}

/**
* @deprecated 4.0..5.0
*/
public function doPublish()
{
Deprecation::notice('5.0', 'Use publishRecursive instead');
return $this->owner->publishRecursive();
}

/**
* Publishes this object to Live, but doesn't publish owned objects.
*
Expand Down Expand Up @@ -1963,22 +1948,6 @@ public function doRevertToLive()
return true;
}

/**
* @deprecated 1.2..2.0 This extension method is redundant and will be removed
*/
public function onAfterRevertToLive()
{
}

/**
* @deprecated 4.0..5.0
*/
public function publish($fromStage, $toStage, $createNewVersion = true)
{
Deprecation::notice('5.0', 'Use copyVersionToStage instead');
$this->owner->copyVersionToStage($fromStage, $toStage, true);
}

/**
* Move a database record from one stage to the other.
*
Expand Down Expand Up @@ -2019,16 +1988,6 @@ public function getMigratingVersion()
return $this->owner->getField(self::MIGRATING_VERSION);
}

/**
* @deprecated 4.0...5.0
* @param string $version The version.
*/
public function migrateVersion($version)
{
Deprecation::notice('5.0', 'use setMigratingVersion instead');
$this->setMigratingVersion($version);
}

/**
* Set the migrating version.
*
Expand Down Expand Up @@ -2681,31 +2640,6 @@ public function writeToStage($stage, $forceInsert = false)
});
}

/**
* Roll the draft version of this record to match the published record.
* Caution: Doesn't overwrite the object properties with the rolled back version.
*
* {@see doRevertToLive()} to reollback to live
*
* @deprecated 4.2..5.0 Use rollbackRecursive() instead
* @param int $version Version number
*/
public function doRollbackTo($version)
{
Deprecation::notice('5.0', 'Use rollbackRecursive() instead');
$owner = $this->owner;
$owner->extend('onBeforeRollback', $version);
$owner->rollbackRecursive($version);
$owner->extend('onAfterRollback', $version);
}

/**
* @deprecated 1.2..2.0 This extension method is redundant and will be removed
*/
public function onAfterRollback()
{
}

/**
* 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)
Expand Down

0 comments on commit 9eb2aee

Please sign in to comment.