diff --git a/application/Espo/ORM/Entity.php b/application/Espo/ORM/Entity.php index afd2757d3d..de046735c0 100644 --- a/application/Espo/ORM/Entity.php +++ b/application/Espo/ORM/Entity.php @@ -72,6 +72,8 @@ abstract class Entity implements IEntity protected $isFetched = false; + protected $isBeingSaved = false; + public function __construct($defs = array(), EntityManager $entityManager = null) { if (empty($this->entityType)) { @@ -486,6 +488,21 @@ abstract class Entity implements IEntity $this->resetFetchedValues(); } + public function isBeingSaved() + { + return $this->isBeingSaved; + } + + public function setAsBeingSaved() + { + $this->isBeingSaved = true; + } + + public function setAsNotBeingSaved() + { + $this->isBeingSaved = false; + } + public function populateDefaults() { foreach ($this->fields as $field => $defs) { @@ -500,4 +517,3 @@ abstract class Entity implements IEntity return $this->entityManager; } } - diff --git a/application/Espo/ORM/Repositories/RDB.php b/application/Espo/ORM/Repositories/RDB.php index dfb32bb6b8..f8110647ef 100644 --- a/application/Espo/ORM/Repositories/RDB.php +++ b/application/Espo/ORM/Repositories/RDB.php @@ -141,6 +141,8 @@ class RDB extends \Espo\ORM\Repository public function save(Entity $entity, array $options = array()) { + $entity->setAsBeingSaved(); + if (empty($options['skipBeforeSave']) && empty($options['skipAll'])) { $this->beforeSave($entity, $options); } @@ -164,6 +166,8 @@ class RDB extends \Espo\ORM\Repository } } } + $entity->setAsNotBeingSaved(); + return $result; }