diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files/l10n/cs.js | 8 | ||||
-rw-r--r-- | apps/files/l10n/cs.json | 8 | ||||
-rw-r--r-- | apps/files/l10n/ga.js | 7 | ||||
-rw-r--r-- | apps/files/l10n/ga.json | 7 | ||||
-rw-r--r-- | apps/files/l10n/it.js | 4 | ||||
-rw-r--r-- | apps/files/l10n/it.json | 4 | ||||
-rw-r--r-- | apps/files/lib/Helper.php | 105 | ||||
-rw-r--r-- | apps/files/tests/HelperTest.php | 34 | ||||
-rw-r--r-- | apps/files_sharing/l10n/eu.js | 2 | ||||
-rw-r--r-- | apps/files_sharing/l10n/eu.json | 2 | ||||
-rw-r--r-- | apps/files_sharing/lib/Controller/ShareAPIController.php | 45 | ||||
-rw-r--r-- | apps/files_sharing/tests/ApiTest.php | 3 | ||||
-rw-r--r-- | apps/files_sharing/tests/Controller/ShareAPIControllerTest.php | 50 | ||||
-rw-r--r-- | apps/files_versions/lib/Storage.php | 8 |
14 files changed, 137 insertions, 150 deletions
diff --git a/apps/files/l10n/cs.js b/apps/files/l10n/cs.js index b6c83a08aee..b28537c6ae4 100644 --- a/apps/files/l10n/cs.js +++ b/apps/files/l10n/cs.js @@ -71,6 +71,7 @@ OC.L10N.register( "Transferred from %1$s on %2$s" : "Převedeno z %1$s na %2$s", "Files compatibility" : "Kompatibilita souborů", "Allow to restrict filenames to ensure files can be synced with all clients. By default all filenames valid on POSIX (e.g. Linux or macOS) are allowed." : "Umožňuje omezit názvy souborů aby bylo zajištěno, že soubory bude možné synchronizovat se všemi klienty. Ve výchozím stavu jsou povoleny veškeré názvy souborů, splňující standard POSIX (např. Linux nebo macOS).", + "After enabling the Windows compatible filenames, existing files cannot be modified anymore but can be renamed to valid new names by their owner." : "Po povolení názvů souborů, kompatibilních s Windows, stávající soubory už nebude možné změnit, ale je možné je přejmenovat na platné nové názvy jejich vlastníkem.", "It is also possible to migrate files automatically after enabling this setting, please refer to the documentation about the occ command." : "Po povolení tohoto natavení je také možné soubory stěhovat automaticky. Další informace viz dokumentace k příkazu occ.", "Enforce Windows compatibility" : "Vynutit kompatibilitu s Windows", "This will block filenames not valid on Windows systems, like using reserved names or special characters. But this will not enforce compatibility of case sensitivity." : "Toto bude blokovat použití názvů souborů, které nejsou platné na strojích s Windows, jako je použití vyhrazených názvů nebo speciálních znaků. Ale nevynutí kompatibilitu v případě rozlišování malých/VELKÝCH písmen.", @@ -96,6 +97,12 @@ OC.L10N.register( "Invalid filename." : "Neplatný název souboru.", "Renamed \"{oldName}\" to \"{newName}\"" : "Přejmenováno „{oldName}“ na „{newName}", "Rename file" : "Přejmenovat soubor", + "Folder" : "Složka", + "Unknown file type" : "Neznámý typ souboru", + "{ext} image" : "{ext}obrázek", + "{ext} video" : "{ext} video", + "{ext} audio" : "{ext} audio", + "{ext} text" : "{ext} text", "Pending" : "Nevyřízené", "Unknown date" : "Neznámé datum", "Clear filter" : "Vyčistit filtr", @@ -106,6 +113,7 @@ OC.L10N.register( "Total rows summary" : "Celkový souhrn řádek", "Toggle selection for all files and folders" : "Vybrat / zrušit výběr všech souborů a složek", "Name" : "Název", + "File type" : "Typ souboru", "Size" : "Velikost", "\"{displayName}\" failed on some elements" : "„{displayName}“ se pro některé prvky nezdařilo", "\"{displayName}\" batch action executed successfully" : "hromadná akce „{displayName}“ úspěšně vykonána", diff --git a/apps/files/l10n/cs.json b/apps/files/l10n/cs.json index 1ee66b0e9c8..4258b4b31f4 100644 --- a/apps/files/l10n/cs.json +++ b/apps/files/l10n/cs.json @@ -69,6 +69,7 @@ "Transferred from %1$s on %2$s" : "Převedeno z %1$s na %2$s", "Files compatibility" : "Kompatibilita souborů", "Allow to restrict filenames to ensure files can be synced with all clients. By default all filenames valid on POSIX (e.g. Linux or macOS) are allowed." : "Umožňuje omezit názvy souborů aby bylo zajištěno, že soubory bude možné synchronizovat se všemi klienty. Ve výchozím stavu jsou povoleny veškeré názvy souborů, splňující standard POSIX (např. Linux nebo macOS).", + "After enabling the Windows compatible filenames, existing files cannot be modified anymore but can be renamed to valid new names by their owner." : "Po povolení názvů souborů, kompatibilních s Windows, stávající soubory už nebude možné změnit, ale je možné je přejmenovat na platné nové názvy jejich vlastníkem.", "It is also possible to migrate files automatically after enabling this setting, please refer to the documentation about the occ command." : "Po povolení tohoto natavení je také možné soubory stěhovat automaticky. Další informace viz dokumentace k příkazu occ.", "Enforce Windows compatibility" : "Vynutit kompatibilitu s Windows", "This will block filenames not valid on Windows systems, like using reserved names or special characters. But this will not enforce compatibility of case sensitivity." : "Toto bude blokovat použití názvů souborů, které nejsou platné na strojích s Windows, jako je použití vyhrazených názvů nebo speciálních znaků. Ale nevynutí kompatibilitu v případě rozlišování malých/VELKÝCH písmen.", @@ -94,6 +95,12 @@ "Invalid filename." : "Neplatný název souboru.", "Renamed \"{oldName}\" to \"{newName}\"" : "Přejmenováno „{oldName}“ na „{newName}", "Rename file" : "Přejmenovat soubor", + "Folder" : "Složka", + "Unknown file type" : "Neznámý typ souboru", + "{ext} image" : "{ext}obrázek", + "{ext} video" : "{ext} video", + "{ext} audio" : "{ext} audio", + "{ext} text" : "{ext} text", "Pending" : "Nevyřízené", "Unknown date" : "Neznámé datum", "Clear filter" : "Vyčistit filtr", @@ -104,6 +111,7 @@ "Total rows summary" : "Celkový souhrn řádek", "Toggle selection for all files and folders" : "Vybrat / zrušit výběr všech souborů a složek", "Name" : "Název", + "File type" : "Typ souboru", "Size" : "Velikost", "\"{displayName}\" failed on some elements" : "„{displayName}“ se pro některé prvky nezdařilo", "\"{displayName}\" batch action executed successfully" : "hromadná akce „{displayName}“ úspěšně vykonána", diff --git a/apps/files/l10n/ga.js b/apps/files/l10n/ga.js index 232c98146f3..a52a16fb4b4 100644 --- a/apps/files/l10n/ga.js +++ b/apps/files/l10n/ga.js @@ -98,6 +98,11 @@ OC.L10N.register( "Renamed \"{oldName}\" to \"{newName}\"" : "Athainmnithe \"{oldName}\" go \"{newName}\"", "Rename file" : "Athainmnigh an comhad", "Folder" : "Fillteán", + "Unknown file type" : "Cineál comhaid anaithnid", + "{ext} image" : "íomhá {ext}", + "{ext} video" : "físeán {ext}", + "{ext} audio" : "fuaim {ext}", + "{ext} text" : "téacs {ext}", "Pending" : "Ar feitheamh", "Unknown date" : "Dáta anaithnid", "Clear filter" : "Glan an scagaire", @@ -108,6 +113,7 @@ OC.L10N.register( "Total rows summary" : "Achoimre ar na sraitheanna iomlána", "Toggle selection for all files and folders" : "Scoránaigh an roghnúchán do gach comhad agus fillteán", "Name" : "Ainm", + "File type" : "Cineál comhaid", "Size" : "Méid", "\"{displayName}\" failed on some elements" : "\"{displayName}\" theip ar roinnt gnéithe", "\"{displayName}\" batch action executed successfully" : "D'éirigh le beart baisce \"{displayName}\" a rith", @@ -186,6 +192,7 @@ OC.L10N.register( "Sort favorites first" : "Sórtáil na cinn is ansa leat ar dtús", "Sort folders before files" : "Sórtáil fillteáin roimh chomhaid", "Show hidden files" : "Taispeáin comhaid i bhfolach", + "Show file type column" : "Taispeáin colún cineál comhaid", "Crop image previews" : "Réamhamhairc íomhá barr", "Enable the grid view" : "Cumasaigh an radharc greille", "Enable folder tree" : "Cumasaigh crann fillteáin", diff --git a/apps/files/l10n/ga.json b/apps/files/l10n/ga.json index db09fb79b39..2da61d98e94 100644 --- a/apps/files/l10n/ga.json +++ b/apps/files/l10n/ga.json @@ -96,6 +96,11 @@ "Renamed \"{oldName}\" to \"{newName}\"" : "Athainmnithe \"{oldName}\" go \"{newName}\"", "Rename file" : "Athainmnigh an comhad", "Folder" : "Fillteán", + "Unknown file type" : "Cineál comhaid anaithnid", + "{ext} image" : "íomhá {ext}", + "{ext} video" : "físeán {ext}", + "{ext} audio" : "fuaim {ext}", + "{ext} text" : "téacs {ext}", "Pending" : "Ar feitheamh", "Unknown date" : "Dáta anaithnid", "Clear filter" : "Glan an scagaire", @@ -106,6 +111,7 @@ "Total rows summary" : "Achoimre ar na sraitheanna iomlána", "Toggle selection for all files and folders" : "Scoránaigh an roghnúchán do gach comhad agus fillteán", "Name" : "Ainm", + "File type" : "Cineál comhaid", "Size" : "Méid", "\"{displayName}\" failed on some elements" : "\"{displayName}\" theip ar roinnt gnéithe", "\"{displayName}\" batch action executed successfully" : "D'éirigh le beart baisce \"{displayName}\" a rith", @@ -184,6 +190,7 @@ "Sort favorites first" : "Sórtáil na cinn is ansa leat ar dtús", "Sort folders before files" : "Sórtáil fillteáin roimh chomhaid", "Show hidden files" : "Taispeáin comhaid i bhfolach", + "Show file type column" : "Taispeáin colún cineál comhaid", "Crop image previews" : "Réamhamhairc íomhá barr", "Enable the grid view" : "Cumasaigh an radharc greille", "Enable folder tree" : "Cumasaigh crann fillteáin", diff --git a/apps/files/l10n/it.js b/apps/files/l10n/it.js index 03a1cda9804..1394712a176 100644 --- a/apps/files/l10n/it.js +++ b/apps/files/l10n/it.js @@ -99,6 +99,10 @@ OC.L10N.register( "Rename file" : "Rinomina file", "Folder" : "Cartella", "Unknown file type" : "Tipo di file sconosciuto", + "{ext} image" : "{ext} image", + "{ext} video" : "{ext} video", + "{ext} audio" : "{ext} audio", + "{ext} text" : "{ext} text", "Pending" : "In corso", "Unknown date" : "Data sconosciuta", "Clear filter" : "Pulisci il filtro", diff --git a/apps/files/l10n/it.json b/apps/files/l10n/it.json index e83848ed70a..cd91fe47818 100644 --- a/apps/files/l10n/it.json +++ b/apps/files/l10n/it.json @@ -97,6 +97,10 @@ "Rename file" : "Rinomina file", "Folder" : "Cartella", "Unknown file type" : "Tipo di file sconosciuto", + "{ext} image" : "{ext} image", + "{ext} video" : "{ext} video", + "{ext} audio" : "{ext} audio", + "{ext} text" : "{ext} text", "Pending" : "In corso", "Unknown date" : "Data sconosciuta", "Clear filter" : "Pulisci il filtro", diff --git a/apps/files/lib/Helper.php b/apps/files/lib/Helper.php index 82d1cc94934..b1439ac7fa5 100644 --- a/apps/files/lib/Helper.php +++ b/apps/files/lib/Helper.php @@ -9,10 +9,6 @@ namespace OCA\Files; use OC\Files\Filesystem; use OCP\Files\FileInfo; -use OCP\Files\IMimeTypeDetector; -use OCP\Files\NotFoundException; -use OCP\ITagManager; -use OCP\Server; use OCP\Util; /** @@ -20,56 +16,6 @@ use OCP\Util; */ class Helper { /** - * @param string $dir - * @return array - * @throws NotFoundException - */ - public static function buildFileStorageStatistics($dir) { - // information about storage capacities - $storageInfo = \OC_Helper::getStorageInfo($dir); - $l = Util::getL10N('files'); - $maxUploadFileSize = Util::maxUploadFilesize($dir, $storageInfo['free']); - $maxHumanFileSize = Util::humanFileSize($maxUploadFileSize); - $maxHumanFileSize = $l->t('Upload (max. %s)', [$maxHumanFileSize]); - - return [ - 'uploadMaxFilesize' => $maxUploadFileSize, - 'maxHumanFilesize' => $maxHumanFileSize, - 'freeSpace' => $storageInfo['free'], - 'quota' => $storageInfo['quota'], - 'total' => $storageInfo['total'], - 'used' => $storageInfo['used'], - 'usedSpacePercent' => $storageInfo['relative'], - 'owner' => $storageInfo['owner'], - 'ownerDisplayName' => $storageInfo['ownerDisplayName'], - 'mountType' => $storageInfo['mountType'], - 'mountPoint' => $storageInfo['mountPoint'], - ]; - } - - /** - * Determine icon for a given file - * - * @param FileInfo $file file info - * @return string icon URL - */ - public static function determineIcon($file) { - if ($file['type'] === 'dir') { - $icon = Server::get(IMimeTypeDetector::class)->mimeTypeIcon('dir'); - // TODO: move this part to the client side, using mountType - if ($file->isShared()) { - $icon = Server::get(IMimeTypeDetector::class)->mimeTypeIcon('dir-shared'); - } elseif ($file->isMounted()) { - $icon = Server::get(IMimeTypeDetector::class)->mimeTypeIcon('dir-external'); - } - } else { - $icon = Server::get(IMimeTypeDetector::class)->mimeTypeIcon($file->getMimetype()); - } - - return substr($icon, 0, -3) . 'svg'; - } - - /** * Comparator function to sort files alphabetically and have * the directories appear first * @@ -162,20 +108,6 @@ class Helper { } /** - * Format file info for JSON - * @param FileInfo[] $fileInfos file infos - * @return array - */ - public static function formatFileInfos($fileInfos) { - $files = []; - foreach ($fileInfos as $i) { - $files[] = self::formatFileInfo($i); - } - - return $files; - } - - /** * Retrieves the contents of the given directory and * returns it as a sorted array of FileInfo. * @@ -192,43 +124,6 @@ class Helper { } /** - * Populate the result set with file tags - * - * @psalm-template T of array{tags?: list<string>, file_source: int, ...array<string, mixed>} - * @param list<T> $fileList - * @return list<T> file list populated with tags - */ - public static function populateTags(array $fileList, ITagManager $tagManager) { - $tagger = $tagManager->load('files'); - $tags = $tagger->getTagsForObjects(array_map(static fn (array $fileData) => $fileData['file_source'], $fileList)); - - if (!is_array($tags)) { - throw new \UnexpectedValueException('$tags must be an array'); - } - - // Set empty tag array - foreach ($fileList as &$fileData) { - $fileData['tags'] = []; - } - unset($fileData); - - if (!empty($tags)) { - foreach ($tags as $fileId => $fileTags) { - foreach ($fileList as &$fileData) { - if ($fileId !== $fileData['file_source']) { - continue; - } - - $fileData['tags'] = $fileTags; - } - unset($fileData); - } - } - - return $fileList; - } - - /** * Sort the given file info array * * @param FileInfo[] $files files to sort diff --git a/apps/files/tests/HelperTest.php b/apps/files/tests/HelperTest.php index 0cf2812f816..5900e94215c 100644 --- a/apps/files/tests/HelperTest.php +++ b/apps/files/tests/HelperTest.php @@ -2,8 +2,6 @@ use OC\Files\FileInfo; use OCA\Files\Helper; -use OCP\ITagManager; -use OCP\ITags; /** * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors @@ -94,36 +92,4 @@ class HelperTest extends \Test\TestCase { $fileNames ); } - - public function testPopulateTags(): void { - $tagManager = $this->createMock(ITagManager::class); - $tagger = $this->createMock(ITags::class); - - $tagManager->method('load') - ->with('files') - ->willReturn($tagger); - - $data = [ - ['file_source' => 10], - ['file_source' => 22, 'foo' => 'bar'], - ['file_source' => 42, 'x' => 'y'], - ]; - - $tags = [ - 10 => ['tag3'], - 42 => ['tag1', 'tag2'], - ]; - - $tagger->method('getTagsForObjects') - ->with([10, 22, 42]) - ->willReturn($tags); - - $result = Helper::populateTags($data, $tagManager); - - $this->assertSame([ - ['file_source' => 10, 'tags' => ['tag3']], - ['file_source' => 22, 'foo' => 'bar', 'tags' => []], - ['file_source' => 42, 'x' => 'y', 'tags' => ['tag1', 'tag2']], - ], $result); - } } diff --git a/apps/files_sharing/l10n/eu.js b/apps/files_sharing/l10n/eu.js index cb02327f28b..d434a96576e 100644 --- a/apps/files_sharing/l10n/eu.js +++ b/apps/files_sharing/l10n/eu.js @@ -300,6 +300,8 @@ OC.L10N.register( "Expires {relativetime}" : "Iraungitzea: {relativetime}", "this share just expired." : "partekatze hau oraintxe iraungi da.", "Shared with you by {owner}" : "{owner} erabiltzaileak zurekin partekatua", + "Internal shares" : "Barneko partekatzeak", + "External shares" : "Kanpoko sareak", "Link to a file" : "Esteka fitxategi batera", "_Accept share_::_Accept shares_" : ["Onartu partekatzea","Onartu partekatzeak"], "Open in Files" : "Ireki Fitxategiak aplikazioan", diff --git a/apps/files_sharing/l10n/eu.json b/apps/files_sharing/l10n/eu.json index 01e001a7624..cf9789e6592 100644 --- a/apps/files_sharing/l10n/eu.json +++ b/apps/files_sharing/l10n/eu.json @@ -298,6 +298,8 @@ "Expires {relativetime}" : "Iraungitzea: {relativetime}", "this share just expired." : "partekatze hau oraintxe iraungi da.", "Shared with you by {owner}" : "{owner} erabiltzaileak zurekin partekatua", + "Internal shares" : "Barneko partekatzeak", + "External shares" : "Kanpoko sareak", "Link to a file" : "Esteka fitxategi batera", "_Accept share_::_Accept shares_" : ["Onartu partekatzea","Onartu partekatzeak"], "Open in Files" : "Ireki Fitxategiak aplikazioan", diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index 446db0b8fcc..23ba9da1568 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -94,6 +94,7 @@ class ShareAPIController extends OCSController { private LoggerInterface $logger, private IProviderFactory $factory, private IMailer $mailer, + private ITagManager $tagManager, private ?string $userId = null, ) { parent::__construct($appName, $request); @@ -472,7 +473,7 @@ class ShareAPIController extends OCSController { $share = $this->formatShare($share); if ($include_tags) { - $share = Helper::populateTags([$share], Server::get(ITagManager::class)); + $share = $this->populateTags([$share]); } else { $share = [$share]; } @@ -847,7 +848,7 @@ class ShareAPIController extends OCSController { } if ($includeTags) { - $formatted = Helper::populateTags($formatted, Server::get(ITagManager::class)); + $formatted = $this->populateTags($formatted); } return $formatted; @@ -1100,8 +1101,7 @@ class ShareAPIController extends OCSController { $formatted = $this->fixMissingDisplayName($formatted); if ($includeTags) { - $formatted = - Helper::populateTags($formatted, Server::get(ITagManager::class)); + $formatted = $this->populateTags($formatted); } return $formatted; @@ -2221,4 +2221,41 @@ class ShareAPIController extends OCSController { throw new OCSException($this->l->t('Failed to generate a unique token')); } } + + /** + * Populate the result set with file tags + * + * @psalm-template T of array{tags?: list<string>, file_source: int, ...array<string, mixed>} + * @param list<T> $fileList + * @return list<T> file list populated with tags + */ + private function populateTags(array $fileList): array { + $tagger = $this->tagManager->load('files'); + $tags = $tagger->getTagsForObjects(array_map(static fn (array $fileData) => $fileData['file_source'], $fileList)); + + if (!is_array($tags)) { + throw new \UnexpectedValueException('$tags must be an array'); + } + + // Set empty tag array + foreach ($fileList as &$fileData) { + $fileData['tags'] = []; + } + unset($fileData); + + if (!empty($tags)) { + foreach ($tags as $fileId => $fileTags) { + foreach ($fileList as &$fileData) { + if ($fileId !== $fileData['file_source']) { + continue; + } + + $fileData['tags'] = $fileTags; + } + unset($fileData); + } + } + + return $fileList; + } } diff --git a/apps/files_sharing/tests/ApiTest.php b/apps/files_sharing/tests/ApiTest.php index 4ef9f536cb9..a712903d768 100644 --- a/apps/files_sharing/tests/ApiTest.php +++ b/apps/files_sharing/tests/ApiTest.php @@ -26,6 +26,7 @@ use OCP\IGroupManager; use OCP\IL10N; use OCP\IPreview; use OCP\IRequest; +use OCP\ITagManager; use OCP\IURLGenerator; use OCP\IUserManager; use OCP\Mail\IMailer; @@ -111,6 +112,7 @@ class ApiTest extends TestCase { $logger = $this->createMock(LoggerInterface::class); $providerFactory = $this->createMock(IProviderFactory::class); $mailer = $this->createMock(IMailer::class); + $tagManager = $this->createMock(ITagManager::class); $dateTimeZone->method('getTimeZone')->willReturn(new \DateTimeZone(date_default_timezone_get())); return new ShareAPIController( @@ -131,6 +133,7 @@ class ApiTest extends TestCase { $logger, $providerFactory, $mailer, + $tagManager, $userId, ); } diff --git a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php index 29eae2dc581..02c133ee5d1 100644 --- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php +++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php @@ -28,6 +28,8 @@ use OCP\IGroupManager; use OCP\IL10N; use OCP\IPreview; use OCP\IRequest; +use OCP\ITagManager; +use OCP\ITags; use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserManager; @@ -76,6 +78,7 @@ class ShareAPIControllerTest extends TestCase { private LoggerInterface&MockObject $logger; private IProviderFactory&MockObject $factory; private IMailer&MockObject $mailer; + private ITagManager&MockObject $tagManager; protected function setUp(): void { $this->shareManager = $this->createMock(IManager::class); @@ -111,6 +114,7 @@ class ShareAPIControllerTest extends TestCase { $this->logger = $this->createMock(LoggerInterface::class); $this->factory = $this->createMock(IProviderFactory::class); $this->mailer = $this->createMock(IMailer::class); + $this->tagManager = $this->createMock(ITagManager::class); $this->ocs = new ShareAPIController( $this->appName, @@ -130,6 +134,7 @@ class ShareAPIControllerTest extends TestCase { $this->logger, $this->factory, $this->mailer, + $this->tagManager, $this->currentUser, ); } @@ -157,6 +162,7 @@ class ShareAPIControllerTest extends TestCase { $this->logger, $this->factory, $this->mailer, + $this->tagManager, $this->currentUser, ])->onlyMethods(['formatShare']) ->getMock(); @@ -841,8 +847,8 @@ class ShareAPIControllerTest extends TestCase { $this->logger, $this->factory, $this->mailer, + $this->tagManager, $this->currentUser, - ]) ->onlyMethods(['canAccessShare']) ->getMock(); @@ -1474,6 +1480,7 @@ class ShareAPIControllerTest extends TestCase { $this->logger, $this->factory, $this->mailer, + $this->tagManager, $this->currentUser, ]) ->onlyMethods(['formatShare']) @@ -1816,8 +1823,9 @@ class ShareAPIControllerTest extends TestCase { $this->logger, $this->factory, $this->mailer, + $this->tagManager, $this->currentUser, - ])->setMethods(['formatShare']) + ])->onlyMethods(['formatShare']) ->getMock(); [$userFolder, $path] = $this->getNonSharedUserFile(); @@ -1913,8 +1921,9 @@ class ShareAPIControllerTest extends TestCase { $this->logger, $this->factory, $this->mailer, + $this->tagManager, $this->currentUser, - ])->setMethods(['formatShare']) + ])->onlyMethods(['formatShare']) ->getMock(); $this->request @@ -2338,8 +2347,9 @@ class ShareAPIControllerTest extends TestCase { $this->logger, $this->factory, $this->mailer, + $this->tagManager, $this->currentUser, - ])->setMethods(['formatShare']) + ])->onlyMethods(['formatShare']) ->getMock(); [$userFolder, $path] = $this->getNonSharedUserFile(); @@ -2408,8 +2418,9 @@ class ShareAPIControllerTest extends TestCase { $this->logger, $this->factory, $this->mailer, + $this->tagManager, $this->currentUser, - ])->setMethods(['formatShare']) + ])->onlyMethods(['formatShare']) ->getMock(); [$userFolder, $path] = $this->getNonSharedUserFile(); @@ -2639,8 +2650,9 @@ class ShareAPIControllerTest extends TestCase { $this->logger, $this->factory, $this->mailer, + $this->tagManager, $this->currentUser, - ])->setMethods(['formatShare']) + ])->onlyMethods(['formatShare']) ->getMock(); $userFolder = $this->getMockBuilder(Folder::class)->getMock(); @@ -5138,4 +5150,30 @@ class ShareAPIControllerTest extends TestCase { $node->method('getId')->willReturn(42); return [$userFolder, $node]; } + + public function testPopulateTags(): void { + $tagger = $this->createMock(ITags::class); + $this->tagManager->method('load') + ->with('files') + ->willReturn($tagger); + $data = [ + ['file_source' => 10], + ['file_source' => 22, 'foo' => 'bar'], + ['file_source' => 42, 'x' => 'y'], + ]; + $tags = [ + 10 => ['tag3'], + 42 => ['tag1', 'tag2'], + ]; + $tagger->method('getTagsForObjects') + ->with([10, 22, 42]) + ->willReturn($tags); + + $result = self::invokePrivate($this->ocs, 'populateTags', [$data]); + $this->assertSame([ + ['file_source' => 10, 'tags' => ['tag3']], + ['file_source' => 22, 'foo' => 'bar', 'tags' => []], + ['file_source' => 42, 'x' => 'y', 'tags' => ['tag1', 'tag2']], + ], $result); + } } diff --git a/apps/files_versions/lib/Storage.php b/apps/files_versions/lib/Storage.php index 4b58d721583..0fb3a0522f4 100644 --- a/apps/files_versions/lib/Storage.php +++ b/apps/files_versions/lib/Storage.php @@ -430,11 +430,17 @@ class Storage { } else { $target = $storage2->fopen($internalPath2, 'w'); $result = $target !== false; - if ($target !== false) { + if ($result) { [, $result] = Files::streamCopy($source, $target, true); + } + // explicit check as S3 library closes streams already + if (is_resource($target)) { fclose($target); } } + } + // explicit check as S3 library closes streams already + if (is_resource($source)) { fclose($source); } |