Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/ACL/ACLCacheWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ protected function formatCacheEntry($entry, array $rules = []) {
public function getFolderContentsById($fileId) {
$results = $this->getCache()->getFolderContentsById($fileId);
$rules = $this->preloadEntries($results);
$entries = array_map(function ($entry) use ($rules) {
return array_filter(array_map(function ($entry) use ($rules) {
return $this->formatCacheEntry($entry, $rules);
}, $results);
return array_filter(array_filter($entries));
}, $results));
}

public function search($pattern) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Command/ACL.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected function configure() {

protected function execute(InputInterface $input, OutputInterface $output) {
$folder = $this->getFolder($input, $output);
if ($folder === false) {
if ($folder === null) {
return -1;
}
if ($input->getOption('enable')) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Command/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected function configure() {

protected function execute(InputInterface $input, OutputInterface $output) {
$folder = $this->getFolder($input, $output);
if ($folder === false) {
if ($folder === null) {
return -1;
}
$helper = $this->getHelper('question');
Expand Down
10 changes: 5 additions & 5 deletions lib/Command/FolderCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ public function __construct(FolderManager $folderManager, IRootFolder $rootFolde
}

/**
* @psalm-return array{id: mixed, mount_point: string, groups: array<empty, empty>|mixed, quota: int, size: int|mixed, acl: bool}|false
* @psalm-return ?array{id: mixed, mount_point: string, groups: array<empty, empty>|mixed, quota: int, size: int|mixed, acl: bool}
*/
protected function getFolder(InputInterface $input, OutputInterface $output) {
protected function getFolder(InputInterface $input, OutputInterface $output): ?array {
$folderId = (int)$input->getArgument('folder_id');
if ((string)$folderId !== $input->getArgument('folder_id')) {
// Protect against removing folderId === 0 when typing a string (e.g. folder name instead of folder id)
$output->writeln('<error>Folder id argument is not an integer. Got ' . $input->getArgument('folder_id') . '</error>');
return false;
return null;
}
$folder = $this->folderManager->getFolder($folderId, $this->rootFolder->getMountPoint()->getNumericStorageId());
if ($folder === false) {
if ($folder === null) {
$output->writeln('<error>Folder not found: ' . $folderId . '</error>');
return false;
return null;
}
return $folder;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Command/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function configure() {

protected function execute(InputInterface $input, OutputInterface $output) {
$folder = $this->getFolder($input, $output);
if ($folder === false) {
if ($folder === null) {
return -1;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Command/Quota.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected function configure() {

protected function execute(InputInterface $input, OutputInterface $output) {
$folder = $this->getFolder($input, $output);
if ($folder === false) {
if ($folder === null) {
return -1;
}
$quotaString = strtolower($input->getArgument('quota'));
Expand Down
2 changes: 1 addition & 1 deletion lib/Command/Rename.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected function configure(): void {

protected function execute(InputInterface $input, OutputInterface $output): int {
$folder = $this->getFolder($input, $output);
if ($folder === false) {
if ($folder === null) {
return -1;
}
$this->folderManager->renameFolder($folder['id'], $input->getArgument('name'));
Expand Down
2 changes: 1 addition & 1 deletion lib/Command/Scan.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$folders = $this->folderManager->getAllFolders();
} else {
$folder = $this->getFolder($input, $output);
if ($folder === false) {
if ($folder === null) {
return -1;
}
$folders = [$folder['id'] => $folder];
Expand Down
4 changes: 2 additions & 2 deletions lib/Controller/FolderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private function checkFolderExists(int $id): ?DataResponse {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
$folder = $this->manager->getFolder($id, $storageId);
if ($folder === false) {
if ($folder === null) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
return null;
Expand All @@ -152,7 +152,7 @@ private function getRootFolderStorageId(): ?int {
public function addFolder(string $mountpoint): DataResponse {
$id = $this->manager->createFolder(trim($mountpoint));
$folder = $this->manager->getFolder($id, $this->rootFolder->getMountPoint()->getNumericStorageId());
if ($folder === false) {
if ($folder === null) {
throw new OCSNotFoundException();
}
return new DataResponse($folder);
Expand Down
13 changes: 8 additions & 5 deletions lib/Folder/FolderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,10 @@ private function getManageAcl(array $mappings): array {
}

/**
* @return array{id: mixed, mount_point: mixed, groups: array<string, array{displayName: string, type: string, permissions: integer}>, quota: int, size: int, acl: bool}|false
* @return ?array{id: mixed, mount_point: mixed, groups: array<string, array{displayName: string, type: string, permissions: integer}>, quota: int, size: int, acl: bool}
* @throws Exception
*/
public function getFolder(int $id, int $rootStorageId) {
public function getFolder(int $id, int $rootStorageId): ?array {
$applicableMap = $this->getAllApplicable();

$query = $this->connection->getQueryBuilder();
Expand All @@ -271,17 +271,20 @@ public function getFolder(int $id, int $rootStorageId) {
$result = $query->executeQuery();
$row = $result->fetch();
$result->closeCursor();
if (!$row) {
return null;
}

$folderMappings = $this->getFolderMappings($id);
return $row ? [
return [
'id' => $id,
'mount_point' => (string)$row['mount_point'],
'groups' => $applicableMap[$id] ?? [],
'quota' => (int)$row['quota'],
'size' => $row['size'] ? $row['size'] : 0,
'size' => $row['size'] ?: 0,
'acl' => (bool)$row['acl'],
'manage' => $this->getManageAcl($folderMappings)
] : false;
];
}

/**
Expand Down