This commit is contained in:
Yuri Kuznetsov
2024-11-15 12:42:53 +02:00
parent 055322ae90
commit 2ffbea5b52
8 changed files with 28 additions and 26 deletions
+1 -1
View File
@@ -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;
@@ -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,
]
]
@@ -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);
@@ -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]);
}
/**
@@ -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();
@@ -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';
+8 -8
View File
@@ -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];
}
/**
@@ -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,
],