major fileManager changes
This commit is contained in:
@@ -223,7 +223,7 @@ class Acl
|
||||
private function buildCache()
|
||||
{
|
||||
$contents = '<' . '?'. 'php return ' . var_export($this->data, true) . ';';
|
||||
$this->fileManager()->setContent($this->cacheFile, $contents);
|
||||
$this->fileManager()->putContents($contents, $this->cacheFile);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ class CronManager
|
||||
|
||||
protected function getLastRunTime()
|
||||
{
|
||||
$lastRunTime = $this->getFileManager()->getContent($this->lastRunTime);
|
||||
$lastRunTime = $this->getFileManager()->getContents($this->lastRunTime);
|
||||
if (!is_int($lastRunTime)) {
|
||||
$lastRunTime = time() - (intval($this->getConfig()->get('cron.minExecutionTime')) + 60);
|
||||
}
|
||||
@@ -79,7 +79,7 @@ class CronManager
|
||||
|
||||
protected function setLastRunTime($time)
|
||||
{
|
||||
return $this->getFileManager()->setContentPHP($time, $this->lastRunTime);
|
||||
return $this->getFileManager()->putContentsPHP($this->lastRunTime, $time);
|
||||
}
|
||||
|
||||
protected function checkLastRunTime()
|
||||
|
||||
@@ -46,7 +46,7 @@ class HookManager
|
||||
protected function loadHooks()
|
||||
{
|
||||
if ($this->getConfig()->get('useCache') && file_exists($this->cacheFile)) {
|
||||
$this->data = $this->getFileManager()->getContent($this->cacheFile);
|
||||
$this->data = $this->getFileManager()->getContents($this->cacheFile);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ class HookManager
|
||||
}
|
||||
|
||||
if ($this->getConfig()->get('useCache')) {
|
||||
$this->getFileManager()->setContentPHP($this->data, $this->cacheFile);
|
||||
$this->getFileManager()->putContentsPHP($this->cacheFile, $this->data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ class ServiceFactory
|
||||
$config = $this->getContainer()->get('config');
|
||||
|
||||
if (file_exists($this->cacheFile) && $config->get('useCache')) {
|
||||
$this->data = $this->getFileManager()->getContent($this->cacheFile);
|
||||
$this->data = $this->getFileManager()->getContents($this->cacheFile);
|
||||
} else {
|
||||
$this->data = $this->getClassNameHash(array($this->paths['corePath'], $this->paths['customPath']));
|
||||
|
||||
@@ -42,7 +42,7 @@ class ServiceFactory
|
||||
$this->data = array_merge($this->data, $this->getClassNameHash(array($path)));
|
||||
}
|
||||
if ($config->get('useCache')) {
|
||||
$result = $this->getFileManager()->setContentPHP($this->data, $this->cacheFile);
|
||||
$result = $this->getFileManager()->putContentsPHP($this->cacheFile, $this->data);
|
||||
if ($result == false) {
|
||||
throw new \Espo\Core\Exceptions\Error();
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ class Config
|
||||
}
|
||||
|
||||
$content = array($name => $value);
|
||||
$status = $this->getFileManager()->mergeContentPHP($content, $this->get('configPath'), '', true);
|
||||
$status = $this->getFileManager()->mergeContentsPHP($this->get('configPath'), $content, true);
|
||||
$this->loadConfig(true);
|
||||
|
||||
return $status;
|
||||
@@ -104,7 +104,7 @@ class Config
|
||||
return false;
|
||||
}
|
||||
|
||||
$status = $this->getFileManager()->mergeContentPHP($values, $this->get('configPath'), '', true);
|
||||
$status = $this->getFileManager()->mergeContentsPHP($this->get('configPath'), $values, true);
|
||||
$this->loadConfig(true);
|
||||
|
||||
return $status;
|
||||
@@ -121,9 +121,9 @@ class Config
|
||||
return $this->configData;
|
||||
}
|
||||
|
||||
$defaultConfig = $this->getFileManager()->getContent($this->defaultConfigPath);
|
||||
$defaultConfig = $this->getFileManager()->getContents($this->defaultConfigPath);
|
||||
|
||||
$config = $this->getFileManager()->getContent($defaultConfig['configPath']);
|
||||
$config = $this->getFileManager()->getContents($defaultConfig['configPath']);
|
||||
if (empty($config)) {
|
||||
$GLOBALS['log']->add('FATAL', 'Check syntax or permission of your '.$defaultConfig['configPath']);
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ class Converter
|
||||
$fileList = $this->getFileManager()->getFileList($this->customTablePath, false, '\.php$', 'file');
|
||||
|
||||
foreach($fileList as $fileName) {
|
||||
$fileData = $this->getFileManager()->getContent($this->customTablePath, $fileName);
|
||||
$fileData = $this->getFileManager()->getContents( array($this->customTablePath, $fileName) );
|
||||
if (is_array($fileData)) {
|
||||
$customTables = Util::merge($customTables, $fileData);
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ class ClassParser
|
||||
}
|
||||
|
||||
if ($cacheFile && file_exists($cacheFile) && $this->getConfig()->get('useCache')) {
|
||||
$data = $this->getFileManager()->getContent($cacheFile);
|
||||
$data = $this->getFileManager()->getContents($cacheFile);
|
||||
} else {
|
||||
$data = $this->getClassNameHash( $this->getInitPaths($paths) );
|
||||
|
||||
@@ -81,7 +81,7 @@ class ClassParser
|
||||
}
|
||||
|
||||
if ($cacheFile && $this->getConfig()->get('useCache')) {
|
||||
$result = $this->getFileManager()->setContentPHP($data, $cacheFile);
|
||||
$result = $this->getFileManager()->putContentsPHP($cacheFile, $data);
|
||||
if ($result == false) {
|
||||
throw new \Espo\Core\Exceptions\Error();
|
||||
}
|
||||
|
||||
@@ -116,80 +116,100 @@ class Manager
|
||||
}
|
||||
|
||||
/**
|
||||
* Get content from file
|
||||
*
|
||||
* @param string $folderPath string - Folder path, Ex. myfolder
|
||||
* @param bool $filePath - File path, Ex. file.json
|
||||
*
|
||||
* @return string | bool | array
|
||||
* 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
|
||||
*/
|
||||
function getContent($folderPath, $filePath = '')
|
||||
public function getContents($paths, $useIncludePath = false, $context = null, $offset = -1, $maxlen = null)
|
||||
{
|
||||
$fullPath= Utils\Util::concatPath($folderPath, $filePath);
|
||||
$fullPath = $this->concatPaths($paths);
|
||||
|
||||
return $this->fileGetContents($fullPath);
|
||||
if (file_exists($fullPath)) {
|
||||
|
||||
if (strtolower(substr($fullPath, -4))=='.php') {
|
||||
return include($fullPath);
|
||||
} else {
|
||||
if (isset($maxlen)) {
|
||||
return file_get_contents($fullPath, $useIncludePath, $context, $offset, $maxlen);
|
||||
} else {
|
||||
return file_get_contents($fullPath, $useIncludePath, $context, $offset);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save content to file
|
||||
*
|
||||
* @param string $data
|
||||
* @param string $folderPath string - Folder path, Ex. myfolder
|
||||
* @param bool $filePath - File path, Ex. file.json
|
||||
*
|
||||
* @return bool
|
||||
* Write data to a file
|
||||
*
|
||||
* @param string | array $paths
|
||||
* @param mixed $data
|
||||
* @param integer $flags
|
||||
* @param resource $context
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function setContent($content, $folderPath, $filePath = '')
|
||||
public function putContents($paths, $data, $flags = 0, $context = null)
|
||||
{
|
||||
$fullPath= Utils\Util::concatPath($folderPath, $filePath);
|
||||
$fullPath = $this->concatPaths($paths); //todo remove after changing the params
|
||||
|
||||
return $this->filePutContents($fullPath, $content);
|
||||
if ($this->checkCreateFile($fullPath) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (file_put_contents($fullPath, $data, $flags, $context) !== FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save PHP content to file
|
||||
*
|
||||
* @param string $data
|
||||
* @param string $folderPath string - Folder path, Ex. myfolder
|
||||
* @param bool $filePath - File path, Ex. file.json
|
||||
* @param string | array $paths
|
||||
* @param string $data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function setContentPHP($content, $folderPath, $filePath = '')
|
||||
public function putContentsPHP($paths, $data)
|
||||
{
|
||||
return $this->setContent($this->getPHPFormat($content), $folderPath, $filePath);
|
||||
return $this->putContents($paths, $this->getPHPFormat($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Save JSON content to file
|
||||
*
|
||||
* @param string | array $paths
|
||||
* @param string $data
|
||||
* @param string $folderPath string - Folder path, Ex. myfolder
|
||||
* @param bool $filePath - File path, Ex. file.json
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function setContentJSON($content, $folderPath, $filePath='')
|
||||
public function putContentsJSON($paths, $data)
|
||||
{
|
||||
if (!Utils\Json::isJSON($content)) {
|
||||
$content= Utils\Json::encode($data);
|
||||
if (!Utils\Json::isJSON($data)) {
|
||||
$data= Utils\Json::encode($data);
|
||||
}
|
||||
return $this->setContent($content, $folderPath, $filePath);
|
||||
|
||||
return $this->putContents($paths, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge file content and save it to a file
|
||||
*
|
||||
* @param string $data JSON string
|
||||
* @param string $folderPath string - Folder path, Ex. myfolder
|
||||
* @param bool $filePath - File path, Ex. file.json
|
||||
* @param string | array $paths
|
||||
* @param string $content JSON string
|
||||
* @param bool $isJSON
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function mergeContent($content, $folderPath, $filePath = '', $isJSON = false)
|
||||
public function mergeContents($paths, $content, $isJSON = false)
|
||||
{
|
||||
$fileContent= $this->getContent($folderPath, $filePath);
|
||||
$fileContent= $this->getContents($paths);
|
||||
|
||||
$savedDataArray= $this->getArrayData($fileContent);
|
||||
$newDataArray= $this->getArrayData($content);
|
||||
@@ -199,22 +219,21 @@ class Manager
|
||||
$data= Utils\Json::encode($data);
|
||||
}
|
||||
|
||||
return $this->setContent($data, $folderPath, $filePath);
|
||||
return $this->putContents($paths, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge PHP content and save it to a file
|
||||
*
|
||||
* @param string $data
|
||||
* @param string $folderPath string - Folder path, Ex. myfolder
|
||||
* @param bool $filePath - File path, Ex. file.json
|
||||
* @param string | array $paths
|
||||
* @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
|
||||
*/
|
||||
function mergeContentPHP($content, $folderPath, $filePath='', $onlyFirstLevel= false)
|
||||
public function mergeContentsPHP($paths, $content, $onlyFirstLevel= false)
|
||||
{
|
||||
$fileContent= $this->getContent($folderPath, $filePath);
|
||||
$fileContent= $this->getContents($paths);
|
||||
|
||||
$savedDataArray= $this->getArrayData($fileContent);
|
||||
$newDataArray= $this->getArrayData($content);
|
||||
@@ -228,69 +247,43 @@ class Manager
|
||||
|
||||
$data= Utils\Util::merge($savedDataArray, $newDataArray);
|
||||
|
||||
return $this->setContentPHP($data, $folderPath, $filePath);
|
||||
return $this->putContentsPHP($paths, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append the content to the end of the file
|
||||
*
|
||||
* @param string $content
|
||||
* @param string $folderPath string - Folder path, Ex. myfolder
|
||||
* @param bool $filePath - File path, Ex. file.json
|
||||
* @param string | array $paths
|
||||
* @param mixed $data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function appendContent($content, $folderPath, $filePath='')
|
||||
public function appendContents($paths, $data)
|
||||
{
|
||||
$fullPath= Utils\Util::concatPath($folderPath, $filePath);
|
||||
|
||||
return $this->filePutContents($fullPath, $content, FILE_APPEND | LOCK_EX);
|
||||
return $this->putContents($paths, $data, FILE_APPEND | LOCK_EX);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Write a string to a file
|
||||
*
|
||||
* @param string $filename
|
||||
* @param mixed $data
|
||||
* @param int $flags
|
||||
*
|
||||
* @return bool
|
||||
* Concat paths
|
||||
* @param string | array $paths Ex. array('pathPart1', 'pathPart2', 'pathPart3')
|
||||
* @return string
|
||||
*/
|
||||
public function filePutContents($filename, $data, $flags = 0)
|
||||
protected function concatPaths($paths)
|
||||
{
|
||||
if ($this->checkCreateFile($filename) === false) {
|
||||
return false;
|
||||
if (is_string($paths)) {
|
||||
return $paths;
|
||||
}
|
||||
|
||||
return (file_put_contents($filename, $data, $flags) !== FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads entire file into a string
|
||||
*
|
||||
* @param string $filename
|
||||
* @param bool $useIncludePath
|
||||
*
|
||||
* @return string | false
|
||||
*/
|
||||
function fileGetContents($filename, $useIncludePath=false)
|
||||
{
|
||||
if (file_exists($filename)) {
|
||||
|
||||
if (strtolower(substr($filename, -4))=='.php') {
|
||||
return include($filename);
|
||||
} else {
|
||||
return file_get_contents($filename, $useIncludePath);
|
||||
}
|
||||
|
||||
$fullPath = '';
|
||||
foreach ($paths as $path) {
|
||||
$fullPath = Utils\Util::concatPath($fullPath, $path);
|
||||
}
|
||||
|
||||
return false;
|
||||
return $fullPath;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new file if not exists with all folders in the path.
|
||||
*
|
||||
@@ -330,10 +323,11 @@ class Manager
|
||||
/**
|
||||
* Remove all files in defined directory
|
||||
*
|
||||
* @param array $filePaths - File paths list
|
||||
* @param string $dirPath - directory path
|
||||
* @return bool
|
||||
*/
|
||||
public function removeFiles($filePaths, $dirPath='')
|
||||
public function removeFiles($filePaths, $dirPath = null)
|
||||
{
|
||||
if (!is_array($filePaths)) {
|
||||
$filePaths = (array) $filePaths;
|
||||
@@ -341,7 +335,7 @@ class Manager
|
||||
|
||||
$result= true;
|
||||
foreach($filePaths as $filePath) {
|
||||
if (!empty($dirPath)) {
|
||||
if (isset($dirPath)) {
|
||||
$filePath= Utils\Util::concatPath($dirPath, $filePath);
|
||||
}
|
||||
|
||||
|
||||
@@ -63,8 +63,8 @@ class UniteFiles
|
||||
$jsonData= $this->getObject('JSON')->encode($content);
|
||||
|
||||
$cacheFile= Utils\Util::concatPath($configParams['cachePath'], $configParams['name']);
|
||||
$result= $this->setContent($jsonData, $cacheFile.'.json');
|
||||
$result&= $this->setContent($this->getFileManager()->getPHPFormat($content), $cacheFile.'.php');
|
||||
$result= $this->putContents($cacheFile.'.json', $jsonData);
|
||||
$result&= $this->putContents($cacheFile.'.php', $this->getFileManager()->getPHPFormat($content));
|
||||
//END: save medatada to cache files
|
||||
|
||||
return $result; */
|
||||
@@ -106,12 +106,12 @@ class UniteFiles
|
||||
|
||||
} else { /*get content from a single file*/
|
||||
if ($fileName == $unsetFileName) {
|
||||
$fileContent = $this->getFileManager()->getContent($dirPath, $fileName);
|
||||
$fileContent = $this->getFileManager()->getContents(array($dirPath, $fileName));
|
||||
$unsets = Utils\Json::getArrayData($fileContent);
|
||||
continue;
|
||||
} /*END: Save data from unset.json*/
|
||||
|
||||
$mergedValues = $this->uniteFilesGetContent($dirPath, $fileName, $defaultValues);
|
||||
$mergedValues = $this->uniteFilesGetContent(array($dirPath, $fileName), $defaultValues);
|
||||
|
||||
if (!empty($mergedValues)) {
|
||||
$name = $this->getFileManager()->getFileName($fileName, '.json');
|
||||
@@ -134,15 +134,14 @@ class UniteFiles
|
||||
/**
|
||||
* Helpful method for get content from files for unite Files
|
||||
*
|
||||
* @param string $folderPath string - Folder path, Ex. myfolder
|
||||
* @param bool $filePath - File path, Ex. file.json
|
||||
* @param string | array $paths
|
||||
* @param string | array() $defaults - It can be a string like ["metadata","layouts"] OR an array with default values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function uniteFilesGetContent($folderPath, $fileName, $defaults)
|
||||
public function uniteFilesGetContent($paths, $defaults)
|
||||
{
|
||||
$fileContent= $this->getFileManager()->getContent($folderPath, $fileName);
|
||||
$fileContent= $this->getFileManager()->getContents($paths);
|
||||
$decoded= Utils\Json::getArrayData($fileContent);
|
||||
|
||||
if (empty($decoded) && !is_array($decoded)) {
|
||||
@@ -177,10 +176,9 @@ class UniteFiles
|
||||
function loadDefaultValues($name, $type='metadata')
|
||||
{
|
||||
$params = $this->getParams();
|
||||
$defaultPath= $params['defaultsPath'];
|
||||
//$defaultPath= $this->getConfig('defaultsPath');
|
||||
$defaultPath= $params['defaultsPath'];
|
||||
|
||||
$defaultValue= $this->getFileManager()->getContent( Utils\Util::concatPath($defaultPath, $type), $name.'.json');
|
||||
$defaultValue= $this->getFileManager()->getContents( array($defaultPath, $type, $name.'.json') );
|
||||
if ($defaultValue!==false) {
|
||||
//return default array
|
||||
return Utils\Json::decode($defaultValue, true);
|
||||
|
||||
@@ -79,7 +79,7 @@ class Layout
|
||||
}
|
||||
}
|
||||
|
||||
return $this->getFileManager()->getContent($fileFullPath);
|
||||
return $this->getFileManager()->getContents($fileFullPath);
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ class Layout
|
||||
$data = Json::encode($data);
|
||||
}
|
||||
|
||||
return $this->getFileManager()->setContent($data, $layoutPath, $name.'.json');
|
||||
return $this->getFileManager()->putContents(array($layoutPath, $name.'.json'), $data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -61,12 +61,16 @@ class Log
|
||||
private $output;
|
||||
private $params;
|
||||
|
||||
protected $logFilePath;
|
||||
|
||||
|
||||
public function __construct(\Espo\Core\Utils\File\Manager $fileManager, \Espo\Core\Utils\Api\Output $output, array $params)
|
||||
{
|
||||
$this->fileManager = $fileManager;
|
||||
$this->output = $output;
|
||||
$this->params = $params;
|
||||
|
||||
$this->logFilePath = Util::concatPath($params['options']['dir'], $params['options']['file']);
|
||||
}
|
||||
|
||||
|
||||
@@ -143,7 +147,7 @@ class Log
|
||||
$text = date('Y-m-d H:i:s') . ' ' . $text;
|
||||
|
||||
$params = $this->getParams();
|
||||
return $this->getFileManager()->appendContent($text, $params['options']['dir'], $params['options']['file']);
|
||||
return $this->getFileManager()->appendContents($this->logFilePath, $text);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -79,7 +79,7 @@ class Metadata
|
||||
if ($reload) {
|
||||
//save medatada to a cache file
|
||||
$metaConfig = $this->getMetaConfig();
|
||||
$isSaved = $this->getFileManager()->setContentPHP($data, $metaConfig['metadataCacheFile']);
|
||||
$isSaved = $this->getFileManager()->putContentsPHP($metaConfig['metadataCacheFile'], $data);
|
||||
if ($isSaved === false) {
|
||||
$GLOBALS['log']->add('FATAL', 'Metadata:init() - metadata has not been saved to a cache file');
|
||||
}
|
||||
@@ -159,7 +159,7 @@ class Metadata
|
||||
}
|
||||
}
|
||||
else if (file_exists($metaConfig['metadataCacheFile'])) {
|
||||
$data = $this->getFileManager()->getContent($metaConfig['metadataCacheFile']);
|
||||
$data = $this->getFileManager()->getContents($metaConfig['metadataCacheFile']);
|
||||
}
|
||||
|
||||
if ($isJSON) {
|
||||
@@ -201,7 +201,7 @@ class Metadata
|
||||
$data= Json::encode($this->meta);
|
||||
//END: merge data with defaults values
|
||||
|
||||
$result= $this->getFileManager()->setContent($data, $fullPath, $scope.'.json');
|
||||
$result= $this->getFileManager()->putContents(array($fullPath, $scope.'.json'), $data);
|
||||
|
||||
return $result;
|
||||
}
|
||||
@@ -221,7 +221,7 @@ class Metadata
|
||||
$this->getConverter()->process();
|
||||
}
|
||||
|
||||
$this->espoMetadata = $this->getFileManager()->getContent($espoMetadataFile);
|
||||
$this->espoMetadata = $this->getFileManager()->getContents($espoMetadataFile);
|
||||
|
||||
return $this->espoMetadata;
|
||||
}
|
||||
@@ -230,7 +230,7 @@ class Metadata
|
||||
{
|
||||
$metaConfig = $this->getMetaConfig();
|
||||
|
||||
$result = $this->getFileManager()->setContentPHP($espoMetadata, $metaConfig['cachePath'], 'ormMetadata.php');
|
||||
$result = $this->getFileManager()->putContentsPHP(array($metaConfig['cachePath'], 'ormMetadata.php'), $espoMetadata);
|
||||
if ($result == false) {
|
||||
$GLOBALS['log']->add('EXCEPTION', 'Metadata::setOrmMetadata() - Cannot save ormMetadata to a file');
|
||||
throw new \Espo\Core\Exceptions\Error();
|
||||
|
||||
@@ -63,11 +63,11 @@ class Route
|
||||
protected function init()
|
||||
{
|
||||
if (file_exists($this->cacheFile) && $this->getConfig()->get('useCache')) {
|
||||
$this->data = $this->getFileManager()->getContent($this->cacheFile);
|
||||
$this->data = $this->getFileManager()->getContents($this->cacheFile);
|
||||
} else {
|
||||
$this->data = $this->uniteFiles();
|
||||
|
||||
$result = $this->getFileManager()->setContentPHP($this->data, $this->cacheFile);
|
||||
$result = $this->getFileManager()->putContentsPHP($this->cacheFile, $this->data);
|
||||
if ($result == false) {
|
||||
$GLOBALS['log']->add('EXCEPTION', 'Route::init() - Cannot save Routes to a file');
|
||||
throw new \Espo\Core\Exceptions\Error();
|
||||
@@ -108,7 +108,7 @@ class Route
|
||||
protected function getAddData($currData, $routeFile)
|
||||
{
|
||||
if (file_exists($routeFile)) {
|
||||
$content= $this->getFileManager()->getContent($routeFile);
|
||||
$content= $this->getFileManager()->getContents($routeFile);
|
||||
$arrayContent = Json::getArrayData($content);
|
||||
if (empty($arrayContent)) {
|
||||
$GLOBALS['log']->add('ERROR', 'Route::uniteFiles() - Empty file or syntax error - ['.$routeFile.']');
|
||||
|
||||
@@ -160,7 +160,7 @@ class Util
|
||||
if (empty($filePath)) {
|
||||
return $folderPath;
|
||||
}
|
||||
if (empty($folderPath)) {
|
||||
if (empty($folderPath)) {
|
||||
return $filePath;
|
||||
}
|
||||
|
||||
|
||||
@@ -303,7 +303,7 @@ class InboundEmail extends \Espo\Services\Record
|
||||
|
||||
$path = 'data/upload/' . $attachment->id;
|
||||
$content = base64_decode($part->getContent());
|
||||
$this->getFileManager()->setContent($content, $path);
|
||||
$this->getFileManager()->putContents($path, $content);
|
||||
$attachmentsIds = $email->get('attachmentsIds');
|
||||
$attachmentsIds[] = $attachment->id;
|
||||
$email->set('attachmentsIds', $attachmentsIds);
|
||||
|
||||
@@ -39,7 +39,7 @@ class Preferences extends \Espo\Core\ORM\Repository
|
||||
$fileName = $this->getFilePath($id);
|
||||
|
||||
if (file_exists($fileName)) {
|
||||
$this->data[$id] = json_decode($this->getFileManager()->getContent($fileName), true);
|
||||
$this->data[$id] = json_decode($this->getFileManager()->getContents($fileName), true);
|
||||
} else {
|
||||
$fields = $this->getMetadata()->get('entityDefs.Preferences.fields');
|
||||
$defaults = array();
|
||||
@@ -65,7 +65,7 @@ class Preferences extends \Espo\Core\ORM\Repository
|
||||
$this->data[$entity->id] = $entity->toArray();
|
||||
|
||||
$fileName = $this->getFilePath($entity->id);
|
||||
$this->getFileManager()->setContent(json_encode($this->data[$entity->id]), $fileName);
|
||||
$this->getFileManager()->putContents($fileName, json_encode($this->data[$entity->id]));
|
||||
return $entity;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ class Attachment extends Record
|
||||
list($prefix, $contents) = explode(',', $data['file']);
|
||||
|
||||
if (!empty($entity->id)) {
|
||||
$this->getFileManager()->setContent(base64_decode($contents), 'data/upload/' . $entity->id);
|
||||
$this->getFileManager()->putContents('data/upload/' . $entity->id, base64_decode($contents));
|
||||
}
|
||||
|
||||
return $entity;
|
||||
|
||||
@@ -94,11 +94,11 @@ class EmailTemplate extends Record
|
||||
$clone->set($data);
|
||||
$this->getEntityManager()->saveEntity($clone);
|
||||
|
||||
$contents = $this->getFileManager()->getContent('data/upload/' . $attachment->id);
|
||||
$contents = $this->getFileManager()->getContents('data/upload/' . $attachment->id);
|
||||
if (empty($contents)) {
|
||||
continue;
|
||||
}
|
||||
$this->getFileManager()->setContent($contents, 'data/upload/' . $clone->id);
|
||||
$this->getFileManager()->putContents('data/upload/' . $clone->id, $contents);
|
||||
|
||||
$attachmentsIds[] = $clone->id;
|
||||
}
|
||||
|
||||
@@ -400,7 +400,7 @@ class Record extends \Espo\Core\Services\Base
|
||||
$this->getEntityManager()->saveEntity($attachment);
|
||||
|
||||
if (!empty($attachment->id)) {
|
||||
$this->getInjection('fileManager')->setContent($csv, 'data/upload/' . $attachment->id);
|
||||
$this->getInjection('fileManager')->putContents('data/upload/' . $attachment->id, $csv);
|
||||
// TODO cron job to remove file
|
||||
return $attachment->id;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ class CronManagerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$this->objects['fileManager']
|
||||
->expects($this->once())
|
||||
->method('getContent')
|
||||
->method('getContents')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$this->objects['config']
|
||||
@@ -64,7 +64,7 @@ class CronManagerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$this->objects['fileManager']
|
||||
->expects($this->once())
|
||||
->method('getContent')
|
||||
->method('getContents')
|
||||
->will($this->returnValue(time()-60));
|
||||
|
||||
$this->objects['config']
|
||||
@@ -80,7 +80,7 @@ class CronManagerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$this->objects['fileManager']
|
||||
->expects($this->once())
|
||||
->method('getContent')
|
||||
->method('getContents')
|
||||
->will($this->returnValue(time()-49));
|
||||
|
||||
$this->objects['config']
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace tests\Espo\Core\Utils\File;
|
||||
|
||||
use tests\ReflectionHelper;
|
||||
|
||||
|
||||
class ManagerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
@@ -11,6 +13,8 @@ class ManagerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
protected $filesPath= 'tests/testData/FileManager';
|
||||
|
||||
protected $reflection;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new \Espo\Core\Utils\File\Manager(
|
||||
@@ -23,6 +27,8 @@ class ManagerTest extends \PHPUnit_Framework_TestCase
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$this->reflection = new ReflectionHelper($this->object);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
@@ -42,6 +48,63 @@ class ManagerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('Donwload', $this->object->getFileName('application/Espo/EntryPoints/Donwload.php'));
|
||||
}
|
||||
|
||||
function testGetContents()
|
||||
{
|
||||
$result = file_get_contents($this->filesPath.'/getContent/test.json');
|
||||
$this->assertEquals($result, $this->object->getContents( array($this->filesPath, 'getContent/test.json') ));
|
||||
}
|
||||
|
||||
|
||||
function testPutContents()
|
||||
{
|
||||
$testPath= $this->filesPath.'/setContent';
|
||||
|
||||
$result= 'next value';
|
||||
$this->assertTrue($this->object->putContents(array($testPath, 'test.json'), $result));
|
||||
|
||||
$this->assertEquals($result, $this->object->getContents( array($testPath, 'test.json')) );
|
||||
|
||||
$this->assertTrue($this->object->putContents(array($testPath, 'test.json'), 'initial value'));
|
||||
}
|
||||
|
||||
|
||||
function testConcatPaths()
|
||||
{
|
||||
$input = 'application/Espo/Resources/metadata/app/panel.json';
|
||||
$result = 'application/Espo/Resources/metadata/app/panel.json';
|
||||
|
||||
$this->assertEquals($result, $this->reflection->invokeMethod('concatPaths', array($input)) );
|
||||
|
||||
|
||||
$input = array(
|
||||
'application',
|
||||
'Espo/Resources/metadata/',
|
||||
'app',
|
||||
'panel.json',
|
||||
);
|
||||
$result = 'application/Espo/Resources/metadata/app/panel.json';
|
||||
|
||||
$this->assertEquals($result, $this->reflection->invokeMethod('concatPaths', array($input)) );
|
||||
|
||||
|
||||
$input = array(
|
||||
'application/Espo/Resources/metadata/app',
|
||||
'panel.json',
|
||||
);
|
||||
$result = 'application/Espo/Resources/metadata/app/panel.json';
|
||||
|
||||
$this->assertEquals($result, $this->reflection->invokeMethod('concatPaths', array($input)) );
|
||||
|
||||
|
||||
$input = array(
|
||||
'application/Espo/Resources/metadata/app/',
|
||||
'panel.json',
|
||||
);
|
||||
$result = 'application/Espo/Resources/metadata/app/panel.json';
|
||||
|
||||
$this->assertEquals($result, $this->reflection->invokeMethod('concatPaths', array($input)) );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ class LayoutTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->objects['fileManager']
|
||||
->expects($this->exactly(1))
|
||||
->method('getContent')
|
||||
->method('getContents')
|
||||
->will($this->returnValue($result));
|
||||
|
||||
$this->assertEquals($result, $this->object->get('User', 'detail'));
|
||||
|
||||
@@ -1 +1 @@
|
||||
next value
|
||||
initial value
|
||||
Reference in New Issue
Block a user