Skip to content

Commit

Permalink
Merge pull request #377 from creative-commoners/pulls/1/stop-depr
Browse files Browse the repository at this point in the history
API Stop using deprecated API
  • Loading branch information
sabina-talipova authored Nov 14, 2022
2 parents ece9003 + 5ce310f commit 4baa7b4
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 54 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
66 changes: 32 additions & 34 deletions src/Versioned.php
Original file line number Diff line number Diff line change
Expand Up @@ -1968,7 +1968,7 @@ public function doRevertToLive()
*/
public function onAfterRevertToLive()
{
Deprecation::notice('1.2.0', 'Will be removed without equivalent functionality to replace it');
// noop
}

/**
Expand All @@ -1977,7 +1977,7 @@ public function onAfterRevertToLive()
public function publish($fromStage, $toStage, $createNewVersion = true)
{
Deprecation::notice('1.0.0', 'Use copyVersionToStage() instead');
$this->owner->copyVersionToStage($fromStage, $toStage, true);
$this->owner->copyVersionToStage($fromStage, $toStage);
}

/**
Expand Down Expand Up @@ -2077,38 +2077,6 @@ public function stagesDiffer()
*/
public function Versions($filter = "", $sort = "", $limit = "", $join = "", $having = "")
{
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
* @return DataList
*/
public function VersionsList()
{
Deprecation::notice('1.5.0', 'Use Versions() instead');
$id = $this->owner->ID ?: $this->owner->OldID;
$class = DataObject::getSchema()->baseDataClass($this->owner);
return Versioned::get_all_versions($class, $id);
}

/**
* Return a list of all the versions available.
*
* @deprecated 1.5.0 Use Versions() instead
* @param string $filter
* @param string $sort
* @param string $limit
* @param string $join
* @param string $having
* @return ArrayList
*/
public function allVersions($filter = "", $sort = "", $limit = "", $join = "", $having = "")
{
Deprecation::notice('1.5.0', 'Use Versions() instead');
/** @var DataObject $owner */
$owner = $this->owner;

Expand Down Expand Up @@ -2164,6 +2132,36 @@ public function allVersions($filter = "", $sort = "", $limit = "", $join = "", $
return $versions;
}

/**
* @internal
* @deprecated 1.5.0 Use allVersions() instead
* @return DataList
*/
public function VersionsList()
{
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);
}

/**
* Return a list of all the versions available.
*
* @deprecated 1.5.0 Use Versions() instead
* @param string $filter
* @param string $sort
* @param string $limit
* @param string $join
* @param string $having
* @return ArrayList
*/
public function allVersions($filter = "", $sort = "", $limit = "", $join = "", $having = "")
{
Deprecation::notice('1.5.0', 'Use Versions() instead');
return $this->Versions($filter, $sort, $limit, $join, $having);
}

/**
* Compare two version, and return the diff between them.
*
Expand Down
4 changes: 3 additions & 1 deletion tests/php/ChangeSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ protected function tearDown(): void
protected function publishAllFixtures()
{
$this->logInWithPermission('ADMIN');
foreach ($this->fixtureFactory->getFixtures() as $class => $fixtures) {
/** @var FixtureTestState $state */
$state = static::$state->getStateByName('fixtures');
foreach ($state->getFixtureFactory(static::class)->getFixtures() as $class => $fixtures) {
foreach ($fixtures as $handle => $id) {
/** @var Versioned|DataObject $object */
$object = $this->objFromFixture($class, $handle);
Expand Down
5 changes: 4 additions & 1 deletion tests/php/VersionedOwnershipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\Dev\SapphireTest;
use DateTime;
use SilverStripe\Dev\State\FixtureTestState;

/**
* Tests ownership API of versioned DataObjects
Expand Down Expand Up @@ -46,7 +47,9 @@ protected function setUp(): void
Versioned::set_stage(Versioned::DRAFT);

// Automatically publish any object named *_published
foreach ($this->getFixtureFactory()->getFixtures() as $class => $fixtures) {
/** @var FixtureTestState $state */
$state = static::$state->getStateByName('fixtures');
foreach ($state->getFixtureFactory(static::class)->getFixtures() as $class => $fixtures) {
foreach ($fixtures as $name => $id) {
if (stripos($name ?? '', '_published') !== false) {
/** @var Versioned|DataObject $object */
Expand Down
22 changes: 11 additions & 11 deletions tests/php/VersionedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public function testPublishCreateNewVersion()
$page1->Content = 'orig';
$page1->write();
$firstVersion = $page1->Version;
$page1->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE, false);
$page1->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
$this->assertEquals(
$firstVersion,
$page1->Version,
Expand All @@ -306,7 +306,7 @@ public function testPublishCreateNewVersion()
$secondVersion = $page1->Version;
$this->assertTrue($firstVersion < $secondVersion, 'write creates new version');

$page1->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE, true);
$page1->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
/** @var VersionedTest\TestObject $thirdVersionObject */
$thirdVersionObject = Versioned::get_latest_version(VersionedTest\TestObject::class, $page1->ID);
$thirdVersion = $thirdVersionObject->Version;
Expand Down Expand Up @@ -896,10 +896,10 @@ public function testAllVersions()
public function testAllVersionsOnUnsavedRecord()
{
$newPage = new VersionedTest\Subclass();
$this->assertCount(0, $newPage->allVersions(), 'No versions on unsaved record');
$this->assertCount(0, $newPage->Versions(), 'No versions on unsaved record');

$singleton = VersionedTest\Subclass::singleton();
$this->assertCount(0, $singleton->allVersions(), 'No versions for singleton');
$this->assertCount(0, $singleton->Versions(), 'No versions for singleton');
}

public function testArchiveRelatedDataWithoutVersioned()
Expand Down 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->Versions();
$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->Versions()->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->Versions()->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->Versions()->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 4baa7b4

Please sign in to comment.