Skip to content

Commit 249e33f

Browse files
Merge pull request #52901 from nextcloud/chore/remove-dead-code-files
2 parents 6b4f5c5 + 4a9dc6c commit 249e33f

File tree

6 files changed

+88
-150
lines changed

6 files changed

+88
-150
lines changed

apps/files/lib/Helper.php

Lines changed: 0 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -9,66 +9,12 @@
99

1010
use OC\Files\Filesystem;
1111
use OCP\Files\FileInfo;
12-
use OCP\Files\IMimeTypeDetector;
13-
use OCP\Files\NotFoundException;
14-
use OCP\ITagManager;
15-
use OCP\Server;
1612
use OCP\Util;
1713

1814
/**
1915
* Helper class for manipulating file information
2016
*/
2117
class Helper {
22-
/**
23-
* @param string $dir
24-
* @return array
25-
* @throws NotFoundException
26-
*/
27-
public static function buildFileStorageStatistics($dir) {
28-
// information about storage capacities
29-
$storageInfo = \OC_Helper::getStorageInfo($dir);
30-
$l = Util::getL10N('files');
31-
$maxUploadFileSize = Util::maxUploadFilesize($dir, $storageInfo['free']);
32-
$maxHumanFileSize = Util::humanFileSize($maxUploadFileSize);
33-
$maxHumanFileSize = $l->t('Upload (max. %s)', [$maxHumanFileSize]);
34-
35-
return [
36-
'uploadMaxFilesize' => $maxUploadFileSize,
37-
'maxHumanFilesize' => $maxHumanFileSize,
38-
'freeSpace' => $storageInfo['free'],
39-
'quota' => $storageInfo['quota'],
40-
'total' => $storageInfo['total'],
41-
'used' => $storageInfo['used'],
42-
'usedSpacePercent' => $storageInfo['relative'],
43-
'owner' => $storageInfo['owner'],
44-
'ownerDisplayName' => $storageInfo['ownerDisplayName'],
45-
'mountType' => $storageInfo['mountType'],
46-
'mountPoint' => $storageInfo['mountPoint'],
47-
];
48-
}
49-
50-
/**
51-
* Determine icon for a given file
52-
*
53-
* @param FileInfo $file file info
54-
* @return string icon URL
55-
*/
56-
public static function determineIcon($file) {
57-
if ($file['type'] === 'dir') {
58-
$icon = Server::get(IMimeTypeDetector::class)->mimeTypeIcon('dir');
59-
// TODO: move this part to the client side, using mountType
60-
if ($file->isShared()) {
61-
$icon = Server::get(IMimeTypeDetector::class)->mimeTypeIcon('dir-shared');
62-
} elseif ($file->isMounted()) {
63-
$icon = Server::get(IMimeTypeDetector::class)->mimeTypeIcon('dir-external');
64-
}
65-
} else {
66-
$icon = Server::get(IMimeTypeDetector::class)->mimeTypeIcon($file->getMimetype());
67-
}
68-
69-
return substr($icon, 0, -3) . 'svg';
70-
}
71-
7218
/**
7319
* Comparator function to sort files alphabetically and have
7420
* the directories appear first
@@ -161,20 +107,6 @@ public static function formatFileInfo(FileInfo $i) {
161107
return $entry;
162108
}
163109

164-
/**
165-
* Format file info for JSON
166-
* @param FileInfo[] $fileInfos file infos
167-
* @return array
168-
*/
169-
public static function formatFileInfos($fileInfos) {
170-
$files = [];
171-
foreach ($fileInfos as $i) {
172-
$files[] = self::formatFileInfo($i);
173-
}
174-
175-
return $files;
176-
}
177-
178110
/**
179111
* Retrieves the contents of the given directory and
180112
* returns it as a sorted array of FileInfo.
@@ -191,43 +123,6 @@ public static function getFiles($dir, $sortAttribute = 'name', $sortDescending =
191123
return self::sortFiles($content, $sortAttribute, $sortDescending);
192124
}
193125

194-
/**
195-
* Populate the result set with file tags
196-
*
197-
* @psalm-template T of array{tags?: list<string>, file_source: int, ...array<string, mixed>}
198-
* @param list<T> $fileList
199-
* @return list<T> file list populated with tags
200-
*/
201-
public static function populateTags(array $fileList, ITagManager $tagManager) {
202-
$tagger = $tagManager->load('files');
203-
$tags = $tagger->getTagsForObjects(array_map(static fn (array $fileData) => $fileData['file_source'], $fileList));
204-
205-
if (!is_array($tags)) {
206-
throw new \UnexpectedValueException('$tags must be an array');
207-
}
208-
209-
// Set empty tag array
210-
foreach ($fileList as &$fileData) {
211-
$fileData['tags'] = [];
212-
}
213-
unset($fileData);
214-
215-
if (!empty($tags)) {
216-
foreach ($tags as $fileId => $fileTags) {
217-
foreach ($fileList as &$fileData) {
218-
if ($fileId !== $fileData['file_source']) {
219-
continue;
220-
}
221-
222-
$fileData['tags'] = $fileTags;
223-
}
224-
unset($fileData);
225-
}
226-
}
227-
228-
return $fileList;
229-
}
230-
231126
/**
232127
* Sort the given file info array
233128
*

apps/files/tests/HelperTest.php

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
use OC\Files\FileInfo;
44
use OCA\Files\Helper;
5-
use OCP\ITagManager;
6-
use OCP\ITags;
75

86
/**
97
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
@@ -94,36 +92,4 @@ public function testSortByName(string $sort, bool $sortDescending, array $expect
9492
$fileNames
9593
);
9694
}
97-
98-
public function testPopulateTags(): void {
99-
$tagManager = $this->createMock(ITagManager::class);
100-
$tagger = $this->createMock(ITags::class);
101-
102-
$tagManager->method('load')
103-
->with('files')
104-
->willReturn($tagger);
105-
106-
$data = [
107-
['file_source' => 10],
108-
['file_source' => 22, 'foo' => 'bar'],
109-
['file_source' => 42, 'x' => 'y'],
110-
];
111-
112-
$tags = [
113-
10 => ['tag3'],
114-
42 => ['tag1', 'tag2'],
115-
];
116-
117-
$tagger->method('getTagsForObjects')
118-
->with([10, 22, 42])
119-
->willReturn($tags);
120-
121-
$result = Helper::populateTags($data, $tagManager);
122-
123-
$this->assertSame([
124-
['file_source' => 10, 'tags' => ['tag3']],
125-
['file_source' => 22, 'foo' => 'bar', 'tags' => []],
126-
['file_source' => 42, 'x' => 'y', 'tags' => ['tag1', 'tag2']],
127-
], $result);
128-
}
12995
}

apps/files_sharing/lib/Controller/ShareAPIController.php

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public function __construct(
9494
private LoggerInterface $logger,
9595
private IProviderFactory $factory,
9696
private IMailer $mailer,
97+
private ITagManager $tagManager,
9798
private ?string $userId = null,
9899
) {
99100
parent::__construct($appName, $request);
@@ -472,7 +473,7 @@ public function getShare(string $id, bool $include_tags = false): DataResponse {
472473
$share = $this->formatShare($share);
473474

474475
if ($include_tags) {
475-
$share = Helper::populateTags([$share], Server::get(ITagManager::class));
476+
$share = $this->populateTags([$share]);
476477
} else {
477478
$share = [$share];
478479
}
@@ -847,7 +848,7 @@ private function getSharedWithMe($node, bool $includeTags): array {
847848
}
848849

849850
if ($includeTags) {
850-
$formatted = Helper::populateTags($formatted, Server::get(ITagManager::class));
851+
$formatted = $this->populateTags($formatted);
851852
}
852853

853854
return $formatted;
@@ -1100,8 +1101,7 @@ private function getFormattedShares(
11001101
$formatted = $this->fixMissingDisplayName($formatted);
11011102

11021103
if ($includeTags) {
1103-
$formatted =
1104-
Helper::populateTags($formatted, Server::get(ITagManager::class));
1104+
$formatted = $this->populateTags($formatted);
11051105
}
11061106

11071107
return $formatted;
@@ -2221,4 +2221,41 @@ public function generateToken(): DataResponse {
22212221
throw new OCSException($this->l->t('Failed to generate a unique token'));
22222222
}
22232223
}
2224+
2225+
/**
2226+
* Populate the result set with file tags
2227+
*
2228+
* @psalm-template T of array{tags?: list<string>, file_source: int, ...array<string, mixed>}
2229+
* @param list<T> $fileList
2230+
* @return list<T> file list populated with tags
2231+
*/
2232+
private function populateTags(array $fileList): array {
2233+
$tagger = $this->tagManager->load('files');
2234+
$tags = $tagger->getTagsForObjects(array_map(static fn (array $fileData) => $fileData['file_source'], $fileList));
2235+
2236+
if (!is_array($tags)) {
2237+
throw new \UnexpectedValueException('$tags must be an array');
2238+
}
2239+
2240+
// Set empty tag array
2241+
foreach ($fileList as &$fileData) {
2242+
$fileData['tags'] = [];
2243+
}
2244+
unset($fileData);
2245+
2246+
if (!empty($tags)) {
2247+
foreach ($tags as $fileId => $fileTags) {
2248+
foreach ($fileList as &$fileData) {
2249+
if ($fileId !== $fileData['file_source']) {
2250+
continue;
2251+
}
2252+
2253+
$fileData['tags'] = $fileTags;
2254+
}
2255+
unset($fileData);
2256+
}
2257+
}
2258+
2259+
return $fileList;
2260+
}
22242261
}

apps/files_sharing/tests/ApiTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use OCP\IL10N;
2727
use OCP\IPreview;
2828
use OCP\IRequest;
29+
use OCP\ITagManager;
2930
use OCP\IURLGenerator;
3031
use OCP\IUserManager;
3132
use OCP\Mail\IMailer;
@@ -111,6 +112,7 @@ private function createOCS($userId) {
111112
$logger = $this->createMock(LoggerInterface::class);
112113
$providerFactory = $this->createMock(IProviderFactory::class);
113114
$mailer = $this->createMock(IMailer::class);
115+
$tagManager = $this->createMock(ITagManager::class);
114116
$dateTimeZone->method('getTimeZone')->willReturn(new \DateTimeZone(date_default_timezone_get()));
115117

116118
return new ShareAPIController(
@@ -131,6 +133,7 @@ private function createOCS($userId) {
131133
$logger,
132134
$providerFactory,
133135
$mailer,
136+
$tagManager,
134137
$userId,
135138
);
136139
}

0 commit comments

Comments
 (0)