mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX Versioned->publish() with $createNewVersion=TRUE now increases version number of in-memory object (fixes #5261) (from r101739)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112030 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
7fc63deda0
commit
fd8e0044c4
@ -2115,7 +2115,9 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Roll the draft version of this page to match the published page
|
* Roll the draft version of this page to match the published page.
|
||||||
|
* Caution: Doesn't overwrite the object properties with the rolled back version.
|
||||||
|
*
|
||||||
* @param $version Either the string 'Live' or a version number
|
* @param $version Either the string 'Live' or a version number
|
||||||
*/
|
*/
|
||||||
function doRollbackTo($version) {
|
function doRollbackTo($version) {
|
||||||
|
@ -476,7 +476,12 @@ class Versioned extends DataObjectDecorator {
|
|||||||
$publisherID = isset(Member::currentUser()->ID) ? Member::currentUser()->ID : 0;
|
$publisherID = isset(Member::currentUser()->ID) ? Member::currentUser()->ID : 0;
|
||||||
if($from) {
|
if($from) {
|
||||||
$from->forceChange();
|
$from->forceChange();
|
||||||
if(!$createNewVersion) $from->migrateVersion($from->Version);
|
if($createNewVersion) {
|
||||||
|
$latest = self::get_latest_version($baseClass, $this->owner->ID);
|
||||||
|
$this->owner->Version = $latest->Version + 1;
|
||||||
|
} else {
|
||||||
|
$from->migrateVersion($from->Version);
|
||||||
|
}
|
||||||
|
|
||||||
// Mark this version as having been published at some stage
|
// Mark this version as having been published at some stage
|
||||||
DB::query("UPDATE \"{$extTable}_versions\" SET \"WasPublished\" = '1', \"PublisherID\" = $publisherID WHERE \"RecordID\" = $from->ID AND \"Version\" = $from->Version");
|
DB::query("UPDATE \"{$extTable}_versions\" SET \"WasPublished\" = '1', \"PublisherID\" = $publisherID WHERE \"RecordID\" = $from->ID AND \"Version\" = $from->Version");
|
||||||
|
@ -57,6 +57,40 @@ class VersionedTest extends SapphireTest {
|
|||||||
$this->assertType('Int', $obj2->dbObject('Version'));
|
$this->assertType('Int', $obj2->dbObject('Version'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testPublishCreateNewVersion() {
|
||||||
|
$page1 = $this->objFromFixture('Page', 'page1');
|
||||||
|
$page1->Content = 'orig';
|
||||||
|
$page1->write();
|
||||||
|
$oldVersion = $page1->Version;
|
||||||
|
$page1->publish('Stage', 'Live', false);
|
||||||
|
$this->assertEquals($oldVersion, $page1->Version, 'publish() with $createNewVersion=FALSE');
|
||||||
|
|
||||||
|
$page1->Content = 'changed';
|
||||||
|
$page1->write();
|
||||||
|
$oldVersion = $page1->Version;
|
||||||
|
$page1->publish('Stage', 'Live', true);
|
||||||
|
$this->assertTrue($oldVersion < $page1->Version, 'publish() with $createNewVersion=TRUE');
|
||||||
|
}
|
||||||
|
|
||||||
|
function testRollbackTo() {
|
||||||
|
$page1 = $this->objFromFixture('Page', 'page1');
|
||||||
|
$page1->Content = 'orig';
|
||||||
|
$page1->write();
|
||||||
|
$page1->publish('Stage', 'Live');
|
||||||
|
$origVersion = $page1->Version;
|
||||||
|
|
||||||
|
$page1->Content = 'changed';
|
||||||
|
$page1->write();
|
||||||
|
$page1->publish('Stage', 'Live');
|
||||||
|
$changedVersion = $page1->Version;
|
||||||
|
|
||||||
|
$page1->doRollbackTo($origVersion);
|
||||||
|
$page1 = Versioned::get_one_by_stage('Page', 'Stage', $page1->ID);
|
||||||
|
|
||||||
|
$this->assertTrue($page1->Version > $changedVersion, 'Create a new higher version number');
|
||||||
|
$this->assertEquals('orig', $page1->Content, 'Copies the content from the old version');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class VersionedTest_DataObject extends DataObject implements TestOnly {
|
class VersionedTest_DataObject extends DataObject implements TestOnly {
|
||||||
|
Loading…
Reference in New Issue
Block a user