diff --git a/application/Espo/Classes/Jobs/Cleanup.php b/application/Espo/Classes/Jobs/Cleanup.php index 93f978b7ad..2dd556232f 100644 --- a/application/Espo/Classes/Jobs/Cleanup.php +++ b/application/Espo/Classes/Jobs/Cleanup.php @@ -612,7 +612,7 @@ class Cleanup implements JobDataLess continue; } - $midKey = $entity->getRelationParam($relation, 'midKeys')[0]; + $midKey = $entity->getRelationParam($relation, RelationParam::MID_KEYS)[0]; if (!$midKey) { continue; diff --git a/application/Espo/Core/Upgrades/Migrations/V8_4/AfterUpgrade.php b/application/Espo/Core/Upgrades/Migrations/V8_4/AfterUpgrade.php index dd8516fa31..792fc049a4 100644 --- a/application/Espo/Core/Upgrades/Migrations/V8_4/AfterUpgrade.php +++ b/application/Espo/Core/Upgrades/Migrations/V8_4/AfterUpgrade.php @@ -31,6 +31,7 @@ namespace Espo\Core\Upgrades\Migrations\V8_4; use Espo\Core\Upgrades\Migration\Script; use Espo\Core\Utils\Metadata; +use Espo\ORM\Defs\Params\RelationParam; use Espo\ORM\Type\RelationType; class AfterUpgrade implements Script @@ -58,7 +59,7 @@ class AfterUpgrade implements Script foreach ($item['links'] as $link => $linkDefs) { $type = $linkDefs['type'] ?? null; $foreignEntityType = $linkDefs['entity'] ?? null; - $midKeys = $linkDefs['midKeys'] ?? null; + $midKeys = $linkDefs[RelationParam::MID_KEYS] ?? null; $isCustom = $linkDefs['isCustom'] ?? false; if ($type !== RelationType::HAS_MANY) { @@ -84,7 +85,7 @@ class AfterUpgrade implements Script $this->metadata->set('entityDefs', $entityType, [ 'links' => [ $link => [ - 'midKeys' => array_reverse($midKeys), + RelationParam::MID_KEYS => array_reverse($midKeys), '_keysSwappedAfterUpgrade' => true, ] ] diff --git a/application/Espo/Core/Utils/Database/Orm/Converter.php b/application/Espo/Core/Utils/Database/Orm/Converter.php index 5da1a85a28..0693b36225 100644 --- a/application/Espo/Core/Utils/Database/Orm/Converter.php +++ b/application/Espo/Core/Utils/Database/Orm/Converter.php @@ -793,7 +793,7 @@ class Converter $uniqueColumnList = []; - foreach (($relationData['midKeys'] ?? []) as $midKey) { + foreach (($relationData[RelationParam::MID_KEYS] ?? []) as $midKey) { $indexName = $midKey; $indexDefs = IndexDefs::fromRaw([IndexParam::COLUMNS => [$midKey]], $indexName); diff --git a/application/Espo/Core/Utils/Database/Orm/Defs/RelationDefs.php b/application/Espo/Core/Utils/Database/Orm/Defs/RelationDefs.php index 0a51f54b21..6fc31d4f0e 100644 --- a/application/Espo/Core/Utils/Database/Orm/Defs/RelationDefs.php +++ b/application/Espo/Core/Utils/Database/Orm/Defs/RelationDefs.php @@ -127,7 +127,7 @@ class RelationDefs */ public function withKey(string $key): self { - return $this->withParam('key', $key); + return $this->withParam(RelationParam::KEY, $key); } /** @@ -135,7 +135,7 @@ class RelationDefs */ public function getKey(): ?string { - return $this->getParam('key'); + return $this->getParam(RelationParam::KEY); } /** @@ -143,7 +143,7 @@ class RelationDefs */ public function withForeignKey(string $foreignKey): self { - return $this->withParam('foreignKey', $foreignKey); + return $this->withParam(RelationParam::FOREIGN_KEY, $foreignKey); } /** @@ -151,7 +151,7 @@ class RelationDefs */ public function getForeignKey(): ?string { - return $this->getParam('foreignKey'); + return $this->getParam(RelationParam::FOREIGN_KEY); } /** @@ -159,7 +159,7 @@ class RelationDefs */ public function withMidKeys(string $midKey, string $foreignMidKey): self { - return $this->withParam('midKeys', [$midKey, $foreignMidKey]); + return $this->withParam(RelationParam::MID_KEYS, [$midKey, $foreignMidKey]); } /** diff --git a/application/Espo/Modules/Crm/Tools/TargetList/OptOutService.php b/application/Espo/Modules/Crm/Tools/TargetList/OptOutService.php index 65966036ac..939a4fde21 100644 --- a/application/Espo/Modules/Crm/Tools/TargetList/OptOutService.php +++ b/application/Espo/Modules/Crm/Tools/TargetList/OptOutService.php @@ -211,14 +211,14 @@ class OptOutService } $linkEntityType = ucfirst( - $seed->getRelationParam($link, 'relationName') ?? '' + $seed->getRelationParam($link, RelationParam::RELATION_NAME) ?? '' ); if ($linkEntityType === '') { throw new RuntimeException(); } - $key = $seed->getRelationParam($link, 'midKeys')[1] ?? null; + $key = $seed->getRelationParam($link, RelationParam::MID_KEYS)[1] ?? null; if (!$key) { throw new RuntimeException(); diff --git a/application/Espo/ORM/Defs/Params/RelationParam.php b/application/Espo/ORM/Defs/Params/RelationParam.php index 37642ab03b..aa26d9670d 100644 --- a/application/Espo/ORM/Defs/Params/RelationParam.php +++ b/application/Espo/ORM/Defs/Params/RelationParam.php @@ -68,15 +68,14 @@ class RelationParam * Additional columns. */ public const ADDITIONAL_COLUMNS = 'additionalColumns'; + /** * A key. - * @todo */ public const KEY = 'key'; /** * A foreign key. - * @todo */ public const FOREIGN_KEY = 'foreignKey'; diff --git a/application/Espo/ORM/Defs/RelationDefs.php b/application/Espo/ORM/Defs/RelationDefs.php index abc8dd17c5..f3a8f5c8b3 100644 --- a/application/Espo/ORM/Defs/RelationDefs.php +++ b/application/Espo/ORM/Defs/RelationDefs.php @@ -203,7 +203,7 @@ class RelationDefs */ public function hasForeignKey(): bool { - return isset($this->data['foreignKey']); + return isset($this->data[RelationParam::FOREIGN_KEY]); } /** @@ -217,7 +217,7 @@ class RelationDefs throw new RuntimeException("No 'foreignKey' parameter defined in the relation '{$this->name}'."); } - return $this->data['foreignKey']; + return $this->data[RelationParam::FOREIGN_KEY]; } /** @@ -225,7 +225,7 @@ class RelationDefs */ public function hasKey(): bool { - return isset($this->data['key']); + return isset($this->data[RelationParam::KEY]); } /** @@ -238,7 +238,7 @@ class RelationDefs throw new RuntimeException("No 'key' parameter defined in the relation '{$this->name}'."); } - return $this->data['key']; + return $this->data[RelationParam::KEY]; } /** @@ -246,7 +246,7 @@ class RelationDefs */ public function hasMidKey(): bool { - return !is_null($this->data['midKeys'][0] ?? null); + return !is_null($this->data[RelationParam::MID_KEYS][0] ?? null); } /** @@ -260,7 +260,7 @@ class RelationDefs throw new RuntimeException("No 'midKey' parameter defined in the relation '{$this->name}'."); } - return $this->data['midKeys'][0]; + return $this->data[RelationParam::MID_KEYS][0]; } /** @@ -270,7 +270,7 @@ class RelationDefs */ public function hasForeignMidKey(): bool { - return !is_null($this->data['midKeys'][1] ?? null); + return !is_null($this->data[RelationParam::MID_KEYS][1] ?? null); } /** @@ -284,7 +284,7 @@ class RelationDefs throw new RuntimeException("No 'foreignMidKey' parameter defined in the relation '{$this->name}'."); } - return $this->data['midKeys'][1]; + return $this->data[RelationParam::MID_KEYS][1]; } /** diff --git a/application/Espo/Tools/LinkManager/LinkManager.php b/application/Espo/Tools/LinkManager/LinkManager.php index ca3dce65d9..dd57200bcf 100644 --- a/application/Espo/Tools/LinkManager/LinkManager.php +++ b/application/Espo/Tools/LinkManager/LinkManager.php @@ -38,6 +38,8 @@ 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\EntityParam; +use Espo\ORM\Defs\Params\FieldParam; use Espo\ORM\Defs\Params\RelationParam; use Espo\ORM\Entity; use Espo\ORM\Type\RelationType; @@ -510,23 +512,23 @@ class LinkManager } if ($entityForeign == $entity) { - $dataLeft['links'][$link]['midKeys'] = ['leftId', 'rightId']; - $dataRight['links'][$linkForeign]['midKeys'] = ['rightId', 'leftId']; + $dataLeft['links'][$link][RelationParam::MID_KEYS] = ['leftId', 'rightId']; + $dataRight['links'][$linkForeign][RelationParam::MID_KEYS] = ['rightId', 'leftId']; } break; case self::CHILDREN_TO_PARENT: $dataLeft = [ - 'fields' => [ + EntityParam::FIELDS => [ $link => [ - 'type' => FieldType::LINK_PARENT, + FieldParam::TYPE => FieldType::LINK_PARENT, 'entityList' => $params['parentEntityTypeList'] ?? null, ], ], 'links' => [ $link => [ - 'type' => Entity::BELONGS_TO_PARENT, + RelationParam::TYPE => Entity::BELONGS_TO_PARENT, 'foreign' => $linkForeign, 'isCustom' => true, ],