repository check
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\ORM;
|
||||
|
||||
abstract class Repository
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -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'])
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user