diff --git a/application/Espo/Core/Formula/AttributeFetcher.php b/application/Espo/Core/Formula/AttributeFetcher.php index 6603ddf8a0..8cd0195813 100644 --- a/application/Espo/Core/Formula/AttributeFetcher.php +++ b/application/Espo/Core/Formula/AttributeFetcher.php @@ -32,6 +32,7 @@ namespace Espo\Core\Formula; use Espo\Core\ORM\Defs\AttributeParam; use Espo\Entities\EmailAddress; use Espo\Entities\PhoneNumber; +use Espo\ORM\Defs\Params\AttributeParam as OrmAttributeParam; use Espo\ORM\Entity; use Espo\Core\ORM\Entity as CoreEntity; use Espo\ORM\EntityManager; @@ -101,7 +102,7 @@ class AttributeFetcher { if ($entity->getAttributeParam($attribute, 'isParentName')) { /** @var ?string $relationName */ - $relationName = $entity->getAttributeParam($attribute, 'relation'); + $relationName = $entity->getAttributeParam($attribute, OrmAttributeParam::RELATION); if ($relationName) { $entity->loadParentNameField($relationName); @@ -112,7 +113,7 @@ class AttributeFetcher if ($entity->getAttributeParam($attribute, AttributeParam::IS_LINK_MULTIPLE_ID_LIST)) { /** @var ?string $relationName */ - $relationName = $entity->getAttributeParam($attribute, 'relation'); + $relationName = $entity->getAttributeParam($attribute, OrmAttributeParam::RELATION); if ($relationName) { $entity->loadLinkMultipleField($relationName); diff --git a/application/Espo/Core/Select/Text/MetadataProvider.php b/application/Espo/Core/Select/Text/MetadataProvider.php index 04b643d07e..e1eef68293 100644 --- a/application/Espo/Core/Select/Text/MetadataProvider.php +++ b/application/Espo/Core/Select/Text/MetadataProvider.php @@ -32,6 +32,7 @@ namespace Espo\Core\Select\Text; use Espo\Core\Utils\Metadata; use Espo\ORM\Defs; +use Espo\ORM\Defs\Params\AttributeParam; use Espo\ORM\Defs\Params\FieldParam; class MetadataProvider @@ -150,6 +151,6 @@ class MetadataProvider return $this->ormDefs ->getEntity($entityType) ->getAttribute($attribute) - ->getParam('relation'); + ->getParam(AttributeParam::RELATION); } } diff --git a/application/Espo/Core/Select/Where/ItemGeneralConverter.php b/application/Espo/Core/Select/Where/ItemGeneralConverter.php index 415471aa36..200c62d6c0 100644 --- a/application/Espo/Core/Select/Where/ItemGeneralConverter.php +++ b/application/Espo/Core/Select/Where/ItemGeneralConverter.php @@ -41,6 +41,7 @@ use Espo\Core\Utils\Metadata; use Espo\Entities\ArrayValue; use Espo\Entities\User; use Espo\ORM\Defs as ORMDefs; +use Espo\ORM\Defs\Params\AttributeParam; use Espo\ORM\Entity; use Espo\ORM\Name\Attribute; use Espo\ORM\Query\Part\Condition as Cond; @@ -500,8 +501,8 @@ class ItemGeneralConverter implements ItemConverter if ($isForeign) { if ($isForeignType) { - $arrayLink = $entityDefs->getAttribute($attribute)->getParam('relation'); - $arrayAttribute = $entityDefs->getAttribute($attribute)->getParam('foreign'); + $arrayLink = $entityDefs->getAttribute($attribute)->getParam(AttributeParam::RELATION); + $arrayAttribute = $entityDefs->getAttribute($attribute)->getParam(AttributeParam::FOREIGN); } else { [$arrayLink, $arrayAttribute] = explode('.', $attribute); } diff --git a/application/Espo/Core/Select/Where/Scanner.php b/application/Espo/Core/Select/Where/Scanner.php index be585096d6..06ba903f6c 100644 --- a/application/Espo/Core/Select/Where/Scanner.php +++ b/application/Espo/Core/Select/Where/Scanner.php @@ -30,6 +30,7 @@ namespace Espo\Core\Select\Where; use Espo\Core\Select\Where\Item\Type; +use Espo\ORM\Defs\Params\AttributeParam; use Espo\ORM\EntityManager; use Espo\ORM\Entity; use Espo\ORM\BaseEntity; @@ -192,7 +193,7 @@ class Scanner $attributeType = $seed->getAttributeType($attribute); if ($attributeType === Entity::FOREIGN) { - $relation = $this->getAttributeParam($seed, $attribute, 'relation'); + $relation = $this->getAttributeParam($seed, $attribute, AttributeParam::RELATION); if ($relation) { $queryBuilder->leftJoin($relation); diff --git a/application/Espo/Core/Utils/Database/Orm/Converter.php b/application/Espo/Core/Utils/Database/Orm/Converter.php index 0693b36225..3f60a380d7 100644 --- a/application/Espo/Core/Utils/Database/Orm/Converter.php +++ b/application/Espo/Core/Utils/Database/Orm/Converter.php @@ -85,8 +85,8 @@ class Converter 'autoincrement' => 'autoincrement', 'entity' => 'entity', FieldParam::NOT_STORABLE => AttributeParam::NOT_STORABLE, - 'link' => 'relation', - 'field' => 'foreign', // @todo Change 'foreign' to 'field'. + 'link' => AttributeParam::RELATION, + 'field' => AttributeParam::FOREIGN, 'unique' => 'unique', 'index' => 'index', FieldParam::DEFAULT => AttributeParam::DEFAULT, @@ -350,8 +350,8 @@ class Converter { $params = $data[$entityType][EntityParam::ATTRIBUTES][$attribute] ?? []; - $foreign = $params['foreign'] ?? null; - $relation = $params['relation'] ?? null; + $foreign = $params[AttributeParam::FOREIGN] ?? null; + $relation = $params[AttributeParam::RELATION] ?? null; if (!$foreign || !$relation) { return null; @@ -359,7 +359,7 @@ class Converter $relationParams = $data[$entityType][EntityParam::RELATIONS][$relation] ?? []; - $foreignEntityType = $relationParams['entity'] ?? null; + $foreignEntityType = $relationParams[RelationParam::ENTITY] ?? null; if (!$foreignEntityType) { return null; diff --git a/application/Espo/Core/Utils/Database/Orm/FieldConverters/File.php b/application/Espo/Core/Utils/Database/Orm/FieldConverters/File.php index 79bc93d7fd..d0efa7bff7 100644 --- a/application/Espo/Core/Utils/Database/Orm/FieldConverters/File.php +++ b/application/Espo/Core/Utils/Database/Orm/FieldConverters/File.php @@ -29,13 +29,16 @@ namespace Espo\Core\Utils\Database\Orm\FieldConverters; +use Espo\Core\Name\Field; use Espo\Core\Utils\Database\Orm\Defs\AttributeDefs; use Espo\Core\Utils\Database\Orm\Defs\EntityDefs; use Espo\Core\Utils\Database\Orm\Defs\RelationDefs; use Espo\Core\Utils\Database\Orm\FieldConverter; use Espo\Entities\Attachment; use Espo\ORM\Defs\FieldDefs; +use Espo\ORM\Defs\Params\AttributeParam; use Espo\ORM\Defs\Params\RelationParam; +use Espo\ORM\Name\Attribute; use Espo\ORM\Type\AttributeType; use Espo\ORM\Type\RelationType; @@ -72,15 +75,15 @@ class File implements FieldConverter if (!$fieldDefs->isNotStorable()) { $nameDefs = $nameDefs->withParamsMerged([ - 'relation' => $name, - 'foreign' => 'name', + AttributeParam::RELATION => $name, + AttributeParam::FOREIGN => Field::NAME, ]); $relationDefs = RelationDefs::create($name) ->withType(RelationType::BELONGS_TO) ->withForeignEntityType(Attachment::ENTITY_TYPE) ->withKey($idName) - ->withForeignKey('id') + ->withForeignKey(Attribute::ID) ->withParam(RelationParam::FOREIGN, null); } diff --git a/application/Espo/Core/Utils/Database/Orm/FieldConverters/LinkParent.php b/application/Espo/Core/Utils/Database/Orm/FieldConverters/LinkParent.php index 8031089aec..b6deb884f1 100644 --- a/application/Espo/Core/Utils/Database/Orm/FieldConverters/LinkParent.php +++ b/application/Espo/Core/Utils/Database/Orm/FieldConverters/LinkParent.php @@ -71,7 +71,7 @@ class LinkParent implements FieldConverter ->withType(AttributeType::VARCHAR) ->withNotStorable() ->withParamsMerged([ - 'relation' => $name, + AttributeParam::RELATION => $name, 'isParentName' => true, 'attributeRole' => 'name', 'fieldType' => FieldType::LINK_PARENT, diff --git a/application/Espo/Core/Utils/Database/Orm/LinkConverters/BelongsTo.php b/application/Espo/Core/Utils/Database/Orm/LinkConverters/BelongsTo.php index 3997ff39d1..d27202e8e2 100644 --- a/application/Espo/Core/Utils/Database/Orm/LinkConverters/BelongsTo.php +++ b/application/Espo/Core/Utils/Database/Orm/LinkConverters/BelongsTo.php @@ -33,6 +33,8 @@ use Espo\Core\Utils\Database\Orm\Defs\AttributeDefs; use Espo\Core\Utils\Database\Orm\Defs\EntityDefs; use Espo\Core\Utils\Database\Orm\Defs\RelationDefs; use Espo\Core\Utils\Database\Orm\LinkConverter; +use Espo\ORM\Defs\Params\AttributeParam; +use Espo\ORM\Defs\Params\RelationParam; use Espo\ORM\Defs\RelationDefs as LinkDefs; use Espo\ORM\Type\AttributeType; use Espo\ORM\Type\RelationType; @@ -47,7 +49,7 @@ class BelongsTo implements LinkConverter $noIndex = $linkDefs->getParam('noIndex'); $noForeignName = $linkDefs->getParam('noForeignName'); $foreignName = $linkDefs->getParam('foreignName') ?? 'name'; - $noJoin = $linkDefs->getParam('noJoin'); + $noJoin = $linkDefs->getParam(RelationParam::NO_JOIN); $idName = $name . 'Id'; $nameName = $name . 'Name'; @@ -63,8 +65,8 @@ class BelongsTo implements LinkConverter ->withForeignKey('id') ->withForeignRelationName($foreignRelationName); - if ($linkDefs->getParam('deferredLoad')) { - $relationDefs = $relationDefs->withParam('deferredLoad', true); + if ($linkDefs->getParam(RelationParam::DEFERRED_LOAD)) { + $relationDefs = $relationDefs->withParam(RelationParam::DEFERRED_LOAD, true); } $nameAttributeDefs = !$noForeignName ? @@ -73,13 +75,13 @@ class BelongsTo implements LinkConverter AttributeDefs::create($nameName) ->withType(AttributeType::VARCHAR) ->withNotStorable() - ->withParam('relation', $name) - ->withParam('foreign', $foreignName) : + ->withParam(AttributeParam::RELATION, $name) + ->withParam(AttributeParam::FOREIGN, $foreignName) : AttributeDefs::create($nameName) ->withType(AttributeType::FOREIGN) - ->withNotStorable(true) // Used to be false before v7.4. - ->withParam('relation', $name) - ->withParam('foreign', $foreignName) + ->withNotStorable() // Used to be false before v7.4. + ->withParam(AttributeParam::RELATION, $name) + ->withParam(AttributeParam::FOREIGN, $foreignName) ) : null; $entityDefs = EntityDefs::create() diff --git a/application/Espo/Core/Utils/Database/Orm/LinkConverters/BelongsToParent.php b/application/Espo/Core/Utils/Database/Orm/LinkConverters/BelongsToParent.php index 6084be64a7..d0cd9aa7cb 100644 --- a/application/Espo/Core/Utils/Database/Orm/LinkConverters/BelongsToParent.php +++ b/application/Espo/Core/Utils/Database/Orm/LinkConverters/BelongsToParent.php @@ -34,6 +34,7 @@ use Espo\Core\Utils\Database\Orm\Defs\EntityDefs; use Espo\Core\Utils\Database\Orm\Defs\RelationDefs; use Espo\Core\Utils\Database\Orm\LinkConverter; use Espo\ORM\Defs\Params\AttributeParam; +use Espo\ORM\Defs\Params\RelationParam; use Espo\ORM\Defs\RelationDefs as LinkDefs; use Espo\ORM\Type\AttributeType; use Espo\ORM\Type\RelationType; @@ -58,8 +59,8 @@ class BelongsToParent implements LinkConverter ->withKey($idName) ->withForeignRelationName($foreignRelationName); - if ($linkDefs->getParam('deferredLoad')) { - $relationDefs = $relationDefs->withParam('deferredLoad', true); + if ($linkDefs->getParam(RelationParam::DEFERRED_LOAD)) { + $relationDefs = $relationDefs->withParam(RelationParam::DEFERRED_LOAD, true); } return EntityDefs::create() diff --git a/application/Espo/Core/Utils/Database/Orm/LinkConverters/HasOne.php b/application/Espo/Core/Utils/Database/Orm/LinkConverters/HasOne.php index 252589fb95..ebc16ca36d 100644 --- a/application/Espo/Core/Utils/Database/Orm/LinkConverters/HasOne.php +++ b/application/Espo/Core/Utils/Database/Orm/LinkConverters/HasOne.php @@ -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\Defs\RelationDefs; use Espo\Core\Utils\Database\Orm\LinkConverter; +use Espo\ORM\Defs\Params\AttributeParam; use Espo\ORM\Defs\RelationDefs as LinkDefs; use Espo\ORM\Name\Attribute; use Espo\ORM\Type\AttributeType; @@ -55,16 +56,16 @@ class HasOne implements LinkConverter $idAttributeDefs = AttributeDefs::create($idName) ->withType($noJoin ? AttributeType::VARCHAR : AttributeType::FOREIGN) ->withNotStorable() - ->withParam('relation', $name) - ->withParam('foreign', Attribute::ID); + ->withParam(AttributeParam::RELATION, $name) + ->withParam(AttributeParam::FOREIGN, Attribute::ID); $nameAttributeDefs = !$noForeignName ? ( AttributeDefs::create($nameName) ->withType($noJoin ? AttributeType::VARCHAR : AttributeType::FOREIGN) ->withNotStorable() - ->withParam('relation', $name) - ->withParam('foreign', $foreignName) + ->withParam(AttributeParam::RELATION, $name) + ->withParam(AttributeParam::FOREIGN, $foreignName) ) : null; $relationDefs = RelationDefs::create($name) diff --git a/application/Espo/Hooks/Common/ForeignFields.php b/application/Espo/Hooks/Common/ForeignFields.php index b1d26c5cf2..99a13b2527 100644 --- a/application/Espo/Hooks/Common/ForeignFields.php +++ b/application/Espo/Hooks/Common/ForeignFields.php @@ -32,6 +32,7 @@ namespace Espo\Hooks\Common; use Espo\Core\Hook\Hook\AfterSave; use Espo\Core\ORM\Repository\Option\SaveOption; use Espo\ORM\Defs; +use Espo\ORM\Defs\Params\AttributeParam; use Espo\ORM\Entity; use Espo\ORM\EntityManager; use Espo\ORM\Repository\Option\SaveOptions; @@ -62,7 +63,8 @@ class ForeignFields implements AfterSave $foreignList = array_filter( $entity->getAttributeList(), fn ($it) => $entity->getAttributeType($it) === AttributeType::FOREIGN); - $relationList = array_map(fn ($it) => $defs->getAttribute($it)->getParam('relation'), $foreignList); + $relationList = array_map( + fn ($it) => $defs->getAttribute($it)->getParam(AttributeParam::RELATION), $foreignList); $relationList = array_filter($relationList, fn ($it) => $entity->isAttributeChanged($it . 'Id')); $relationList = array_values($relationList); diff --git a/application/Espo/ORM/BaseEntity.php b/application/Espo/ORM/BaseEntity.php index 3c13f57527..8f5c13be93 100644 --- a/application/Espo/ORM/BaseEntity.php +++ b/application/Espo/ORM/BaseEntity.php @@ -457,8 +457,8 @@ class BaseEntity implements Entity $type = $this->getAttributeType($attribute); return $type === AttributeType::FOREIGN && - $this->getAttributeParam($attribute, 'relation') === substr($attribute, 0, -2) && - $this->getAttributeParam($attribute, 'foreign') === Attribute::ID && + $this->getAttributeParam($attribute, AttributeParam::RELATION) === substr($attribute, 0, -2) && + $this->getAttributeParam($attribute, AttributeParam::FOREIGN) === Attribute::ID && str_ends_with($attribute, 'Id'); } @@ -583,8 +583,8 @@ class BaseEntity implements Entity return null; } - $relation = $entityDefs->getAttribute($attribute)->getParam('relation'); - $foreign = $entityDefs->getAttribute($attribute)->getParam('foreign'); + $relation = $entityDefs->getAttribute($attribute)->getParam(AttributeParam::RELATION); + $foreign = $entityDefs->getAttribute($attribute)->getParam(AttributeParam::FOREIGN); if (!$relation) { return null; diff --git a/application/Espo/ORM/Defs/Params/AttributeParam.php b/application/Espo/ORM/Defs/Params/AttributeParam.php index 68f0213777..6652ac1870 100644 --- a/application/Espo/ORM/Defs/Params/AttributeParam.php +++ b/application/Espo/ORM/Defs/Params/AttributeParam.php @@ -63,4 +63,14 @@ class AttributeParam * A default value. */ public const DEFAULT = 'default'; + + /** + * A relation. For foreign attributes. + */ + public const RELATION = 'relation'; + + /** + * A foreign attribute name. For foreign attributes. + */ + public const FOREIGN = 'foreign'; } diff --git a/application/Espo/ORM/Defs/Params/RelationParam.php b/application/Espo/ORM/Defs/Params/RelationParam.php index aa26d9670d..201511a47c 100644 --- a/application/Espo/ORM/Defs/Params/RelationParam.php +++ b/application/Espo/ORM/Defs/Params/RelationParam.php @@ -81,7 +81,16 @@ class RelationParam /** * Middle keys. - * @todo */ public const MID_KEYS = 'midKeys'; + + /** + * No join. + */ + public const NO_JOIN = 'noJoin'; + + /** + * Deferred load. + */ + public const DEFERRED_LOAD = 'deferredLoad'; } diff --git a/application/Espo/ORM/QueryComposer/BaseQueryComposer.php b/application/Espo/ORM/QueryComposer/BaseQueryComposer.php index 88e1e44fb7..1ef1548b58 100644 --- a/application/Espo/ORM/QueryComposer/BaseQueryComposer.php +++ b/application/Espo/ORM/QueryComposer/BaseQueryComposer.php @@ -2069,14 +2069,14 @@ abstract class BaseQueryComposer implements QueryComposer if ( $entity->getAttributeType($field) == AttributeType::FOREIGN && - $this->getAttributeParam($entity, $field, 'relation') + $this->getAttributeParam($entity, $field, AttributeParam::RELATION) ) { - $relationsToJoin[] = $this->getAttributeParam($entity, $field, 'relation'); + $relationsToJoin[] = $this->getAttributeParam($entity, $field, AttributeParam::RELATION); } else if ( $this->getAttributeParam($entity, $field, 'fieldType') == FieldType::LINK_ONE && - $this->getAttributeParam($entity, $field, 'relation') + $this->getAttributeParam($entity, $field, AttributeParam::RELATION) ) { - $relationsToJoin[] = $this->getAttributeParam($entity, $field, 'relation'); + $relationsToJoin[] = $this->getAttributeParam($entity, $field, AttributeParam::RELATION); } } } @@ -2088,7 +2088,7 @@ abstract class BaseQueryComposer implements QueryComposer continue; } - if ($this->getRelationParam($entity, $relationName, 'noJoin')) { + if ($this->getRelationParam($entity, $relationName, RelationParam::NO_JOIN)) { continue; } @@ -2394,13 +2394,13 @@ abstract class BaseQueryComposer implements QueryComposer switch ($attributeType) { case Entity::FOREIGN: - $relationName = $this->getAttributeParam($entity, $attribute, 'relation'); + $relationName = $this->getAttributeParam($entity, $attribute, AttributeParam::RELATION); if (!$relationName) { return null; } - $foreign = $this->getAttributeParam($entity, $attribute, 'foreign'); + $foreign = $this->getAttributeParam($entity, $attribute, AttributeParam::FOREIGN); if (is_array($foreign)) { $wsCount = 0; @@ -2709,8 +2709,8 @@ abstract class BaseQueryComposer implements QueryComposer if ($attributeType === Entity::FOREIGN) { // @todo Add a test. - $relationName = $this->getAttributeParam($entity, $attribute, 'relation'); - $foreign = $this->getAttributeParam($entity, $attribute, 'foreign'); + $relationName = $this->getAttributeParam($entity, $attribute, AttributeParam::RELATION); + $foreign = $this->getAttributeParam($entity, $attribute, AttributeParam::FOREIGN); if (!$relationName) { throw new RuntimeException("No 'relation' param for field $entityType.$attribute."); @@ -3276,7 +3276,7 @@ abstract class BaseQueryComposer implements QueryComposer } $relTable = $this->toDb( - $this->getRelationParam($entity, $relationName, 'relationName') + $this->getRelationParam($entity, $relationName, RelationParam::RELATION_NAME) ); $distantTable = $this->toDb($foreignEntityType); diff --git a/application/Espo/ORM/Relation/RDBRelations.php b/application/Espo/ORM/Relation/RDBRelations.php index b4c22c7226..b5543d8a0c 100644 --- a/application/Espo/ORM/Relation/RDBRelations.php +++ b/application/Espo/ORM/Relation/RDBRelations.php @@ -31,6 +31,7 @@ namespace Espo\ORM\Relation; use Espo\ORM\BaseEntity; use Espo\ORM\Defs\Defs; +use Espo\ORM\Defs\Params\RelationParam; use Espo\ORM\Entity; use Espo\ORM\EntityCollection; use Espo\ORM\EntityManager; @@ -311,7 +312,7 @@ class RDBRelations implements Relations ->getEntity($this->entity->getEntityType()) ->getRelation($relation); - if (!$defs->getParam('deferredLoad')) { + if (!$defs->getParam(RelationParam::DEFERRED_LOAD)) { return null; } diff --git a/application/Espo/ORM/Repository/RDBRelationSelectBuilder.php b/application/Espo/ORM/Repository/RDBRelationSelectBuilder.php index 9926d85565..a4d0aaa01b 100644 --- a/application/Espo/ORM/Repository/RDBRelationSelectBuilder.php +++ b/application/Espo/ORM/Repository/RDBRelationSelectBuilder.php @@ -159,7 +159,7 @@ class RDBRelationSelectBuilder { $transformedWhere = []; - $middleName = lcfirst($this->getRelationParam('relationName')); + $middleName = lcfirst($this->getRelationParam(RelationParam::RELATION_NAME)); foreach ($where as $key => $value) { $transformedKey = $key; @@ -447,7 +447,7 @@ class RDBRelationSelectBuilder } if (!$this->middleTableAlias) { - $middleName = $this->getRelationParam('relationName'); + $middleName = $this->getRelationParam(RelationParam::RELATION_NAME); if (!$middleName) { throw new RuntimeException("No relation name."); diff --git a/application/Espo/Tools/Export/Export.php b/application/Espo/Tools/Export/Export.php index 1a7e078ed1..0277867bc9 100644 --- a/application/Espo/Tools/Export/Export.php +++ b/application/Espo/Tools/Export/Export.php @@ -32,6 +32,7 @@ namespace Espo\Tools\Export; use Espo\Core\ORM\Defs\AttributeParam; use Espo\Core\ORM\Repository\Option\SaveOption; use Espo\Core\Record\Select\ApplierClassNameListProvider; +use Espo\ORM\Defs\Params\AttributeParam as OrmAttributeParam; use Espo\Tools\Export\Collection as ExportCollection; use Espo\Tools\Export\Processor\Params as ProcessorParams; use Espo\ORM\Entity; @@ -198,7 +199,7 @@ class Export [$relation, $foreign] = str_contains($attribute, '_') ? explode('_', $attribute) : [ - $this->getAttributeParam($entity, $attribute, 'relation'), + $this->getAttributeParam($entity, $attribute, OrmAttributeParam::RELATION), $this->getAttributeParam($entity, $attribute, 'foreign') ]; diff --git a/application/Espo/Tools/Export/Format/Xlsx/AdditionalFieldsLoader.php b/application/Espo/Tools/Export/Format/Xlsx/AdditionalFieldsLoader.php index b23e50933a..139c4742c4 100644 --- a/application/Espo/Tools/Export/Format/Xlsx/AdditionalFieldsLoader.php +++ b/application/Espo/Tools/Export/Format/Xlsx/AdditionalFieldsLoader.php @@ -32,6 +32,7 @@ namespace Espo\Tools\Export\Format\Xlsx; use Espo\Core\ORM\Entity as CoreEntity; use Espo\Core\ORM\Type\FieldType; use Espo\Core\Utils\Metadata; +use Espo\ORM\Defs\Params\RelationParam; use Espo\ORM\Entity; use Espo\Tools\Export\AdditionalFieldsLoader as AdditionalFieldsLoaderInterface; @@ -62,7 +63,7 @@ class AdditionalFieldsLoader implements AdditionalFieldsLoaderInterface ( ( $entity->getRelationType($link) === Entity::BELONGS_TO && - $entity->getRelationParam($link, 'noJoin') + $entity->getRelationParam($link, RelationParam::NO_JOIN) ) || $entity->getRelationType($link) === Entity::HAS_ONE ) && diff --git a/application/Espo/Tools/Export/Format/Xlsx/ParamsHandler.php b/application/Espo/Tools/Export/Format/Xlsx/ParamsHandler.php index cc9633d3ff..7c111b80aa 100644 --- a/application/Espo/Tools/Export/Format/Xlsx/ParamsHandler.php +++ b/application/Espo/Tools/Export/Format/Xlsx/ParamsHandler.php @@ -31,6 +31,7 @@ namespace Espo\Tools\Export\Format\Xlsx; use Espo\Core\ORM\Type\FieldType; use Espo\Core\Utils\Metadata; +use Espo\ORM\Defs\Params\RelationParam; use Espo\ORM\Entity; use Espo\Tools\Export\Params; use Espo\Tools\Export\Processor; @@ -107,7 +108,7 @@ class ParamsHandler implements ProcessorParamsHandler continue; } - if ($linkType === Entity::BELONGS_TO && !empty($defs['noJoin'])) { + if ($linkType === Entity::BELONGS_TO && !empty($defs[RelationParam::NO_JOIN])) { if ($this->metadata->get(['entityDefs', $entityType, 'fields', $link])) { $linkList[] = $link; } diff --git a/application/Espo/Tools/Import/Import.php b/application/Espo/Tools/Import/Import.php index 2dccb984ba..f4e3d78691 100644 --- a/application/Espo/Tools/Import/Import.php +++ b/application/Espo/Tools/Import/Import.php @@ -29,6 +29,7 @@ namespace Espo\Tools\Import; +use Espo\Core\Name\Field; use Espo\Core\ORM\Type\FieldType; use Espo\Core\PhoneNumber\Sanitizer as PhoneNumberSanitizer; use Espo\Core\FieldValidation\Exceptions\ValidationError; @@ -631,8 +632,8 @@ class Import return; } - $foreignAttribute = $entity->getAttributeParam($attribute, 'foreign'); - $relation = $entity->getAttributeParam($attribute, 'relation'); + $foreignAttribute = $entity->getAttributeParam($attribute, AttributeParam::FOREIGN); + $relation = $entity->getAttributeParam($attribute, AttributeParam::RELATION); if (!$relation) { return; @@ -1366,7 +1367,7 @@ class Import if ( $entity->getAttributeType($attribute) === Entity::FOREIGN && - $entity->getAttributeParam($attribute, 'foreign') === 'name' + $entity->getAttributeParam($attribute, AttributeParam::FOREIGN) === Field::NAME ) { $this->processForeignAttribute($entity, $attribute); } @@ -1400,7 +1401,7 @@ class Import if ( $entity->getAttributeType($attribute) === Entity::FOREIGN && - $entity->getAttributeParam($attribute, 'foreign') !== 'name' && + $entity->getAttributeParam($attribute, AttributeParam::FOREIGN) !== Field::NAME && $this->getFieldParam($this->entityType, $attribute, 'relateOnImport') ) { $this->processForeignAttribute($entity, $attribute); diff --git a/application/Espo/Tools/Stream/HookProcessor.php b/application/Espo/Tools/Stream/HookProcessor.php index 5b3bf964d5..e371f16ee1 100644 --- a/application/Espo/Tools/Stream/HookProcessor.php +++ b/application/Espo/Tools/Stream/HookProcessor.php @@ -41,6 +41,7 @@ use Espo\Entities\Autofollow; use Espo\Entities\User; use Espo\Entities\Preferences; +use Espo\ORM\Defs\Params\RelationParam; use Espo\ORM\EntityManager; use Espo\ORM\Entity; use Espo\ORM\Defs\RelationDefs; @@ -601,7 +602,7 @@ class HookProcessor $entityType = $entity->getEntityType(); $foreignEntityType = $foreignEntity->getEntityType(); - $foreignLink = $entity->getRelationParam($link, 'foreign'); + $foreignLink = $entity->getRelationParam($link, RelationParam::FOREIGN); if ( !empty($options[self::OPTION_NO_STREAM]) || @@ -634,7 +635,7 @@ class HookProcessor $entityType = $entity->getEntityType(); $foreignEntityType = $foreignEntity->getEntityType(); - $foreignLink = $entity->getRelationParam($link, 'foreign'); + $foreignLink = $entity->getRelationParam($link, RelationParam::FOREIGN); if ( !empty($options[self::OPTION_NO_STREAM]) ||