mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
Merge pull request #1637 from open-sausages/pulls/4.0/add-status-flag
API Cleaned up versioned status checks
This commit is contained in:
commit
1e898782c6
@ -664,7 +664,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
||||
$actions = $form->Actions();
|
||||
|
||||
if($record) {
|
||||
$deletedFromStage = $record->getIsDeletedFromStage();
|
||||
$deletedFromStage = !$record->isOnDraft();
|
||||
|
||||
$fields->push($idField = new HiddenField("ID", false, $id));
|
||||
// Necessary for different subsites
|
||||
|
@ -44,7 +44,7 @@ class CMSSiteTreeFilter_PublishedPages extends CMSSiteTreeFilter
|
||||
$pages = Versioned::get_including_deleted('SilverStripe\\CMS\\Model\\SiteTree');
|
||||
$pages = $this->applyDefaultFilters($pages);
|
||||
$pages = $pages->filterByCallback(function (SiteTree $page) {
|
||||
return $page->getExistsOnLive();
|
||||
return $page->isPublished();
|
||||
});
|
||||
return $pages;
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ class CMSSiteTreeFilter_StatusDeletedPages extends CMSSiteTreeFilter
|
||||
|
||||
$pages = $pages->filterByCallback(function (SiteTree $page) {
|
||||
// Doesn't exist on either stage or live
|
||||
return $page->getIsDeletedFromStage() && !$page->getExistsOnLive();
|
||||
return $page->isArchived();
|
||||
});
|
||||
return $pages;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ class CMSSiteTreeFilter_StatusDraftPages extends CMSSiteTreeFilter
|
||||
$pages = $this->applyDefaultFilters($pages);
|
||||
$pages = $pages->filterByCallback(function (SiteTree $page) {
|
||||
// If page exists on stage but not on live
|
||||
return (!$page->getIsDeletedFromStage() && $page->getIsAddedToStage());
|
||||
return $page->isOnDraftOnly();
|
||||
});
|
||||
return $pages;
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ class CMSSiteTreeFilter_StatusRemovedFromDraftPages extends CMSSiteTreeFilter
|
||||
$pages = $this->applyDefaultFilters($pages);
|
||||
$pages = $pages->filterByCallback(function (SiteTree $page) {
|
||||
// If page is removed from stage but not live
|
||||
return $page->getIsDeletedFromStage() && $page->getExistsOnLive();
|
||||
return $page->isOnLiveOnly();
|
||||
});
|
||||
return $pages;
|
||||
}
|
||||
|
@ -530,7 +530,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
if($this->ParentID && self::config()->nested_urls) {
|
||||
$parent = $this->Parent();
|
||||
// If page is removed select parent from version history (for archive page view)
|
||||
if((!$parent || !$parent->exists()) && $this->getIsDeletedFromStage()) {
|
||||
if((!$parent || !$parent->exists()) && !$this->isOnDraft()) {
|
||||
$parent = Versioned::get_latest_version(self::class, $this->ParentID);
|
||||
}
|
||||
$base = $parent->RelativeLink($this->URLSegment);
|
||||
@ -891,7 +891,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
*/
|
||||
public function canAddChildren($member = null) {
|
||||
// Disable adding children to archived pages
|
||||
if($this->getIsDeletedFromStage()) {
|
||||
if(!$this->isOnDraft()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2259,7 +2259,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
return $actions;
|
||||
}
|
||||
|
||||
if($this->isPublished() && $this->canPublish() && !$this->getIsDeletedFromStage() && $this->canUnpublish()) {
|
||||
if($this->isPublished() && $this->canPublish() && $this->isOnDraft() && $this->canUnpublish()) {
|
||||
// "unpublish"
|
||||
$moreOptions->push(
|
||||
FormAction::create('unpublish', _t('SiteTree.BUTTONUNPUBLISH', 'Unpublish'), 'delete')
|
||||
@ -2268,8 +2268,8 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
);
|
||||
}
|
||||
|
||||
if($this->stagesDiffer(Versioned::DRAFT, Versioned::LIVE) && !$this->getIsDeletedFromStage()) {
|
||||
if($this->isPublished() && $this->canEdit()) {
|
||||
if($this->stagesDiffer(Versioned::DRAFT, Versioned::LIVE) && $this->isOnDraft()) {
|
||||
if($this->isPublished() && $this->canEdit()) {
|
||||
// "rollback"
|
||||
$moreOptions->push(
|
||||
FormAction::create('rollback', _t('SiteTree.BUTTONCANCELDRAFT', 'Cancel draft changes'), 'delete')
|
||||
@ -2279,7 +2279,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
}
|
||||
|
||||
if($this->canEdit()) {
|
||||
if($this->getIsDeletedFromStage()) {
|
||||
if(!$this->isOnDraft()) {
|
||||
// The usual major actions are not available, so we provide alternatives here.
|
||||
if($existsOnLive) {
|
||||
// "restore"
|
||||
@ -2339,7 +2339,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
}
|
||||
}
|
||||
|
||||
if($this->canPublish() && !$this->getIsDeletedFromStage()) {
|
||||
if($this->canPublish() && $this->isOnDraft()) {
|
||||
// "publish", as with "save", it supports an alternate state to show when action is needed.
|
||||
$majorActions->push(
|
||||
$publish = FormAction::create('publish', _t('SiteTree.BUTTONPUBLISHED', 'Published'))
|
||||
@ -2394,8 +2394,9 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
*/
|
||||
protected function isParentArchived() {
|
||||
if($parentID = $this->ParentID) {
|
||||
$parentPage = Versioned::get_latest_version("SilverStripe\\CMS\\Model\\SiteTree", $parentID);
|
||||
if(!$parentPage || $parentPage->IsDeletedFromStage) {
|
||||
/** @var SiteTree $parentPage */
|
||||
$parentPage = Versioned::get_latest_version(self::class, $parentID);
|
||||
if(!$parentPage || !$parentPage->isOnDraft()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -2614,24 +2615,22 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
public function getStatusFlags($cached = true) {
|
||||
if(!$this->_cache_statusFlags || !$cached) {
|
||||
$flags = array();
|
||||
if($this->getIsDeletedFromStage()) {
|
||||
if($this->isPublished()) {
|
||||
$flags['removedfromdraft'] = array(
|
||||
'text' => _t('SiteTree.REMOVEDFROMDRAFTSHORT', 'Removed from draft'),
|
||||
'title' => _t('SiteTree.REMOVEDFROMDRAFTHELP', 'Page is published, but has been deleted from draft'),
|
||||
);
|
||||
} else {
|
||||
$flags['archived'] = array(
|
||||
'text' => _t('SiteTree.ARCHIVEDPAGESHORT', 'Archived'),
|
||||
'title' => _t('SiteTree.ARCHIVEDPAGEHELP', 'Page is removed from draft and live'),
|
||||
);
|
||||
}
|
||||
} else if($this->getIsAddedToStage()) {
|
||||
if($this->isOnLiveOnly()) {
|
||||
$flags['removedfromdraft'] = array(
|
||||
'text' => _t('SiteTree.ONLIVEONLYSHORT', 'On live only'),
|
||||
'title' => _t('SiteTree.ONLIVEONLYSHORTHELP', 'Page is published, but has been deleted from draft'),
|
||||
);
|
||||
} elseif ($this->isArchived()) {
|
||||
$flags['archived'] = array(
|
||||
'text' => _t('SiteTree.ARCHIVEDPAGESHORT', 'Archived'),
|
||||
'title' => _t('SiteTree.ARCHIVEDPAGEHELP', 'Page is removed from draft and live'),
|
||||
);
|
||||
} else if($this->isOnDraftOnly()) {
|
||||
$flags['addedtodraft'] = array(
|
||||
'text' => _t('SiteTree.ADDEDTODRAFTSHORT', 'Draft'),
|
||||
'title' => _t('SiteTree.ADDEDTODRAFTHELP', "Page has not been published yet")
|
||||
);
|
||||
} else if($this->getIsModifiedOnStage()) {
|
||||
} else if($this->isModifiedOnDraft()) {
|
||||
$flags['modified'] = array(
|
||||
'text' => _t('SiteTree.MODIFIEDONDRAFTSHORT', 'Modified'),
|
||||
'title' => _t('SiteTree.MODIFIEDONDRAFTHELP', 'Page has unpublished changes'),
|
||||
@ -2777,66 +2776,6 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
return $classes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares current draft with live version, and returns true if no draft version of this page exists but the page
|
||||
* is still published (eg, after triggering "Delete from draft site" in the CMS).
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getIsDeletedFromStage() {
|
||||
if(!$this->ID) return true;
|
||||
if($this->isNew()) return false;
|
||||
|
||||
$stageVersion = Versioned::get_versionnumber_by_stage('SilverStripe\\CMS\\Model\\SiteTree', Versioned::DRAFT, $this->ID);
|
||||
|
||||
// Return true for both completely deleted pages and for pages just deleted from stage
|
||||
return !($stageVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if this page exists on the live site
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getExistsOnLive() {
|
||||
return $this->isPublished();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares current draft with live version, and returns true if these versions differ, meaning there have been
|
||||
* unpublished changes to the draft site.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getIsModifiedOnStage() {
|
||||
// New unsaved pages could be never be published
|
||||
if($this->isNew()) return false;
|
||||
|
||||
$stageVersion = Versioned::get_versionnumber_by_stage('SilverStripe\\CMS\\Model\\SiteTree', 'Stage', $this->ID);
|
||||
$liveVersion = Versioned::get_versionnumber_by_stage('SilverStripe\\CMS\\Model\\SiteTree', 'Live', $this->ID);
|
||||
|
||||
$isModified = ($stageVersion && $stageVersion != $liveVersion);
|
||||
$this->extend('getIsModifiedOnStage', $isModified);
|
||||
|
||||
return $isModified;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares current draft with live version, and returns true if no live version exists, meaning the page was never
|
||||
* published.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getIsAddedToStage() {
|
||||
// New unsaved pages could be never be published
|
||||
if($this->isNew()) return false;
|
||||
|
||||
$stageVersion = Versioned::get_versionnumber_by_stage('SilverStripe\\CMS\\Model\\SiteTree', 'Stage', $this->ID);
|
||||
$liveVersion = Versioned::get_versionnumber_by_stage('SilverStripe\\CMS\\Model\\SiteTree', 'Live', $this->ID);
|
||||
|
||||
return ($stageVersion && !$liveVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops extendCMSFields() being called on getCMSFields(). This is useful when you need access to fields added by
|
||||
* subclasses of SiteTree in a extension. Call before calling parent::getCMSFields(), and reenable afterwards.
|
||||
|
@ -153,21 +153,18 @@ class FileLinkTrackingTest extends SapphireTest {
|
||||
|
||||
public function testLinkRewritingOnAPublishedPageDoesntMakeItEditedOnDraft() {
|
||||
// Publish the source page
|
||||
/** @var Page $page */
|
||||
$page = $this->objFromFixture('Page', 'page1');
|
||||
$this->assertTrue($page->publishRecursive());
|
||||
$this->assertFalse($page->getIsModifiedOnStage());
|
||||
$this->assertFalse($page->isModifiedOnDraft());
|
||||
|
||||
// Rename the file
|
||||
$file = $this->objFromFixture('SilverStripe\\Assets\\Image', 'file1');
|
||||
$file->Name = 'renamed-test-file.jpg';
|
||||
$file->write();
|
||||
|
||||
// Caching hack
|
||||
Versioned::prepopulate_versionnumber_cache('SilverStripe\\CMS\\Model\\SiteTree', 'Stage', array($page->ID));
|
||||
Versioned::prepopulate_versionnumber_cache('SilverStripe\\CMS\\Model\\SiteTree', 'Live', array($page->ID));
|
||||
|
||||
// Confirm that the page hasn't gone green.
|
||||
$this->assertFalse($page->getIsModifiedOnStage());
|
||||
$this->assertFalse($page->isModifiedOnDraft());
|
||||
}
|
||||
|
||||
public function testTwoFileRenamesInARowWork() {
|
||||
|
@ -219,37 +219,57 @@ class SiteTreeTest extends SapphireTest {
|
||||
// newly created page
|
||||
$createdPage = new SiteTree();
|
||||
$createdPage->write();
|
||||
$this->assertFalse($createdPage->getIsDeletedFromStage());
|
||||
$this->assertTrue($createdPage->getIsAddedToStage());
|
||||
$this->assertTrue($createdPage->getIsModifiedOnStage());
|
||||
$this->assertTrue($createdPage->isOnDraft());
|
||||
$this->assertFalse($createdPage->isPublished());
|
||||
$this->assertTrue($createdPage->isOnDraftOnly());
|
||||
$this->assertTrue($createdPage->isModifiedOnDraft());
|
||||
|
||||
// published page
|
||||
$publishedPage = new SiteTree();
|
||||
$publishedPage->write();
|
||||
$publishedPage->copyVersionToStage('Stage','Live');
|
||||
$this->assertFalse($publishedPage->getIsDeletedFromStage());
|
||||
$this->assertFalse($publishedPage->getIsAddedToStage());
|
||||
$this->assertFalse($publishedPage->getIsModifiedOnStage());
|
||||
$this->assertTrue($publishedPage->isOnDraft());
|
||||
$this->assertTrue($publishedPage->isPublished());
|
||||
$this->assertFalse($publishedPage->isOnDraftOnly());
|
||||
$this->assertFalse($publishedPage->isOnLiveOnly());
|
||||
$this->assertFalse($publishedPage->isModifiedOnDraft());
|
||||
|
||||
// published page, deleted from stage
|
||||
$deletedFromDraftPage = new SiteTree();
|
||||
$deletedFromDraftPage->write();
|
||||
$deletedFromDraftPageID = $deletedFromDraftPage->ID;
|
||||
$deletedFromDraftPage->copyVersionToStage('Stage','Live');
|
||||
$deletedFromDraftPage->deleteFromStage('Stage');
|
||||
$this->assertTrue($deletedFromDraftPage->getIsDeletedFromStage());
|
||||
$this->assertFalse($deletedFromDraftPage->getIsAddedToStage());
|
||||
$this->assertFalse($deletedFromDraftPage->getIsModifiedOnStage());
|
||||
$this->assertFalse($deletedFromDraftPage->isArchived());
|
||||
$this->assertFalse($deletedFromDraftPage->isOnDraft());
|
||||
$this->assertTrue($deletedFromDraftPage->isPublished());
|
||||
$this->assertFalse($deletedFromDraftPage->isOnDraftOnly());
|
||||
$this->assertTrue($deletedFromDraftPage->isOnLiveOnly());
|
||||
$this->assertFalse($deletedFromDraftPage->isModifiedOnDraft());
|
||||
|
||||
// published page, deleted from live
|
||||
$deletedFromLivePage = new SiteTree();
|
||||
$deletedFromLivePage->write();
|
||||
$deletedFromLivePage->copyVersionToStage('Stage','Live');
|
||||
$deletedFromLivePage->deleteFromStage('Stage');
|
||||
$deletedFromLivePage->deleteFromStage('Live');
|
||||
$this->assertTrue($deletedFromLivePage->getIsDeletedFromStage());
|
||||
$this->assertFalse($deletedFromLivePage->getIsAddedToStage());
|
||||
$this->assertFalse($deletedFromLivePage->getIsModifiedOnStage());
|
||||
$this->assertFalse($deletedFromLivePage->isArchived());
|
||||
$this->assertTrue($deletedFromLivePage->isOnDraft());
|
||||
$this->assertFalse($deletedFromLivePage->isPublished());
|
||||
$this->assertTrue($deletedFromLivePage->isOnDraftOnly());
|
||||
$this->assertFalse($deletedFromLivePage->isOnLiveOnly());
|
||||
$this->assertTrue($deletedFromLivePage->isModifiedOnDraft());
|
||||
|
||||
// published page, deleted from both stages
|
||||
$deletedFromAllStagesPage = new SiteTree();
|
||||
$deletedFromAllStagesPage->write();
|
||||
$deletedFromAllStagesPage->copyVersionToStage('Stage','Live');
|
||||
$deletedFromAllStagesPage->deleteFromStage('Stage');
|
||||
$deletedFromAllStagesPage->deleteFromStage('Live');
|
||||
$this->assertTrue($deletedFromAllStagesPage->isArchived());
|
||||
$this->assertFalse($deletedFromAllStagesPage->isOnDraft());
|
||||
$this->assertFalse($deletedFromAllStagesPage->isPublished());
|
||||
$this->assertFalse($deletedFromAllStagesPage->isOnDraftOnly());
|
||||
$this->assertFalse($deletedFromAllStagesPage->isOnLiveOnly());
|
||||
$this->assertFalse($deletedFromAllStagesPage->isModifiedOnDraft());
|
||||
|
||||
// published page, modified
|
||||
$modifiedOnDraftPage = new SiteTree();
|
||||
@ -257,9 +277,12 @@ class SiteTreeTest extends SapphireTest {
|
||||
$modifiedOnDraftPage->copyVersionToStage('Stage','Live');
|
||||
$modifiedOnDraftPage->Content = 'modified';
|
||||
$modifiedOnDraftPage->write();
|
||||
$this->assertFalse($modifiedOnDraftPage->getIsDeletedFromStage());
|
||||
$this->assertFalse($modifiedOnDraftPage->getIsAddedToStage());
|
||||
$this->assertTrue($modifiedOnDraftPage->getIsModifiedOnStage());
|
||||
$this->assertFalse($modifiedOnDraftPage->isArchived());
|
||||
$this->assertTrue($modifiedOnDraftPage->isOnDraft());
|
||||
$this->assertTrue($modifiedOnDraftPage->isPublished());
|
||||
$this->assertFalse($modifiedOnDraftPage->isOnDraftOnly());
|
||||
$this->assertFalse($modifiedOnDraftPage->isOnLiveOnly());
|
||||
$this->assertTrue($modifiedOnDraftPage->isModifiedOnDraft());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1222,21 +1245,23 @@ class SiteTreeTest extends SapphireTest {
|
||||
public function testArchivedPages() {
|
||||
$this->logInWithPermission('ADMIN');
|
||||
|
||||
/** @var Page $page */
|
||||
$page = $this->objFromFixture('Page', 'home');
|
||||
$this->assertTrue($page->canAddChildren());
|
||||
$this->assertFalse($page->getIsDeletedFromStage());
|
||||
$this->assertTrue($page->isOnDraft());
|
||||
$this->assertFalse($page->isPublished());
|
||||
|
||||
// Publish
|
||||
$page->publishRecursive();
|
||||
$this->assertTrue($page->canAddChildren());
|
||||
$this->assertFalse($page->getIsDeletedFromStage());
|
||||
$this->assertTrue($page->isOnDraft());
|
||||
$this->assertTrue($page->isPublished());
|
||||
|
||||
// Archive
|
||||
$page->doArchive();
|
||||
$this->assertFalse($page->canAddChildren());
|
||||
$this->assertTrue($page->getIsDeletedFromStage());
|
||||
$this->assertFalse($page->isOnDraft());
|
||||
$this->assertTrue($page->isArchived());
|
||||
$this->assertFalse($page->isPublished());
|
||||
}
|
||||
|
||||
|
@ -277,42 +277,42 @@ class VirtualPageTest extends FunctionalTest {
|
||||
$vp->write();
|
||||
|
||||
// VP is oragne
|
||||
$this->assertTrue($vp->getIsAddedToStage());
|
||||
$this->assertTrue($vp->isOnDraftOnly());
|
||||
|
||||
// VP is still orange after we publish
|
||||
$p->publishRecursive();
|
||||
$this->assertTrue($vp->getIsAddedToStage());
|
||||
$this->assertTrue($vp->isOnDraftOnly());
|
||||
|
||||
// A new VP created after P's initial construction
|
||||
$vp2 = new VirtualPage();
|
||||
$vp2->CopyContentFromID = $p->ID;
|
||||
$vp2->write();
|
||||
$this->assertTrue($vp2->getIsAddedToStage());
|
||||
$this->assertTrue($vp2->isOnDraftOnly());
|
||||
|
||||
// Also remains orange after a republish
|
||||
$p->Content = "new content";
|
||||
$p->write();
|
||||
$p->publishRecursive();
|
||||
$this->assertTrue($vp2->getIsAddedToStage());
|
||||
$this->assertTrue($vp2->isOnDraftOnly());
|
||||
|
||||
// VP is now published
|
||||
$vp->publishRecursive();
|
||||
|
||||
$this->assertTrue($vp->getExistsOnLive());
|
||||
$this->assertFalse($vp->getIsModifiedOnStage());
|
||||
$this->assertTrue($vp->isPublished());
|
||||
$this->assertFalse($vp->isModifiedOnDraft());
|
||||
|
||||
// P edited, P goes green. Change set interface should indicate to the user that the owned page has
|
||||
// modifications, although the virtual page record itself will not appear as having pending changes.
|
||||
$p->Content = "third content";
|
||||
$p->write();
|
||||
|
||||
$this->assertTrue($p->getIsModifiedOnStage());
|
||||
$this->assertFalse($vp->getIsModifiedOnStage());
|
||||
$this->assertTrue($p->isModifiedOnDraft());
|
||||
$this->assertFalse($vp->isModifiedOnDraft());
|
||||
|
||||
// Publish, VP goes black
|
||||
$p->publishRecursive();
|
||||
$this->assertTrue($vp->getExistsOnLive());
|
||||
$this->assertFalse($vp->getIsModifiedOnStage());
|
||||
$this->assertTrue($vp->isPublished());
|
||||
$this->assertFalse($vp->isModifiedOnDraft());
|
||||
}
|
||||
|
||||
public function testUnpublishingSourcePageOfAVirtualPageAlsoUnpublishesVirtualPage() {
|
||||
|
Loading…
Reference in New Issue
Block a user