Skip to content

Commit

Permalink
FIX Ensure orphaned pages don't result in exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Dec 20, 2023
1 parent e1da194 commit af67ed3
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions code/Model/SiteTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ public function getMimeType()
*/
public function RelativeLink($action = null)
{
if ($this->ParentID && self::config()->get('nested_urls')) {
if (self::config()->get('nested_urls') && $this->ParentID && $this->getParent()?->exists()) {
$parent = $this->getParent();
// If page is removed select parent from version history (for archive page view)
if ((!$parent || !$parent->exists()) && !$this->isOnDraft()) {
Expand Down Expand Up @@ -1175,7 +1175,7 @@ public function canView($member = null)

// check for inherit
if ($this->CanViewType === InheritedPermissions::INHERIT) {
if ($this->ParentID) {
if ($this->ParentID && $this->getParent()?->exists()) {
return $this->getParent()->canView($member);
} else {
return $this->getSiteConfig()->canViewPages($member);
Expand Down Expand Up @@ -1870,7 +1870,7 @@ public function validate()
public function validURLSegment()
{
// Check known urlsegment blacklists
if (self::config()->get('nested_urls') && $this->ParentID) {
if (self::config()->get('nested_urls') && $this->ParentID && $this->getParent()?->exists()) {
// Guard against url segments for sub-pages
$parent = $this->getParent();
if ($controller = ModelAsController::controller_for($parent)) {
Expand Down Expand Up @@ -2132,7 +2132,7 @@ public function getCMSFields()

$baseLink = Controller::join_links(
Director::absoluteBaseURL(),
(self::config()->get('nested_urls') && $this->ParentID ? $this->getParent()->RelativeLink(true) : null)
(self::config()->get('nested_urls') && $this->ParentID ? $this->getParent()?->RelativeLink(true) : null)
);

$urlsegment = SiteTreeURLSegmentField::create("URLSegment", $this->fieldLabel('URLSegment'))
Expand Down Expand Up @@ -3048,7 +3048,7 @@ public function Level($level)
public function getPageLevel()
{
if ($this->ParentID) {
return 1 + $this->getParent()->getPageLevel();
return 1 + $this->getParent()?->getPageLevel();
}
return 1;
}
Expand Down

0 comments on commit af67ed3

Please sign in to comment.