diff --git a/application/Espo/Core/Templates/Metadata/Event/selectDefs.json b/application/Espo/Core/Templates/Metadata/Event/selectDefs.json new file mode 100644 index 0000000000..217d8b6594 --- /dev/null +++ b/application/Espo/Core/Templates/Metadata/Event/selectDefs.json @@ -0,0 +1,8 @@ +{ + "selectAttributesDependancyMap": { + "duration": [ + "dateStart", + "dateEnd" + ] + } +} \ No newline at end of file diff --git a/application/Espo/Tools/EntityManager/EntityManager.php b/application/Espo/Tools/EntityManager/EntityManager.php index 69f5264b42..4414a01eee 100644 --- a/application/Espo/Tools/EntityManager/EntityManager.php +++ b/application/Espo/Tools/EntityManager/EntityManager.php @@ -477,6 +477,8 @@ class EntityManager } $this->getMetadata()->set('clientDefs', $name, $clientDefsData); + $this->processMetadataCreateSelectDefs($templatePath, $name, $type); + $this->getBaseLanguage()->set('Global', 'scopeNames', $name, $labelSingular); $this->getBaseLanguage()->set('Global', 'scopeNamesPlural', $name, $labelPlural); @@ -493,6 +495,21 @@ class EntityManager return true; } + private function processMetadataCreateSelectDefs(string $templatePath, string $name, string $type): void + { + $path = $templatePath . "/Metadata/{$type}/selectDefs.json"; + + if (!$this->getFileManager()->isFile($path)) { + return; + } + + $contents = $this->getFileManager()->getContents($path); + + $data = Json::decode($contents, true); + + $this->getMetadata()->set('selectDefs', $name, $data); + } + public function update($name, $data) { if (!$this->getMetadata()->get('scopes.' . $name)) { diff --git a/upgrades/6.2/scripts/AfterUpgrade.php b/upgrades/6.2/scripts/AfterUpgrade.php index 434ba5c161..9c269226e0 100644 --- a/upgrades/6.2/scripts/AfterUpgrade.php +++ b/upgrades/6.2/scripts/AfterUpgrade.php @@ -27,13 +27,20 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ +use Espo\Core\Container; +use Espo\Core\Utils\Metadata; +use Espo\Core\Utils\File\Manager as FileManager; +use Espo\Core\Utils\Json; + class AfterUpgrade { - public function run($container) + public function run(Container $container): void { $entityManager = $container->get('entityManager'); $this->updateTemplates($entityManager); + + $this->updateEventMetadata($container->get('metadata'), $container->get('fileManager')); } protected function updateTemplates($entityManager) @@ -56,4 +63,34 @@ class AfterUpgrade $entityManager->saveEntity($template); } } + + private function updateEventMetadata(Metadata $metadata, FileManager $fileManager): void + { + $defs = $metadata->get(['scopes']); + + $toSave = false; + + $path = "application/Espo/Core/Templates/Metadata/Event/selectDefs.json"; + + $contents = $fileManager->getContents($path); + + $data = Json::decode($contents, true); + + foreach ($defs as $entityType => $item) { + $isCustom = $item['isCustom'] ?? false; + $type = $item['type'] ?? false; + + if (!$isCustom || $type !== 'Event') { + continue; + } + + $toSave = true; + + $metadata->set('selectDefs', $entityType, $data); + } + + if ($toSave) { + $metadata->save(); + } + } }