mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
BUG Fix behaviour towards versioned but unstagable records
This commit is contained in:
parent
ee5084815f
commit
3be0478e1c
@ -121,22 +121,23 @@ abstract class SilverStripeNavigatorItem extends ViewableData
|
|||||||
*/
|
*/
|
||||||
public function isArchived()
|
public function isArchived()
|
||||||
{
|
{
|
||||||
$recordClass = get_class($this->record);
|
/** @var Versioned|DataObject $record */
|
||||||
if (!$recordClass::has_extension(Versioned::class)) {
|
$record = $this->record;
|
||||||
|
if (!$record->hasExtension(Versioned::class) || !$record->hasStages()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($this->record->_cached_isArchived)) {
|
if (!isset($record->_cached_isArchived)) {
|
||||||
$baseClass = $this->record->baseClass();
|
$baseClass = $record->baseClass();
|
||||||
$currentDraft = Versioned::get_by_stage($baseClass, Versioned::DRAFT)->byID($this->record->ID);
|
$currentDraft = Versioned::get_by_stage($baseClass, Versioned::DRAFT)->byID($record->ID);
|
||||||
$currentLive = Versioned::get_by_stage($baseClass, Versioned::LIVE)->byID($this->record->ID);
|
$currentLive = Versioned::get_by_stage($baseClass, Versioned::LIVE)->byID($record->ID);
|
||||||
|
|
||||||
$this->record->_cached_isArchived = (
|
$record->_cached_isArchived = (
|
||||||
(!$currentDraft || ($currentDraft && $this->record->Version != $currentDraft->Version))
|
(!$currentDraft || ($currentDraft && $record->Version != $currentDraft->Version))
|
||||||
&& (!$currentLive || ($currentLive && $this->record->Version != $currentLive->Version))
|
&& (!$currentLive || ($currentLive && $record->Version != $currentLive->Version))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->record->_cached_isArchived;
|
return $record->_cached_isArchived;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ namespace SilverStripe\CMS\Controllers;
|
|||||||
use SilverStripe\CMS\Model\RedirectorPage;
|
use SilverStripe\CMS\Model\RedirectorPage;
|
||||||
use SilverStripe\Control\Controller;
|
use SilverStripe\Control\Controller;
|
||||||
use SilverStripe\Core\Convert;
|
use SilverStripe\Core\Convert;
|
||||||
|
use SilverStripe\ORM\DataObject;
|
||||||
use SilverStripe\ORM\FieldType\DBDatetime;
|
use SilverStripe\ORM\FieldType\DBDatetime;
|
||||||
use SilverStripe\ORM\FieldType\DBField;
|
use SilverStripe\ORM\FieldType\DBField;
|
||||||
use SilverStripe\Versioned\Versioned;
|
use SilverStripe\Versioned\Versioned;
|
||||||
@ -53,12 +54,14 @@ class SilverStripeNavigatorItem_ArchiveLink extends SilverStripeNavigatorItem
|
|||||||
|
|
||||||
public function canView($member = null)
|
public function canView($member = null)
|
||||||
{
|
{
|
||||||
$recordClass = get_class($this->record);
|
/** @var Versioned|DataObject $record */
|
||||||
|
$record = $this->record;
|
||||||
return (
|
return (
|
||||||
$recordClass::has_extension(Versioned::class)
|
$record->hasExtension(Versioned::class)
|
||||||
|
&& $record->hasStages()
|
||||||
&& $this->isArchived()
|
&& $this->isArchived()
|
||||||
// Don't follow redirects in preview, they break the CMS editing form
|
// Don't follow redirects in preview, they break the CMS editing form
|
||||||
&& !($this->record instanceof RedirectorPage)
|
&& !($record instanceof RedirectorPage)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ namespace SilverStripe\CMS\Controllers;
|
|||||||
use SilverStripe\CMS\Model\RedirectorPage;
|
use SilverStripe\CMS\Model\RedirectorPage;
|
||||||
use SilverStripe\Control\Controller;
|
use SilverStripe\Control\Controller;
|
||||||
use SilverStripe\Core\Convert;
|
use SilverStripe\Core\Convert;
|
||||||
|
use SilverStripe\ORM\DataObject;
|
||||||
use SilverStripe\Versioned\Versioned;
|
use SilverStripe\Versioned\Versioned;
|
||||||
|
|
||||||
class SilverStripeNavigatorItem_LiveLink extends SilverStripeNavigatorItem
|
class SilverStripeNavigatorItem_LiveLink extends SilverStripeNavigatorItem
|
||||||
@ -51,9 +52,11 @@ class SilverStripeNavigatorItem_LiveLink extends SilverStripeNavigatorItem
|
|||||||
|
|
||||||
public function canView($member = null)
|
public function canView($member = null)
|
||||||
{
|
{
|
||||||
$recordClass = get_class($this->record);
|
/** @var Versioned|DataObject $record */
|
||||||
|
$record = $this->record;
|
||||||
return (
|
return (
|
||||||
$recordClass::has_extension(Versioned::class)
|
$record->hasExtension(Versioned::class)
|
||||||
|
&& $record->hasStages()
|
||||||
&& $this->getLivePage()
|
&& $this->getLivePage()
|
||||||
// Don't follow redirects in preview, they break the CMS editing form
|
// Don't follow redirects in preview, they break the CMS editing form
|
||||||
&& !($this->record instanceof RedirectorPage)
|
&& !($this->record instanceof RedirectorPage)
|
||||||
|
@ -5,6 +5,7 @@ use SilverStripe\CMS\Model\RedirectorPage;
|
|||||||
use SilverStripe\Control\Controller;
|
use SilverStripe\Control\Controller;
|
||||||
use SilverStripe\Core\ClassInfo;
|
use SilverStripe\Core\ClassInfo;
|
||||||
use SilverStripe\Core\Convert;
|
use SilverStripe\Core\Convert;
|
||||||
|
use SilverStripe\ORM\DataObject;
|
||||||
use SilverStripe\Versioned\Versioned;
|
use SilverStripe\Versioned\Versioned;
|
||||||
use SiteTreeFutureState;
|
use SiteTreeFutureState;
|
||||||
|
|
||||||
@ -57,11 +58,14 @@ class SilverStripeNavigatorItem_StageLink extends SilverStripeNavigatorItem
|
|||||||
|
|
||||||
public function canView($member = null)
|
public function canView($member = null)
|
||||||
{
|
{
|
||||||
|
/** @var Versioned|DataObject $record */
|
||||||
|
$record = $this->record;
|
||||||
return (
|
return (
|
||||||
$this->record->hasExtension(Versioned::class)
|
$record->hasExtension(Versioned::class)
|
||||||
|
&& $record->hasStages()
|
||||||
&& $this->getDraftPage()
|
&& $this->getDraftPage()
|
||||||
// Don't follow redirects in preview, they break the CMS editing form
|
// Don't follow redirects in preview, they break the CMS editing form
|
||||||
&& !($this->record instanceof RedirectorPage)
|
&& !($record instanceof RedirectorPage)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
namespace SilverStripe\CMS\Tests\Controllers;
|
namespace SilverStripe\CMS\Tests\Controllers;
|
||||||
|
|
||||||
use SilverStripe\CMS\Controllers\SilverStripeNavigator;
|
use SilverStripe\CMS\Controllers\SilverStripeNavigator;
|
||||||
|
use SilverStripe\CMS\Controllers\SilverStripeNavigatorItem_ArchiveLink;
|
||||||
|
use SilverStripe\CMS\Controllers\SilverStripeNavigatorItem_LiveLink;
|
||||||
use SilverStripe\CMS\Controllers\SilverStripeNavigatorItem_StageLink;
|
use SilverStripe\CMS\Controllers\SilverStripeNavigatorItem_StageLink;
|
||||||
use SilverStripe\Dev\SapphireTest;
|
use SilverStripe\Dev\SapphireTest;
|
||||||
use SilverStripe\Security\Member;
|
use SilverStripe\Security\Member;
|
||||||
@ -11,6 +13,10 @@ class SilverStripeNavigatorTest extends SapphireTest
|
|||||||
{
|
{
|
||||||
protected static $fixture_file = 'CMSMainTest.yml';
|
protected static $fixture_file = 'CMSMainTest.yml';
|
||||||
|
|
||||||
|
protected static $extra_dataobjects = [
|
||||||
|
SilverStripeNavigatorTest\UnstagedRecord::class,
|
||||||
|
];
|
||||||
|
|
||||||
public function testGetItems()
|
public function testGetItems()
|
||||||
{
|
{
|
||||||
$page = $this->objFromFixture('Page', 'page1');
|
$page = $this->objFromFixture('Page', 'page1');
|
||||||
@ -29,6 +35,8 @@ class SilverStripeNavigatorTest extends SapphireTest
|
|||||||
$classes,
|
$classes,
|
||||||
'Autodiscovers new classes'
|
'Autodiscovers new classes'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Non-versioned items don't have stage / live
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCanView()
|
public function testCanView()
|
||||||
@ -47,5 +55,13 @@ class SilverStripeNavigatorTest extends SapphireTest
|
|||||||
$items = $navigator->getItems();
|
$items = $navigator->getItems();
|
||||||
$classes = array_map('get_class', $items->toArray());
|
$classes = array_map('get_class', $items->toArray());
|
||||||
$this->assertContains(SilverStripeNavigatorTest_ProtectedTestItem::class, $classes);
|
$this->assertContains(SilverStripeNavigatorTest_ProtectedTestItem::class, $classes);
|
||||||
|
|
||||||
|
// Unversioned record shouldn't be viewable in stage / live specific views
|
||||||
|
$unversioned = new SilverStripeNavigatorTest\UnstagedRecord();
|
||||||
|
$navigator2 = new SilverStripeNavigator($unversioned);
|
||||||
|
$classes = array_map('get_class', $navigator2->getItems()->toArray());
|
||||||
|
$this->assertNotContains(SilverStripeNavigatorItem_LiveLink::class, $classes);
|
||||||
|
$this->assertNotContains(SilverStripeNavigatorItem_StageLink::class, $classes);
|
||||||
|
$this->assertNotContains(SilverStripeNavigatorItem_ArchiveLink::class, $classes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\CMS\Tests\Controllers\SilverStripeNavigatorTest;
|
||||||
|
|
||||||
|
use SilverStripe\Dev\TestOnly;
|
||||||
|
use SilverStripe\ORM\CMSPreviewable;
|
||||||
|
use SilverStripe\ORM\DataObject;
|
||||||
|
use SilverStripe\Versioned\Versioned;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Versioned but not staged
|
||||||
|
*/
|
||||||
|
class UnstagedRecord extends DataObject implements TestOnly, CMSPreviewable
|
||||||
|
{
|
||||||
|
private static $table_name = 'SilverStripeNavigatorTest_UnversionedRecord';
|
||||||
|
|
||||||
|
private static $extensions = [
|
||||||
|
Versioned::class . '.versioned',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function PreviewLink($action = null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To determine preview mechanism (e.g. embedded / iframe)
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getMimeType()
|
||||||
|
{
|
||||||
|
return 'text/html';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function CMSEditLink()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user