mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
API Update Versioned methods
This commit is contained in:
parent
87ee4365e7
commit
3c2b53157e
@ -25,18 +25,22 @@ abstract class CMSBatchAction extends Object {
|
||||
/**
|
||||
* Run this action for the given set of pages.
|
||||
* Return a set of status-updated JavaScript to return to the CMS.
|
||||
*
|
||||
* @param SS_List $objs
|
||||
* @return string
|
||||
*/
|
||||
abstract public function run(SS_List $objs);
|
||||
|
||||
/**
|
||||
* Helper method for responding to a back action request
|
||||
* @param $successMessage string - The message to return as a notification.
|
||||
* @param string $successMessage The message to return as a notification.
|
||||
* Can have up to two %d's in it. The first will be replaced by the number of successful
|
||||
* changes, the second by the number of failures
|
||||
* @param $status array - A status array like batchactions builds. Should be
|
||||
* @param array $status A status array like batchactions builds. Should be
|
||||
* key => value pairs, the key can be any string: "error" indicates errors, anything
|
||||
* else indicates a type of success. The value is an array. We don't care what's in it,
|
||||
* we just use count($value) to find the number of items that succeeded or failed
|
||||
* @return string
|
||||
*/
|
||||
public function response($successMessage, $status) {
|
||||
$count = 0;
|
||||
@ -69,10 +73,12 @@ abstract class CMSBatchAction extends Object {
|
||||
* Helper method for processing batch actions.
|
||||
* Returns a set of status-updating JavaScript to return to the CMS.
|
||||
*
|
||||
* @param $objs The SS_List of objects to perform this batch action
|
||||
* @param SS_List $objs The SS_List of objects to perform this batch action
|
||||
* on.
|
||||
* @param $helperMethod The method to call on each of those objects.
|
||||
* @return JSON encoded map in the following format:
|
||||
* @param string $helperMethod The method to call on each of those objects.
|
||||
* @param string $successMessage
|
||||
* @param array $arguments
|
||||
* @return string JSON encoded map in the following format:
|
||||
* {
|
||||
* 'modified': {
|
||||
* 3: {'TreeTitle': 'Page3'},
|
||||
@ -117,10 +123,11 @@ abstract class CMSBatchAction extends Object {
|
||||
/**
|
||||
* Helper method for applicablePages() methods. Acts as a skeleton implementation.
|
||||
*
|
||||
* @param $ids The IDs passed to applicablePages
|
||||
* @param $methodName The canXXX() method to call on each page to check if the action is applicable
|
||||
* @param $checkStagePages Set to true if you want to check stage pages
|
||||
* @param $checkLivePages Set to true if you want to check live pages (e.g, for deleted-from-draft)
|
||||
* @param array $ids The IDs passed to applicablePages
|
||||
* @param string $methodName The canXXX() method to call on each page to check if the action is applicable
|
||||
* @param bool $checkStagePages Set to true if you want to check stage pages
|
||||
* @param bool $checkLivePages Set to true if you want to check live pages (e.g, for deleted-from-draft)
|
||||
* @return array
|
||||
*/
|
||||
public function applicablePagesHelper($ids, $methodName, $checkStagePages = true, $checkLivePages = true) {
|
||||
if(!is_array($ids)) user_error("Bad \$ids passed to applicablePagesHelper()", E_USER_WARNING);
|
||||
@ -141,7 +148,7 @@ abstract class CMSBatchAction extends Object {
|
||||
}
|
||||
$onlyOnLive = array_keys($onlyOnLive);
|
||||
|
||||
if($checkLivePages && $onlyOnLive && $managedClass::has_extension('Versioned')) {
|
||||
if($checkLivePages && $onlyOnLive && Object::has_extension($managedClass, 'Versioned')) {
|
||||
// Get the pages that only exist on live (deleted from stage)
|
||||
$livePages = Versioned::get_by_stage($managedClass, "Live")->byIDs($onlyOnLive);
|
||||
foreach($livePages as $obj) {
|
||||
|
@ -117,8 +117,14 @@ The usual call to `DataObject->write()` will write to whatever stage is currentl
|
||||
`<class>_versions` table. To avoid this, use [api:Versioned::writeWithoutVersion()] instead.
|
||||
|
||||
To move a saved version from one stage to another, call [writeToStage(<stage>)](api:Versioned->writeToStage()) on the
|
||||
object. The process of moving a version to a different stage is also called "publishing", so we've created a shortcut
|
||||
for this: `publish(<from-stage>, <to-stage>)`.
|
||||
object. The process of moving a version to a different stage is also called "publishing". This can be
|
||||
done via one of several ways:
|
||||
|
||||
* `copyVersionToStage` which will allow you to specify a source (which could be either a version
|
||||
number, or a stage), as well as a destination stage.
|
||||
* `publishSingle` Publishes this record to live from the draft.
|
||||
* `publishRecursive` Publishes this record, and any dependant objects this record may refer to.
|
||||
See "DataObject ownership" for reference on dependant objects.
|
||||
|
||||
:::php
|
||||
$record = Versioned::get_by_stage('MyRecord', 'Stage')->byID(99);
|
||||
@ -127,7 +133,7 @@ for this: `publish(<from-stage>, <to-stage>)`.
|
||||
// and write a row to `MyRecord_versions`.
|
||||
$record->write();
|
||||
// will copy the saved record information to the `MyRecord_Live` table
|
||||
$record->publish('Stage', 'Live');
|
||||
$record->publishRecursive();
|
||||
|
||||
Similarly, an "unpublish" operation does the reverse, and removes a record from a specific stage.
|
||||
|
||||
|
@ -112,7 +112,7 @@ end of each test.
|
||||
for($i=0; $i<100; $i++) {
|
||||
$page = new Page(array('Title' => "Page $i"));
|
||||
$page->write();
|
||||
$page->publish('Stage', 'Live');
|
||||
$page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
||||
}
|
||||
|
||||
// set custom configuration for the test.
|
||||
|
@ -275,7 +275,7 @@ publish a page, which requires a method call.
|
||||
$blueprint = Injector::inst()->create('FixtureBlueprint', 'Member');
|
||||
|
||||
$blueprint->addCallback('afterCreate', function($obj, $identifier, $data, $fixtures) {
|
||||
$obj->publish('Stage', 'Live');
|
||||
$obj->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
||||
});
|
||||
|
||||
$page = $factory->define('Page', $blueprint);
|
||||
|
@ -704,6 +704,17 @@ For instance:
|
||||
}
|
||||
|
||||
|
||||
Additionally, the following api methods have been added:
|
||||
|
||||
* `Versioned::publishRecursive` Publishes this object, and all owned objects
|
||||
* `Versioned::publishSingle` Publishes this object, but not owned objects
|
||||
* `Versioned::copyVersionToStage` Replaces the old `publish` method.
|
||||
|
||||
These methods are deprecated:
|
||||
|
||||
* `Versioned::publish` Replaced by `Versioned::copyVersionToStage`
|
||||
* `Versioned::doPublish` Replaced by `Versioned::publishRecursive`
|
||||
|
||||
### Implementation of ownership API
|
||||
|
||||
In order to support the recursive publishing of dataobjects, a new API has been developed to allow
|
||||
|
@ -757,7 +757,7 @@ class File extends DataObject implements ShortcodeHandler, AssetContainer {
|
||||
// Relies on Parent() returning the stage record
|
||||
$parent = $this->Parent();
|
||||
if($parent && $parent->exists()) {
|
||||
$parent->doPublish();
|
||||
$parent->publishRecursive();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,7 @@ class FileMigrationHelper extends Object {
|
||||
|
||||
// Save and publish
|
||||
$file->write();
|
||||
$file->doPublish();
|
||||
$file->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -260,7 +260,7 @@ class Folder extends File {
|
||||
|
||||
// No publishing UX for folders, so just cascade changes live
|
||||
if(Versioned::get_stage() === Versioned::DRAFT) {
|
||||
$this->publish(Versioned::DRAFT, Versioned::LIVE);
|
||||
$this->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
||||
}
|
||||
|
||||
// Update draft version of all child records
|
||||
|
@ -158,7 +158,7 @@ class ChangeSetItem extends DataObject {
|
||||
case static::CHANGE_CREATED: {
|
||||
// Non-recursive publish
|
||||
$object = $this->getObjectInStage(Versioned::DRAFT);
|
||||
$object->publish(Versioned::DRAFT, Versioned::LIVE);
|
||||
$object->publishSingle();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1444,11 +1444,43 @@ class Versioned extends DataExtension implements TemplateGlobalProvider {
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a simple doPublish action for Versioned dataobjects
|
||||
* @deprecated 4.0..5.0
|
||||
*/
|
||||
public function doPublish() {
|
||||
Deprecation::notice('5.0', 'Use publishRecursive instead');
|
||||
return $this->owner->publishRecursive();
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish this object and all owned objects to Live
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function publishRecursive() {
|
||||
$owner = $this->owner;
|
||||
if(!$owner->publishSingle()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Publish owned objects
|
||||
foreach ($owner->findOwned(false) as $object) {
|
||||
/** @var Versioned|DataObject $object */
|
||||
$object->publishRecursive();
|
||||
}
|
||||
|
||||
// Unlink any objects disowned as a result of this action
|
||||
// I.e. objects which aren't owned anymore by this record, but are by the old live record
|
||||
$owner->unlinkDisownedObjects(Versioned::DRAFT, Versioned::LIVE);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Publishes this object to Live, but doesn't publish owned objects.
|
||||
*
|
||||
* @return bool True if publish was successful
|
||||
*/
|
||||
public function doPublish() {
|
||||
public function publishSingle() {
|
||||
$owner = $this->owner;
|
||||
if(!$owner->canPublish()) {
|
||||
return false;
|
||||
@ -1456,28 +1488,11 @@ class Versioned extends DataExtension implements TemplateGlobalProvider {
|
||||
|
||||
$owner->invokeWithExtensions('onBeforePublish');
|
||||
$owner->write();
|
||||
$owner->publish(static::DRAFT, static::LIVE);
|
||||
$owner->copyVersionToStage(static::DRAFT, static::LIVE);
|
||||
$owner->invokeWithExtensions('onAfterPublish');
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger publishing of owned objects
|
||||
*/
|
||||
public function onAfterPublish() {
|
||||
$owner = $this->owner;
|
||||
|
||||
// Publish owned objects
|
||||
foreach ($owner->findOwned(false) as $object) {
|
||||
/** @var Versioned|DataObject $object */
|
||||
$object->doPublish();
|
||||
}
|
||||
|
||||
// Unlink any objects disowned as a result of this action
|
||||
// I.e. objects which aren't owned anymore by this record, but are by the old live record
|
||||
$owner->unlinkDisownedObjects(Versioned::DRAFT, Versioned::LIVE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set foreign keys of has_many objects to 0 where those objects were
|
||||
* disowned as a result of a partial publish / unpublish.
|
||||
@ -1628,7 +1643,7 @@ class Versioned extends DataExtension implements TemplateGlobalProvider {
|
||||
}
|
||||
|
||||
$owner->invokeWithExtensions('onBeforeRevertToLive');
|
||||
$owner->publish("Live", "Stage", false);
|
||||
$owner->copyVersionToStage(static::LIVE, static::DRAFT, false);
|
||||
$owner->invokeWithExtensions('onAfterRevertToLive');
|
||||
return true;
|
||||
}
|
||||
@ -1653,6 +1668,14 @@ class Versioned extends DataExtension implements TemplateGlobalProvider {
|
||||
$owner->unlinkDisownedObjects(Versioned::LIVE, Versioned::DRAFT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 4.0..5.0
|
||||
*/
|
||||
public function publish($fromStage, $toStage, $createNewVersion = false) {
|
||||
Deprecation::notice('5.0', 'Use copyVersionToStage instead');
|
||||
$this->owner->copyVersionToStage($fromStage, $toStage, $createNewVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move a database record from one stage to the other.
|
||||
*
|
||||
@ -1661,7 +1684,7 @@ class Versioned extends DataExtension implements TemplateGlobalProvider {
|
||||
* @param bool $createNewVersion Set this to true to create a new version number.
|
||||
* By default, the existing version number will be copied over.
|
||||
*/
|
||||
public function publish($fromStage, $toStage, $createNewVersion = false) {
|
||||
public function copyVersionToStage($fromStage, $toStage, $createNewVersion = false) {
|
||||
$owner = $this->owner;
|
||||
$owner->invokeWithExtensions('onBeforeVersionedPublish', $fromStage, $toStage, $createNewVersion);
|
||||
|
||||
@ -1787,7 +1810,7 @@ class Versioned extends DataExtension implements TemplateGlobalProvider {
|
||||
public function allVersions($filter = "", $sort = "", $limit = "", $join = "", $having = "") {
|
||||
// Make sure the table names are not postfixed (e.g. _Live)
|
||||
$oldMode = static::get_reading_mode();
|
||||
static::set_stage('Stage');
|
||||
static::set_stage(static::DRAFT);
|
||||
|
||||
$owner = $this->owner;
|
||||
$list = DataObject::get(get_class($owner), $filter, $sort, $join, $limit);
|
||||
@ -2047,7 +2070,7 @@ class Versioned extends DataExtension implements TemplateGlobalProvider {
|
||||
*/
|
||||
public static function get_versionnumber_by_stage($class, $stage, $id, $cache = true) {
|
||||
$baseClass = ClassInfo::baseDataClass($class);
|
||||
$stageTable = ($stage == 'Stage') ? $baseClass : "{$baseClass}_{$stage}";
|
||||
$stageTable = ($stage == static::DRAFT) ? $baseClass : "{$baseClass}_{$stage}";
|
||||
|
||||
// cached call
|
||||
if($cache && isset(self::$cache_versionnumber[$baseClass][$stage][$id])) {
|
||||
@ -2104,7 +2127,7 @@ class Versioned extends DataExtension implements TemplateGlobalProvider {
|
||||
}
|
||||
|
||||
$baseClass = ClassInfo::baseDataClass($class);
|
||||
$stageTable = ($stage == 'Stage') ? $baseClass : "{$baseClass}_{$stage}";
|
||||
$stageTable = ($stage == static::DRAFT) ? $baseClass : "{$baseClass}_{$stage}";
|
||||
|
||||
$versions = DB::prepared_query("SELECT \"ID\", \"Version\" FROM \"$stageTable\" $filter", $parameters)->map();
|
||||
|
||||
@ -2184,7 +2207,7 @@ class Versioned extends DataExtension implements TemplateGlobalProvider {
|
||||
public function doRollbackTo($version) {
|
||||
$owner = $this->owner;
|
||||
$owner->extend('onBeforeRollback', $version);
|
||||
$owner->publish($version, "Stage", true);
|
||||
$owner->copyVersionToStage($version, static::DRAFT, true);
|
||||
$owner->writeWithoutVersion();
|
||||
$owner->extend('onAfterRollback', $version);
|
||||
}
|
||||
|
@ -114,7 +114,8 @@ class VersionedGridFieldItemRequest extends GridFieldDetailForm_ItemRequest {
|
||||
* @return SS_HTTPResponse
|
||||
*/
|
||||
public function doPublish($data, $form) {
|
||||
$record = $this->getRecord();
|
||||
/** @var Versioned|DataObject $record */
|
||||
$record = $this->getRecord();
|
||||
$isNewRecord = $record->ID == 0;
|
||||
|
||||
// Check permission
|
||||
@ -126,7 +127,7 @@ class VersionedGridFieldItemRequest extends GridFieldDetailForm_ItemRequest {
|
||||
try {
|
||||
// Initial save and reload
|
||||
$record = $this->saveFormIntoRecord($data, $form);
|
||||
$record->doPublish();
|
||||
$record->publishRecursive();
|
||||
|
||||
} catch(ValidationException $e) {
|
||||
return $this->generateValidationResponse($form, $e);
|
||||
|
@ -26,7 +26,7 @@ class AssetControlExtensionTest extends SapphireTest {
|
||||
$object1->Header->setFromLocalFile($fish1, 'Header/MyObjectHeader.jpg');
|
||||
$object1->Download->setFromString('file content', 'Documents/File.txt');
|
||||
$object1->write();
|
||||
$object1->doPublish();
|
||||
$object1->publishSingle();
|
||||
|
||||
$object2 = new AssetControlExtensionTest_Object();
|
||||
$object2->Title = 'Unversioned';
|
||||
@ -37,7 +37,7 @@ class AssetControlExtensionTest extends SapphireTest {
|
||||
$object3->Title = 'Archived';
|
||||
$object3->Header->setFromLocalFile($fish1, 'Archived/MyObjectHeader.jpg');
|
||||
$object3->write();
|
||||
$object3->doPublish();
|
||||
$object3->publishSingle();
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
@ -170,8 +170,8 @@ class AssetControlExtensionTest extends SapphireTest {
|
||||
$this->assertEquals(AssetStore::VISIBILITY_PROTECTED, $object3->Header->getVisibility());
|
||||
|
||||
// Publish changes to versioned records
|
||||
$object1->doPublish();
|
||||
$object3->doPublish();
|
||||
$object1->publishSingle();
|
||||
$object3->publishSingle();
|
||||
|
||||
// After publishing, old object1 is deleted, but since object3 has archiving enabled,
|
||||
// the orphaned file is intentionally left in the protected store
|
||||
|
@ -50,7 +50,7 @@ class FileTest extends SapphireTest {
|
||||
'ErrorCode' => 404
|
||||
));
|
||||
$page->write();
|
||||
$page->publish('Stage', 'Live');
|
||||
$page->copyVersionToStage('Stage', 'Live');
|
||||
}
|
||||
}
|
||||
|
||||
@ -234,9 +234,10 @@ class FileTest extends SapphireTest {
|
||||
}
|
||||
|
||||
public function testSetNameChangesFilesystemOnWrite() {
|
||||
/** @var File $file */
|
||||
$file = $this->objFromFixture('File', 'asdf');
|
||||
$this->logInWithPermission('ADMIN');
|
||||
$file->doPublish();
|
||||
$file->publishRecursive();
|
||||
$oldTuple = $file->File->getValue();
|
||||
|
||||
// Rename
|
||||
@ -266,7 +267,7 @@ class FileTest extends SapphireTest {
|
||||
);
|
||||
|
||||
// After publish
|
||||
$file->doPublish();
|
||||
$file->publishRecursive();
|
||||
$this->assertFalse(
|
||||
$this->getAssetStore()->exists($oldTuple['Filename'], $oldTuple['Hash']),
|
||||
'Old file is finally removed after publishing new file'
|
||||
@ -280,7 +281,7 @@ class FileTest extends SapphireTest {
|
||||
public function testSetParentIDChangesFilesystemOnWrite() {
|
||||
$file = $this->objFromFixture('File', 'asdf');
|
||||
$this->logInWithPermission('ADMIN');
|
||||
$file->doPublish();
|
||||
$file->publishRecursive();
|
||||
$subfolder = $this->objFromFixture('Folder', 'subfolder');
|
||||
$oldTuple = $file->File->getValue();
|
||||
|
||||
@ -312,7 +313,7 @@ class FileTest extends SapphireTest {
|
||||
);
|
||||
|
||||
// After publish
|
||||
$file->doPublish();
|
||||
$file->publishSingle();
|
||||
$this->assertFalse(
|
||||
$this->getAssetStore()->exists($oldTuple['Filename'], $oldTuple['Hash']),
|
||||
'Old file is finally removed after publishing new file'
|
||||
@ -408,9 +409,10 @@ class FileTest extends SapphireTest {
|
||||
}
|
||||
|
||||
public function testDeleteFile() {
|
||||
/** @var File $file */
|
||||
$file = $this->objFromFixture('File', 'asdf');
|
||||
$this->logInWithPermission('ADMIN');
|
||||
$file->doPublish();
|
||||
$file->publishSingle();
|
||||
$tuple = $file->File->getValue();
|
||||
|
||||
// Before delete
|
||||
|
@ -111,14 +111,16 @@ class FolderTest extends SapphireTest {
|
||||
$folder2 = $this->objFromFixture('Folder', 'folder2');
|
||||
|
||||
// Publish file1
|
||||
/** @var File $file1 */
|
||||
$file1 = DataObject::get_by_id('File', $this->idFromFixture('File', 'file1-folder1'), false);
|
||||
$file1->doPublish();
|
||||
$file1->publishRecursive();
|
||||
|
||||
// set ParentID. This should cause updateFilesystem to be called on all children
|
||||
$folder1->ParentID = $folder2->ID;
|
||||
$folder1->write();
|
||||
|
||||
// Check if the file in the folder moved along
|
||||
/** @var File $file1Draft */
|
||||
$file1Draft = Versioned::get_by_stage('File', Versioned::DRAFT)->byID($file1->ID);
|
||||
$this->assertFileExists(AssetStoreTest_SpyStore::getLocalPath($file1Draft));
|
||||
|
||||
@ -135,6 +137,7 @@ class FolderTest extends SapphireTest {
|
||||
);
|
||||
|
||||
// Published (live) version remains in the old location
|
||||
/** @var File $file1Live */
|
||||
$file1Live = Versioned::get_by_stage('File', Versioned::LIVE)->byID($file1->ID);
|
||||
$this->assertEquals(
|
||||
ASSETS_PATH . '/FolderTest/FileTest-folder1/55b443b601/File1.txt',
|
||||
@ -142,7 +145,7 @@ class FolderTest extends SapphireTest {
|
||||
);
|
||||
|
||||
// Publishing the draft to live should move the new file to the public store
|
||||
$file1Draft->doPublish();
|
||||
$file1Draft->publishRecursive();
|
||||
$this->assertEquals(
|
||||
ASSETS_PATH . '/FolderTest/FileTest-folder2/FileTest-folder1/55b443b601/File1.txt',
|
||||
AssetStoreTest_SpyStore::getLocalPath($file1Draft)
|
||||
|
@ -36,7 +36,7 @@ class ChangeSetItemTest extends SapphireTest {
|
||||
'New objects that aren\'t yet published should return created'
|
||||
);
|
||||
|
||||
$object->doPublish();
|
||||
$object->publishRecursive();
|
||||
|
||||
$this->assertEquals(
|
||||
ChangeSetItem::CHANGE_NONE, $item->ChangeType,
|
||||
@ -51,7 +51,7 @@ class ChangeSetItemTest extends SapphireTest {
|
||||
'Object that have unpublished changes written to draft should show as modified'
|
||||
);
|
||||
|
||||
$object->doPublish();
|
||||
$object->publishRecursive();
|
||||
|
||||
$this->assertEquals(
|
||||
ChangeSetItem::CHANGE_NONE, $item->ChangeType,
|
||||
|
@ -118,7 +118,9 @@ class ChangeSetTest extends SapphireTest {
|
||||
$this->logInWithPermission('ADMIN');
|
||||
foreach($this->fixtureFactory->getFixtures() as $class => $fixtures) {
|
||||
foreach ($fixtures as $handle => $id) {
|
||||
$this->objFromFixture($class, $handle)->doPublish();
|
||||
/** @var Versioned|DataObject $object */
|
||||
$object = $this->objFromFixture($class, $handle);
|
||||
$object->publishSingle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -93,7 +93,9 @@ class DataDifferencerTest extends SapphireTest {
|
||||
*/
|
||||
class DataDifferencerTest_Object extends DataObject implements TestOnly {
|
||||
|
||||
private static $extensions = array('Versioned("Stage", "Live")');
|
||||
private static $extensions = array(
|
||||
'Versioned'
|
||||
);
|
||||
|
||||
private static $db = array(
|
||||
'Choices' => "Varchar",
|
||||
|
@ -337,7 +337,7 @@ class DataObjectLazyLoadingTest extends SapphireTest {
|
||||
$obj1->PageName = "old-value";
|
||||
$obj1->ExtraField = "old-value";
|
||||
$obj1ID = $obj1->write();
|
||||
$obj1->publish('Stage', 'Live');
|
||||
$obj1->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
||||
|
||||
$obj1 = VersionedLazySub_DataObject::get()->byID($obj1ID);
|
||||
$this->assertEquals(
|
||||
|
@ -149,10 +149,10 @@ class HierarchyTest extends SapphireTest {
|
||||
$obj2b = $this->objFromFixture('HierarchyTest_Object', 'obj2b');
|
||||
|
||||
// Get a published set of objects for our fixture
|
||||
$obj1->publish("Stage", "Live");
|
||||
$obj2->publish("Stage", "Live");
|
||||
$obj2a->publish("Stage", "Live");
|
||||
$obj2b->publish("Stage", "Live");
|
||||
$obj1->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
||||
$obj2->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
||||
$obj2a->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
||||
$obj2b->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
||||
|
||||
// Then delete 2a from stage and move 2b to a sub-node of 1.
|
||||
$obj2a->delete();
|
||||
@ -536,7 +536,7 @@ class HierarchyTest_Object extends DataObject implements TestOnly {
|
||||
|
||||
private static $extensions = array(
|
||||
'Hierarchy',
|
||||
"Versioned('Stage', 'Live')",
|
||||
'Versioned',
|
||||
);
|
||||
|
||||
public function cmstreeclasses() {
|
||||
|
@ -30,7 +30,7 @@ class VersionedOwnershipTest extends SapphireTest {
|
||||
if(stripos($name, '_published') !== false) {
|
||||
/** @var Versioned|DataObject $object */
|
||||
$object = DataObject::get($class)->byID($id);
|
||||
$object->publish(Versioned::DRAFT, Versioned::LIVE);
|
||||
$object->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -277,7 +277,7 @@ class VersionedOwnershipTest extends SapphireTest {
|
||||
$this->assertDOSEquals($oldLiveBanners, $parentLive->Banners());
|
||||
|
||||
// On publishing of owner, all children should now be updated
|
||||
$parent->doPublish();
|
||||
$parent->publishRecursive();
|
||||
|
||||
// Now check each object has the correct state
|
||||
$parentDraft = Versioned::get_by_stage('VersionedOwnershipTest_Subclass', Versioned::DRAFT)
|
||||
@ -325,7 +325,7 @@ class VersionedOwnershipTest extends SapphireTest {
|
||||
|
||||
// Second test: multi-level unpublish should recursively cascade down all owning objects
|
||||
// Publish related2 again
|
||||
$subclass2->doPublish();
|
||||
$subclass2->publishRecursive();
|
||||
$this->assertTrue($subclass2->isPublished());
|
||||
$this->assertTrue($related2->isPublished());
|
||||
$this->assertTrue($attachment3->isPublished());
|
||||
|
@ -65,11 +65,11 @@ class VersionedTest extends SapphireTest {
|
||||
$obj = new VersionedTest_Subclass();
|
||||
$obj->ExtraField = 'Foo'; // ensure that child version table gets written
|
||||
$obj->write();
|
||||
$obj->publish('Stage', 'Live');
|
||||
$obj->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
||||
|
||||
$obj->ExtraField = 'Bar'; // ensure that child version table gets written
|
||||
$obj->write();
|
||||
$obj->publish('Stage', 'Live');
|
||||
$obj->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
||||
|
||||
$versions = DB::query("SELECT COUNT(*) FROM \"VersionedTest_Subclass_versions\""
|
||||
. " WHERE \"RecordID\" = '$obj->ID'")->value();
|
||||
@ -92,7 +92,7 @@ class VersionedTest extends SapphireTest {
|
||||
|
||||
// test that it doesn't delete records that we need
|
||||
$obj->write();
|
||||
$obj->publish('Stage', 'Live');
|
||||
$obj->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
||||
|
||||
$count = DB::query("SELECT COUNT(*) FROM \"VersionedTest_Subclass_versions\""
|
||||
. " WHERE \"RecordID\" = '$obj->ID'")->value();
|
||||
@ -117,14 +117,14 @@ class VersionedTest extends SapphireTest {
|
||||
);
|
||||
|
||||
// Fail publishing from live to stage
|
||||
$obj->publish('Live', 'Stage');
|
||||
$obj->copyVersionToStage(Versioned::LIVE, Versioned::DRAFT);
|
||||
}
|
||||
|
||||
public function testDuplicate() {
|
||||
$obj1 = new VersionedTest_Subclass();
|
||||
$obj1->ExtraField = 'Foo';
|
||||
$obj1->write(); // version 1
|
||||
$obj1->publish('Stage', 'Live');
|
||||
$obj1->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
||||
$obj1->ExtraField = 'Foo2';
|
||||
$obj1->write(); // version 2
|
||||
|
||||
@ -217,7 +217,7 @@ class VersionedTest extends SapphireTest {
|
||||
$page1->Content = 'orig';
|
||||
$page1->write();
|
||||
$firstVersion = $page1->Version;
|
||||
$page1->publish('Stage', 'Live', false);
|
||||
$page1->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE, false);
|
||||
$this->assertEquals(
|
||||
$firstVersion,
|
||||
$page1->Version,
|
||||
@ -229,7 +229,7 @@ class VersionedTest extends SapphireTest {
|
||||
$secondVersion = $page1->Version;
|
||||
$this->assertTrue($firstVersion < $secondVersion, 'write creates new version');
|
||||
|
||||
$page1->publish('Stage', 'Live', true);
|
||||
$page1->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE, true);
|
||||
$thirdVersion = Versioned::get_latest_version('VersionedTest_DataObject', $page1->ID)->Version;
|
||||
$liveVersion = Versioned::get_versionnumber_by_stage('VersionedTest_DataObject', 'Live', $page1->ID);
|
||||
$stageVersion = Versioned::get_versionnumber_by_stage('VersionedTest_DataObject', 'Stage', $page1->ID);
|
||||
@ -253,12 +253,12 @@ class VersionedTest extends SapphireTest {
|
||||
$page1 = $this->objFromFixture('VersionedTest_AnotherSubclass', 'subclass1');
|
||||
$page1->Content = 'orig';
|
||||
$page1->write();
|
||||
$page1->publish('Stage', 'Live');
|
||||
$page1->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
||||
$origVersion = $page1->Version;
|
||||
|
||||
$page1->Content = 'changed';
|
||||
$page1->write();
|
||||
$page1->publish('Stage', 'Live');
|
||||
$page1->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
||||
$changedVersion = $page1->Version;
|
||||
|
||||
$page1->doRollbackTo($origVersion);
|
||||
@ -287,7 +287,7 @@ class VersionedTest extends SapphireTest {
|
||||
|
||||
$page1->Content = 'orig';
|
||||
$page1->write();
|
||||
$page1->publish('Stage', 'Live');
|
||||
$page1->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
||||
|
||||
$this->assertEquals(1,
|
||||
DB::query('SELECT COUNT(*) FROM "VersionedTest_DataObject" WHERE "ID" = '.$pageID)->value());
|
||||
@ -842,7 +842,7 @@ class VersionedTest extends SapphireTest {
|
||||
$record->ExtraField = "Test A";
|
||||
$record->writeToStage("Stage");
|
||||
$this->assertRecordHasLatestVersion($record, 1);
|
||||
$record->publish("Stage", "Live");
|
||||
$record->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
||||
$this->assertRecordHasLatestVersion($record, 1);
|
||||
$record->Title = "Test A2";
|
||||
$record->ExtraField = "Test A2";
|
||||
@ -854,7 +854,7 @@ class VersionedTest extends SapphireTest {
|
||||
$record->ExtraField = "Test B";
|
||||
$record->writeToStage("Stage");
|
||||
$this->assertRecordHasLatestVersion($record, 1);
|
||||
$record->publish("Stage", "Live");
|
||||
$record->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
||||
$this->assertRecordHasLatestVersion($record, 1);
|
||||
$record->ExtraField = "Test B2";
|
||||
$record->writeToStage("Stage");
|
||||
@ -865,7 +865,7 @@ class VersionedTest extends SapphireTest {
|
||||
$record->Title = "Test C";
|
||||
$record->writeToStage("Stage");
|
||||
$this->assertRecordHasLatestVersion($record, 1);
|
||||
$record->publish("Stage", "Live");
|
||||
$record->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
||||
$this->assertRecordHasLatestVersion($record, 1);
|
||||
$record->Title = "Test C2";
|
||||
$record->writeToStage("Stage");
|
||||
@ -877,7 +877,7 @@ class VersionedTest extends SapphireTest {
|
||||
$record->AnotherField = "Test A";
|
||||
$record->writeToStage("Stage");
|
||||
$this->assertRecordHasLatestVersion($record, 1);
|
||||
$record->publish("Stage", "Live");
|
||||
$record->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
||||
$this->assertRecordHasLatestVersion($record, 1);
|
||||
$record->Title = "Test A2";
|
||||
$record->AnotherField = "Test A2";
|
||||
@ -890,7 +890,7 @@ class VersionedTest extends SapphireTest {
|
||||
$record->AnotherField = "Test B";
|
||||
$record->writeToStage("Stage");
|
||||
$this->assertRecordHasLatestVersion($record, 1);
|
||||
$record->publish("Stage", "Live");
|
||||
$record->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
||||
$this->assertRecordHasLatestVersion($record, 1);
|
||||
$record->AnotherField = "Test B2";
|
||||
$record->writeToStage("Stage");
|
||||
@ -901,7 +901,7 @@ class VersionedTest extends SapphireTest {
|
||||
$record->Title = "Test C";
|
||||
$record->writeToStage("Stage");
|
||||
$this->assertRecordHasLatestVersion($record, 1);
|
||||
$record->publish("Stage", "Live");
|
||||
$record->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
||||
$this->assertRecordHasLatestVersion($record, 1);
|
||||
$record->Title = "Test C2";
|
||||
$record->writeToStage("Stage");
|
||||
@ -915,7 +915,7 @@ class VersionedTest extends SapphireTest {
|
||||
"NewField" => "Varchar",
|
||||
));
|
||||
|
||||
VersionedTest_RelatedWithoutVersion::add_extension("Versioned('Stage', 'Live')");
|
||||
VersionedTest_RelatedWithoutVersion::add_extension("Versioned");
|
||||
$this->resetDBSchema(true);
|
||||
$testData = new VersionedTest_RelatedWithoutVersion();
|
||||
$testData->NewField = 'Test';
|
||||
@ -945,7 +945,7 @@ class VersionedTest extends SapphireTest {
|
||||
$this->assertFalse($private->canView());
|
||||
|
||||
// Writing the private page to live should be fine though
|
||||
$private->publish("Stage", "Live");
|
||||
$private->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
||||
$privateLive = Versioned::get_one_by_stage('VersionedTest_DataObject', 'Live', array('"ID"' => $privateID));
|
||||
$this->assertTrue($private->canView());
|
||||
$this->assertTrue($privateLive->canView());
|
||||
@ -984,8 +984,8 @@ class VersionedTest extends SapphireTest {
|
||||
$this->assertFalse($private->canViewStage('Live'));
|
||||
|
||||
// Writing records to live should make both stage and live modes viewable
|
||||
$private->publish("Stage", "Live");
|
||||
$public->publish("Stage", "Live");
|
||||
$private->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
||||
$public->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE);
|
||||
$this->assertTrue($public->canViewStage('Stage'));
|
||||
$this->assertTrue($private->canViewStage('Stage'));
|
||||
$this->assertTrue($public->canViewStage('Live'));
|
||||
@ -1012,6 +1012,7 @@ class VersionedTest extends SapphireTest {
|
||||
*
|
||||
* @package framework
|
||||
* @subpackage tests
|
||||
* @mixin Versioned
|
||||
*/
|
||||
class VersionedTest_DataObject extends DataObject implements TestOnly {
|
||||
private static $db = array(
|
||||
@ -1021,7 +1022,7 @@ class VersionedTest_DataObject extends DataObject implements TestOnly {
|
||||
);
|
||||
|
||||
private static $extensions = array(
|
||||
"Versioned('Stage', 'Live')",
|
||||
"Versioned",
|
||||
);
|
||||
|
||||
private static $has_one = array(
|
||||
@ -1046,6 +1047,9 @@ class VersionedTest_DataObject extends DataObject implements TestOnly {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @mixin Versioned
|
||||
*/
|
||||
class VersionedTest_WithIndexes extends DataObject implements TestOnly {
|
||||
|
||||
private static $db = array(
|
||||
@ -1106,6 +1110,9 @@ class VersionedTest_UnversionedWithField extends DataObject implements TestOnly
|
||||
private static $db = array('Version' => 'Varchar(255)');
|
||||
}
|
||||
|
||||
/**
|
||||
* @mixin Versioned
|
||||
*/
|
||||
class VersionedTest_SingleStage extends DataObject implements TestOnly {
|
||||
private static $db = array(
|
||||
'Name' => 'Varchar'
|
||||
@ -1118,6 +1125,8 @@ class VersionedTest_SingleStage extends DataObject implements TestOnly {
|
||||
|
||||
/**
|
||||
* Versioned dataobject with public stage mode
|
||||
*
|
||||
* @mixin Versioned
|
||||
*/
|
||||
class VersionedTest_PublicStage extends DataObject implements TestOnly {
|
||||
private static $db = array(
|
||||
@ -1144,6 +1153,9 @@ class VersionedTest_PublicStage extends DataObject implements TestOnly {
|
||||
|
||||
/**
|
||||
* Public access is provided via extension rather than overriding canViewVersioned
|
||||
*
|
||||
* @mixin Versioned
|
||||
* @mixin VersionedTest_PublicExtension
|
||||
*/
|
||||
class VersionedTest_PublicViaExtension extends DataObject implements TestOnly {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user