Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend
This commit is contained in:
@@ -36,6 +36,8 @@ class EntityManager extends Base
|
||||
'password' => $config->get('database.password'),
|
||||
'metadata' => $this->getContainer()->get('metadata')->getOrmMetadata(),
|
||||
'repositoryFactoryClassName' => '\\Espo\\Core\\ORM\\RepositoryFactory',
|
||||
'driver' => $config->get('database.driver'),
|
||||
'platform' => $config->get('database.platform')
|
||||
);
|
||||
|
||||
$entityManager = new \Espo\Core\ORM\EntityManager($params);
|
||||
|
||||
@@ -32,8 +32,6 @@ use \Espo\Core\Interfaces\Injectable;
|
||||
|
||||
class RDB extends \Espo\ORM\Repositories\RDB implements Injectable
|
||||
{
|
||||
public static $mapperClassName = '\\Espo\\Core\\ORM\\DB\\MysqlMapper';
|
||||
|
||||
protected $dependencies = array(
|
||||
'metadata'
|
||||
);
|
||||
|
||||
@@ -43,7 +43,7 @@ abstract class Mapper implements IMapper
|
||||
protected $fieldsMapCache = array();
|
||||
protected $aliasesCache = array();
|
||||
|
||||
protected $returnCollection = true;
|
||||
protected $returnCollection = false;
|
||||
|
||||
protected $collectionClass = "\\Espo\\ORM\\EntityCollection";
|
||||
|
||||
@@ -76,7 +76,7 @@ abstract class Mapper implements IMapper
|
||||
'additionalColumnsConditions'
|
||||
);
|
||||
|
||||
public function __construct(PDO $pdo, \Espo\ORM\EntityFactory $entityFactory, Query $query) {
|
||||
public function __construct(PDO $pdo, \Espo\ORM\EntityFactory $entityFactory, Query\Base $query) {
|
||||
$this->pdo = $pdo;
|
||||
$this->query = $query;
|
||||
$this->entityFactory = $entityFactory;
|
||||
|
||||
@@ -20,14 +20,14 @@
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\ORM\DB;
|
||||
namespace Espo\ORM\DB\Query;
|
||||
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\IEntity;
|
||||
use Espo\ORM\EntityFactory;
|
||||
use PDO;
|
||||
|
||||
class Query
|
||||
class Base
|
||||
{
|
||||
protected static $selectParamList = array(
|
||||
'select',
|
||||
+8
-4
@@ -20,10 +20,14 @@
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\ORM\DB;
|
||||
namespace Espo\ORM\DB\Query;
|
||||
|
||||
class MysqlMapper extends \Espo\ORM\DB\MysqlMapper
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\IEntity;
|
||||
use Espo\ORM\EntityFactory;
|
||||
use PDO;
|
||||
|
||||
class Mysql extends Base
|
||||
{
|
||||
protected $returnCollection = false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -41,12 +41,28 @@ class EntityManager
|
||||
|
||||
protected $query;
|
||||
|
||||
protected $driverPlatformMap = array(
|
||||
'pdo_mysql' => 'Mysql',
|
||||
'mysqli' => 'Mysql',
|
||||
);
|
||||
|
||||
public function __construct($params)
|
||||
{
|
||||
$this->params = $params;
|
||||
|
||||
$this->metadata = new Metadata();
|
||||
|
||||
if (empty($this->params['platform'])) {
|
||||
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']];
|
||||
}
|
||||
|
||||
if (!empty($params['metadata'])) {
|
||||
$this->setMetadata($params['metadata']);
|
||||
}
|
||||
@@ -69,16 +85,36 @@ class EntityManager
|
||||
public function getQuery()
|
||||
{
|
||||
if (empty($this->query)) {
|
||||
$this->query = new DB\Query($this->getPDO(), $this->entityFactory);
|
||||
$platform = $this->params['platform'];
|
||||
$className = '\\Espo\\ORM\\DB\\Query\\' . ucfirst($platform);
|
||||
$this->query = new $className($this->getPDO(), $this->entityFactory);
|
||||
}
|
||||
return $this->query;
|
||||
}
|
||||
|
||||
public function getMapper($className)
|
||||
protected function getMapperClassName($name)
|
||||
{
|
||||
if (empty($this->mappers[$className])) {
|
||||
// TODO use factory
|
||||
$className = null;
|
||||
|
||||
switch ($name) {
|
||||
case 'RDB':
|
||||
$platform = $this->params['platform'];
|
||||
$className = '\\Espo\\ORM\\DB\\' . ucfirst($platform) . 'Mapper';
|
||||
break;
|
||||
}
|
||||
|
||||
return $className;
|
||||
}
|
||||
|
||||
public function getMapper($name)
|
||||
{
|
||||
if ($name{0} == '\\') {
|
||||
$className = $name;
|
||||
} else {
|
||||
$className = $this->getMapperClassName($name);
|
||||
}
|
||||
|
||||
if (empty($this->mappers[$className])) {
|
||||
$this->mappers[$className] = new $className($this->getPDO(), $this->entityFactory, $this->getQuery());
|
||||
}
|
||||
return $this->mappers[$className];
|
||||
@@ -90,7 +126,9 @@ class EntityManager
|
||||
|
||||
$port = empty($params['port']) ? '' : 'port=' . $params['port'] . ';';
|
||||
|
||||
$this->pdo = new \PDO('mysql:host='.$params['host'].';'.$port.'dbname=' . $params['dbname'] . ';charset=utf8', $params['user'], $params['password']);
|
||||
$platform = strtolower($params['platform']);
|
||||
|
||||
$this->pdo = new \PDO($platform . ':host='.$params['host'].';'.$port.'dbname=' . $params['dbname'] . ';charset=utf8', $params['user'], $params['password']);
|
||||
$this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,9 +31,6 @@ use \Espo\ORM\IEntity;
|
||||
|
||||
class RDB extends \Espo\ORM\Repository
|
||||
{
|
||||
|
||||
public static $mapperClassName = '\\Espo\\ORM\\DB\\MysqlMapper';
|
||||
|
||||
/**
|
||||
* @var Object Mapper.
|
||||
*/
|
||||
@@ -66,7 +63,7 @@ class RDB extends \Espo\ORM\Repository
|
||||
protected function getMapper()
|
||||
{
|
||||
if (empty($this->mapper)) {
|
||||
$this->mapper = $this->getEntityManager()->getMapper(self::$mapperClassName);
|
||||
$this->mapper = $this->getEntityManager()->getMapper('RDB');
|
||||
}
|
||||
return $this->mapper;
|
||||
}
|
||||
|
||||
@@ -1 +1,5 @@
|
||||
[{"name":"name","width":30,"link":true},{"name":"userName"},{"name":"emailAddress"}]
|
||||
[
|
||||
{"name":"name", "width":35, "link":true},
|
||||
{"name":"userName"},
|
||||
{"name":"emailAddress"}
|
||||
]
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
"tooltip": true
|
||||
},
|
||||
"name": {
|
||||
"type": "personName"
|
||||
"type": "personName",
|
||||
"view": "User.Fields.Name"
|
||||
},
|
||||
"password": {
|
||||
"type": "password",
|
||||
|
||||
Reference in New Issue
Block a user