diff --git a/application/Espo/Repositories/Portal.php b/application/Espo/Repositories/Portal.php index cccd61b3ea..2993c046fd 100644 --- a/application/Espo/Repositories/Portal.php +++ b/application/Espo/Repositories/Portal.php @@ -52,10 +52,13 @@ class Portal extends \Espo\Core\ORM\Repositories\RDB if ($entity->has('isDefault')) { if ($entity->get('isDefault')) { $this->getConfig()->set('defaultPortalId', $entity->id); + $this->getConfig()->save(); } else { - $this->getConfig()->set('defaultPortalId', null); + if ($entity->isAttributeChanged('isDefault')) { + $this->getConfig()->set('defaultPortalId', null); + $this->getConfig()->save(); + } } - $this->getConfig()->save(); } } } diff --git a/application/Espo/Services/Portal.php b/application/Espo/Services/Portal.php index 844865eb5f..afed86bb18 100644 --- a/application/Espo/Services/Portal.php +++ b/application/Espo/Services/Portal.php @@ -33,6 +33,8 @@ use \Espo\ORM\Entity; class Portal extends Record { + protected $getEntityBeforeUpdate = true; + public function loadAdditionalFields(Entity $entity) { parent::loadAdditionalFields($entity); @@ -51,8 +53,10 @@ class Portal extends Record $url = $siteUrl . '?entryPoint=portal'; if ($entity->id === $this->getConfig()->get('defaultPortalId')) { $entity->set('isDefault', true); + $entity->setFetched('isDefault', true); } else { $url .= '&id=' . $entity->id; + $entity->setFetched('isDefault', false); } $entity->set('url', $url); }