aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2024-10-10 12:40:31 +0200
committerCôme Chilliet <come.chilliet@nextcloud.com>2024-10-15 10:40:25 +0200
commit1580c8612b01bfa780d1a7372080a27d182fb7dd (patch)
treeb2776d0cd254ac9d6e54828978ce18b702f550d5 /apps/files_trashbin
parent4ff9b3e0ce53227e2be47c4c2dcb1fdc3e540b5f (diff)
downloadnextcloud-server-1580c8612b01bfa780d1a7372080a27d182fb7dd.tar.gz
nextcloud-server-1580c8612b01bfa780d1a7372080a27d182fb7dd.zip
chore(apps): Apply new rector configuration to autouse classes
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'apps/files_trashbin')
-rw-r--r--apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php3
-rw-r--r--apps/files_trashbin/lib/Command/ExpireTrash.php3
-rw-r--r--apps/files_trashbin/lib/Command/RestoreAllFiles.php3
-rw-r--r--apps/files_trashbin/lib/Controller/PreviewController.php3
-rw-r--r--apps/files_trashbin/lib/Helper.php7
-rw-r--r--apps/files_trashbin/lib/Sabre/TrashRoot.php3
-rw-r--r--apps/files_trashbin/lib/Trash/LegacyTrashBackend.php2
-rw-r--r--apps/files_trashbin/lib/Trashbin.php33
-rw-r--r--apps/files_trashbin/lib/UserMigration/TrashbinMigrator.php3
-rw-r--r--apps/files_trashbin/tests/Command/CleanUpTest.php3
-rw-r--r--apps/files_trashbin/tests/StorageTest.php26
-rw-r--r--apps/files_trashbin/tests/TrashbinTest.php147
12 files changed, 130 insertions, 106 deletions
diff --git a/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php b/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php
index 651f5035c1c..b5980b27c0a 100644
--- a/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php
+++ b/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php
@@ -6,6 +6,7 @@
*/
namespace OCA\Files_Trashbin\BackgroundJob;
+use OC\Files\View;
use OCA\Files_Trashbin\Expiration;
use OCA\Files_Trashbin\Helper;
use OCA\Files_Trashbin\Trashbin;
@@ -70,7 +71,7 @@ class ExpireTrash extends TimedJob {
\OC_Util::setupFS($user);
// Check if this user has a trashbin directory
- $view = new \OC\Files\View('/' . $user);
+ $view = new View('/' . $user);
if (!$view->is_dir('/files_trashbin/files')) {
return false;
}
diff --git a/apps/files_trashbin/lib/Command/ExpireTrash.php b/apps/files_trashbin/lib/Command/ExpireTrash.php
index 33a5ac83dbf..c27d74c0c26 100644
--- a/apps/files_trashbin/lib/Command/ExpireTrash.php
+++ b/apps/files_trashbin/lib/Command/ExpireTrash.php
@@ -6,6 +6,7 @@
*/
namespace OCA\Files_Trashbin\Command;
+use OC\Files\View;
use OCA\Files_Trashbin\Expiration;
use OCA\Files_Trashbin\Helper;
use OCA\Files_Trashbin\Trashbin;
@@ -103,7 +104,7 @@ class ExpireTrash extends Command {
\OC_Util::setupFS($user);
// Check if this user has a trashbin directory
- $view = new \OC\Files\View('/' . $user);
+ $view = new View('/' . $user);
if (!$view->is_dir('/files_trashbin/files')) {
return false;
}
diff --git a/apps/files_trashbin/lib/Command/RestoreAllFiles.php b/apps/files_trashbin/lib/Command/RestoreAllFiles.php
index 969791379c1..81b59543a4e 100644
--- a/apps/files_trashbin/lib/Command/RestoreAllFiles.php
+++ b/apps/files_trashbin/lib/Command/RestoreAllFiles.php
@@ -7,6 +7,7 @@ namespace OCA\Files_Trashbin\Command;
use OC\Core\Command\Base;
use OCA\Files_Trashbin\Trash\ITrashManager;
+use OCA\Files_Trashbin\Trash\TrashItem;
use OCP\Files\IRootFolder;
use OCP\IDBConnection;
use OCP\IL10N;
@@ -246,7 +247,7 @@ class RestoreAllFiles extends Base {
$trashItemClass = get_class($trashItem);
// Check scope with exact class name for locally deleted files
- if ($scope === self::SCOPE_USER && $trashItemClass !== \OCA\Files_Trashbin\Trash\TrashItem::class) {
+ if ($scope === self::SCOPE_USER && $trashItemClass !== TrashItem::class) {
$output->writeln('Skipping <info>' . $trashItem->getName() . '</info> because it is not a user trash item', OutputInterface::VERBOSITY_VERBOSE);
continue;
}
diff --git a/apps/files_trashbin/lib/Controller/PreviewController.php b/apps/files_trashbin/lib/Controller/PreviewController.php
index b006ba5e5ac..78d501b68d4 100644
--- a/apps/files_trashbin/lib/Controller/PreviewController.php
+++ b/apps/files_trashbin/lib/Controller/PreviewController.php
@@ -14,6 +14,7 @@ use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
use OCP\AppFramework\Http\DataResponse;
+use OCP\AppFramework\Http\FileDisplayResponse;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\Folder;
use OCP\Files\IMimeTypeDetector;
@@ -111,7 +112,7 @@ class PreviewController extends Controller {
}
$f = $this->previewManager->getPreview($file, $x, $y, !$a, IPreview::MODE_FILL, $mimeType);
- $response = new Http\FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]);
+ $response = new FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]);
// Cache previews for 24H
$response->cacheFor(3600 * 24);
diff --git a/apps/files_trashbin/lib/Helper.php b/apps/files_trashbin/lib/Helper.php
index 2e7916d9c6d..7aeb737a56c 100644
--- a/apps/files_trashbin/lib/Helper.php
+++ b/apps/files_trashbin/lib/Helper.php
@@ -7,6 +7,7 @@
namespace OCA\Files_Trashbin;
use OC\Files\FileInfo;
+use OC\Files\View;
use OCP\Constants;
use OCP\Files\Cache\ICacheEntry;
@@ -25,7 +26,7 @@ class Helper {
$result = [];
$timestamp = null;
- $view = new \OC\Files\View('/' . $user . '/files_trashbin/files');
+ $view = new View('/' . $user . '/files_trashbin/files');
if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) {
throw new \Exception('Directory does not exists');
@@ -36,7 +37,7 @@ class Helper {
$absoluteDir = $view->getAbsolutePath($dir);
$internalPath = $mount->getInternalPath($absoluteDir);
- $extraData = \OCA\Files_Trashbin\Trashbin::getExtraData($user);
+ $extraData = Trashbin::getExtraData($user);
$dirContent = $storage->getCache()->getFolderContents($mount->getInternalPath($view->getAbsolutePath($dir)));
foreach ($dirContent as $entry) {
$entryName = $entry->getName();
@@ -98,7 +99,7 @@ class Helper {
$entry = \OCA\Files\Helper::formatFileInfo($i);
$entry['id'] = $i->getId();
$entry['etag'] = $entry['mtime']; // add fake etag, it is only needed to identify the preview image
- $entry['permissions'] = \OCP\Constants::PERMISSION_READ;
+ $entry['permissions'] = Constants::PERMISSION_READ;
$files[] = $entry;
}
return $files;
diff --git a/apps/files_trashbin/lib/Sabre/TrashRoot.php b/apps/files_trashbin/lib/Sabre/TrashRoot.php
index 3421a56bd5a..e2661ccdec7 100644
--- a/apps/files_trashbin/lib/Sabre/TrashRoot.php
+++ b/apps/files_trashbin/lib/Sabre/TrashRoot.php
@@ -10,6 +10,7 @@ namespace OCA\Files_Trashbin\Sabre;
use OCA\Files_Trashbin\Trash\ITrashItem;
use OCA\Files_Trashbin\Trash\ITrashManager;
+use OCA\Files_Trashbin\Trashbin;
use OCP\Files\FileInfo;
use OCP\IUser;
use Sabre\DAV\Exception\Forbidden;
@@ -30,7 +31,7 @@ class TrashRoot implements ICollection {
}
public function delete() {
- \OCA\Files_Trashbin\Trashbin::deleteAll();
+ Trashbin::deleteAll();
foreach ($this->trashManager->listTrashRoot($this->user) as $trashItem) {
$this->trashManager->removeItem($trashItem);
}
diff --git a/apps/files_trashbin/lib/Trash/LegacyTrashBackend.php b/apps/files_trashbin/lib/Trash/LegacyTrashBackend.php
index 862c746c239..0fd370a6cf1 100644
--- a/apps/files_trashbin/lib/Trash/LegacyTrashBackend.php
+++ b/apps/files_trashbin/lib/Trash/LegacyTrashBackend.php
@@ -92,7 +92,7 @@ class LegacyTrashBackend implements ITrashBackend {
$this->deletedFiles[$normalized] = $normalized;
if ($filesPath = $view->getRelativePath($normalized)) {
$filesPath = trim($filesPath, '/');
- $result = \OCA\Files_Trashbin\Trashbin::move2trash($filesPath);
+ $result = Trashbin::move2trash($filesPath);
} else {
$result = false;
}
diff --git a/apps/files_trashbin/lib/Trashbin.php b/apps/files_trashbin/lib/Trashbin.php
index a30ba0ce055..f6e5a3830ad 100644
--- a/apps/files_trashbin/lib/Trashbin.php
+++ b/apps/files_trashbin/lib/Trashbin.php
@@ -19,6 +19,8 @@ use OCA\Files_Trashbin\AppInfo\Application;
use OCA\Files_Trashbin\Command\Expire;
use OCA\Files_Trashbin\Events\BeforeNodeRestoredEvent;
use OCA\Files_Trashbin\Events\NodeRestoredEvent;
+use OCA\Files_Trashbin\Exceptions\CopyRecursiveException;
+use OCA\Files_Versions\Storage;
use OCP\App\IAppManager;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\EventDispatcher\Event;
@@ -39,6 +41,7 @@ use OCP\IDBConnection;
use OCP\Lock\ILockingProvider;
use OCP\Lock\LockedException;
use OCP\Server;
+use OCP\Util;
use Psr\Log\LoggerInterface;
/** @template-implements IEventListener<BeforeNodeDeletedEvent> */
@@ -293,7 +296,7 @@ class Trashbin implements IEventListener {
if ($sourceStorage->getCache()->inCache($sourceInternalPath)) {
$trashStorage->getUpdater()->renameFromStorage($sourceStorage, $sourceInternalPath, $trashInternalPath);
}
- } catch (\OCA\Files_Trashbin\Exceptions\CopyRecursiveException $e) {
+ } catch (CopyRecursiveException $e) {
$moveSuccessful = false;
if ($trashStorage->file_exists($trashInternalPath)) {
$trashStorage->unlink($trashInternalPath);
@@ -329,7 +332,7 @@ class Trashbin implements IEventListener {
if (!$result) {
\OC::$server->get(LoggerInterface::class)->error('trash bin database couldn\'t be updated', ['app' => 'files_trashbin']);
}
- \OCP\Util::emitHook('\OCA\Files_Trashbin\Trashbin', 'post_moveToTrash', ['filePath' => Filesystem::normalizePath($file_path),
+ Util::emitHook('\OCA\Files_Trashbin\Trashbin', 'post_moveToTrash', ['filePath' => Filesystem::normalizePath($file_path),
'trashPath' => Filesystem::normalizePath(static::getTrashFilename($filename, $timestamp))]);
self::retainVersions($filename, $owner, $ownerPath, $timestamp);
@@ -356,11 +359,11 @@ class Trashbin implements IEventListener {
$config = \OC::$server->get(IConfig::class);
$userTrashbinSize = $config->getUserValue($user, 'files_trashbin', 'trashbin_size', '-1');
if (is_numeric($userTrashbinSize) && ($userTrashbinSize > -1)) {
- return \OCP\Util::numericToNumber($userTrashbinSize);
+ return Util::numericToNumber($userTrashbinSize);
}
$systemTrashbinSize = $config->getAppValue('files_trashbin', 'trashbin_size', '-1');
if (is_numeric($systemTrashbinSize)) {
- return \OCP\Util::numericToNumber($systemTrashbinSize);
+ return Util::numericToNumber($systemTrashbinSize);
}
return -1;
}
@@ -374,7 +377,7 @@ class Trashbin implements IEventListener {
* @param int $timestamp when the file was deleted
*/
private static function retainVersions($filename, $owner, $ownerPath, $timestamp) {
- if (\OCP\Server::get(IAppManager::class)->isEnabledForUser('files_versions') && !empty($ownerPath)) {
+ if (Server::get(IAppManager::class)->isEnabledForUser('files_versions') && !empty($ownerPath)) {
$user = OC_User::getUser();
$rootView = new View('/');
@@ -383,7 +386,7 @@ class Trashbin implements IEventListener {
self::copy_recursive($owner . '/files_versions/' . $ownerPath, $owner . '/files_trashbin/versions/' . static::getTrashFilename(basename($ownerPath), $timestamp), $rootView);
}
self::move($rootView, $owner . '/files_versions/' . $ownerPath, $user . '/files_trashbin/versions/' . static::getTrashFilename($filename, $timestamp));
- } elseif ($versions = \OCA\Files_Versions\Storage::getVersions($owner, $ownerPath)) {
+ } elseif ($versions = Storage::getVersions($owner, $ownerPath)) {
foreach ($versions as $v) {
if ($owner !== $user) {
self::copy($rootView, $owner . '/files_versions' . $v['path'] . '.v' . $v['version'], $owner . '/files_trashbin/versions/' . static::getTrashFilename($v['name'] . '.v' . $v['version'], $timestamp));
@@ -505,7 +508,7 @@ class Trashbin implements IEventListener {
$view->chroot('/' . $user . '/files');
$view->touch('/' . $location . '/' . $uniqueFilename, $mtime);
$view->chroot($fakeRoot);
- \OCP\Util::emitHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', ['filePath' => $targetPath, 'trashPath' => $sourcePath]);
+ Util::emitHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', ['filePath' => $targetPath, 'trashPath' => $sourcePath]);
$sourceNode = self::getNodeForPath($sourcePath);
$targetNode = self::getNodeForPath($targetPath);
@@ -542,7 +545,7 @@ class Trashbin implements IEventListener {
* @return false|null
*/
private static function restoreVersions(View $view, $file, $filename, $uniqueFilename, $location, $timestamp) {
- if (\OCP\Server::get(IAppManager::class)->isEnabledForUser('files_versions')) {
+ if (Server::get(IAppManager::class)->isEnabledForUser('files_versions')) {
$user = OC_User::getUser();
$rootView = new View('/');
@@ -700,7 +703,7 @@ class Trashbin implements IEventListener {
*/
private static function deleteVersions(View $view, $file, $filename, $timestamp, string $user): int|float {
$size = 0;
- if (\OCP\Server::get(IAppManager::class)->isEnabledForUser('files_versions')) {
+ if (Server::get(IAppManager::class)->isEnabledForUser('files_versions')) {
if ($view->is_dir('files_trashbin/versions/' . $file)) {
$size += self::calculateSize(new View('/' . $user . '/files_trashbin/versions/' . $file));
$view->unlink('files_trashbin/versions/' . $file);
@@ -778,7 +781,7 @@ class Trashbin implements IEventListener {
$quota = PHP_INT_MAX;
}
} else {
- $quota = \OCP\Util::computerFileSize($quota);
+ $quota = Util::computerFileSize($quota);
// invalid quota
if ($quota === false) {
$quota = PHP_INT_MAX;
@@ -802,7 +805,7 @@ class Trashbin implements IEventListener {
$availableSpace = $quota;
}
- return \OCP\Util::numericToNumber($availableSpace);
+ return Util::numericToNumber($availableSpace);
}
/**
@@ -902,7 +905,7 @@ class Trashbin implements IEventListener {
try {
$size += self::delete($filename, $user, $timestamp);
$count++;
- } catch (\OCP\Files\NotPermittedException $e) {
+ } catch (NotPermittedException $e) {
\OC::$server->get(LoggerInterface::class)->warning('Removing "' . $filename . '" from trashbin failed.',
[
'exception' => $e,
@@ -944,7 +947,7 @@ class Trashbin implements IEventListener {
$size += $view->filesize($pathDir);
$result = $view->copy($pathDir, $destination . '/' . $i['name']);
if (!$result) {
- throw new \OCA\Files_Trashbin\Exceptions\CopyRecursiveException();
+ throw new CopyRecursiveException();
}
$view->touch($destination . '/' . $i['name'], $view->filemtime($pathDir));
}
@@ -953,7 +956,7 @@ class Trashbin implements IEventListener {
$size += $view->filesize($source);
$result = $view->copy($source, $destination);
if (!$result) {
- throw new \OCA\Files_Trashbin\Exceptions\CopyRecursiveException();
+ throw new CopyRecursiveException();
}
$view->touch($destination, $view->filemtime($source));
}
@@ -1033,7 +1036,7 @@ class Trashbin implements IEventListener {
private static function getUniqueFilename($location, $filename, View $view) {
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$name = pathinfo($filename, PATHINFO_FILENAME);
- $l = \OCP\Util::getL10N('files_trashbin');
+ $l = Util::getL10N('files_trashbin');
$location = '/' . trim($location, '/');
diff --git a/apps/files_trashbin/lib/UserMigration/TrashbinMigrator.php b/apps/files_trashbin/lib/UserMigration/TrashbinMigrator.php
index 87c8647450f..b58efbb38a6 100644
--- a/apps/files_trashbin/lib/UserMigration/TrashbinMigrator.php
+++ b/apps/files_trashbin/lib/UserMigration/TrashbinMigrator.php
@@ -10,6 +10,7 @@ declare(strict_types=1);
namespace OCA\Files_Trashbin\UserMigration;
use OCA\Files_Trashbin\AppInfo\Application;
+use OCA\Files_Trashbin\Trashbin;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
@@ -81,7 +82,7 @@ class TrashbinMigrator implements IMigrator, ISizeEstimationMigrator {
$exportDestination->copyFolder($trashbinFolder, static::PATH_FILES_FOLDER);
$originalLocations = [];
// TODO Export all extra data and bump migrator to v2
- foreach (\OCA\Files_Trashbin\Trashbin::getExtraData($uid) as $filename => $extraData) {
+ foreach (Trashbin::getExtraData($uid) as $filename => $extraData) {
$locationData = [];
foreach ($extraData as $timestamp => ['location' => $location]) {
$locationData[$timestamp] = $location;
diff --git a/apps/files_trashbin/tests/Command/CleanUpTest.php b/apps/files_trashbin/tests/Command/CleanUpTest.php
index b071fa8ecdd..fef57f44f24 100644
--- a/apps/files_trashbin/tests/Command/CleanUpTest.php
+++ b/apps/files_trashbin/tests/Command/CleanUpTest.php
@@ -10,6 +10,7 @@ use OC\User\Manager;
use OCA\Files_Trashbin\Command\CleanUp;
use OCP\Files\IRootFolder;
use OCP\IDBConnection;
+use OCP\UserInterface;
use Symfony\Component\Console\Exception\InvalidOptionException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\NullOutput;
@@ -175,7 +176,7 @@ class CleanUpTest extends TestCase {
->setMethods(['removeDeletedFiles'])
->setConstructorArgs([$this->rootFolder, $this->userManager, $this->dbConnection])
->getMock();
- $backend = $this->createMock(\OCP\UserInterface::class);
+ $backend = $this->createMock(UserInterface::class);
$backend->method('getUsers')
->with('', 500, 0)
->willReturn($backendUsers);
diff --git a/apps/files_trashbin/tests/StorageTest.php b/apps/files_trashbin/tests/StorageTest.php
index 8271109037c..0d56ecf0a71 100644
--- a/apps/files_trashbin/tests/StorageTest.php
+++ b/apps/files_trashbin/tests/StorageTest.php
@@ -9,12 +9,14 @@ namespace OCA\Files_Trashbin\Tests;
use OC\Files\Filesystem;
use OC\Files\Storage\Common;
use OC\Files\Storage\Temporary;
+use OC\Files\View;
use OCA\Files_Trashbin\AppInfo\Application;
use OCA\Files_Trashbin\Events\MoveToTrashEvent;
use OCA\Files_Trashbin\Storage;
use OCA\Files_Trashbin\Trash\ITrashManager;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\Constants;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Cache\ICache;
use OCP\Files\Folder;
@@ -83,10 +85,10 @@ class StorageTest extends \Test\TestCase {
// this will setup the FS
$this->loginAsUser($this->user);
- \OCA\Files_Trashbin\Storage::setupStorage();
+ Storage::setupStorage();
- $this->rootView = new \OC\Files\View('/');
- $this->userView = new \OC\Files\View('/' . $this->user . '/files/');
+ $this->rootView = new View('/');
+ $this->userView = new View('/' . $this->user . '/files/');
$this->userView->file_put_contents('test.txt', 'foo');
$this->userView->file_put_contents(static::LONG_FILENAME, 'foo');
$this->userView->file_put_contents(static::MAX_FILENAME, 'foo');
@@ -96,7 +98,7 @@ class StorageTest extends \Test\TestCase {
}
protected function tearDown(): void {
- \OC\Files\Filesystem::getLoader()->removeStorageWrapper('oc_trashbin');
+ Filesystem::getLoader()->removeStorageWrapper('oc_trashbin');
$this->logout();
$user = \OC::$server->getUserManager()->get($this->user);
if ($user !== null) {
@@ -191,7 +193,7 @@ class StorageTest extends \Test\TestCase {
*/
public function testCrossStorageDeleteFile(): void {
$storage2 = new Temporary([]);
- \OC\Files\Filesystem::mount($storage2, [], $this->user . '/files/substorage');
+ Filesystem::mount($storage2, [], $this->user . '/files/substorage');
$this->userView->file_put_contents('substorage/subfile.txt', 'foo');
$storage2->getScanner()->scan('');
@@ -217,7 +219,7 @@ class StorageTest extends \Test\TestCase {
*/
public function testCrossStorageDeleteFolder(): void {
$storage2 = new Temporary([]);
- \OC\Files\Filesystem::mount($storage2, [], $this->user . '/files/substorage');
+ Filesystem::mount($storage2, [], $this->user . '/files/substorage');
$this->userView->mkdir('substorage/folder');
$this->userView->file_put_contents('substorage/folder/subfile.txt', 'bar');
@@ -322,14 +324,14 @@ class StorageTest extends \Test\TestCase {
->setShareType(IShare::TYPE_USER)
->setSharedBy($this->user)
->setSharedWith($recipientUser)
- ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+ ->setPermissions(Constants::PERMISSION_ALL);
$share = \OC::$server->getShareManager()->createShare($share);
\OC::$server->getShareManager()->acceptShare($share, $recipientUser);
$this->loginAsUser($recipientUser);
// delete as recipient
- $recipientView = new \OC\Files\View('/' . $recipientUser . '/files');
+ $recipientView = new View('/' . $recipientUser . '/files');
$recipientView->unlink('share/test.txt');
// rescan trash storage for both users
@@ -374,14 +376,14 @@ class StorageTest extends \Test\TestCase {
->setShareType(IShare::TYPE_USER)
->setSharedBy($this->user)
->setSharedWith($recipientUser)
- ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+ ->setPermissions(Constants::PERMISSION_ALL);
$share = \OC::$server->getShareManager()->createShare($share);
\OC::$server->getShareManager()->acceptShare($share, $recipientUser);
$this->loginAsUser($recipientUser);
// delete as recipient
- $recipientView = new \OC\Files\View('/' . $recipientUser . '/files');
+ $recipientView = new View('/' . $recipientUser . '/files');
$recipientView->rmdir('share/folder');
// rescan trash storage
@@ -424,7 +426,7 @@ class StorageTest extends \Test\TestCase {
*/
public function testKeepFileAndVersionsWhenMovingFileBetweenStorages(): void {
$storage2 = new Temporary([]);
- \OC\Files\Filesystem::mount($storage2, [], $this->user . '/files/substorage');
+ Filesystem::mount($storage2, [], $this->user . '/files/substorage');
// trigger a version (multiple would not work because of the expire logic)
$this->userView->file_put_contents('test.txt', 'v1');
@@ -463,7 +465,7 @@ class StorageTest extends \Test\TestCase {
*/
public function testKeepFileAndVersionsWhenMovingFolderBetweenStorages(): void {
$storage2 = new Temporary([]);
- \OC\Files\Filesystem::mount($storage2, [], $this->user . '/files/substorage');
+ Filesystem::mount($storage2, [], $this->user . '/files/substorage');
// trigger a version (multiple would not work because of the expire logic)
$this->userView->file_put_contents('folder/inside.txt', 'v1');
diff --git a/apps/files_trashbin/tests/TrashbinTest.php b/apps/files_trashbin/tests/TrashbinTest.php
index 11501891c77..72aa9b280e8 100644
--- a/apps/files_trashbin/tests/TrashbinTest.php
+++ b/apps/files_trashbin/tests/TrashbinTest.php
@@ -4,10 +4,21 @@
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/
+use OC\AllConfig;
use OC\AppFramework\Bootstrap\BootContext;
use OC\AppFramework\DependencyInjection\DIContainer;
+use OC\Files\Cache\Watcher;
+use OC\Files\Filesystem;
+use OC\Files\Storage\Local;
+use OC\Files\View;
use OCA\Files_Sharing\AppInfo\Application;
use OCA\Files_Trashbin\AppInfo\Application as TrashbinApplication;
+use OCA\Files_Trashbin\Expiration;
+use OCA\Files_Trashbin\Helper;
+use OCA\Files_Trashbin\Trashbin;
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\Constants;
+use OCP\IConfig;
use OCP\Share\IShare;
/**
@@ -56,9 +67,9 @@ class TrashbinTest extends \Test\TestCase {
$config = \OC::$server->getConfig();
//configure trashbin
- self::$rememberRetentionObligation = $config->getSystemValue('trashbin_retention_obligation', \OCA\Files_Trashbin\Expiration::DEFAULT_RETENTION_OBLIGATION);
- /** @var \OCA\Files_Trashbin\Expiration $expiration */
- $expiration = \OC::$server->query(\OCA\Files_Trashbin\Expiration::class);
+ self::$rememberRetentionObligation = $config->getSystemValue('trashbin_retention_obligation', Expiration::DEFAULT_RETENTION_OBLIGATION);
+ /** @var Expiration $expiration */
+ $expiration = \OC::$server->query(Expiration::class);
$expiration->setRetentionObligation('auto, 2');
// register trashbin hooks
@@ -78,13 +89,13 @@ class TrashbinTest extends \Test\TestCase {
$user->delete();
}
- /** @var \OCA\Files_Trashbin\Expiration $expiration */
- $expiration = \OC::$server->query(\OCA\Files_Trashbin\Expiration::class);
+ /** @var Expiration $expiration */
+ $expiration = \OC::$server->query(Expiration::class);
$expiration->setRetentionObligation(self::$rememberRetentionObligation);
\OC_Hook::clear();
- \OC\Files\Filesystem::getLoader()->removeStorageWrapper('oc_trashbin');
+ Filesystem::getLoader()->removeStorageWrapper('oc_trashbin');
if (self::$trashBinStatus) {
\OC::$server->getAppManager()->enableApp('files_trashbin');
@@ -98,12 +109,12 @@ class TrashbinTest extends \Test\TestCase {
\OC::$server->getAppManager()->enableApp('files_trashbin');
$config = \OC::$server->getConfig();
- $mockConfig = $this->createMock(\OCP\IConfig::class);
+ $mockConfig = $this->createMock(IConfig::class);
$mockConfig
->method('getSystemValue')
->willReturnCallback(static function ($key, $default) use ($config) {
if ($key === 'filesystem_check_changes') {
- return \OC\Files\Cache\Watcher::CHECK_ONCE;
+ return Watcher::CHECK_ONCE;
} else {
return $config->getSystemValue($key, $default);
}
@@ -118,16 +129,16 @@ class TrashbinTest extends \Test\TestCase {
->willReturnCallback(static function ($appName, $key, $default = '') use ($config) {
return $config->getAppValue($appName, $key, $default);
});
- $this->overwriteService(\OC\AllConfig::class, $mockConfig);
+ $this->overwriteService(AllConfig::class, $mockConfig);
$this->trashRoot1 = '/' . self::TEST_TRASHBIN_USER1 . '/files_trashbin';
$this->trashRoot2 = '/' . self::TEST_TRASHBIN_USER2 . '/files_trashbin';
- $this->rootView = new \OC\Files\View();
+ $this->rootView = new View();
self::loginHelper(self::TEST_TRASHBIN_USER1);
}
protected function tearDown(): void {
- $this->restoreService(\OC\AllConfig::class);
+ $this->restoreService(AllConfig::class);
// disable trashbin to be able to properly clean up
\OC::$server->getAppManager()->disableApp('files_trashbin');
@@ -149,23 +160,23 @@ class TrashbinTest extends \Test\TestCase {
public function testExpireOldFiles(): void {
/** @var \OCP\AppFramework\Utility\ITimeFactory $time */
- $time = \OC::$server->query(\OCP\AppFramework\Utility\ITimeFactory::class);
+ $time = \OC::$server->query(ITimeFactory::class);
$currentTime = $time->getTime();
$expireAt = $currentTime - 2 * 24 * 60 * 60;
$expiredDate = $currentTime - 3 * 24 * 60 * 60;
// create some files
- \OC\Files\Filesystem::file_put_contents('file1.txt', 'file1');
- \OC\Files\Filesystem::file_put_contents('file2.txt', 'file2');
- \OC\Files\Filesystem::file_put_contents('file3.txt', 'file3');
+ Filesystem::file_put_contents('file1.txt', 'file1');
+ Filesystem::file_put_contents('file2.txt', 'file2');
+ Filesystem::file_put_contents('file3.txt', 'file3');
// delete them so that they end up in the trash bin
- \OC\Files\Filesystem::unlink('file1.txt');
- \OC\Files\Filesystem::unlink('file2.txt');
- \OC\Files\Filesystem::unlink('file3.txt');
+ Filesystem::unlink('file1.txt');
+ Filesystem::unlink('file2.txt');
+ Filesystem::unlink('file3.txt');
//make sure that files are in the trash bin
- $filesInTrash = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'name');
+ $filesInTrash = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'name');
$this->assertSame(3, count($filesInTrash));
// every second file will get a date in the past so that it will get expired
@@ -185,7 +196,7 @@ class TrashbinTest extends \Test\TestCase {
#$this->assertSame('file2.txt', $remainingFile['name']);
// check that file1.txt and file3.txt was really deleted
- $newTrashContent = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1);
+ $newTrashContent = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1);
$this->assertSame(1, count($newTrashContent));
$element = reset($newTrashContent);
// TODO: failing test
@@ -204,11 +215,11 @@ class TrashbinTest extends \Test\TestCase {
$expiredDate = $currentTime - 3 * 24 * 60 * 60;
// create some files
- \OC\Files\Filesystem::mkdir($folder);
- \OC\Files\Filesystem::file_put_contents($folder . 'user1-1.txt', 'file1');
- \OC\Files\Filesystem::file_put_contents($folder . 'user1-2.txt', 'file2');
- \OC\Files\Filesystem::file_put_contents($folder . 'user1-3.txt', 'file3');
- \OC\Files\Filesystem::file_put_contents($folder . 'user1-4.txt', 'file4');
+ Filesystem::mkdir($folder);
+ Filesystem::file_put_contents($folder . 'user1-1.txt', 'file1');
+ Filesystem::file_put_contents($folder . 'user1-2.txt', 'file2');
+ Filesystem::file_put_contents($folder . 'user1-3.txt', 'file3');
+ Filesystem::file_put_contents($folder . 'user1-4.txt', 'file4');
//share user1-4.txt with user2
$node = \OC::$server->getUserFolder(self::TEST_TRASHBIN_USER1)->get($folder);
@@ -217,16 +228,16 @@ class TrashbinTest extends \Test\TestCase {
->setNode($node)
->setSharedBy(self::TEST_TRASHBIN_USER1)
->setSharedWith(self::TEST_TRASHBIN_USER2)
- ->setPermissions(\OCP\Constants::PERMISSION_ALL);
+ ->setPermissions(Constants::PERMISSION_ALL);
$share = \OC::$server->getShareManager()->createShare($share);
\OC::$server->getShareManager()->acceptShare($share, self::TEST_TRASHBIN_USER2);
// delete them so that they end up in the trash bin
- \OC\Files\Filesystem::unlink($folder . 'user1-1.txt');
- \OC\Files\Filesystem::unlink($folder . 'user1-2.txt');
- \OC\Files\Filesystem::unlink($folder . 'user1-3.txt');
+ Filesystem::unlink($folder . 'user1-1.txt');
+ Filesystem::unlink($folder . 'user1-2.txt');
+ Filesystem::unlink($folder . 'user1-3.txt');
- $filesInTrash = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'name');
+ $filesInTrash = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'name');
$this->assertSame(3, count($filesInTrash));
// every second file will get a date in the past so that it will get expired
@@ -235,27 +246,27 @@ class TrashbinTest extends \Test\TestCase {
// login as user2
self::loginHelper(self::TEST_TRASHBIN_USER2);
- $this->assertTrue(\OC\Files\Filesystem::file_exists($folder . 'user1-4.txt'));
+ $this->assertTrue(Filesystem::file_exists($folder . 'user1-4.txt'));
// create some files
- \OC\Files\Filesystem::file_put_contents('user2-1.txt', 'file1');
- \OC\Files\Filesystem::file_put_contents('user2-2.txt', 'file2');
+ Filesystem::file_put_contents('user2-1.txt', 'file1');
+ Filesystem::file_put_contents('user2-2.txt', 'file2');
// delete them so that they end up in the trash bin
- \OC\Files\Filesystem::unlink('user2-1.txt');
- \OC\Files\Filesystem::unlink('user2-2.txt');
+ Filesystem::unlink('user2-1.txt');
+ Filesystem::unlink('user2-2.txt');
- $filesInTrashUser2 = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER2, 'name');
+ $filesInTrashUser2 = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER2, 'name');
$this->assertSame(2, count($filesInTrashUser2));
// every second file will get a date in the past so that it will get expired
$this->manipulateDeleteTime($filesInTrashUser2, $this->trashRoot2, $expiredDate);
- \OC\Files\Filesystem::unlink($folder . 'user1-4.txt');
+ Filesystem::unlink($folder . 'user1-4.txt');
$this->runCommands();
- $filesInTrashUser2AfterDelete = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER2);
+ $filesInTrashUser2AfterDelete = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER2);
// user2-1.txt should have been expired
$this->verifyArray($filesInTrashUser2AfterDelete, ['user2-2.txt', 'user1-4.txt']);
@@ -263,7 +274,7 @@ class TrashbinTest extends \Test\TestCase {
self::loginHelper(self::TEST_TRASHBIN_USER1);
// user1-1.txt and user1-3.txt should have been expired
- $filesInTrashUser1AfterDelete = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1);
+ $filesInTrashUser1AfterDelete = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1);
$this->verifyArray($filesInTrashUser1AfterDelete, ['user1-2.txt', 'user1-4.txt']);
}
@@ -303,7 +314,7 @@ class TrashbinTest extends \Test\TestCase {
$counter = ($counter + 1) % 2;
if ($counter === 1) {
$source = $trashRoot . '/files/' . $file['name'] . '.d' . $file['mtime'];
- $target = \OC\Files\Filesystem::normalizePath($trashRoot . '/files/' . $file['name'] . '.d' . $expireDate);
+ $target = Filesystem::normalizePath($trashRoot . '/files/' . $file['name'] . '.d' . $expireDate);
$this->rootView->rename($source, $target);
$file['mtime'] = $expireDate;
}
@@ -319,19 +330,19 @@ class TrashbinTest extends \Test\TestCase {
public function testExpireOldFilesUtilLimitsAreMet(): void {
// create some files
- \OC\Files\Filesystem::file_put_contents('file1.txt', 'file1');
- \OC\Files\Filesystem::file_put_contents('file2.txt', 'file2');
- \OC\Files\Filesystem::file_put_contents('file3.txt', 'file3');
+ Filesystem::file_put_contents('file1.txt', 'file1');
+ Filesystem::file_put_contents('file2.txt', 'file2');
+ Filesystem::file_put_contents('file3.txt', 'file3');
// delete them so that they end up in the trash bin
- \OC\Files\Filesystem::unlink('file3.txt');
+ Filesystem::unlink('file3.txt');
sleep(1); // make sure that every file has a unique mtime
- \OC\Files\Filesystem::unlink('file2.txt');
+ Filesystem::unlink('file2.txt');
sleep(1); // make sure that every file has a unique mtime
- \OC\Files\Filesystem::unlink('file1.txt');
+ Filesystem::unlink('file1.txt');
//make sure that files are in the trash bin
- $filesInTrash = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
+ $filesInTrash = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
$this->assertSame(3, count($filesInTrash));
$testClass = new TrashbinForTesting();
@@ -340,7 +351,7 @@ class TrashbinTest extends \Test\TestCase {
// the two oldest files (file3.txt and file2.txt) should be deleted
$this->assertSame(10, $sizeOfDeletedFiles);
- $newTrashContent = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1);
+ $newTrashContent = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1);
$this->assertSame(1, count($newTrashContent));
$element = reset($newTrashContent);
$this->assertSame('file1.txt', $element['name']);
@@ -360,14 +371,14 @@ class TrashbinTest extends \Test\TestCase {
$this->assertFalse($userFolder->nodeExists('file1.txt'));
- $filesInTrash = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
+ $filesInTrash = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
$this->assertCount(1, $filesInTrash);
/** @var \OCP\Files\FileInfo */
$trashedFile = $filesInTrash[0];
$this->assertTrue(
- OCA\Files_Trashbin\Trashbin::restore(
+ Trashbin::restore(
'file1.txt.d' . $trashedFile->getMtime(),
$trashedFile->getName(),
$trashedFile->getMtime()
@@ -393,14 +404,14 @@ class TrashbinTest extends \Test\TestCase {
$this->assertFalse($userFolder->nodeExists('folder/file1.txt'));
- $filesInTrash = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
+ $filesInTrash = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
$this->assertCount(1, $filesInTrash);
/** @var \OCP\Files\FileInfo */
$trashedFile = $filesInTrash[0];
$this->assertTrue(
- OCA\Files_Trashbin\Trashbin::restore(
+ Trashbin::restore(
'file1.txt.d' . $trashedFile->getMtime(),
$trashedFile->getName(),
$trashedFile->getMtime()
@@ -426,14 +437,14 @@ class TrashbinTest extends \Test\TestCase {
$this->assertFalse($userFolder->nodeExists('folder'));
- $filesInTrash = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
+ $filesInTrash = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
$this->assertCount(1, $filesInTrash);
/** @var \OCP\Files\FileInfo */
$trashedFolder = $filesInTrash[0];
$this->assertTrue(
- OCA\Files_Trashbin\Trashbin::restore(
+ Trashbin::restore(
'folder.d' . $trashedFolder->getMtime(),
$trashedFolder->getName(),
$trashedFolder->getMtime()
@@ -459,14 +470,14 @@ class TrashbinTest extends \Test\TestCase {
$this->assertFalse($userFolder->nodeExists('folder'));
- $filesInTrash = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
+ $filesInTrash = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
$this->assertCount(1, $filesInTrash);
/** @var \OCP\Files\FileInfo */
$trashedFile = $filesInTrash[0];
$this->assertTrue(
- OCA\Files_Trashbin\Trashbin::restore(
+ Trashbin::restore(
'folder.d' . $trashedFile->getMtime() . '/file1.txt',
'file1.txt',
$trashedFile->getMtime()
@@ -493,7 +504,7 @@ class TrashbinTest extends \Test\TestCase {
$this->assertFalse($userFolder->nodeExists('folder/file1.txt'));
- $filesInTrash = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
+ $filesInTrash = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
$this->assertCount(1, $filesInTrash);
/** @var \OCP\Files\FileInfo */
@@ -503,7 +514,7 @@ class TrashbinTest extends \Test\TestCase {
$folder->delete();
$this->assertTrue(
- OCA\Files_Trashbin\Trashbin::restore(
+ Trashbin::restore(
'file1.txt.d' . $trashedFile->getMtime(),
$trashedFile->getName(),
$trashedFile->getMtime()
@@ -529,7 +540,7 @@ class TrashbinTest extends \Test\TestCase {
$this->assertFalse($userFolder->nodeExists('file1.txt'));
- $filesInTrash = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
+ $filesInTrash = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
$this->assertCount(1, $filesInTrash);
/** @var \OCP\Files\FileInfo */
@@ -540,7 +551,7 @@ class TrashbinTest extends \Test\TestCase {
$file->putContent('bar');
$this->assertTrue(
- OCA\Files_Trashbin\Trashbin::restore(
+ Trashbin::restore(
'file1.txt.d' . $trashedFile->getMtime(),
$trashedFile->getName(),
$trashedFile->getMtime()
@@ -570,7 +581,7 @@ class TrashbinTest extends \Test\TestCase {
$this->assertFalse($userFolder->nodeExists('folder/file1.txt'));
- $filesInTrash = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
+ $filesInTrash = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
$this->assertCount(1, $filesInTrash);
/** @var \OCP\Files\FileInfo */
@@ -581,7 +592,7 @@ class TrashbinTest extends \Test\TestCase {
$file->putContent('bar');
$this->assertTrue(
- OCA\Files_Trashbin\Trashbin::restore(
+ Trashbin::restore(
'file1.txt.d' . $trashedFile->getMtime(),
$trashedFile->getName(),
$trashedFile->getMtime()
@@ -600,7 +611,7 @@ class TrashbinTest extends \Test\TestCase {
*/
public function testRestoreUnexistingFile(): void {
$this->assertFalse(
- OCA\Files_Trashbin\Trashbin::restore(
+ Trashbin::restore(
'unexist.txt.d123456',
'unexist.txt',
'123456'
@@ -624,7 +635,7 @@ class TrashbinTest extends \Test\TestCase {
$this->assertFalse($userFolder->nodeExists('folder/file1.txt'));
- $filesInTrash = OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
+ $filesInTrash = Helper::getTrashFiles('/', self::TEST_TRASHBIN_USER1, 'mtime');
$this->assertCount(1, $filesInTrash);
/** @var \OCP\Files\FileInfo */
@@ -632,13 +643,13 @@ class TrashbinTest extends \Test\TestCase {
// delete source folder
[$storage, $internalPath] = $this->rootView->resolvePath('/' . self::TEST_TRASHBIN_USER1 . '/files/folder');
- if ($storage instanceof \OC\Files\Storage\Local) {
+ if ($storage instanceof Local) {
$folderAbsPath = $storage->getSourcePath($internalPath);
// make folder read-only
chmod($folderAbsPath, 0555);
$this->assertTrue(
- OCA\Files_Trashbin\Trashbin::restore(
+ Trashbin::restore(
'file1.txt.d' . $trashedFile->getMtime(),
$trashedFile->getName(),
$trashedFile->getMtime()
@@ -666,7 +677,7 @@ class TrashbinTest extends \Test\TestCase {
\OC_Util::tearDownFS();
\OC_User::setUserId('');
- \OC\Files\Filesystem::tearDown();
+ Filesystem::tearDown();
\OC_User::setUserId($user);
\OC_Util::setupFS($user);
\OC::$server->getUserFolder($user);
@@ -675,7 +686,7 @@ class TrashbinTest extends \Test\TestCase {
// just a dummy class to make protected methods available for testing
-class TrashbinForTesting extends \OCA\Files_Trashbin\Trashbin {
+class TrashbinForTesting extends Trashbin {
/**
* @param OCP\Files\FileInfo[] $files