mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 06:56:05 +00:00
added clear cache for 'rebuild', added DataManager
This commit is contained in:
@@ -30,37 +30,22 @@ class Admin extends \Espo\Core\Controllers\Base
|
||||
protected function checkGlobalAccess()
|
||||
{
|
||||
if (!$this->getUser()->isAdmin()) {
|
||||
throw new Forbidden();
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
|
||||
public function actionRebuild($params, $data)
|
||||
public function actionRebuild($params, $data)
|
||||
{
|
||||
try {
|
||||
$result = $this->getContainer()->get('schema')->rebuild();
|
||||
} catch (\Exception $e) {
|
||||
$result = false;
|
||||
$GLOBALS['log']->error('Fault to rebuild database schema'.'. Details: '.$e->getMessage());
|
||||
}
|
||||
$result = $this->getContainer()->get('dataManager')->rebuild();
|
||||
|
||||
if ($result === false) {
|
||||
throw new Error("Error while rebuilding database");
|
||||
}
|
||||
|
||||
return json_encode($result);
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function actionClearCache($params, $data)
|
||||
{
|
||||
$cacheDir = $this->getContainer()->get('config')->get('cachePath');
|
||||
$result = $this->getContainer()->get('dataManager')->clearCache();
|
||||
|
||||
$result = $this->getContainer()->get('fileManager')->removeInDir($cacheDir);
|
||||
|
||||
if ($result === false) {
|
||||
throw new Error("Error while clearing cache");
|
||||
}
|
||||
|
||||
return json_encode($result);
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function actionJobs()
|
||||
|
||||
@@ -193,6 +193,13 @@ class Container
|
||||
);
|
||||
}
|
||||
|
||||
private function loadDataManager()
|
||||
{
|
||||
return new \Espo\Core\DataManager(
|
||||
$this
|
||||
);
|
||||
}
|
||||
|
||||
public function setUser($user)
|
||||
{
|
||||
$this->data['user'] = $user;
|
||||
|
||||
111
application/Espo/Core/DataManager.php
Normal file
111
application/Espo/Core/DataManager.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: http://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core;
|
||||
|
||||
class DataManager
|
||||
{
|
||||
private $container;
|
||||
|
||||
public function __construct(Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
protected function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuild the system with metadata, database and cache clearing
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function rebuild()
|
||||
{
|
||||
$result = $this->clearCache();
|
||||
|
||||
$result &= $this->rebuildMetadata();
|
||||
|
||||
$result &= $this->rebuildDatabase();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear a cache
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function clearCache()
|
||||
{
|
||||
$cacheDir = $this->getContainer()->get('config')->get('cachePath');
|
||||
|
||||
$result = $this->getContainer()->get('fileManager')->removeInDir($cacheDir);
|
||||
|
||||
if ($result === false) {
|
||||
throw new Error("Error while clearing cache");
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuild database
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function rebuildDatabase()
|
||||
{
|
||||
try {
|
||||
$result = $this->getContainer()->get('schema')->rebuild();
|
||||
} catch (\Exception $e) {
|
||||
$result = false;
|
||||
$GLOBALS['log']->error('Fault to rebuild database schema'.'. Details: '.$e->getMessage());
|
||||
}
|
||||
|
||||
if ($result === false) {
|
||||
throw new Error("Error while rebuilding database");
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuild metadata
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function rebuildMetadata()
|
||||
{
|
||||
$metadata = $this->getContainer()->get('metadata');
|
||||
|
||||
$metadata->init(true);
|
||||
|
||||
$ormMeta = $metadata->getOrmMetadata(true);
|
||||
|
||||
return empty($ormMeta) ? false : true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -18,7 +18,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Utils\File;
|
||||
|
||||
@@ -103,16 +103,16 @@ class Manager
|
||||
* Convert file list to a single array
|
||||
*
|
||||
* @param aray $fileList
|
||||
* @param string $parentDirName
|
||||
* @param string $parentDirName
|
||||
*
|
||||
* @return aray
|
||||
*/
|
||||
protected function getSingeFileList(array $fileList, $parentDirName = '')
|
||||
{
|
||||
$singleFileList = array();
|
||||
foreach($fileList as $dirName => $fileName) {
|
||||
|
||||
if (is_array($fileName)) {
|
||||
foreach($fileList as $dirName => $fileName) {
|
||||
|
||||
if (is_array($fileName)) {
|
||||
$currentDir = Utils\Util::concatPath($parentDirName, $dirName);
|
||||
$singleFileList = array_merge($singleFileList, $this->getSingeFileList($fileName, $currentDir));
|
||||
} else {
|
||||
@@ -125,17 +125,17 @@ class Manager
|
||||
|
||||
/**
|
||||
* Reads entire file into a string
|
||||
*
|
||||
* @param string | array $paths Ex. 'path.php' OR array('dir', 'path.php')
|
||||
* @param boolean $useIncludePath
|
||||
* @param resource $context
|
||||
* @param integer $offset
|
||||
* @param integer $maxlen
|
||||
* @return mixed
|
||||
*
|
||||
* @param string | array $path Ex. 'path.php' OR array('dir', 'path.php')
|
||||
* @param boolean $useIncludePath
|
||||
* @param resource $context
|
||||
* @param integer $offset
|
||||
* @param integer $maxlen
|
||||
* @return mixed
|
||||
*/
|
||||
public function getContents($paths, $useIncludePath = false, $context = null, $offset = -1, $maxlen = null)
|
||||
public function getContents($path, $useIncludePath = false, $context = null, $offset = -1, $maxlen = null)
|
||||
{
|
||||
$fullPath = $this->concatPaths($paths);
|
||||
$fullPath = $this->concatPaths($path);
|
||||
|
||||
if (file_exists($fullPath)) {
|
||||
|
||||
@@ -145,79 +145,81 @@ class Manager
|
||||
if (isset($maxlen)) {
|
||||
return file_get_contents($fullPath, $useIncludePath, $context, $offset, $maxlen);
|
||||
} else {
|
||||
return file_get_contents($fullPath, $useIncludePath, $context, $offset);
|
||||
}
|
||||
return file_get_contents($fullPath, $useIncludePath, $context, $offset);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Write data to a file
|
||||
*
|
||||
* @param string | array $paths
|
||||
* @param mixed $data
|
||||
* @param integer $flags
|
||||
* @param resource $context
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @param string | array $path
|
||||
* @param mixed $data
|
||||
* @param integer $flags
|
||||
* @param resource $context
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function putContents($paths, $data, $flags = 0, $context = null)
|
||||
public function putContents($path, $data, $flags = 0, $context = null)
|
||||
{
|
||||
$fullPath = $this->concatPaths($paths); //todo remove after changing the params
|
||||
$fullPath = $this->concatPaths($path); //todo remove after changing the params
|
||||
|
||||
if ($this->checkCreateFile($fullPath) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (file_put_contents($fullPath, $data, $flags, $context) !== FALSE);
|
||||
return (file_put_contents($fullPath, $data, $flags, $context) !== FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save PHP content to file
|
||||
*
|
||||
* @param string | array $paths
|
||||
* @param string $data
|
||||
* @param string | array $path
|
||||
* @param string $data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function putContentsPHP($paths, $data)
|
||||
public function putContentsPHP($path, $data)
|
||||
{
|
||||
return $this->putContents($paths, $this->getPHPFormat($data));
|
||||
return $this->putContents($path, $this->getPHPFormat($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Save JSON content to file
|
||||
*
|
||||
* @param string | array $paths
|
||||
* @param string | array $path
|
||||
* @param string $data
|
||||
* @param integer $flags
|
||||
* @param resource $context
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function putContentsJSON($paths, $data)
|
||||
public function putContentsJSON($path, $data)
|
||||
{
|
||||
if (!Utils\Json::isJSON($data)) {
|
||||
$data= Utils\Json::encode($data);
|
||||
$data = Utils\Json::encode($data);
|
||||
}
|
||||
|
||||
return $this->putContents($paths, $data);
|
||||
return $this->putContents($path, $data, JSON_PRETTY_PRINT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge file content and save it to a file
|
||||
*
|
||||
* @param string | array $paths
|
||||
* @param string | array $path
|
||||
* @param string $content JSON string
|
||||
* @param bool $isJSON
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function mergeContents($paths, $content, $isJSON = false)
|
||||
public function mergeContents($path, $content, $isJSON = false)
|
||||
{
|
||||
$fileContent= $this->getContents($paths);
|
||||
$fileContent = $this->getContents($path);
|
||||
|
||||
$savedDataArray= $this->getArrayData($fileContent);
|
||||
$newDataArray= $this->getArrayData($content);
|
||||
@@ -227,21 +229,21 @@ class Manager
|
||||
$data= Utils\Json::encode($data);
|
||||
}
|
||||
|
||||
return $this->putContents($paths, $data, JSON_PRETTY_PRINT);
|
||||
return $this->putContents($path, $data, JSON_PRETTY_PRINT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge PHP content and save it to a file
|
||||
*
|
||||
* @param string | array $paths
|
||||
* @param string | array $path
|
||||
* @param string $content
|
||||
* @param bool $onlyFirstLevel - Merge only first level. Ex. current: array('test'=>array('item1', 'item2')). $content= array('test'=>array('item1'),). Result will be array('test'=>array('item1')).
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function mergeContentsPHP($paths, $content, $onlyFirstLevel= false)
|
||||
public function mergeContentsPHP($path, $content, $onlyFirstLevel= false)
|
||||
{
|
||||
$fileContent= $this->getContents($paths);
|
||||
$fileContent = $this->getContents($path);
|
||||
|
||||
$savedDataArray= $this->getArrayData($fileContent);
|
||||
$newDataArray= $this->getArrayData($content);
|
||||
@@ -255,20 +257,41 @@ class Manager
|
||||
|
||||
$data= Utils\Util::merge($savedDataArray, $newDataArray);
|
||||
|
||||
return $this->putContentsPHP($paths, $data);
|
||||
return $this->putContentsPHP($path, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append the content to the end of the file
|
||||
*
|
||||
* @param string | array $paths
|
||||
* @param string | array $path
|
||||
* @param mixed $data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function appendContents($paths, $data)
|
||||
public function appendContents($path, $data)
|
||||
{
|
||||
return $this->putContents($paths, $data, FILE_APPEND | LOCK_EX);
|
||||
return $this->putContents($path, $data, FILE_APPEND | LOCK_EX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset some element of content data
|
||||
*
|
||||
* @param string | array $path
|
||||
* @param array | string $unsets [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function unsetContents($path, $unsets)
|
||||
{
|
||||
$currentData = $this->getContents($path);
|
||||
|
||||
$currentDataArray= $this->getArrayData($currentData);
|
||||
if (!is_array($currentDataArray)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$unsettedData = Utils\Util::unsetInArray($currentData, $unsets);
|
||||
|
||||
return $this->putContents($path, $unsettedData);
|
||||
}
|
||||
|
||||
|
||||
@@ -293,8 +316,8 @@ class Manager
|
||||
|
||||
/**
|
||||
* Create a new dir
|
||||
*
|
||||
* @param string | array $path
|
||||
*
|
||||
* @param string | array $path
|
||||
* @param int $permission - ex. 0755
|
||||
* @return bool
|
||||
*/
|
||||
@@ -307,18 +330,18 @@ class Manager
|
||||
}
|
||||
|
||||
if (!isset($permission)) {
|
||||
$defaultPermissions = $this->getPermissionUtils()->getDefaultPermissions();
|
||||
$defaultPermissions = $this->getPermissionUtils()->getDefaultPermissions();
|
||||
$permission = (string) $defaultPermissions['dir'];
|
||||
$permission = base_convert($permission, 8, 10);
|
||||
$permission = base_convert($permission, 8, 10);
|
||||
}
|
||||
|
||||
try {
|
||||
$result = mkdir($fullPath, $permission, true);
|
||||
} catch (\Exception $e) {
|
||||
$GLOBALS['log']->critical('Permission denied: unable to generate a folder on the server - '.$fullPath);
|
||||
} catch (\Exception $e) {
|
||||
$GLOBALS['log']->critical('Permission denied: unable to generate a folder on the server - '.$fullPath);
|
||||
}
|
||||
|
||||
return isset($result) ? $result : false;
|
||||
return isset($result) ? $result : false;
|
||||
}
|
||||
|
||||
|
||||
@@ -357,7 +380,7 @@ class Manager
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove all files in defined directory
|
||||
*
|
||||
@@ -390,7 +413,7 @@ class Manager
|
||||
*
|
||||
* @param string $dirPath - directory path
|
||||
* @param bool $removeWithDir - if remove with directory
|
||||
*
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function removeInDir($dirPath, $removeWithDir = false)
|
||||
@@ -398,21 +421,21 @@ class Manager
|
||||
$fileList= $this->getFileList($dirPath, false);
|
||||
|
||||
$result = true;
|
||||
foreach ($fileList as $file) {
|
||||
foreach ($fileList as $file) {
|
||||
$fullPath = Utils\Util::concatPath($dirPath, $file);
|
||||
if (is_dir($fullPath)) {
|
||||
$result &= $this->removeInDir($fullPath, true);
|
||||
} else {
|
||||
$result &= unlink($fullPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($removeWithDir) {
|
||||
rmdir($dirPath);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** //TODO remove
|
||||
@@ -444,7 +467,7 @@ class Manager
|
||||
* @return array
|
||||
*/
|
||||
public function getFileName($fileName, $ext='')
|
||||
{
|
||||
{
|
||||
if (empty($ext)) {
|
||||
$fileName= substr($fileName, 0, strrpos($fileName, '.', -1));
|
||||
}
|
||||
@@ -458,7 +481,7 @@ class Manager
|
||||
}
|
||||
}
|
||||
|
||||
$exFileName = explode('/', Utils\Util::toFormat($fileName, '/'));
|
||||
$exFileName = explode('/', Utils\Util::toFormat($fileName, '/'));
|
||||
|
||||
return end($exFileName);
|
||||
}
|
||||
@@ -473,16 +496,16 @@ class Manager
|
||||
* @return array
|
||||
*/
|
||||
public function getDirName($path, $isFullPath = true)
|
||||
{
|
||||
{
|
||||
$pathInfo = pathinfo($path);
|
||||
|
||||
if (!$isFullPath) {
|
||||
$pieces = explode('/', $pathInfo['dirname']);
|
||||
|
||||
return $pieces[count($pieces)-1];
|
||||
return $pieces[count($pieces)-1];
|
||||
}
|
||||
|
||||
return $pathInfo['dirname'];
|
||||
return $pathInfo['dirname'];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -18,13 +18,13 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Utils;
|
||||
|
||||
class Metadata
|
||||
{
|
||||
protected $meta = null;
|
||||
protected $meta = null;
|
||||
|
||||
protected $scopes = array();
|
||||
|
||||
@@ -34,17 +34,17 @@ class Metadata
|
||||
private $converter;
|
||||
|
||||
/**
|
||||
* @var string - uses for loading default values
|
||||
*/
|
||||
* @var string - uses for loading default values
|
||||
*/
|
||||
private $name = 'metadata';
|
||||
|
||||
private $cacheFile = 'data/cache/application/metadata.php';
|
||||
private $cacheFile = 'data/cache/application/metadata.php';
|
||||
|
||||
private $paths = array(
|
||||
'corePath' => 'application/Espo/Resources/metadata',
|
||||
'modulePath' => 'application/Espo/Modules/{*}/Resources/metadata',
|
||||
'customPath' => 'custom/Espo/Custom/Resources/metadata',
|
||||
);
|
||||
'modulePath' => 'application/Espo/Modules/{*}/Resources/metadata',
|
||||
'customPath' => 'custom/Espo/Custom/Resources/metadata',
|
||||
);
|
||||
|
||||
|
||||
protected $ormMeta = null;
|
||||
@@ -52,7 +52,7 @@ class Metadata
|
||||
private $ormCacheFile = 'data/cache/application/ormMetadata.php';
|
||||
|
||||
|
||||
|
||||
|
||||
private $moduleList = null;
|
||||
|
||||
public function __construct(\Espo\Core\Utils\Config $config, \Espo\Core\Utils\File\Manager $fileManager)
|
||||
@@ -62,8 +62,8 @@ class Metadata
|
||||
|
||||
$this->unifier = new \Espo\Core\Utils\File\Unifier($this->fileManager);
|
||||
|
||||
$this->converter = new \Espo\Core\Utils\Database\Converter($this, $this->fileManager);
|
||||
|
||||
$this->converter = new \Espo\Core\Utils\Database\Converter($this, $this->fileManager);
|
||||
|
||||
$this->init(!$this->isCached());
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ class Metadata
|
||||
return $this->unifier;
|
||||
}
|
||||
|
||||
protected function getFileManager()
|
||||
protected function getFileManager()
|
||||
{
|
||||
return $this->fileManager;
|
||||
}
|
||||
@@ -91,10 +91,10 @@ class Metadata
|
||||
|
||||
public function isCached()
|
||||
{
|
||||
if (!$this->getConfig()->get('useCache')) {
|
||||
return false;
|
||||
if (!$this->getConfig()->get('useCache')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (file_exists($this->cacheFile)) {
|
||||
return true;
|
||||
}
|
||||
@@ -103,9 +103,9 @@ class Metadata
|
||||
}
|
||||
|
||||
|
||||
public function init($reload = false)
|
||||
public function init($reload = false)
|
||||
{
|
||||
$data = $this->getMetadataOnly(false, $reload);
|
||||
$data = $this->getMetadataOnly(false, $reload);
|
||||
if ($data === false) {
|
||||
$GLOBALS['log']->emergency('Metadata:init() - metadata has not been created');
|
||||
}
|
||||
@@ -113,17 +113,17 @@ class Metadata
|
||||
$this->meta = $data;
|
||||
|
||||
if ($reload) {
|
||||
//save medatada to a cache file
|
||||
$isSaved = $this->getFileManager()->putContentsPHP($this->cacheFile, $data);
|
||||
//save medatada to a cache file
|
||||
$isSaved = $this->getFileManager()->putContentsPHP($this->cacheFile, $data);
|
||||
if ($isSaved === false) {
|
||||
$GLOBALS['log']->emergency('Metadata:init() - metadata has not been saved to a cache file');
|
||||
$GLOBALS['log']->emergency('Metadata:init() - metadata has not been saved to a cache file');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get unified metadata
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getData()
|
||||
@@ -137,7 +137,7 @@ class Metadata
|
||||
|
||||
|
||||
/**
|
||||
* Get Metadata
|
||||
* Get Metadata
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $return
|
||||
@@ -146,12 +146,12 @@ class Metadata
|
||||
*/
|
||||
public function get($key = null, $returns = null)
|
||||
{
|
||||
return Util::getValueByKey($this->getData(), $key, $returns);
|
||||
return Util::getValueByKey($this->getData(), $key, $returns);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get All Metadata context
|
||||
* Get All Metadata context
|
||||
*
|
||||
* @param $isJSON
|
||||
* @param bool $reload
|
||||
@@ -165,15 +165,15 @@ class Metadata
|
||||
}
|
||||
|
||||
if ($isJSON) {
|
||||
return Json::encode($this->meta);
|
||||
}
|
||||
return Json::encode($this->meta);
|
||||
}
|
||||
return $this->meta;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get Metadata only without saving it to the a file and database sync
|
||||
* Get Metadata only without saving it to the a file and database sync
|
||||
*
|
||||
* @param $isJSON
|
||||
* @param bool $reload
|
||||
@@ -184,36 +184,36 @@ class Metadata
|
||||
{
|
||||
$data = false;
|
||||
if (!file_exists($this->cacheFile) || $reload) {
|
||||
$data = $this->getUnifier()->unify($this->name, $this->paths, true);
|
||||
$data = $this->getUnifier()->unify($this->name, $this->paths, true);
|
||||
|
||||
if ($data === false) {
|
||||
$GLOBALS['log']->emergency('Metadata:getMetadata() - metadata unite file cannot be created');
|
||||
$GLOBALS['log']->emergency('Metadata:getMetadata() - metadata unite file cannot be created');
|
||||
}
|
||||
|
||||
$data = $this->setLanguageFromConfig($data);
|
||||
$data = $this->setLanguageFromConfig($data);
|
||||
}
|
||||
else if (file_exists($this->cacheFile)) {
|
||||
else if (file_exists($this->cacheFile)) {
|
||||
$data = $this->getFileManager()->getContents($this->cacheFile);
|
||||
}
|
||||
|
||||
if ($isJSON) {
|
||||
$data = Json::encode($data);
|
||||
}
|
||||
$data = Json::encode($data);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set language list and default for Settings, Preferences metadata
|
||||
*
|
||||
*
|
||||
* @param array $data Meta
|
||||
* @return array $data
|
||||
*/
|
||||
protected function setLanguageFromConfig($data)
|
||||
{
|
||||
$entityList = array(
|
||||
'Settings',
|
||||
'Preferences',
|
||||
'Settings',
|
||||
'Preferences',
|
||||
);
|
||||
|
||||
$languageList = $this->getConfig()->get('languageList');
|
||||
@@ -221,20 +221,19 @@ class Metadata
|
||||
|
||||
foreach ($entityList as $entityName) {
|
||||
if (isset($data['entityDefs'][$entityName]['fields']['language'])) {
|
||||
$data['entityDefs'][$entityName]['fields']['language']['options'] = $languageList;
|
||||
$data['entityDefs'][$entityName]['fields']['language']['default'] = $language;
|
||||
}
|
||||
$data['entityDefs'][$entityName]['fields']['language']['options'] = $languageList;
|
||||
$data['entityDefs'][$entityName]['fields']['language']['default'] = $language;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Set Metadata data
|
||||
* Ex. $type= menu, $scope= Account then will be created a file metadataFolder/menu/Account.json
|
||||
*
|
||||
*
|
||||
* @param JSON string $data
|
||||
* @param string $type - ex. menu
|
||||
* @param string $scope - Account
|
||||
@@ -243,39 +242,39 @@ class Metadata
|
||||
*/
|
||||
public function set($data, $type, $scope)
|
||||
{
|
||||
$path = $this->paths['corePath'];
|
||||
$moduleName = $this->getScopeModuleName($scope);
|
||||
$path = $this->paths['customPath'];
|
||||
|
||||
if ($moduleName !== false) {
|
||||
$path = str_replace('{*}', $moduleName, $this->paths['modulePath']);
|
||||
}
|
||||
if (file_exists($path)) {
|
||||
$result = $this->getFileManager()->mergeContents(array($path, $type, $scope.'.json'), $data, true);
|
||||
} else {
|
||||
$result = $this->getFileManager()->putContentsJSON(array($path, $type, $scope.'.json'), $data);
|
||||
}
|
||||
|
||||
$result= $this->getFileManager()->mergeContents(array($path, $type, $scope.'.json'), $data, true);
|
||||
$this->init(true);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
public function getOrmMetadata()
|
||||
public function getOrmMetadata($reload = false)
|
||||
{
|
||||
if (!empty($this->ormMeta)) {
|
||||
if (!empty($this->ormMeta) && !$reload) {
|
||||
return $this->ormMeta;
|
||||
}
|
||||
|
||||
if (!file_exists($this->ormCacheFile) || !$this->getConfig()->get('useCache')) {
|
||||
$this->getConverter()->process();
|
||||
if (!file_exists($this->ormCacheFile) || !$this->getConfig()->get('useCache') || $reload) {
|
||||
$this->getConverter()->process();
|
||||
}
|
||||
|
||||
$this->ormMeta = $this->getFileManager()->getContents($this->ormCacheFile);
|
||||
|
||||
return $this->ormMeta;
|
||||
return $this->ormMeta;
|
||||
}
|
||||
|
||||
public function setOrmMetadata(array $ormMeta)
|
||||
{
|
||||
$result = $this->getFileManager()->putContentsPHP($this->ormCacheFile, $ormMeta);
|
||||
if ($result == false) {
|
||||
throw new \Espo\Core\Exceptions\Error('Metadata::setOrmMetadata() - Cannot save ormMetadata to a file');
|
||||
if ($result == false) {
|
||||
throw new \Espo\Core\Exceptions\Error('Metadata::setOrmMetadata() - Cannot save ormMetadata to a file');
|
||||
}
|
||||
|
||||
$this->ormMeta = $ormMeta;
|
||||
@@ -283,10 +282,9 @@ class Metadata
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Entity path, ex. Espo.Entities.Account or Modules\Crm\Entities\MyModule
|
||||
*
|
||||
/**
|
||||
* Get Entity path, ex. Espo.Entities.Account or Modules\Crm\Entities\MyModule
|
||||
*
|
||||
* @param string $entityName
|
||||
* @param bool $delim - delimiter
|
||||
*
|
||||
@@ -298,7 +296,7 @@ class Metadata
|
||||
|
||||
return implode($delim, array($path, 'Entities', Util::normilizeClassName(ucfirst($entityName))));
|
||||
}
|
||||
|
||||
|
||||
public function getRepositoryPath($entityName, $delim = '\\')
|
||||
{
|
||||
$path = $this->getScopePath($entityName, $delim);
|
||||
@@ -308,29 +306,29 @@ class Metadata
|
||||
|
||||
|
||||
/**
|
||||
* Get Scopes
|
||||
* Get Scopes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getScopes()
|
||||
{
|
||||
if (!empty($this->scopes)) {
|
||||
return $this->scopes;
|
||||
}
|
||||
if (!empty($this->scopes)) {
|
||||
return $this->scopes;
|
||||
}
|
||||
|
||||
$metadata = $this->getMetadataOnly(false);
|
||||
|
||||
$scopes = array();
|
||||
$scopes = array();
|
||||
foreach ($metadata['scopes'] as $name => $details) {
|
||||
$scopes[$name] = isset($details['module']) ? $details['module'] : false;
|
||||
$scopes[$name] = isset($details['module']) ? $details['module'] : false;
|
||||
}
|
||||
|
||||
return $this->scopes = $scopes;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Module List
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getModuleList()
|
||||
@@ -353,7 +351,7 @@ class Metadata
|
||||
|
||||
|
||||
/**
|
||||
* Get module name if it's a custom module or empty string for core entity
|
||||
* Get module name if it's a custom module or empty string for core entity
|
||||
*
|
||||
* @param string $scopeName
|
||||
*
|
||||
@@ -361,13 +359,13 @@ class Metadata
|
||||
*/
|
||||
public function getScopeModuleName($scopeName)
|
||||
{
|
||||
return $this->get('scopes.' . $scopeName . '.module', false);
|
||||
return $this->get('scopes.' . $scopeName . '.module', false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Scope path, ex. "Modules/Crm" for Account
|
||||
*
|
||||
* Get Scope path, ex. "Modules/Crm" for Account
|
||||
*
|
||||
* @param string $scopeName
|
||||
* @param string $delim - delimiter
|
||||
*
|
||||
@@ -375,19 +373,19 @@ class Metadata
|
||||
*/
|
||||
public function getScopePath($scopeName, $delim = '/')
|
||||
{
|
||||
$moduleName = $this->getScopeModuleName($scopeName);
|
||||
$moduleName = $this->getScopeModuleName($scopeName);
|
||||
|
||||
$path = ($moduleName !== false) ? 'Espo/Modules/'.$moduleName : 'Espo';
|
||||
$path = ($moduleName !== false) ? 'Espo/Modules/'.$moduleName : 'Espo';
|
||||
|
||||
if ($delim != '/') {
|
||||
$path = str_replace('/', $delim, $path);
|
||||
$path = str_replace('/', $delim, $path);
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if scope exists
|
||||
* Check if scope exists
|
||||
*
|
||||
* @param string $scopeName
|
||||
*
|
||||
@@ -395,7 +393,7 @@ class Metadata
|
||||
*/
|
||||
public function isScopeExists($scopeName)
|
||||
{
|
||||
$scopeModuleMap= $this->getScopes();
|
||||
$scopeModuleMap= $this->getScopes();
|
||||
|
||||
$lowerEntityName= strtolower($scopeName);
|
||||
foreach($scopeModuleMap as $rowEntityName => $rowModuleName) {
|
||||
@@ -407,7 +405,4 @@ class Metadata
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -18,7 +18,7 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
************************************************************************/
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Utils;
|
||||
|
||||
@@ -29,7 +29,7 @@ class Util
|
||||
* @var string - default directory separator
|
||||
*/
|
||||
protected static $separator = DIRECTORY_SEPARATOR;
|
||||
|
||||
|
||||
protected static $reservedWords = array('Case');
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ class Util
|
||||
foreach($mainArray as $maKey => $maVal) {
|
||||
$found = false;
|
||||
foreach($array as $aKey => $aVal) {
|
||||
if ((string)$maKey == (string)$aKey){
|
||||
if ((string)$maKey == (string)$aKey){
|
||||
$found = true;
|
||||
if (is_array($maVal) && is_array($aVal)){
|
||||
$array[$maKey] = static::merge($aVal, $maVal);
|
||||
@@ -223,7 +223,7 @@ class Util
|
||||
|
||||
return is_array($object) ? array_map("static::objectToArray", $object) : $object;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Appends 'Obj' if name is reserved PHP word.
|
||||
*
|
||||
@@ -294,21 +294,27 @@ class Util
|
||||
* Unset content items defined in the unset.json
|
||||
*
|
||||
* @param array $content
|
||||
* @param array $unsets in format
|
||||
* @param string | array $unsets in format
|
||||
* array(
|
||||
* 'EntityName1' => array( 'unset1', 'unset2' ),
|
||||
* 'EntityName2' => array( 'unset1', 'unset2' ),
|
||||
* 'EntityName1' => array( 'unset1', 'unset2' ),
|
||||
* 'EntityName2' => array( 'unset1', 'unset2' ),
|
||||
* )
|
||||
* OR
|
||||
* array('EntityName1.unset1', 'EntityName1.unset2', .....)
|
||||
* OR
|
||||
* 'EntityName1.unset1'
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function unsetInArray(array $content, array $unsets)
|
||||
public static function unsetInArray(array $content, $unsets)
|
||||
{
|
||||
if (is_string($unsets)) {
|
||||
$unsets = (array) $unsets;
|
||||
}
|
||||
|
||||
foreach($unsets as $rootKey => $unsetItem){
|
||||
$unsetItem = is_array($unsetItem) ? $unsetItem : (array) $unsetItem;
|
||||
|
||||
|
||||
foreach($unsetItem as $unsetSett){
|
||||
if (!empty($unsetSett)){
|
||||
$keyItems = explode('.', $unsetSett);
|
||||
@@ -320,7 +326,7 @@ class Util
|
||||
$currVal = "if (isset({$currVal})) unset({$currVal});";
|
||||
eval($currVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $content;
|
||||
@@ -329,9 +335,9 @@ class Util
|
||||
|
||||
/**
|
||||
* Get class name from the file path
|
||||
*
|
||||
*
|
||||
* @param string $filePath
|
||||
*
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getClassName($filePath)
|
||||
@@ -341,16 +347,16 @@ class Util
|
||||
$className = '\\'.static::toFormat($className, '\\');
|
||||
|
||||
return $className;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return values of defined $key.
|
||||
*
|
||||
* @param array $array
|
||||
* Return values of defined $key.
|
||||
*
|
||||
* @param array $array
|
||||
* @param string $key Ex. of key is "entityDefs", "entityDefs.User"
|
||||
* @param mixed $returns
|
||||
* @return mixed
|
||||
* @param mixed $returns
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getValueByKey(array $array, $key = null, $returns = null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user