diff --git a/application/Espo/Controllers/Metadata.php b/application/Espo/Controllers/Metadata.php index cd97e3bdd4..e53737ae1b 100644 --- a/application/Espo/Controllers/Metadata.php +++ b/application/Espo/Controllers/Metadata.php @@ -7,6 +7,6 @@ class Metadata extends \Espo\Core\Controllers\Base public function actionRead($params, $data) { - return $this->getMetadata()->get(true); + return $this->getMetadata()->getAll(true); } } diff --git a/application/Espo/Core/Doctrine/EspoConverter.php b/application/Espo/Core/Doctrine/EspoConverter.php index 9db0af48d4..d68a9ae361 100644 --- a/application/Espo/Core/Doctrine/EspoConverter.php +++ b/application/Espo/Core/Doctrine/EspoConverter.php @@ -27,11 +27,7 @@ class EspoConverter $this->metadata = $metadata; $this->fileManager = $fileManager; - $this->schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->getEntityManager()); - $this->entityGenerator = new \Doctrine\ORM\Tools\EntityGenerator(); - - $this->disconnectedClassMetadataFactory = new \Doctrine\ORM\Tools\DisconnectedClassMetadataFactory(); - $this->disconnectedClassMetadataFactory->setEntityManager($this->getEntityManager()); // $em is EntityManager instance + $this->doctrineHelper = new \Espo\Core\Doctrine\Helper($this->getEntityManager()->getWrapped()); } protected function getEntityManager() @@ -101,7 +97,7 @@ class EspoConverter { $GLOBALS['log']->add('Debug', 'Metadata:get() - converting to doctrine metadata'); - $meta = $this->getMetadata()->get(); + $meta = $this->getMetadata()->getAll(); return; //TODO $this->setMeta($meta); diff --git a/application/Espo/Core/Doctrine/Helper.php b/application/Espo/Core/Doctrine/Helper.php index 7b60f88cd8..5a2a75efc6 100644 --- a/application/Espo/Core/Doctrine/Helper.php +++ b/application/Espo/Core/Doctrine/Helper.php @@ -6,9 +6,22 @@ class Helper { private $entityManager; + private $schemaTool; + + private $disconnectedClassMetadataFactory; + + private $entityGenerator; + + public function __construct(\Espo\Core\EntityManager $entityManager) { $this->entityManager = $entityManager; + + $this->schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->getEntityManager()); + $this->entityGenerator = new \Doctrine\ORM\Tools\EntityGenerator(); + + $this->disconnectedClassMetadataFactory = new \Doctrine\ORM\Tools\DisconnectedClassMetadataFactory(); + $this->disconnectedClassMetadataFactory->setEntityManager($this->getEntityManager()); // $em is EntityManager instance } protected function getEntityManager() @@ -16,5 +29,20 @@ class Helper return $this->entityManager; } + protected function getSchemaTool() + { + return $this->schemaTool; + } + + protected function getDisconnectedClassMetadataFactory() + { + return $this->disconnectedClassMetadataFactory; + } + + protected function getEntityGenerator() + { + return $this->entityGenerator; + } + } \ No newline at end of file diff --git a/application/Espo/Core/Utils/Metadata.php b/application/Espo/Core/Utils/Metadata.php index a34fa18d30..7d56ea02b7 100644 --- a/application/Espo/Core/Utils/Metadata.php +++ b/application/Espo/Core/Utils/Metadata.php @@ -76,14 +76,43 @@ class Metadata /** - * Get Metadata context + * Get Metadata + * + * @param string $key + * @param mixed $return + * + * @return array + */ + public function get($key = '', $returns = null) + { + if (empty($key)) { + return $this->meta; + } + + $keys = explode('.', $key); + + $lastMeta = $this->meta; + foreach($keys as $keyName) { + if (isset($lastMeta[$keyName]) && is_array($lastMeta)) { + $lastMeta = $lastMeta[$keyName]; + } else { + return $returns; + } + } + + return $lastMeta; + } + + + /** + * Get All Metadata context * * @param $isJSON * @param bool $reload * * @return json | array */ - public function get($isJSON = false, $reload = false) + public function getAll($isJSON = false, $reload = false) { if ($reload) { $this->init();