Skip to content

Commit

Permalink
FIX Restore write to getOwnerPage and prevent write recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
robbieaverill authored and ScopeyNZ committed Jul 11, 2019
1 parent 8637239 commit 66f0942
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/Models/ElementalArea.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,6 @@ public function ElementControllers()
return $controllers;
}

public function onBeforeWrite()
{
$this->getOwnerPage();
parent::onBeforeWrite();
}

/**
* @return null|DataObject
* @throws \Psr\Container\NotFoundExceptionInterface
Expand Down Expand Up @@ -197,14 +191,17 @@ public function getOwnerPage()
throw $ex;
}

if ($page) {
if ($page && $page->exists()) {
if ($this->OwnerClassName !== $class) {
$this->OwnerClassName = $class;
$this->write();

// Avoid recursion: only write if it's already in the database
if ($this->isInDB()) {
$this->write();
}
}

$this->cacheData['area_relation_name'] = $page;
return $page;
return $this->cacheData['area_relation_name'] = $page->first();
}
}
}
Expand Down

0 comments on commit 66f0942

Please # to comment.