diff options
Diffstat (limited to 'apps/files')
-rw-r--r-- | apps/files/lib/Command/Scan.php | 3 | ||||
-rw-r--r-- | apps/files/lib/Command/ScanAppData.php | 3 | ||||
-rw-r--r-- | apps/files/lib/Controller/ApiController.php | 8 | ||||
-rw-r--r-- | apps/files/lib/Controller/ViewController.php | 8 | ||||
-rw-r--r-- | apps/files/lib/Helper.php | 12 | ||||
-rw-r--r-- | apps/files/lib/Listener/LoadSearchPluginsListener.php | 3 | ||||
-rw-r--r-- | apps/files/lib/Listener/RenderReferenceEventListener.php | 3 | ||||
-rw-r--r-- | apps/files/lib/Service/OwnershipTransferService.php | 13 | ||||
-rw-r--r-- | apps/files/lib/Settings/PersonalSettings.php | 3 | ||||
-rw-r--r-- | apps/files/tests/Command/DeleteOrphanedFilesTest.php | 5 | ||||
-rw-r--r-- | apps/files/tests/Controller/ApiControllerTest.php | 8 | ||||
-rw-r--r-- | apps/files/tests/Controller/ViewControllerTest.php | 10 | ||||
-rw-r--r-- | apps/files/tests/HelperTest.php | 15 | ||||
-rw-r--r-- | apps/files/tests/Service/TagServiceTest.php | 5 |
14 files changed, 62 insertions, 37 deletions
diff --git a/apps/files/lib/Command/Scan.php b/apps/files/lib/Command/Scan.php index 283ce17cd85..cf1cb04b9af 100644 --- a/apps/files/lib/Command/Scan.php +++ b/apps/files/lib/Command/Scan.php @@ -11,6 +11,7 @@ use OC\Core\Command\Base; use OC\Core\Command\InterruptedException; use OC\DB\Connection; use OC\DB\ConnectionAdapter; +use OC\Files\Utils\Scanner; use OC\FilesMetadata\FilesMetadataManager; use OC\ForbiddenException; use OCP\EventDispatcher\IEventDispatcher; @@ -98,7 +99,7 @@ class Scan extends Base { protected function scanFiles(string $user, string $path, ?string $scanMetadata, OutputInterface $output, bool $backgroundScan = false, bool $recursive = true, bool $homeOnly = false): void { $connection = $this->reconnectToDatabase($output); - $scanner = new \OC\Files\Utils\Scanner( + $scanner = new Scanner( $user, new ConnectionAdapter($connection), \OC::$server->get(IEventDispatcher::class), diff --git a/apps/files/lib/Command/ScanAppData.php b/apps/files/lib/Command/ScanAppData.php index 4d89389fe32..4c52297003f 100644 --- a/apps/files/lib/Command/ScanAppData.php +++ b/apps/files/lib/Command/ScanAppData.php @@ -9,6 +9,7 @@ use OC\Core\Command\Base; use OC\Core\Command\InterruptedException; use OC\DB\Connection; use OC\DB\ConnectionAdapter; +use OC\Files\Utils\Scanner; use OC\ForbiddenException; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\IRootFolder; @@ -65,7 +66,7 @@ class ScanAppData extends Base { } $connection = $this->reconnectToDatabase($output); - $scanner = new \OC\Files\Utils\Scanner( + $scanner = new Scanner( null, new ConnectionAdapter($connection), \OC::$server->query(IEventDispatcher::class), diff --git a/apps/files/lib/Controller/ApiController.php b/apps/files/lib/Controller/ApiController.php index 0ca4a1efd4b..118a4fcb9e2 100644 --- a/apps/files/lib/Controller/ApiController.php +++ b/apps/files/lib/Controller/ApiController.php @@ -8,6 +8,7 @@ namespace OCA\Files\Controller; use OC\Files\Node\Node; +use OCA\Files\Helper; use OCA\Files\ResponseDefinitions; use OCA\Files\Service\TagService; use OCA\Files\Service\UserConfig; @@ -30,6 +31,7 @@ use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; +use OCP\Files\StorageNotAvailableException; use OCP\IConfig; use OCP\IL10N; use OCP\IPreview; @@ -124,11 +126,11 @@ class ApiController extends Controller { if (!is_null($tags)) { try { $this->tagService->updateFileTags($path, $tags); - } catch (\OCP\Files\NotFoundException $e) { + } catch (NotFoundException $e) { return new DataResponse([ 'message' => $e->getMessage() ], Http::STATUS_NOT_FOUND); - } catch (\OCP\Files\StorageNotAvailableException $e) { + } catch (StorageNotAvailableException $e) { return new DataResponse([ 'message' => $e->getMessage() ], Http::STATUS_SERVICE_UNAVAILABLE); @@ -150,7 +152,7 @@ class ApiController extends Controller { $shareTypesForNodes = $this->getShareTypesForNodes($nodes); return array_values(array_map(function (Node $node) use ($shareTypesForNodes) { $shareTypes = $shareTypesForNodes[$node->getId()] ?? []; - $file = \OCA\Files\Helper::formatFileInfo($node->getFileInfo()); + $file = Helper::formatFileInfo($node->getFileInfo()); $file['hasPreview'] = $this->previewManager->isAvailable($node); $parts = explode('/', dirname($node->getPath()), 4); if (isset($parts[3])) { diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php index b5c61aaa5f4..b6aeb079add 100644 --- a/apps/files/lib/Controller/ViewController.php +++ b/apps/files/lib/Controller/ViewController.php @@ -8,6 +8,7 @@ namespace OCA\Files\Controller; use OC\Files\FilenameValidator; +use OC\Files\Filesystem; use OCA\Files\AppInfo\Application; use OCA\Files\Event\LoadAdditionalScriptsEvent; use OCA\Files\Event\LoadSearchPlugins; @@ -36,6 +37,7 @@ use OCP\IL10N; use OCP\IRequest; use OCP\IURLGenerator; use OCP\IUserSession; +use OCP\Util; /** * @package OCA\Files\Controller @@ -69,7 +71,7 @@ class ViewController extends Controller { * @throws \OCP\Files\NotFoundException */ protected function getStorageInfo(string $dir = '/') { - $rootInfo = \OC\Files\Filesystem::getFileInfo('/', false); + $rootInfo = Filesystem::getFileInfo('/', false); return \OC_Helper::getStorageInfo($dir, $rootInfo ?: null); } @@ -138,8 +140,8 @@ class ViewController extends Controller { } // Load the files we need - \OCP\Util::addInitScript('files', 'init'); - \OCP\Util::addScript('files', 'main'); + Util::addInitScript('files', 'init'); + Util::addScript('files', 'main'); $userId = $this->userSession->getUser()->getUID(); diff --git a/apps/files/lib/Helper.php b/apps/files/lib/Helper.php index 6126c1270eb..4ddab45d441 100644 --- a/apps/files/lib/Helper.php +++ b/apps/files/lib/Helper.php @@ -7,8 +7,10 @@ */ namespace OCA\Files; +use OC\Files\Filesystem; use OCP\Files\FileInfo; use OCP\ITagManager; +use OCP\Util; /** * Helper class for manipulating file information @@ -22,9 +24,9 @@ class Helper { public static function buildFileStorageStatistics($dir) { // information about storage capacities $storageInfo = \OC_Helper::getStorageInfo($dir); - $l = \OCP\Util::getL10N('files'); - $maxUploadFileSize = \OCP\Util::maxUploadFilesize($dir, $storageInfo['free']); - $maxHumanFileSize = \OCP\Util::humanFileSize($maxUploadFileSize); + $l = Util::getL10N('files'); + $maxUploadFileSize = Util::maxUploadFilesize($dir, $storageInfo['free']); + $maxHumanFileSize = Util::humanFileSize($maxUploadFileSize); $maxHumanFileSize = $l->t('Upload (max. %s)', [$maxHumanFileSize]); return [ @@ -80,7 +82,7 @@ class Helper { } elseif ($aType !== 'dir' and $bType === 'dir') { return 1; } else { - return \OCP\Util::naturalSortCompare($a->getName(), $b->getName()); + return Util::naturalSortCompare($a->getName(), $b->getName()); } } @@ -181,7 +183,7 @@ class Helper { * @return \OCP\Files\FileInfo[] files */ public static function getFiles($dir, $sortAttribute = 'name', $sortDescending = false, $mimetypeFilter = '') { - $content = \OC\Files\Filesystem::getDirectoryContent($dir, $mimetypeFilter); + $content = Filesystem::getDirectoryContent($dir, $mimetypeFilter); return self::sortFiles($content, $sortAttribute, $sortDescending); } diff --git a/apps/files/lib/Listener/LoadSearchPluginsListener.php b/apps/files/lib/Listener/LoadSearchPluginsListener.php index c9792242b2c..4cc4ca22f83 100644 --- a/apps/files/lib/Listener/LoadSearchPluginsListener.php +++ b/apps/files/lib/Listener/LoadSearchPluginsListener.php @@ -11,6 +11,7 @@ namespace OCA\Files\Listener; use OCA\Files\Event\LoadSearchPlugins; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; +use OCP\Util; /** @template-implements IEventListener<LoadSearchPlugins> */ class LoadSearchPluginsListener implements IEventListener { @@ -19,6 +20,6 @@ class LoadSearchPluginsListener implements IEventListener { return; } - \OCP\Util::addScript('files', 'search'); + Util::addScript('files', 'search'); } } diff --git a/apps/files/lib/Listener/RenderReferenceEventListener.php b/apps/files/lib/Listener/RenderReferenceEventListener.php index fc8b4d08aeb..b7470e5acf5 100644 --- a/apps/files/lib/Listener/RenderReferenceEventListener.php +++ b/apps/files/lib/Listener/RenderReferenceEventListener.php @@ -11,6 +11,7 @@ namespace OCA\Files\Listener; use OCP\Collaboration\Reference\RenderReferenceEvent; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; +use OCP\Util; /** @template-implements IEventListener<RenderReferenceEvent> */ class RenderReferenceEventListener implements IEventListener { @@ -19,6 +20,6 @@ class RenderReferenceEventListener implements IEventListener { return; } - \OCP\Util::addScript('files', 'reference-files'); + Util::addScript('files', 'reference-files'); } } diff --git a/apps/files/lib/Service/OwnershipTransferService.php b/apps/files/lib/Service/OwnershipTransferService.php index 5a57fae5075..2b06d18efcf 100644 --- a/apps/files/lib/Service/OwnershipTransferService.php +++ b/apps/files/lib/Service/OwnershipTransferService.php @@ -13,6 +13,7 @@ use Closure; use OC\Encryption\Manager as EncryptionManager; use OC\Files\Filesystem; use OC\Files\View; +use OCA\Encryption\Util; use OCA\Files\Exception\TransferOwnershipException; use OCP\Encryption\IManager as IEncryptionManager; use OCP\Files\Config\IUserMountCache; @@ -21,9 +22,11 @@ use OCP\Files\IHomeStorage; use OCP\Files\InvalidPathException; use OCP\Files\IRootFolder; use OCP\Files\Mount\IMountManager; +use OCP\Files\NotFoundException; use OCP\IUser; use OCP\IUserManager; use OCP\L10N\IFactory; +use OCP\Server; use OCP\Share\IManager as IShareManager; use OCP\Share\IShare; use Symfony\Component\Console\Helper\ProgressBar; @@ -227,7 +230,7 @@ class OwnershipTransferService { $progress->start(); if ($this->encryptionManager->isEnabled()) { - $masterKeyEnabled = \OCP\Server::get(\OCA\Encryption\Util::class)->isMasterKeyEnabled(); + $masterKeyEnabled = Server::get(Util::class)->isMasterKeyEnabled(); } else { $masterKeyEnabled = false; } @@ -416,7 +419,7 @@ class OwnershipTransferService { ):void { $output->writeln('Restoring shares ...'); $progress = new ProgressBar($output, count($shares)); - $rootFolder = \OCP\Server::get(IRootFolder::class); + $rootFolder = Server::get(IRootFolder::class); foreach ($shares as ['share' => $share, 'suffix' => $suffix]) { try { @@ -453,7 +456,7 @@ class OwnershipTransferService { // Normally the ID is preserved, // but for transferes between different storages the ID might change $newNodeId = $share->getNode()->getId(); - } catch (\OCP\Files\NotFoundException) { + } catch (NotFoundException) { // ID has changed due to transfer between different storages // Try to get the new ID from the target path and suffix of the share $node = $rootFolder->get(Filesystem::normalizePath($targetLocation . '/' . $suffix)); @@ -465,7 +468,7 @@ class OwnershipTransferService { $this->shareManager->updateShare($share); } } - } catch (\OCP\Files\NotFoundException $e) { + } catch (NotFoundException $e) { $output->writeln('<error>Share with id ' . $share->getId() . ' points at deleted file, skipping</error>'); } catch (\Throwable $e) { $output->writeln('<error>Could not restore share with id ' . $share->getId() . ':' . $e->getMessage() . ' : ' . $e->getTraceAsString() . '</error>'); @@ -545,7 +548,7 @@ class OwnershipTransferService { $this->shareManager->moveShare($share, $destinationUid); continue; } - } catch (\OCP\Files\NotFoundException $e) { + } catch (NotFoundException $e) { $output->writeln('<error>Share with id ' . $share->getId() . ' points at deleted file, skipping</error>'); } catch (\Throwable $e) { $output->writeln('<error>Could not restore share with id ' . $share->getId() . ':' . $e->getTraceAsString() . '</error>'); diff --git a/apps/files/lib/Settings/PersonalSettings.php b/apps/files/lib/Settings/PersonalSettings.php index 484e4bde2b8..fe43265bc13 100644 --- a/apps/files/lib/Settings/PersonalSettings.php +++ b/apps/files/lib/Settings/PersonalSettings.php @@ -11,10 +11,11 @@ namespace OCA\Files\Settings; use OCA\Files\AppInfo\Application; use OCP\AppFramework\Http\TemplateResponse; use OCP\Settings\ISettings; +use OCP\Util; class PersonalSettings implements ISettings { public function getForm(): TemplateResponse { - \OCP\Util::addScript(Application::APP_ID, 'settings-personal'); + Util::addScript(Application::APP_ID, 'settings-personal'); return new TemplateResponse(Application::APP_ID, 'settings-personal'); } diff --git a/apps/files/tests/Command/DeleteOrphanedFilesTest.php b/apps/files/tests/Command/DeleteOrphanedFilesTest.php index 6e9fbead34e..e480f7b632e 100644 --- a/apps/files/tests/Command/DeleteOrphanedFilesTest.php +++ b/apps/files/tests/Command/DeleteOrphanedFilesTest.php @@ -12,6 +12,7 @@ use OCA\Files\Command\DeleteOrphanedFiles; use OCP\Files\IRootFolder; use OCP\Files\StorageNotAvailableException; use OCP\IDBConnection; +use OCP\Server; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Test\TestCase; @@ -32,7 +33,7 @@ class DeleteOrphanedFilesTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->connection = \OCP\Server::get(IDBConnection::class); + $this->connection = Server::get(IDBConnection::class); $this->user1 = $this->getUniqueID('user1_'); @@ -81,7 +82,7 @@ class DeleteOrphanedFilesTest extends TestCase { ->disableOriginalConstructor() ->getMock(); - $rootFolder = \OCP\Server::get(IRootFolder::class); + $rootFolder = Server::get(IRootFolder::class); // scan home storage so that mounts are properly setup $rootFolder->getUserFolder($this->user1)->getStorage()->getScanner()->scan(''); diff --git a/apps/files/tests/Controller/ApiControllerTest.php b/apps/files/tests/Controller/ApiControllerTest.php index ad2a6a15b2b..e7f8b962a45 100644 --- a/apps/files/tests/Controller/ApiControllerTest.php +++ b/apps/files/tests/Controller/ApiControllerTest.php @@ -12,6 +12,8 @@ use OCA\Files\Service\UserConfig; use OCA\Files\Service\ViewConfig; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; +use OCP\AppFramework\Http\FileDisplayResponse; +use OCP\AppFramework\Http\Response; use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IRootFolder; @@ -211,7 +213,7 @@ class ApiControllerTest extends TestCase { $ret = $this->apiController->getThumbnail(10, 10, 'known.jpg'); $this->assertEquals(Http::STATUS_OK, $ret->getStatus()); - $this->assertInstanceOf(Http\FileDisplayResponse::class, $ret); + $this->assertInstanceOf(FileDisplayResponse::class, $ret); } public function testShowHiddenFiles(): void { @@ -221,7 +223,7 @@ class ApiControllerTest extends TestCase { ->method('setUserValue') ->with($this->user->getUID(), 'files', 'show_hidden', '0'); - $expected = new Http\Response(); + $expected = new Response(); $actual = $this->apiController->showHiddenFiles($show); $this->assertEquals($expected, $actual); @@ -234,7 +236,7 @@ class ApiControllerTest extends TestCase { ->method('setUserValue') ->with($this->user->getUID(), 'files', 'crop_image_previews', '1'); - $expected = new Http\Response(); + $expected = new Response(); $actual = $this->apiController->cropImagePreviews($crop); $this->assertEquals($expected, $actual); diff --git a/apps/files/tests/Controller/ViewControllerTest.php b/apps/files/tests/Controller/ViewControllerTest.php index a6eba1f9eaf..0c0647cc415 100644 --- a/apps/files/tests/Controller/ViewControllerTest.php +++ b/apps/files/tests/Controller/ViewControllerTest.php @@ -12,7 +12,9 @@ use OCA\Files\Controller\ViewController; use OCA\Files\Service\UserConfig; use OCA\Files\Service\ViewConfig; use OCP\App\IAppManager; -use OCP\AppFramework\Http; +use OCP\AppFramework\Http\ContentSecurityPolicy; +use OCP\AppFramework\Http\RedirectResponse; +use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Services\IInitialState; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\File; @@ -133,11 +135,11 @@ class ViewControllerTest extends TestCase { ->method('getAppValue') ->willReturnArgument(2); - $expected = new Http\TemplateResponse( + $expected = new TemplateResponse( 'files', 'index', ); - $policy = new Http\ContentSecurityPolicy(); + $policy = new ContentSecurityPolicy(); $policy->addAllowedWorkerSrcDomain('\'self\''); $policy->addAllowedFrameDomain('\'self\''); $expected->setContentSecurityPolicy($policy); @@ -193,7 +195,7 @@ class ViewControllerTest extends TestCase { ->with('files.view.indexViewFileid', ['view' => 'trashbin', 'dir' => '/test.d1462861890/sub', 'fileid' => '123']) ->willReturn('/apps/files/trashbin/123?dir=/test.d1462861890/sub'); - $expected = new Http\RedirectResponse('/apps/files/trashbin/123?dir=/test.d1462861890/sub'); + $expected = new RedirectResponse('/apps/files/trashbin/123?dir=/test.d1462861890/sub'); $this->assertEquals($expected, $this->viewController->index('', '', '123')); } } diff --git a/apps/files/tests/HelperTest.php b/apps/files/tests/HelperTest.php index fdcef8f7125..27b1de1322f 100644 --- a/apps/files/tests/HelperTest.php +++ b/apps/files/tests/HelperTest.php @@ -1,5 +1,10 @@ <?php +use OC\Files\FileInfo; +use OCA\Files\Helper; +use OCP\ITagManager; +use OCP\ITags; + /** * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 ownCloud, Inc. @@ -7,7 +12,7 @@ */ class HelperTest extends \Test\TestCase { private function makeFileInfo($name, $size, $mtime, $isDir = false) { - return new \OC\Files\FileInfo( + return new FileInfo( '/' . $name, null, '/', @@ -79,7 +84,7 @@ class HelperTest extends \Test\TestCase { $this->markTestSkipped('Skip mtime sorting on 32bit'); } $files = self::getTestFileList(); - $files = \OCA\Files\Helper::sortFiles($files, $sort, $sortDescending); + $files = Helper::sortFiles($files, $sort, $sortDescending); $fileNames = []; foreach ($files as $fileInfo) { $fileNames[] = $fileInfo->getName(); @@ -91,8 +96,8 @@ class HelperTest extends \Test\TestCase { } public function testPopulateTags(): void { - $tagManager = $this->createMock(\OCP\ITagManager::class); - $tagger = $this->createMock(\OCP\ITags::class); + $tagManager = $this->createMock(ITagManager::class); + $tagger = $this->createMock(ITags::class); $tagManager->method('load') ->with('files') @@ -113,7 +118,7 @@ class HelperTest extends \Test\TestCase { ->with([10, 22, 42]) ->willReturn($tags); - $result = \OCA\Files\Helper::populateTags($data, 'id', $tagManager); + $result = Helper::populateTags($data, 'id', $tagManager); $this->assertSame([ ['id' => 10, 'tags' => ['tag3']], diff --git a/apps/files/tests/Service/TagServiceTest.php b/apps/files/tests/Service/TagServiceTest.php index 7922c45a639..0e3ac66ef38 100644 --- a/apps/files/tests/Service/TagServiceTest.php +++ b/apps/files/tests/Service/TagServiceTest.php @@ -10,6 +10,7 @@ namespace OCA\Files\Tests\Service; use OCA\Files\Service\TagService; use OCP\Activity\IManager; use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\NotFoundException; use OCP\ITags; use OCP\IUser; use OCP\IUserSession; @@ -43,7 +44,7 @@ class TagServiceTest extends \Test\TestCase { private $dispatcher; /** - * @var \OCA\Files\Service\TagService|\PHPUnit\Framework\MockObject\MockObject + * @var TagService|\PHPUnit\Framework\MockObject\MockObject */ private $tagService; @@ -134,7 +135,7 @@ class TagServiceTest extends \Test\TestCase { $caught = false; try { $this->tagService->updateFileTags('subdir/unexist.txt', [$tag1]); - } catch (\OCP\Files\NotFoundException $e) { + } catch (NotFoundException $e) { $caught = true; } $this->assertTrue($caught); |