diff --git a/application/Espo/Core/Utils/File/Manager.php b/application/Espo/Core/Utils/File/Manager.php index 683bf4b0bf..0123b1df6e 100644 --- a/application/Espo/Core/Utils/File/Manager.php +++ b/application/Espo/Core/Utils/File/Manager.php @@ -1,4 +1,4 @@ -concatPaths($path); + + if (file_exists($fullPath)) { + return true; + } + + if (!isset($permission)) { + $defaultPermissions = $this->getPermissionUtils()->getDefaultPermissions(); + $permission = (string) $defaultPermissions['dir']; + $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); + } + + return isset($result) ? $result : false; + } + /** * Create a new file if not exists with all folders in the path. @@ -310,10 +340,10 @@ class Manager return true; } - $pathParts= pathinfo($filePath); + $pathParts = pathinfo($filePath); if (!file_exists($pathParts['dirname'])) { - $dirPermission= $defaultPermissions['dir']; - $dirPermission= is_string($dirPermission) ? base_convert($dirPermission,8,10) : $dirPermission; + $dirPermission = $defaultPermissions['dir']; + $dirPermission = is_string($dirPermission) ? base_convert($dirPermission,8,10) : $dirPermission; if (!mkdir($pathParts['dirname'], $dirPermission, true)) { $GLOBALS['log']->critical('Permission denied: unable to generate a folder on the server - '.$pathParts['dirname']); @@ -438,21 +468,21 @@ class Manager * Get a directory name from the path * * @param string $path + * @param bool $isFullPath * * @return array */ - public function getDirName($path) - { - $pieces= explode(Utils\Util::getSeparator(), $path); - if (empty($pieces[count($pieces)-1])) { - unset($pieces[count($pieces)-1]); - } + public function getDirName($path, $isFullPath = true) + { + $pathInfo = pathinfo($path); - if ($this->getFileName($path)!=$path) { - return $pieces[count($pieces)-2]; + if (!$isFullPath) { + $pieces = explode('/', $pathInfo['dirname']); + + return $pieces[count($pieces)-1]; } - return $pieces[count($pieces)-1]; + return $pathInfo['dirname']; } @@ -470,27 +500,7 @@ class Manager return false; } - return 'getFileManager()->getFileList($dirPath, $recursively, '\.json$'); - $defaultValues = $this->loadDefaultValues($this->getFileManager()->getDirName($dirPath), $type); + $dirName = $this->getFileManager()->getDirName($dirPath, false); + $defaultValues = $this->loadDefaultValues($dirName, $type); $content= array(); $unsets= array(); diff --git a/install/core/Installer.php b/install/core/Installer.php index 63e0eab5cd..06ff5c3468 100644 --- a/install/core/Installer.php +++ b/install/core/Installer.php @@ -208,7 +208,7 @@ class Installer $entity->set('userName', $userName); $entity->set('password', md5($password)); - $entity->set('lastName', 'Administrator'); + $entity->set('lastName', 'Admin'); $entity->set('isAdmin', '1'); $userId = $this->getEntityManager()->saveEntity($entity); diff --git a/tests/Espo/Core/Utils/File/ManagerTest.php b/tests/Espo/Core/Utils/File/ManagerTest.php index a0784c3b97..040a456688 100644 --- a/tests/Espo/Core/Utils/File/ManagerTest.php +++ b/tests/Espo/Core/Utils/File/ManagerTest.php @@ -105,6 +105,61 @@ class ManagerTest extends \PHPUnit_Framework_TestCase $this->assertEquals($result, $this->reflection->invokeMethod('concatPaths', array($input)) ); } + function testGetDirName() + { + $input = 'data/logs/espo.log'; + $result = 'logs'; + $this->assertEquals($result, $this->object->getDirName($input, false)); + + $input = 'data/logs/espo.log/'; + $result = 'logs'; + $this->assertEquals($result, $this->object->getDirName($input, false)); + + $input = 'application/Espo/Resources/metadata/entityDefs'; + $result = 'metadata'; + $this->assertEquals($result, $this->object->getDirName($input, false)); + + $input = 'application/Espo/Resources/metadata/entityDefs/'; + $result = 'metadata'; + $this->assertEquals($result, $this->object->getDirName($input, false)); + + $input = '/application/Espo/Resources/metadata/entityDefs'; + $result = 'metadata'; + $this->assertEquals($result, $this->object->getDirName($input, false)); + + $input = 'notRealPath/logs/espo.log'; + $result = 'logs'; + $this->assertEquals($result, $this->object->getDirName($input, false)); + } + + + function testGetDirNameFullPath() + { + $input = 'data/logs/espo.log'; + $result = 'data/logs'; + $this->assertEquals($result, $this->object->getDirName($input)); + + $input = 'data/logs/espo.log/'; + $result = 'data/logs'; + $this->assertEquals($result, $this->object->getDirName($input)); + + $input = 'application/Espo/Resources/metadata/entityDefs'; + $result = 'application/Espo/Resources/metadata'; + $this->assertEquals($result, $this->object->getDirName($input)); + + $input = 'application/Espo/Resources/metadata/entityDefs/'; + $result = 'application/Espo/Resources/metadata'; + $this->assertEquals($result, $this->object->getDirName($input)); + + $input = '/application/Espo/Resources/metadata/entityDefs'; + $result = '/application/Espo/Resources/metadata'; + $this->assertEquals($result, $this->object->getDirName($input)); + + $input = 'notRealPath/logs/espo.log'; + $result = 'notRealPath/logs'; + $this->assertEquals($result, $this->object->getDirName($input)); + } + } diff --git a/tests/testData/Utils/Config/config.php b/tests/testData/Utils/Config/config.php index 75e3d8b7ab..c2460e7f50 100644 --- a/tests/testData/Utils/Config/config.php +++ b/tests/testData/Utils/Config/config.php @@ -1,24 +1,4 @@ - diff --git a/tests/testData/Utils/Config/testArray.php b/tests/testData/Utils/Config/testArray.php index b43cc79273..a08299cda4 100644 --- a/tests/testData/Utils/Config/testArray.php +++ b/tests/testData/Utils/Config/testArray.php @@ -1,24 +1,4 @@ - 'Another Wrong Value', diff --git a/tests/testData/Utils/I18n/cache/application/languages/en_GB.php b/tests/testData/Utils/I18n/cache/application/languages/en_GB.php index ba2aa268fc..286f81fa3c 100644 --- a/tests/testData/Utils/I18n/cache/application/languages/en_GB.php +++ b/tests/testData/Utils/I18n/cache/application/languages/en_GB.php @@ -1,24 +1,4 @@ - diff --git a/tests/testData/Utils/I18n/cache/application/languages/en_US.php b/tests/testData/Utils/I18n/cache/application/languages/en_US.php index 3832c5a7c0..3e5e8e9bc8 100644 --- a/tests/testData/Utils/I18n/cache/application/languages/en_US.php +++ b/tests/testData/Utils/I18n/cache/application/languages/en_US.php @@ -1,24 +1,4 @@ -