diff --git a/code/Model/SiteTree.php b/code/Model/SiteTree.php index a9bb223d..aaa06a91 100755 --- a/code/Model/SiteTree.php +++ b/code/Model/SiteTree.php @@ -2641,8 +2641,10 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi // Need to update pages linking to this one as no longer broken foreach ($stageSelf->DependentPages() as $page) { - /** @var SiteTree $page */ - $page->writeWithoutVersion(); + if ($page->hasExtension(Versioned::class)) { + /** @var Versioned $page */ + $page->writeWithoutVersion(); + } } } diff --git a/tests/php/Model/SiteTreeTest.php b/tests/php/Model/SiteTreeTest.php index 876778d7..a0afb4cc 100644 --- a/tests/php/Model/SiteTreeTest.php +++ b/tests/php/Model/SiteTreeTest.php @@ -11,6 +11,7 @@ use SilverStripe\CMS\Model\VirtualPage; use SilverStripe\CMS\Tests\Controllers\SiteTreeTest_NamespaceMapTestController; use SilverStripe\CMS\Tests\CMSEditLinkExtensionTest\BelongsToPage; use SilverStripe\CMS\Tests\CMSEditLinkExtensionTest\PageWithChild; +use SilverStripe\CMS\Tests\Model\SiteTreeBrokenLinksTest\NotPageObject; use SilverStripe\CMS\Tests\Page\SiteTreeTest_NamespaceMapTest; use SilverStripe\Control\ContentNegotiator; use SilverStripe\Control\Controller; @@ -67,6 +68,7 @@ class SiteTreeTest extends SapphireTest SiteTreeTest_DataObject::class, PageWithChild::class, BelongsToPage::class, + NotPageObject::class, ]; public function reservedSegmentsProvider() @@ -2112,4 +2114,23 @@ class SiteTreeTest extends SapphireTest ], ]; } + + public function testOnAfterRevertToLive() + { + // Create new page and publish it + $page = SiteTree::create(); + $page->Content = 'Test content'; + $id = $page->write(); + $page->publishRecursive(); + + // Add link to non-page object + /** @var NotPageObject $obj */ + $obj = $this->objFromFixture(NotPageObject::class, 'object1'); + $obj->Content = 'Link to Page'; + $obj->write(); + + //Test that method doesn't throw exception + $this->expectNotToPerformAssertions(); + $page->onAfterRevertToLive(); + } } diff --git a/tests/php/Model/SiteTreeTest.yml b/tests/php/Model/SiteTreeTest.yml index da181d4e..ea5d0d15 100644 --- a/tests/php/Model/SiteTreeTest.yml +++ b/tests/php/Model/SiteTreeTest.yml @@ -128,3 +128,7 @@ SilverStripe\CMS\Tests\Model\SiteTreeTest_DataObject: relations: Title: 'Linked DataObject' Pages: =>SilverStripe\CMS\Model\SiteTree.home,=>SilverStripe\CMS\Model\SiteTree.about,=>SilverStripe\CMS\Model\SiteTree.staff + +SilverStripe\CMS\Tests\Model\SiteTreeBrokenLinksTest\NotPageObject: + object1: + Content: 'Everything will be ok'