MCPcopy Create free account
hub / github.com/error311/FileRise / getFolderList

Method getFolderList

src/FileRise/Domain/FolderModel.php:1968–2029  ·  view source on GitHub ↗

* Retrieves the list of folders (including "root") along with file count metadata. * (Ownership filtering is handled in the controller; this function remains unchanged.) */

($parent = null, ?string $username = null, array $perms = [], bool $includeCounts = true)

Source from the content-addressed store, hash-verified

1966 * (Ownership filtering is handled in the controller; this function remains unchanged.)
1967 */
1968 public static function getFolderList($parent = null, ?string $username = null, array $perms = [], bool $includeCounts = true): array
1969 {
1970 $storage = self::storage();
1971 if (!$storage->isLocal()) {
1972 return self::getFolderListRemote($parent, $username, $perms, $includeCounts);
1973 }
1974
1975 $baseDir = realpath(self::uploadRoot());
1976 if ($baseDir === false) {
1977 return []; // or ["error" => "..."]
1978 }
1979
1980 if ($parent !== null && !$includeCounts) {
1981 $folderInfoList = self::getFolderListLocalShallow((string)$parent, $includeCounts, $baseDir);
1982 if ($username !== null) {
1983 $folderInfoList = array_values(array_filter(
1984 $folderInfoList,
1985 fn($row) => ACL::canRead($username, $perms, $row['folder'])
1986 ));
1987 }
1988 return $folderInfoList;
1989 }
1990
1991 $folderInfoList = [];
1992
1993 // root
1994 $rootMetaFile = self::getMetadataFilePath('root');
1995 $rootFileCount = null;
1996 if ($includeCounts && file_exists($rootMetaFile)) {
1997 $rootMetadata = json_decode(file_get_contents($rootMetaFile), true);
1998 $rootFileCount = is_array($rootMetadata) ? count($rootMetadata) : 0;
1999 }
2000 $folderInfoList[] = [
2001 "folder" => "root",
2002 "fileCount" => $rootFileCount,
2003 "metadataFile" => basename($rootMetaFile)
2004 ];
2005
2006 // subfolders
2007 $subfolders = is_dir($baseDir) ? self::getSubfolders($baseDir) : [];
2008 foreach ($subfolders as $folder) {
2009 $metaFile = self::getMetadataFilePath($folder);
2010 $fileCount = null;
2011 if ($includeCounts && file_exists($metaFile)) {
2012 $metadata = json_decode(file_get_contents($metaFile), true);
2013 $fileCount = is_array($metadata) ? count($metadata) : 0;
2014 }
2015 $folderInfoList[] = [
2016 "folder" => $folder,
2017 "fileCount" => $fileCount,
2018 "metadataFile" => basename($metaFile)
2019 ];
2020 }
2021
2022 if ($username !== null) {
2023 $folderInfoList = array_values(array_filter(
2024 $folderInfoList,
2025 fn($row) => ACL::canRead($username, $perms, $row['folder'])

Callers 1

getFolderList.phpFile · 0.45

Calls 8

storageMethod · 0.95
getFolderListRemoteMethod · 0.95
uploadRootMethod · 0.95
getMetadataFilePathMethod · 0.95
getSubfoldersMethod · 0.95
canReadMethod · 0.80
isLocalMethod · 0.45

Tested by

no test coverage detected