Skip to content

Commit

Permalink
Merge pull request #364 from wilr/wilr-patch-1
Browse files Browse the repository at this point in the history
FIX comparing versions when class changes (#363)
  • Loading branch information
GuySartorelli authored Jul 22, 2022
2 parents e62ad75 + 0dda24a commit 8658256
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/Versioned.php
Original file line number Diff line number Diff line change
Expand Up @@ -1688,7 +1688,7 @@ public function canViewVersioned($member = null)

// If we weren't definitely loaded from live, and we can't view non-live content, we need to
// check to make sure this version is the live version and so can be viewed
$latestVersion = Versioned::get_versionnumber_by_stage(get_class($owner), static::LIVE, $owner->ID);
$latestVersion = Versioned::get_versionnumber_by_stage($this->owner->baseClass(), static::LIVE, $owner->ID);
if ($latestVersion == $owner->Version) {
// Even if this is loaded from a non-live stage, this is the live version
return true;
Expand Down Expand Up @@ -1730,7 +1730,8 @@ public function canViewStage($stage = self::LIVE, $member = null)
Versioned::set_stage($stage);

$owner = $this->owner;
$versionFromStage = DataObject::get(get_class($owner))->byID($owner->ID);
$baseClass = DataObject::getSchema()->baseDataClass($owner);
$versionFromStage = DataObject::get($baseClass)->byID($owner->ID);

return $versionFromStage ? $versionFromStage->canView($member) : false;
});
Expand Down Expand Up @@ -1936,8 +1937,10 @@ public function hasPublishedOwners()
return false;
}
// Count live owners
$baseClass = $this->owner->baseClass();

/** @var Versioned|RecursivePublishable|DataObject $liveRecord */
$liveRecord = static::get_by_stage(get_class($this->owner), Versioned::LIVE)->byID($this->owner->ID);
$liveRecord = static::get_by_stage($baseClass, Versioned::LIVE)->byID($this->owner->ID);
return $liveRecord->findOwners(false)->count() > 0;
}

Expand Down Expand Up @@ -2083,7 +2086,7 @@ public function Versions($filter = "", $sort = "", $limit = "", $join = "", $hav
public function VersionsList()
{
$id = $this->owner->ID ?: $this->owner->OldID;
$class = get_class($this->owner);
$class = DataObject::getSchema()->baseDataClass($this->owner);
return Versioned::get_all_versions($class, $id);
}

Expand Down Expand Up @@ -2159,8 +2162,10 @@ public function allVersions($filter = "", $sort = "", $limit = "", $join = "", $
public function compareVersions($from, $to)
{
$owner = $this->owner;
$fromRecord = Versioned::get_version(get_class($owner), $owner->ID, $from);
$toRecord = Versioned::get_version(get_class($owner), $owner->ID, $to);
$baseClass = $this->owner->baseClass();

$fromRecord = Versioned::get_version($baseClass, $owner->ID, $from);
$toRecord = Versioned::get_version($baseClass, $owner->ID, $to);

$diff = new DataDifferencer($fromRecord, $toRecord);

Expand Down Expand Up @@ -2780,7 +2785,7 @@ public function isLatestVersion()
}

/** @var Versioned|DataObject $version */
$version = static::get_latest_version(get_class($owner), $owner->ID);
$version = static::get_latest_version($this->owner->baseClass(), $owner->ID);
return ($version->Version == $owner->Version);
}

Expand Down

0 comments on commit 8658256

Please sign in to comment.