diff --git a/application/Espo/ORM/EntityManager.php b/application/Espo/ORM/EntityManager.php index d894f73fef..809bfe57b9 100644 --- a/application/Espo/ORM/EntityManager.php +++ b/application/Espo/ORM/EntityManager.php @@ -29,6 +29,8 @@ namespace Espo\ORM; +use \Espo\Core\Exceptions\Error; + class EntityManager { @@ -158,6 +160,10 @@ class EntityManager public function getEntity($name, $id = null) { + if (!$this->hasRepository($name)) { + throw new Error("ORM: Repository '{$name}' does not exist."); + } + return $this->getRepository($name)->get($id); } @@ -175,6 +181,10 @@ class EntityManager public function getRepository($name) { + if (!$this->hasRepository($name)) { + throw new Error("ORM: Repository '{$name}' does not exist."); + } + if (empty($this->repositoryHash[$name])) { $this->repositoryHash[$name] = $this->repositoryFactory->create($name); } diff --git a/application/Espo/ORM/Repository.php b/application/Espo/ORM/Repository.php index 89a4c7e64b..45f43ebc1e 100644 --- a/application/Espo/ORM/Repository.php +++ b/application/Espo/ORM/Repository.php @@ -28,6 +28,7 @@ ************************************************************************/ namespace Espo\ORM; + abstract class Repository { /** diff --git a/application/Espo/Repositories/EmailAddress.php b/application/Espo/Repositories/EmailAddress.php index fbe119a36e..0feb0504f1 100644 --- a/application/Espo/Repositories/EmailAddress.php +++ b/application/Espo/Repositories/EmailAddress.php @@ -143,6 +143,9 @@ class EmailAddress extends \Espo\Core\ORM\Repositories\RDB $sth->execute(); while ($row = $sth->fetch()) { if (!empty($row['entityType']) && !empty($row['entityId'])) { + if (!$this->getEntityManager()->hasRepository($row['entityType'])) { + return; + } if ($onlyName) { $entity = $this->getEntityManager()->getRepository($row['entityType']) ->select(['id', 'name']) diff --git a/application/Espo/Repositories/PhoneNumber.php b/application/Espo/Repositories/PhoneNumber.php index 9a31d51b59..706757c764 100644 --- a/application/Espo/Repositories/PhoneNumber.php +++ b/application/Espo/Repositories/PhoneNumber.php @@ -137,6 +137,9 @@ class PhoneNumber extends \Espo\Core\ORM\Repositories\RDB $sth->execute(); while ($row = $sth->fetch()) { if (!empty($row['entityType']) && !empty($row['entityId'])) { + if (!$this->getEntityManager()->hasRepository($row['entityType'])) { + return; + } $entity = $this->getEntityManager()->getEntity($row['entityType'], $row['entityId']); if ($entity) { return $entity;