orm fixes
This commit is contained in:
@@ -30,11 +30,13 @@
|
||||
namespace Espo\ORM;
|
||||
|
||||
use Espo\ORM\{
|
||||
Mapper\Mapper,
|
||||
QueryComposer\QueryComposer,
|
||||
Mapper\Mapper,
|
||||
Mapper\BaseMapper,
|
||||
Repository\RepositoryFactory,
|
||||
Repository\Repository,
|
||||
Locker\Locker,
|
||||
Locker\BaseLocker,
|
||||
};
|
||||
|
||||
use PDO;
|
||||
@@ -90,10 +92,13 @@ class EntityManager
|
||||
if (empty($this->params['driver'])) {
|
||||
throw new Exception('No database driver specified.');
|
||||
}
|
||||
|
||||
$driver = $this->params['driver'];
|
||||
|
||||
if (empty($this->driverPlatformMap[$driver])) {
|
||||
throw new Exception("Database driver '{$driver}' is not supported.");
|
||||
}
|
||||
|
||||
$this->params['platform'] = $this->driverPlatformMap[$this->params['driver']];
|
||||
}
|
||||
|
||||
@@ -144,6 +149,10 @@ class EntityManager
|
||||
if (!$className) {
|
||||
$platform = $this->params['platform'];
|
||||
$className = 'Espo\\ORM\\Locker\\' . ucfirst($platform) . 'Locker';
|
||||
|
||||
if (!class_exists($className)) {
|
||||
$className = BaseLocker::class;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$className || !class_exists($className)) {
|
||||
@@ -181,13 +190,15 @@ class EntityManager
|
||||
{
|
||||
$className = null;
|
||||
|
||||
switch ($name) {
|
||||
case 'RDB':
|
||||
$platform = $this->params['platform'];
|
||||
$className = 'Espo\\ORM\\Mapper\\' . ucfirst($platform) . 'Mapper';
|
||||
break;
|
||||
$classNameMap = $this->params['mapperClassNameMap'] ?? [];
|
||||
|
||||
$className = $classNameMap[$name] ?? null;
|
||||
|
||||
if (!$className && $name === 'RDB') {
|
||||
$className = $this->getRDBMapperClassName();
|
||||
}
|
||||
|
||||
|
||||
if (!$className || !class_exists($className)) {
|
||||
throw new RuntimeException("Mapper '{$name}' does not exist.");
|
||||
}
|
||||
@@ -195,6 +206,19 @@ class EntityManager
|
||||
return $className;
|
||||
}
|
||||
|
||||
protected function getRDBMapperClassName() : string
|
||||
{
|
||||
$platform = $this->params['platform'];
|
||||
|
||||
$className = 'Espo\\ORM\\Mapper\\' . ucfirst($platform) . 'Mapper';
|
||||
|
||||
if (!class_exists($className)) {
|
||||
$className = BaseMapper::class;
|
||||
}
|
||||
|
||||
return $className;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Mapper.
|
||||
*/
|
||||
@@ -227,6 +251,7 @@ class EntityManager
|
||||
$platform = strtolower($params['platform']);
|
||||
|
||||
$options = [];
|
||||
|
||||
if (isset($params['sslCA'])) {
|
||||
$options[PDO::MYSQL_ATTR_SSL_CA] = $params['sslCA'];
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ use Espo\ORM\{
|
||||
use PDO;
|
||||
use RuntimeException;
|
||||
|
||||
abstract class BaseLocker implements Locker
|
||||
class BaseLocker implements Locker
|
||||
{
|
||||
protected $pdo;
|
||||
protected $queryComposer;
|
||||
|
||||
@@ -88,7 +88,7 @@ abstract class BaseMapper implements Mapper
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first entity from DB.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function selectOne(Select $select) : ?Entity
|
||||
{
|
||||
@@ -112,7 +112,7 @@ abstract class BaseMapper implements Mapper
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a number of entities in DB.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function count(Select $select) : int
|
||||
{
|
||||
@@ -158,9 +158,10 @@ abstract class BaseMapper implements Mapper
|
||||
}
|
||||
|
||||
/**
|
||||
* Select enities from DB.
|
||||
* {@inheritdoc}
|
||||
* @todo Change return type to SthCollection once PHP 7.4 is a min version.
|
||||
*/
|
||||
public function select(Select $select) : SthCollection
|
||||
public function select(Select $select) : Collection
|
||||
{
|
||||
$entityType = $select->getFrom();
|
||||
|
||||
@@ -1199,7 +1200,7 @@ abstract class BaseMapper implements Mapper
|
||||
}
|
||||
|
||||
/**
|
||||
* Mass insert collection into DB.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function massInsert(Collection $collection)
|
||||
{
|
||||
@@ -1286,7 +1287,7 @@ abstract class BaseMapper implements Mapper
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an entity in DB.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function update(Entity $entity)
|
||||
{
|
||||
@@ -1375,7 +1376,7 @@ abstract class BaseMapper implements Mapper
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark an entity as deleted in DB.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function delete(Entity $entity) : bool
|
||||
{
|
||||
|
||||
@@ -38,43 +38,27 @@ use Espo\ORM\{
|
||||
interface Mapper
|
||||
{
|
||||
/**
|
||||
* Get the first entity from DB.
|
||||
* Get a first entity from DB.
|
||||
*/
|
||||
public function selectOne(Select $select) : ?Entity;
|
||||
|
||||
/**
|
||||
* Select a list of entities according to given parameters.
|
||||
* Select enities from DB.
|
||||
*/
|
||||
public function select(Select $select) : Collection;
|
||||
|
||||
/**
|
||||
* Returns count of records according to given parameters.
|
||||
*
|
||||
* @return Record count.
|
||||
* Get a number of records in DB.
|
||||
*/
|
||||
public function count(Select $select) : int;
|
||||
|
||||
/**
|
||||
* Selects related entity or list of entities.
|
||||
*
|
||||
* @return List of entities or one entity.
|
||||
*/
|
||||
public function selectRelated(Entity $entity, string $relationName, ?Select $select = null);
|
||||
|
||||
/**
|
||||
* Returns count of related records according to given parameters.
|
||||
*
|
||||
* @return A number of records.
|
||||
*/
|
||||
public function countRelated(Entity $entity, string $relationName, ?Select $select = null) : int;
|
||||
|
||||
/**
|
||||
* Insert an entity into DB.
|
||||
*/
|
||||
public function insert(Entity $entity);
|
||||
|
||||
/**
|
||||
* Insert an entity collaction.
|
||||
* Insert a collection into DB.
|
||||
*/
|
||||
public function massInsert(Collection $collection);
|
||||
|
||||
@@ -84,7 +68,7 @@ interface Mapper
|
||||
public function update(Entity $entity);
|
||||
|
||||
/**
|
||||
* Delete an entity (mark as deleted).
|
||||
* Mark an entity as deleted in DB.
|
||||
*/
|
||||
public function delete(Entity $entity);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user