Skip to content

Commit

Permalink
API Stop using deprecated API
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Nov 6, 2022
1 parent ece9003 commit 168698e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
6 changes: 0 additions & 6 deletions src/Dev/VersionedTestSessionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* Decorates TestSession object to update get / post requests with versioned querystring arguments.
* Session vars assigned by FunctionalTest::useDraftSite are respected here.
*
* @deprecated 2.2.0 Use ?stage=Stage|Live in your request's querystring instead
* @property TestSession $owner
*/
class VersionedTestSessionExtension extends VersionedStateExtension
Expand All @@ -22,11 +21,6 @@ class VersionedTestSessionExtension extends VersionedStateExtension
*
* @param string $url
*/
public function __construct()
{
Deprecation::notice('2.2.0', 'Use ?stage=Stage|Live in your request\'s querystring instead', Deprecation::SCOPE_CLASS);
}

public function updateLink(&$url)
{
$session = $this->owner->session();
Expand Down
9 changes: 8 additions & 1 deletion src/GraphQL/Resolvers/VersionedResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,17 @@ public static function resolveVersionList(array $resolverContext): Closure
}

// Get all versions
return $object->VersionsList();
return self::getVersionsList($object);
};
}

private static function getVersionsList(DataObject $object)
{
$id = $object->ID ?: $object->OldID;
$class = DataObject::getSchema()->baseDataClass($object);
return Versioned::get_all_versions($class, $id);
}

/**
* @param DataList $list
* @param array $args
Expand Down
10 changes: 4 additions & 6 deletions src/Versioned.php
Original file line number Diff line number Diff line change
Expand Up @@ -2074,22 +2074,22 @@ public function stagesDiffer()
* @param string $join Deprecated, use leftJoin($table, $joinClause) instead
* @param string $having
* @return ArrayList
* @deprecated 1.12.0 Use allVersions() instead'
*/
public function Versions($filter = "", $sort = "", $limit = "", $join = "", $having = "")
{
Deprecation::notice('1.12.0', 'Use allVersions() instead');
return $this->allVersions($filter, $sort, $limit, $join, $having);
}

/**
* NOTE: Versions() will be replaced with this method in SilverStripe 5.0
*
* @internal
* @deprecated 1.5.0 Use Versions() instead
* @deprecated 1.5.0 Use allVersions() instead
* @return DataList
*/
public function VersionsList()
{
Deprecation::notice('1.5.0', 'Use Versions() instead');
Deprecation::notice('1.5.0', 'Use allVersions() instead');
$id = $this->owner->ID ?: $this->owner->OldID;
$class = DataObject::getSchema()->baseDataClass($this->owner);
return Versioned::get_all_versions($class, $id);
Expand All @@ -2098,7 +2098,6 @@ public function VersionsList()
/**
* Return a list of all the versions available.
*
* @deprecated 1.5.0 Use Versions() instead
* @param string $filter
* @param string $sort
* @param string $limit
Expand All @@ -2108,7 +2107,6 @@ public function VersionsList()
*/
public function allVersions($filter = "", $sort = "", $limit = "", $join = "", $having = "")
{
Deprecation::notice('1.5.0', 'Use Versions() instead');
/** @var DataObject $owner */
$owner = $this->owner;

Expand Down
14 changes: 7 additions & 7 deletions tests/php/VersionedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ public function testLazyLoadFieldsRetrieval()

public function testReadingNotPersistentWhenUseSessionFalse()
{
Config::modify()->update(Versioned::class, 'use_session', false);
Config::modify()->set(Versioned::class, 'use_session', false);

$session = new Session([]);
$this->logInWithPermission('ADMIN');
Expand Down Expand Up @@ -1563,7 +1563,7 @@ public function testAuthor()
$record = new VersionedTest\TestObject();
$record->write();

$versions = $record->VersionsList();
$versions = $record->allVersions();
$latestVersion = $versions->last();

$author = $latestVersion->Author();
Expand All @@ -1578,7 +1578,7 @@ public function testPublisher()
$record->write();
$record->publishRecursive();

$versions = $record->VersionsList();
$versions = Versioned::get_all_versions(get_class($record), $record->ID);
$latestVersion = $versions->last();

$publisher = $latestVersion->Publisher();
Expand Down Expand Up @@ -1613,7 +1613,7 @@ public function testWriteWithoutVersion()
1 => 'First version',
2 => 'Second version original',
],
$record->VersionsList()->map('Version', 'Name')->toArray()
$record->allVersions()->map('Version', 'Name')->toArray()
);


Expand All @@ -1633,7 +1633,7 @@ public function testWriteWithoutVersion()

// ...however the versions list has the original value
// Note that publication creates a new version
$versions = $record->VersionsList()->map('Version', 'Name')->toArray();
$versions = $record->allVersions()->map('Version', 'Name')->toArray();
$this->assertEquals(
[
1 => 'First version',
Expand All @@ -1644,7 +1644,7 @@ public function testWriteWithoutVersion()
);

// The second version has WasPublished = true
$versions = $record->VersionsList()->map('Version', 'WasPublished')->toArray();
$versions = $record->allVersions()->map('Version', 'WasPublished')->toArray();
$this->assertEquals(
[
1 => 0,
Expand All @@ -1669,7 +1669,7 @@ public function testArchivedEntries()
$record->doArchive();

// ensure the version entries are correct
$versions = $record->VersionsList()->toArray();
$versions = Versioned::get_all_versions(get_class($record), $record->ID)->toArray();
$this->assertCount(3, $versions, 'All versions should be retrieved');

/** @var TestObject $createdVersion */
Expand Down

0 comments on commit 168698e

Please sign in to comment.