ref
This commit is contained in:
@@ -33,6 +33,7 @@ use Espo\Core\Utils\Database\Orm\Defs\AttributeDefs;
|
||||
use Espo\Core\Utils\Database\Orm\Defs\EntityDefs;
|
||||
use Espo\Core\Utils\Database\Orm\FieldConverter;
|
||||
use Espo\ORM\Defs\FieldDefs;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\Name\Attribute;
|
||||
use Espo\ORM\Type\AttributeType;
|
||||
use RuntimeException;
|
||||
@@ -66,7 +67,7 @@ class RelationshipRole implements FieldConverter
|
||||
/** @var ?string $link */
|
||||
$link = $data['link'] ?? null;
|
||||
/** @var ?string $relationName */
|
||||
$relationName = $data['relationName'] ?? null;
|
||||
$relationName = $data[RelationParam::RELATION_NAME] ?? null;
|
||||
/** @var ?string $nearKey */
|
||||
$nearKey = $data['nearKey'] ?? null;
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ use Espo\Entities\ScheduledJob;
|
||||
use Espo\Entities\ScheduledJobLogRecord;
|
||||
use Espo\Entities\UniqueId;
|
||||
use Espo\Entities\UserReaction;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\Name\Attribute;
|
||||
use Espo\ORM\Query\DeleteBuilder;
|
||||
use Espo\ORM\Repository\RDBRepository;
|
||||
@@ -605,7 +606,7 @@ class Cleanup implements JobDataLess
|
||||
}
|
||||
|
||||
try {
|
||||
$relationName = $entity->getRelationParam($relation, 'relationName');
|
||||
$relationName = $entity->getRelationParam($relation, RelationParam::RELATION_NAME);
|
||||
|
||||
if (!$relationName) {
|
||||
continue;
|
||||
|
||||
@@ -41,6 +41,7 @@ use Espo\ORM\Defs\AttributeDefs;
|
||||
use Espo\ORM\Defs\FieldDefs;
|
||||
use Espo\ORM\Defs\IndexDefs;
|
||||
use Espo\ORM\Defs\Params\AttributeParam;
|
||||
use Espo\ORM\Defs\Params\EntityParam;
|
||||
use Espo\ORM\Defs\Params\FieldParam;
|
||||
use Espo\ORM\Defs\Params\IndexParam;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
@@ -103,7 +104,7 @@ class Converter
|
||||
private array $idParams = [];
|
||||
|
||||
/** @var string[] */
|
||||
private array $copyEntityProperties = ['indexes'];
|
||||
private array $copyEntityProperties = [EntityParam::INDEXES];
|
||||
|
||||
private IndexHelper $indexHelper;
|
||||
|
||||
@@ -200,7 +201,7 @@ class Converter
|
||||
|
||||
$ormMetadata[$entityType] = [
|
||||
'attributes' => [],
|
||||
'relations' => [],
|
||||
EntityParam::RELATIONS => [],
|
||||
];
|
||||
|
||||
foreach ($this->copyEntityProperties as $optionName) {
|
||||
@@ -356,7 +357,7 @@ class Converter
|
||||
return null;
|
||||
}
|
||||
|
||||
$relationParams = $data[$entityType]['relations'][$relation] ?? [];
|
||||
$relationParams = $data[$entityType][EntityParam::RELATIONS][$relation] ?? [];
|
||||
|
||||
$foreignEntityType = $relationParams['entity'] ?? null;
|
||||
|
||||
@@ -375,7 +376,7 @@ class Converter
|
||||
*/
|
||||
private function convertFields(string $entityType, array &$entityMetadata): array
|
||||
{
|
||||
$entityMetadata['fields'] ??= [];
|
||||
$entityMetadata[EntityParam::FIELDS] ??= [];
|
||||
|
||||
// List of unmerged fields with default field definitions in $output.
|
||||
$unmergedFields = [Field::NAME];
|
||||
@@ -385,7 +386,8 @@ class Converter
|
||||
AttributeParam::TYPE => Entity::ID,
|
||||
],
|
||||
'name' => [
|
||||
AttributeParam::TYPE => $entityMetadata['fields'][Field::NAME][FieldParam::TYPE] ?? Entity::VARCHAR,
|
||||
AttributeParam::TYPE => $entityMetadata[EntityParam::FIELDS][Field::NAME][FieldParam::TYPE] ??
|
||||
Entity::VARCHAR,
|
||||
AttributeParam::NOT_STORABLE => true,
|
||||
],
|
||||
Attribute::DELETED => [
|
||||
@@ -398,7 +400,7 @@ class Converter
|
||||
unset($output[Attribute::DELETED]);
|
||||
}
|
||||
|
||||
foreach ($entityMetadata['fields'] as $attribute => $attributeParams) {
|
||||
foreach ($entityMetadata[EntityParam::FIELDS] as $attribute => $attributeParams) {
|
||||
if (empty($attributeParams[AttributeParam::TYPE])) {
|
||||
continue;
|
||||
}
|
||||
@@ -507,7 +509,7 @@ class Converter
|
||||
$scopeDefs = $this->metadata->get(['scopes', $entityType]) ?? [];
|
||||
|
||||
if ($scopeDefs['stream'] ?? false) {
|
||||
if (!isset($entityMetadata['fields'][Field::IS_FOLLOWED])) {
|
||||
if (!isset($entityMetadata[EntityParam::FIELDS][Field::IS_FOLLOWED])) {
|
||||
$ormMetadata[$entityType]['attributes'][Field::IS_FOLLOWED] = [
|
||||
AttributeParam::TYPE => Entity::BOOL,
|
||||
AttributeParam::NOT_STORABLE => true,
|
||||
@@ -530,7 +532,7 @@ class Converter
|
||||
|
||||
// @todo Refactor.
|
||||
if ($scopeDefs['stars'] ?? false) {
|
||||
if (!isset($entityMetadata['fields'][Field::IS_STARRED])) {
|
||||
if (!isset($entityMetadata[EntityParam::FIELDS][Field::IS_STARRED])) {
|
||||
$ormMetadata[$entityType]['attributes'][Field::IS_STARRED] = [
|
||||
AttributeParam::TYPE => Entity::BOOL,
|
||||
AttributeParam::NOT_STORABLE => true,
|
||||
@@ -698,7 +700,7 @@ class Converter
|
||||
}
|
||||
|
||||
$fieldList = $this->metadata
|
||||
->get(['entityDefs', $entityType, 'collection', 'textFilterFields'], ['name']);
|
||||
->get(['entityDefs', $entityType, 'collection', 'textFilterFields'], [Field::NAME]);
|
||||
|
||||
$fullTextSearchColumnList = [];
|
||||
|
||||
@@ -739,11 +741,11 @@ class Converter
|
||||
if (!empty($fullTextSearchColumnList)) {
|
||||
$ormMetadata[$entityType]['fullTextSearchColumnList'] = $fullTextSearchColumnList;
|
||||
|
||||
if (!array_key_exists('indexes', $ormMetadata[$entityType])) {
|
||||
$ormMetadata[$entityType]['indexes'] = [];
|
||||
if (!array_key_exists(EntityParam::INDEXES, $ormMetadata[$entityType])) {
|
||||
$ormMetadata[$entityType][EntityParam::INDEXES] = [];
|
||||
}
|
||||
|
||||
$ormMetadata[$entityType]['indexes']['system_fullTextSearch'] = [
|
||||
$ormMetadata[$entityType][EntityParam::INDEXES]['system_fullTextSearch'] = [
|
||||
IndexParam::COLUMNS => $fullTextSearchColumnList,
|
||||
IndexParam::FLAGS => ['fulltext']
|
||||
];
|
||||
@@ -757,37 +759,37 @@ class Converter
|
||||
{
|
||||
$defs = &$ormMetadata[$entityType];
|
||||
|
||||
$defs['indexes'] ??= [];
|
||||
$defs[EntityParam::INDEXES] ??= [];
|
||||
|
||||
if (isset($defs['attributes'])) {
|
||||
$indexList = self::getEntityIndexListFromAttributes($defs['attributes']);
|
||||
|
||||
foreach ($indexList as $indexName => $indexParams) {
|
||||
if (!isset($defs['indexes'][$indexName])) {
|
||||
$defs['indexes'][$indexName] = $indexParams;
|
||||
if (!isset($defs[EntityParam::INDEXES][$indexName])) {
|
||||
$defs[EntityParam::INDEXES][$indexName] = $indexParams;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($defs['indexes'] as $indexName => &$indexData) {
|
||||
foreach ($defs[EntityParam::INDEXES] as $indexName => &$indexData) {
|
||||
$indexDefs = IndexDefs::fromRaw($indexData, $indexName);
|
||||
|
||||
if (!$indexDefs->getKey()) {
|
||||
$indexData['key'] = $this->composeIndexKey($indexDefs, $entityType);
|
||||
$indexData[IndexParam::KEY] = $this->composeIndexKey($indexDefs, $entityType);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($defs['relations'])) {
|
||||
foreach ($defs['relations'] as &$relationData) {
|
||||
if (isset($defs[EntityParam::RELATIONS])) {
|
||||
foreach ($defs[EntityParam::RELATIONS] as &$relationData) {
|
||||
$type = $relationData[RelationParam::TYPE] ?? null;
|
||||
|
||||
if ($type !== Entity::MANY_MANY) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$relationName = $relationData['relationName'] ?? '';
|
||||
$relationName = $relationData[RelationParam::RELATION_NAME] ?? '';
|
||||
|
||||
$relationData['indexes'] ??= [];
|
||||
$relationData[RelationParam::INDEXES] ??= [];
|
||||
|
||||
$uniqueColumnList = [];
|
||||
|
||||
@@ -796,7 +798,7 @@ class Converter
|
||||
|
||||
$indexDefs = IndexDefs::fromRaw([IndexParam::COLUMNS => [$midKey]], $indexName);
|
||||
|
||||
$relationData['indexes'][$indexName] = [
|
||||
$relationData[RelationParam::INDEXES][$indexName] = [
|
||||
IndexParam::COLUMNS => $indexDefs->getColumnList(),
|
||||
IndexParam::KEY => $this->composeIndexKey($indexDefs, ucfirst($relationName)),
|
||||
];
|
||||
@@ -804,7 +806,7 @@ class Converter
|
||||
$uniqueColumnList[] = $midKey;
|
||||
}
|
||||
|
||||
foreach ($relationData['indexes'] as $indexName => &$indexData) {
|
||||
foreach ($relationData[RelationParam::INDEXES] as $indexName => &$indexData) {
|
||||
if (!empty($indexData[IndexParam::KEY])) {
|
||||
continue;
|
||||
}
|
||||
@@ -827,7 +829,7 @@ class Converter
|
||||
IndexParam::COLUMNS => $uniqueColumnList,
|
||||
], $indexName);
|
||||
|
||||
$relationData['indexes'][$indexName] = [
|
||||
$relationData[RelationParam::INDEXES][$indexName] = [
|
||||
IndexParam::TYPE => self::INDEX_TYPE_UNIQUE,
|
||||
IndexParam::COLUMNS => $indexDefs->getColumnList(),
|
||||
IndexParam::KEY => $this->composeIndexKey($indexDefs, ucfirst($relationName)),
|
||||
@@ -879,7 +881,7 @@ class Converter
|
||||
{
|
||||
$result = [];
|
||||
|
||||
foreach ($defs['relations'] as $name => $relationParams) {
|
||||
foreach ($defs[EntityParam::RELATIONS] as $name => $relationParams) {
|
||||
$relationDefs = RelationDefs::fromRaw($relationParams, $name);
|
||||
|
||||
if ($relationDefs->getType() !== Entity::MANY_MANY) {
|
||||
@@ -939,8 +941,8 @@ class Converter
|
||||
}
|
||||
|
||||
foreach ($relationDefs->getIndexList() as $indexDefs) {
|
||||
$itemDefs['indexes'] ??= [];
|
||||
$itemDefs['indexes'][] = self::convertIndexDefsToRaw($indexDefs);
|
||||
$itemDefs[EntityParam::INDEXES] ??= [];
|
||||
$itemDefs[EntityParam::INDEXES][] = self::convertIndexDefsToRaw($indexDefs);
|
||||
}
|
||||
|
||||
$result[$relationEntityType] = $itemDefs;
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
|
||||
namespace Espo\Core\Utils\Database\Orm\Defs;
|
||||
|
||||
use Espo\ORM\Defs\Params\EntityParam;
|
||||
|
||||
/**
|
||||
* @immutable
|
||||
*/
|
||||
@@ -135,7 +137,7 @@ class EntityDefs
|
||||
$relationsData[$name] = $relationDefs->toAssoc();
|
||||
}
|
||||
|
||||
$data['relations'] = $relationsData;
|
||||
$data[EntityParam::RELATIONS] = $relationsData;
|
||||
}
|
||||
|
||||
if (count($this->indexes)) {
|
||||
@@ -145,7 +147,7 @@ class EntityDefs
|
||||
$indexesData[$name] = $indexDefs->toAssoc();
|
||||
}
|
||||
|
||||
$data['indexes'] = $indexesData;
|
||||
$data[EntityParam::INDEXES] = $indexesData;
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
namespace Espo\Core\Utils\Database\Orm\Defs;
|
||||
|
||||
use Espo\Core\Utils\Util;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\Type\RelationType;
|
||||
|
||||
class RelationDefs
|
||||
@@ -110,7 +111,7 @@ class RelationDefs
|
||||
*/
|
||||
public function withRelationshipName(string $name): self
|
||||
{
|
||||
return $this->withParam('relationName', $name);
|
||||
return $this->withParam(RelationParam::RELATION_NAME, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,7 +119,7 @@ class RelationDefs
|
||||
*/
|
||||
public function getRelationshipName(): ?string
|
||||
{
|
||||
return $this->getParam('relationName');
|
||||
return $this->getParam(RelationParam::RELATION_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -40,6 +40,7 @@ use Espo\Core\Utils\Log;
|
||||
use Espo\Core\Utils\Util;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\ORM\Defs\Params\AttributeParam;
|
||||
use Espo\ORM\Defs\Params\EntityParam;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\Defs\RelationDefs;
|
||||
use Espo\ORM\Type\AttributeType;
|
||||
@@ -53,11 +54,11 @@ class RelationConverter
|
||||
|
||||
/** @var string[] */
|
||||
private $mergeParams = [
|
||||
'relationName',
|
||||
RelationParam::RELATION_NAME,
|
||||
'conditions',
|
||||
'additionalColumns',
|
||||
'noJoin',
|
||||
'indexes',
|
||||
RelationParam::INDEXES,
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
@@ -83,11 +84,11 @@ class RelationConverter
|
||||
null;
|
||||
|
||||
/** @var ?string $relationshipName */
|
||||
$relationshipName = $params['relationName'] ?? null;
|
||||
$relationshipName = $params[RelationParam::RELATION_NAME] ?? null;
|
||||
|
||||
if ($relationshipName) {
|
||||
$relationshipName = lcfirst($relationshipName);
|
||||
$params['relationName'] = $relationshipName;
|
||||
$params[RelationParam::RELATION_NAME] = $relationshipName;
|
||||
}
|
||||
|
||||
$linkType = $params[RelationParam::TYPE] ?? null;
|
||||
@@ -110,9 +111,9 @@ class RelationConverter
|
||||
|
||||
$raw = $convertedEntityDefs->toAssoc();
|
||||
|
||||
if (isset($raw['relations'][$name])) {
|
||||
$this->mergeParams($raw['relations'][$name], $params, $foreignParams ?? []);
|
||||
$this->correct($raw['relations'][$name]);
|
||||
if (isset($raw[EntityParam::RELATIONS][$name])) {
|
||||
$this->mergeParams($raw[EntityParam::RELATIONS][$name], $params, $foreignParams ?? []);
|
||||
$this->correct($raw[EntityParam::RELATIONS][$name]);
|
||||
}
|
||||
|
||||
return [$entityType => $raw];
|
||||
|
||||
@@ -39,6 +39,7 @@ use Espo\ORM\Defs\AttributeDefs;
|
||||
use Espo\ORM\Defs\EntityDefs;
|
||||
use Espo\ORM\Defs\IndexDefs;
|
||||
use Espo\ORM\Defs\Params\AttributeParam;
|
||||
use Espo\ORM\Defs\Params\EntityParam;
|
||||
use Espo\ORM\Defs\RelationDefs;
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
@@ -104,7 +105,7 @@ class Builder
|
||||
}
|
||||
|
||||
foreach ($ormMeta as $entityType => $entityParams) {
|
||||
foreach (($entityParams['relations'] ?? []) as $relationName => $relationParams) {
|
||||
foreach (($entityParams[EntityParam::RELATIONS] ?? []) as $relationName => $relationParams) {
|
||||
$relationDefs = RelationDefs::fromRaw($relationParams, $relationName);
|
||||
|
||||
if ($relationDefs->getType() !== Entity::MANY_MANY) {
|
||||
|
||||
@@ -33,6 +33,7 @@ use Espo\Core\ORM\Type\FieldType;
|
||||
use Espo\Core\Utils\Util;
|
||||
use Espo\ORM\Defs\IndexDefs;
|
||||
use Espo\ORM\Defs\Params\AttributeParam;
|
||||
use Espo\ORM\Defs\Params\EntityParam;
|
||||
use Espo\ORM\Defs\Params\IndexParam;
|
||||
|
||||
class Utils
|
||||
@@ -50,7 +51,7 @@ class Utils
|
||||
$indexList = [];
|
||||
|
||||
foreach ($defs as $entityType => $entityParams) {
|
||||
$indexes = $entityParams['indexes'] ?? [];
|
||||
$indexes = $entityParams[EntityParam::INDEXES] ?? [];
|
||||
|
||||
foreach ($indexes as $indexName => $indexParams) {
|
||||
$indexDefs = IndexDefs::fromRaw($indexParams, $indexName);
|
||||
|
||||
@@ -36,6 +36,7 @@ use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\Core\Exceptions\NotFound;
|
||||
use Espo\Core\HookManager;
|
||||
use Espo\Modules\Crm\Entities\TargetList;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\EntityManager;
|
||||
use RuntimeException;
|
||||
|
||||
@@ -107,7 +108,7 @@ class RecordService
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
$linkEntityType = ucfirst($entity->getRelationParam($link, 'relationName') ?? '');
|
||||
$linkEntityType = ucfirst($entity->getRelationParam($link, RelationParam::RELATION_NAME) ?? '');
|
||||
|
||||
if ($linkEntityType === '') {
|
||||
throw new RuntimeException();
|
||||
|
||||
@@ -32,6 +32,7 @@ namespace Espo\ORM;
|
||||
use Espo\ORM\DataLoader\EmptyLoader;
|
||||
use Espo\ORM\DataLoader\Loader;
|
||||
use Espo\ORM\Defs\Params\AttributeParam;
|
||||
use Espo\ORM\Defs\Params\EntityParam;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\Name\Attribute;
|
||||
use Espo\ORM\Relation\EmptyRelations;
|
||||
@@ -100,7 +101,7 @@ class BaseEntity implements Entity
|
||||
$this->entityManager = $entityManager;
|
||||
|
||||
$this->attributesDefs = $defs['attributes'] ?? $this->attributesDefs;
|
||||
$this->relationsDefs = $defs['relations'] ?? $this->relationsDefs;
|
||||
$this->relationsDefs = $defs[EntityParam::RELATIONS] ?? $this->relationsDefs;
|
||||
|
||||
if ($valueAccessorFactory) {
|
||||
$this->valueAccessor = $valueAccessorFactory->create($this);
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
namespace Espo\ORM\Defs;
|
||||
|
||||
use Espo\ORM\Defs\Params\EntityParam;
|
||||
use RuntimeException;
|
||||
|
||||
class EntityDefs
|
||||
@@ -87,7 +88,7 @@ class EntityDefs
|
||||
public function getRelationNameList(): array
|
||||
{
|
||||
/** @var string[] */
|
||||
return array_keys($this->data['relations'] ?? []);
|
||||
return array_keys($this->data[EntityParam::RELATIONS] ?? []);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,7 +99,7 @@ class EntityDefs
|
||||
public function getIndexNameList(): array
|
||||
{
|
||||
/** @var string[] */
|
||||
return array_keys($this->data['indexes'] ?? []);
|
||||
return array_keys($this->data[EntityParam::INDEXES] ?? []);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,7 +110,7 @@ class EntityDefs
|
||||
public function getFieldNameList(): array
|
||||
{
|
||||
/** @var string[] */
|
||||
return array_keys($this->data['fields'] ?? []);
|
||||
return array_keys($this->data[EntityParam::FIELDS] ?? []);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -379,7 +380,7 @@ class EntityDefs
|
||||
|
||||
private function loadRelation(string $name): ?RelationDefs
|
||||
{
|
||||
$raw = $this->data['relations'][$name] ?? null;
|
||||
$raw = $this->data[EntityParam::RELATIONS][$name] ?? null;
|
||||
|
||||
if (!$raw) {
|
||||
return null;
|
||||
@@ -399,7 +400,7 @@ class EntityDefs
|
||||
|
||||
private function loadIndex(string $name): ?IndexDefs
|
||||
{
|
||||
$raw = $this->data['indexes'][$name] ?? null;
|
||||
$raw = $this->data[EntityParam::INDEXES][$name] ?? null;
|
||||
|
||||
if (!$raw) {
|
||||
return null;
|
||||
@@ -419,7 +420,7 @@ class EntityDefs
|
||||
|
||||
private function loadField(string $name): ?FieldDefs
|
||||
{
|
||||
$raw = $this->data['fields'][$name] ?? null;
|
||||
$raw = $this->data[EntityParam::FIELDS][$name] ?? null;
|
||||
|
||||
if (!$raw) {
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2024 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\ORM\Defs\Params;
|
||||
|
||||
/**
|
||||
* An entity parameter.
|
||||
*/
|
||||
class EntityParam
|
||||
{
|
||||
/**
|
||||
* Fields.
|
||||
*/
|
||||
public const FIELDS = 'fields';
|
||||
|
||||
/**
|
||||
* Relations.
|
||||
*/
|
||||
public const RELATIONS = 'relations';
|
||||
|
||||
/**
|
||||
* Indexes.
|
||||
*/
|
||||
public const INDEXES = 'indexes';
|
||||
}
|
||||
@@ -38,4 +38,14 @@ class RelationParam
|
||||
* A type.
|
||||
*/
|
||||
public const TYPE = 'type';
|
||||
|
||||
/**
|
||||
* Indexes.
|
||||
*/
|
||||
public const INDEXES = 'indexes';
|
||||
|
||||
/**
|
||||
* A relation name.
|
||||
*/
|
||||
public const RELATION_NAME = 'relationName';
|
||||
}
|
||||
|
||||
@@ -292,7 +292,7 @@ class RelationDefs
|
||||
*/
|
||||
public function hasRelationshipName(): bool
|
||||
{
|
||||
return isset($this->data['relationName']);
|
||||
return isset($this->data[RelationParam::RELATION_NAME]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -306,7 +306,7 @@ class RelationDefs
|
||||
throw new RuntimeException("No 'relationName' parameter defined in the relation '{$this->name}'.");
|
||||
}
|
||||
|
||||
return $this->data['relationName'];
|
||||
return $this->data[RelationParam::RELATION_NAME];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -323,7 +323,7 @@ class RelationDefs
|
||||
|
||||
$list = [];
|
||||
|
||||
foreach (($this->data['indexes'] ?? []) as $name => $item) {
|
||||
foreach (($this->data[RelationParam::INDEXES] ?? []) as $name => $item) {
|
||||
$list[] = IndexDefs::fromRaw($item, $name);
|
||||
}
|
||||
|
||||
|
||||
@@ -596,7 +596,7 @@ class BaseMapper implements RDBMapper
|
||||
switch ($relType) {
|
||||
case Entity::MANY_MANY:
|
||||
|
||||
$middleName = ucfirst($this->getRelationParam($entity, $relationName, 'relationName'));
|
||||
$middleName = ucfirst($this->getRelationParam($entity, $relationName, RelationParam::RELATION_NAME));
|
||||
|
||||
$nearKey = $keySet['nearKey'] ?? null;
|
||||
$distantKey = $keySet['distantKey'] ?? null;
|
||||
@@ -662,7 +662,7 @@ class BaseMapper implements RDBMapper
|
||||
throw new RuntimeException("Empty ID passed to 'getRelationColumn'.");
|
||||
}
|
||||
|
||||
$middleName = ucfirst($this->getRelationParam($entity, $relationName, 'relationName'));
|
||||
$middleName = ucfirst($this->getRelationParam($entity, $relationName, RelationParam::RELATION_NAME));
|
||||
|
||||
$keySet = $this->helper->getRelationKeys($entity, $relationName);
|
||||
|
||||
|
||||
@@ -31,7 +31,9 @@ namespace Espo\ORM\QueryComposer;
|
||||
|
||||
use Espo\Core\ORM\Type\FieldType;
|
||||
use Espo\ORM\Defs\Params\AttributeParam;
|
||||
use Espo\ORM\Defs\Params\EntityParam;
|
||||
use Espo\ORM\Defs\Params\IndexParam;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\EntityFactory;
|
||||
use Espo\ORM\BaseEntity;
|
||||
@@ -725,7 +727,7 @@ abstract class BaseQueryComposer implements QueryComposer
|
||||
}
|
||||
|
||||
foreach ($indexList as $indexName) {
|
||||
$indexKey = $this->metadata->get($entityType, ['indexes', $indexName, IndexParam::KEY]);
|
||||
$indexKey = $this->metadata->get($entityType, [EntityParam::INDEXES, $indexName, IndexParam::KEY]);
|
||||
|
||||
if ($indexKey) {
|
||||
$indexKeyList[] = $indexKey;
|
||||
@@ -3298,7 +3300,7 @@ abstract class BaseQueryComposer implements QueryComposer
|
||||
foreach ($indexList as $indexName) {
|
||||
$indexKey = $this->metadata->get(
|
||||
$entity->getEntityType(),
|
||||
['relations', $relationName, 'indexes', $indexName, IndexParam::KEY]
|
||||
[EntityParam::RELATIONS, $relationName, RelationParam::INDEXES, $indexName, IndexParam::KEY]
|
||||
);
|
||||
|
||||
if ($indexKey) {
|
||||
|
||||
@@ -34,6 +34,7 @@ use Espo\Core\ORM\Type\FieldType;
|
||||
use Espo\Core\Utils\Log;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\Entities\User;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\Type\RelationType;
|
||||
use Espo\Tools\EntityManager\Hook\UpdateHook;
|
||||
use Espo\Tools\EntityManager\Params;
|
||||
@@ -92,7 +93,7 @@ class CollaboratorsUpdateHook implements UpdateHook
|
||||
self::FIELD => [
|
||||
'type' => RelationType::HAS_MANY,
|
||||
'entity' => User::ENTITY_TYPE,
|
||||
'relationName' => self::RELATION_NAME,
|
||||
RelationParam::RELATION_NAME => self::RELATION_NAME,
|
||||
'layoutRelationshipsDisabled' => true,
|
||||
],
|
||||
],
|
||||
|
||||
@@ -35,6 +35,7 @@ use Espo\Core\Utils\Metadata;
|
||||
use Espo\Core\Utils\Route;
|
||||
use Espo\Core\Utils\Util;
|
||||
use Espo\Core\ServiceFactory;
|
||||
use Espo\ORM\Defs\Params\EntityParam;
|
||||
use Espo\ORM\EntityManager;
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
@@ -329,7 +330,7 @@ class NameUtil
|
||||
foreach ($scopeList as $entityType) {
|
||||
$relationsDefs = $this->entityManager
|
||||
->getMetadata()
|
||||
->get($entityType, 'relations');
|
||||
->get($entityType, EntityParam::RELATIONS);
|
||||
|
||||
if (empty($relationsDefs)) {
|
||||
continue;
|
||||
|
||||
@@ -38,6 +38,7 @@ use Espo\Core\Utils\Language;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\Core\Utils\Route;
|
||||
use Espo\Core\Utils\Util;
|
||||
use Espo\ORM\Defs\Params\RelationParam;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\ORM\Type\RelationType;
|
||||
use Espo\Tools\LinkManager\Hook\HookProcessor as LinkHookProcessor;
|
||||
@@ -470,7 +471,7 @@ class LinkManager
|
||||
'links' => [
|
||||
$link => [
|
||||
'type' => Entity::HAS_MANY,
|
||||
'relationName' => $relationName,
|
||||
RelationParam::RELATION_NAME => $relationName,
|
||||
'foreign' => $linkForeign,
|
||||
'entity' => $entityForeign,
|
||||
'audited' => $auditedForeign,
|
||||
@@ -491,7 +492,7 @@ class LinkManager
|
||||
'links' => [
|
||||
$linkForeign => [
|
||||
'type' => Entity::HAS_MANY,
|
||||
'relationName' => $relationName,
|
||||
RelationParam::RELATION_NAME => $relationName,
|
||||
'foreign' => $link,
|
||||
'entity' => $entity,
|
||||
'audited' => $audited,
|
||||
@@ -874,8 +875,8 @@ class LinkManager
|
||||
$type = LinkType::ONE_TO_ONE_RIGHT;
|
||||
}
|
||||
|
||||
$name = $this->metadata->get(['entityDefs', $entity, $link, 'relationName']) ??
|
||||
$this->metadata->get(['entityDefs', $entityForeign, $linkForeign, 'relationName']);
|
||||
$name = $this->metadata->get(['entityDefs', $entity, $link, RelationParam::RELATION_NAME]) ??
|
||||
$this->metadata->get(['entityDefs', $entityForeign, $linkForeign, RelationParam::RELATION_NAME]);
|
||||
|
||||
$linkParams = null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user