From 6bdd811e41e92a248761f70cadd979ef22856af3 Mon Sep 17 00:00:00 2001 From: Taras Machyshyn Date: Thu, 7 Nov 2013 17:31:21 +0200 Subject: [PATCH] get scope map from Metadata/scopes --- .gitignore | 6 ++ application/Espo/Controllers/Metadata.php | 5 +- application/Espo/Utils/BaseUtils.php | 34 +++-------- application/Espo/Utils/FileManager.php | 2 +- application/Espo/Utils/Metadata.php | 73 ++++++++++++++++------- 5 files changed, 70 insertions(+), 50 deletions(-) diff --git a/.gitignore b/.gitignore index e31f5993ca..1e01c1f017 100755 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,9 @@ data/cache/* application/config.php /test.php /test2.php +application/Espo/Metadata/scopes/CustomTest.json +application/Espo/Metadata/customTest/* +application/Espo/Layouts/customTest/* +application/Modules/Crm/Metadata/customTest/* +application/Modules/Crm/Layouts/customTest/* + diff --git a/application/Espo/Controllers/Metadata.php b/application/Espo/Controllers/Metadata.php index 9e357de33a..4c42c635d7 100644 --- a/application/Espo/Controllers/Metadata.php +++ b/application/Espo/Controllers/Metadata.php @@ -9,10 +9,9 @@ class Metadata extends Utils\Controllers\Controller public function read($params, $data) { - $metadata= new Utils\Metadata(); - $devMode= !$metadata->getObject('Configurator')->get('useCache'); + $metadata= new Utils\Metadata(); - $data= $metadata->getMetadata(true, $devMode); + $data= $metadata->getMetadata(true); return array($data, 'Cannot reach metadata data'); } diff --git a/application/Espo/Utils/BaseUtils.php b/application/Espo/Utils/BaseUtils.php index 010e7ad8de..1dfc04e1d5 100755 --- a/application/Espo/Utils/BaseUtils.php +++ b/application/Espo/Utils/BaseUtils.php @@ -14,7 +14,7 @@ class BaseUtils /** * @var array - scope list */ - protected $scopes= array(); + public $scopes= array(); /** @@ -80,33 +80,15 @@ class BaseUtils return $this->scopes; } + $metadata = new Utils\Metadata(); + $metadataList = $metadata->getMetadataOnly(false); - $this->scopes = array( - 'customTest' => '', - 'Attachment' => '', - 'Comment' => '', - 'Attachment' => '', - 'EmailTemplate' => '', - 'Role' => '', - 'Team' => '', - 'User' => '', - 'Product' => 'Crm', - 'Account' => 'Crm', - 'Contact' => 'Crm', - 'Lead' => 'Crm', - 'Opportunity' => 'Crm', - 'Calendar' => 'Crm', - 'Meeting' => 'Crm', - 'Call' => 'Crm', - 'Task' => 'Crm', - 'Case' => 'Crm', - 'Prospect' => 'Crm', - 'Email' => 'Crm', - 'emailTemplate' => 'Crm', - 'inboundEmail' => 'Crm', - ); + $scopes = array(); + foreach($metadataList['scopes'] as $name => $details) { + $scopes[$name] = isset($details['module']) ? $details['module'] : ''; + } - return $this->scopes; + return $this->scopes = $scopes; } diff --git a/application/Espo/Utils/FileManager.php b/application/Espo/Utils/FileManager.php index e215229e7d..b7291c8206 100755 --- a/application/Espo/Utils/FileManager.php +++ b/application/Espo/Utils/FileManager.php @@ -208,7 +208,7 @@ class FileManager extends BaseUtils * @param string $configParams - ["name", "cachePath", "corePath", "customPath"] * @param bool $recursively - Note: only for first level of sub directory, other levels of sub directories will be ignored * - * @return bool + * @return array */ public function uniteFiles($configParams, $recursively=false) { diff --git a/application/Espo/Utils/Metadata.php b/application/Espo/Utils/Metadata.php index fee465f54f..2caefbedb0 100755 --- a/application/Espo/Utils/Metadata.php +++ b/application/Espo/Utils/Metadata.php @@ -17,22 +17,30 @@ class Metadata extends FileManager * Get Metadata context * * @param $isJSON + * @param bool $reload + * * @return json | array */ //HERE --- ADD CREATING DOCTRINE METADATA - function getMetadata($isJSON=true, $reload=false) + public function getMetadata($isJSON=true, $reload=false) { $config= $this->getConfig(); - if (!file_exists($config->cacheFile) || $reload) { - $result= $this->uniteFiles($config, true); + if (!$this->getObject('Configurator')->get('useCache')) { + $reload = true; + } - if ($result===false) { - $this->getObject('Log')->add('FATAL', 'Metadata:getMetadata() - metadata unite file cannot be created'); + if (!file_exists($config->cacheFile) || $reload) { + $data= $this->getMetadataOnly(false, true); + if ($data === false) { + return false; } + //save medatada to cache files + $this->setContentPHP($data, $this->getConfig()->cacheFile); + $this->getObject('Log')->add('Debug', 'Metadata:getMetadata() - converting to doctrine metadata'); - if ($this->convertToDoctrine($this->getContent($config->cacheFile))) { + if ($this->convertToDoctrine($data)) { $this->getObject('Log')->add('Debug', 'Metadata:getMetadata() - database rebuild'); try{ @@ -43,19 +51,49 @@ class Metadata extends FileManager } } - if (file_exists($config->cacheFile)) { - $data= $this->getContent($config->cacheFile); - if ($isJSON) { - $data= $this->getObject('JSON')->encode($data); - } + return $this->getMetadataOnly($isJSON, false); + } - return $data; + + + /** + * Get Metadata only without saving it to the a file and database sync + * + * @param $isJSON + * @param bool $reload + * + * @return json | array + */ + + public function getMetadataOnly($isJSON=true, $reload=false) + { + $config= $this->getConfig(); + + if (!$this->getObject('Configurator')->get('useCache')) { + $reload = true; } - return false; + $data = false; + if (!file_exists($config->cacheFile) || $reload) { + $data= $this->uniteFiles($config, true); + + if ($data === false) { + $this->getObject('Log')->add('FATAL', 'Metadata:getMetadata() - metadata unite file cannot be created'); + } + } + else if (file_exists($config->cacheFile)) { + $data= $this->getContent($config->cacheFile); + } + + if ($isJSON) { + $data= $this->getObject('JSON')->encode($data); + } + + return $data; } + /** * Set Metadata data * Ex. $type= menu, $scope= Account then will be created a file metadataFolder/menu/Account.json @@ -199,7 +237,7 @@ class Metadata extends FileManager * @param string $configParams - ["name", "cachePath", "corePath", "customPath"] * @param bool $recursively - Note: only for first level of sub directory, other levels of sub directories will be ignored * - * @return bool + * @return array */ function uniteFiles($configParams, $recursively=false) { @@ -217,16 +255,11 @@ class Metadata extends FileManager foreach($dirList as $dirName) { $curPath= str_replace('{*}', $dirName, $configParams->customPath); $content= $this->merge($content, $this->uniteFilesSingle($curPath, $configParams->name, $recursively, $dirName)); - - //print_r($content ); } } - //END: merge matadata files - //save medatada to cache files - return $this->setContentPHP($content, $this->getConfig()->cacheFile); - //END: save medatada to cache files + return $content; } /**