diff --git a/VERSIONS b/VERSIONS index 27ce440db651f76e75e1882642e69c299e4572bd..e30b4508f434c6811f181af0f018af0c12b7284a 100644 --- a/VERSIONS +++ b/VERSIONS @@ -1,3 +1,7 @@ + - Amélioration : Administration : amélioration des performances d'affichage des dossiers volumineux dans l'explorateur de fichiers (dossier albums). + + + 05/04/2022 - v8.0.155 - fonctionnalité #152400 : Enrichissements : Prise en charge de la nouvelle API ELECTRE NG, ATTENTION : la mise à jour des identifiants est requise diff --git a/library/Class/FileManager.php b/library/Class/FileManager.php index 084c7b5643bd2b6cca2b3e68ca2a94d8c8ea29d6..8b43c0a5fe80f80de4ee566aa2bf6153656c7224 100644 --- a/library/Class/FileManager.php +++ b/library/Class/FileManager.php @@ -25,26 +25,28 @@ class Class_FileManager extends Class_Entity { protected static $_file_system, $_open_bar = false, - $_icon; + $_icon, + $_user_has_right_on_path_cache = []; const REGEX_NAME = '/^[a-z0-9][a-z0-9_\-\.]+$/i'; - protected $_attribs = ['Id' => '', - 'Realpath' => '', - 'Path' => '', - 'Pathinfo' => '', - 'Name' => '', - 'Basename' => '', - 'ParentPath' => '', - 'BrowserParam' => '', - 'MTime' => '', - 'Size' => '', - 'FileSize' => 0, - 'Dir' => '', - 'Dimensions' => '', - 'Type' => '', - 'Extension' => '', - 'Dot' => '', - 'Writable' => '']; + protected + $_attribs = ['Id' => '', + 'Realpath' => '', + 'Path' => '', + 'Pathinfo' => '', + 'Name' => '', + 'Basename' => '', + 'ParentPath' => '', + 'BrowserParam' => '', + 'MTime' => '', + 'Size' => '', + 'FileSize' => 0, + 'Dir' => '', + 'Dimensions' => '', + 'Type' => '', + 'Extension' => '', + 'Dot' => '', + 'Writable' => '']; public static function getClassVar() {} @@ -308,16 +310,19 @@ class Class_FileManager extends Class_Entity { public static function userHasRightOnPath($path) { + if ( isset(static::$_user_has_right_on_path_cache[$path])) + return static::$_user_has_right_on_path_cache[$path]; + if(static::isOpenBar()) - return true; + return static::$_user_has_right_on_path_cache[$path] = true; if (!$user = Class_Users::getIdentity()) - return false; + return static::$_user_has_right_on_path_cache[$path] = false; if (!$user->canAccessBackend()) - return false; + return static::$_user_has_right_on_path_cache[$path] = false; - return static::_checkPathPermissions($user, $path); + return static::$_user_has_right_on_path_cache[$path] = static::_checkPathPermissions($user, $path); } @@ -375,6 +380,7 @@ class Class_FileManager extends Class_Entity { public static function reset() { static::$_open_bar = false; static::setFileSystem(null); + static::$_user_has_right_on_path_cache = []; } diff --git a/library/Class/FileManager/FileSystem.php b/library/Class/FileManager/FileSystem.php index 4ab1e7e080e12464332d958758ec81dd5834cfdb..a0777ac0d5abbd436f6aea5f80834ba2d92c27bc 100644 --- a/library/Class/FileManager/FileSystem.php +++ b/library/Class/FileManager/FileSystem.php @@ -21,15 +21,22 @@ class Class_FileManager_FileSystem { - use Trait_Translator; + + use + Trait_Translator, + Trait_StaticFileSystem, + Trait_StaticCommand; + const LISTING_LIMIT = 200; + protected static $_limited = true, $_cache_status = true; + protected $_cached_paths = [], $_oversized = []; @@ -129,7 +136,7 @@ class Class_FileManager_FileSystem { public function create($path) { - return mkdir($path); + return static::getFileSystem()->mkdir($path); } @@ -146,14 +153,14 @@ class Class_FileManager_FileSystem { public function rename($old, $new) { return ($old == $new) ? true - : rename($old, $new); + : static::getFileSystem()->rename($old, $new); } public function copy($old, $new) { return ($old == $new) ? true - : copy($old, $new); + : static::getFileSystem()->copy($old, $new); } @@ -186,17 +193,17 @@ class Class_FileManager_FileSystem { public function isDeepWritable($path) { $result = true; foreach($this->_glob($path, false) as $item) - $result &= (is_dir($item) + $result &= (static::getFileSystem()->is_dir($item) ? $this->isDeepWritable($item) - : is_writable($item) && ($found = Class_FileManager::find($item)) && empty($found->getModels())); + : static::getFileSystem()->is_writable($item) && ($found = Class_FileManager::find($item)) && empty($found->getModels())); - return $result && is_writable($path); + return $result && static::getFileSystem()->is_writable($path); } public function delete($path) { - return unlink($path); + return static::getFileSystem()->unlink($path); } @@ -204,11 +211,11 @@ class Class_FileManager_FileSystem { if($source_dir == $destination_dir) return false; - if (!file_exists($destination_dir)) + if ( ! static::getFileSystem()->file_exists($destination_dir)) $this->create($destination_dir); $result = true; - foreach (scandir($source_dir) as $item) + foreach (static::getFileSystem()->scandir($source_dir) as $item) $result &= $this->_copyDirItems($source_dir .'/'. $item, $destination_dir .'/'. $item, $item); @@ -218,16 +225,16 @@ class Class_FileManager_FileSystem { protected function _copyDirItems($source_dir_item, $destination_dir_item, $item) { - if (!is_readable($source_dir_item)) + if ( ! static::getFileSystem()->is_readable($source_dir_item)) return false; if ($item == '.' || $item == '..') return true; - if (!is_dir($source_dir_item)) + if ( ! static::getFileSystem()->is_dir($source_dir_item)) return $this->copy($source_dir_item, $destination_dir_item); - if (!file_exists($destination_dir_item)) + if ( ! static::getFileSystem()->file_exists($destination_dir_item)) $this->create($destination_dir_item); return $this->copyDir($source_dir_item, $destination_dir_item); @@ -301,10 +308,10 @@ class Class_FileManager_FileSystem { protected function _newfileManager($path) { - if(!is_readable($path)) + if( ! static::getFileSystem()->is_readable($path)) return null; - $info = pathinfo($path); + $info = static::getFileSystem()->pathinfo($path); $dirname = ('.' == $info['dirname']) ? '' @@ -312,12 +319,12 @@ class Class_FileManager_FileSystem { $basename = $info['basename']; $path = implode('/', array_filter([$dirname, $basename])); - $size = filesize($path); - $mtime = filemtime($path); + $size = static::getFileSystem()->filesize($path); + $mtime = static::getFileSystem()->filemtime($path); return (new Class_FileManager) ->setId($path) - ->setRealpath(realpath($path)) + ->setRealpath(static::getFileSystem()->realpath($path)) ->setPath($path) ->setPathinfo($info) ->setName($basename) @@ -333,7 +340,7 @@ class Class_FileManager_FileSystem { protected function _isWritable($path) { - $system_writable = is_writable($path); + $system_writable = static::getFileSystem()->is_writable($path); $object_writable = Class_FileManager::isPathWritable($path); return $system_writable && $object_writable; } @@ -344,12 +351,25 @@ class Class_FileManager_FileSystem { $closure = function() use ($path) { - $paths = glob($path . '/{,.}[!.,!..]*', GLOB_BRACE); - $paths = (array_filter($paths, - function($path) - { - return Class_FileManager::userHasRightOnPath($path); - })); + if ( ! $handle = static::getFileSystem()->opendir($path)) + return []; + + $paths = []; + + while ( (false !== ($entry = static::getFileSystem()->readdir($handle))) + && (static::LISTING_LIMIT >= count($paths))) { + if ( '.' == $entry + || '..' == $entry) + continue; + + $pathname = $path . '/' . $entry; + + if (Class_FileManager::userHasRightOnPath($pathname)) + $paths [] = $pathname; + } + + static::getFileSystem()->closedir($handle); + sort($paths, SORT_NATURAL); return $paths; }; @@ -373,9 +393,8 @@ class Class_FileManager_FileSystem { $path, $term); - exec($cmd, $found); - - if(empty($found)) + static::getCommand()->exec($cmd, $found); + if( ! $found = static::getCommand()->getOutput()) return []; sort($found, SORT_NATURAL); @@ -394,18 +413,18 @@ class Class_FileManager_FileSystem { public function createImage($path, $content) { - return file_put_contents($path, $content); + return static::getFileSystem()->file_put_contents($path, $content); } public function getContent($path) { - return file_get_contents($path); + return static::getFileSystem()->file_get_contents($path); } public function readfile($path) { ob_end_clean(); - return readfile($path); + return static::getFileSystem()->readfile($path); } diff --git a/library/Class/Testing/FileSystem.php b/library/Class/Testing/FileSystem.php index 7c83ae6a180cb1df23e07698d9281a1ba74c4669..5e651a087ab6693db3ab44a3e9497d2a9356f6c0 100644 --- a/library/Class/Testing/FileSystem.php +++ b/library/Class/Testing/FileSystem.php @@ -27,7 +27,8 @@ class Class_Testing_FileSystem extends Class_Testing_Abstract { 'getcwd', 'file_exists', 'scandir', 'is_dir', 'opendir', 'readdir', 'closedir', 'mkdir', 'glob', 'file', 'fwrite','rename', 'getimagesize', 'file_get_contents', 'sha1_file', 'is_file', 'pathinfo', - 'is_readable', 'file_put_contents', 'filesize' + 'is_readable', 'file_put_contents', 'filesize', 'realpath', 'filemtime', 'is_writable', + 'readfile' ], $_error = 'Call to unknown fileSystem method '; } \ No newline at end of file