diff options
Diffstat (limited to 'apps/files_trashbin/lib')
-rw-r--r-- | apps/files_trashbin/lib/Command/Expire.php | 4 | ||||
-rw-r--r-- | apps/files_trashbin/lib/Helper.php | 4 | ||||
-rw-r--r-- | apps/files_trashbin/lib/Sabre/RootCollection.php | 4 | ||||
-rw-r--r-- | apps/files_trashbin/lib/Storage.php | 12 | ||||
-rw-r--r-- | apps/files_trashbin/lib/Trashbin.php | 70 |
5 files changed, 52 insertions, 42 deletions
diff --git a/apps/files_trashbin/lib/Command/Expire.php b/apps/files_trashbin/lib/Command/Expire.php index f526438600e..6c89b6d736c 100644 --- a/apps/files_trashbin/lib/Command/Expire.php +++ b/apps/files_trashbin/lib/Command/Expire.php @@ -9,6 +9,8 @@ namespace OCA\Files_Trashbin\Command; use OC\Command\FileAccess; use OCA\Files_Trashbin\Trashbin; use OCP\Command\ICommand; +use OCP\IUserManager; +use OCP\Server; class Expire implements ICommand { use FileAccess; @@ -22,7 +24,7 @@ class Expire implements ICommand { } public function handle() { - $userManager = \OC::$server->getUserManager(); + $userManager = Server::get(IUserManager::class); if (!$userManager->userExists($this->user)) { // User has been deleted already return; diff --git a/apps/files_trashbin/lib/Helper.php b/apps/files_trashbin/lib/Helper.php index 7aeb737a56c..50107b3bf71 100644 --- a/apps/files_trashbin/lib/Helper.php +++ b/apps/files_trashbin/lib/Helper.php @@ -10,6 +10,8 @@ use OC\Files\FileInfo; use OC\Files\View; use OCP\Constants; use OCP\Files\Cache\ICacheEntry; +use OCP\Files\IMimeTypeDetector; +use OCP\Server; class Helper { /** @@ -63,7 +65,7 @@ class Helper { $i = [ 'name' => $name, 'mtime' => $timestamp, - 'mimetype' => $type === 'dir' ? 'httpd/unix-directory' : \OC::$server->getMimeTypeDetector()->detectPath($name), + 'mimetype' => $type === 'dir' ? 'httpd/unix-directory' : Server::get(IMimeTypeDetector::class)->detectPath($name), 'type' => $type, 'directory' => ($dir === '/') ? '' : $dir, 'size' => $entry->getSize(), diff --git a/apps/files_trashbin/lib/Sabre/RootCollection.php b/apps/files_trashbin/lib/Sabre/RootCollection.php index 06b0ffbeba2..8886dae0895 100644 --- a/apps/files_trashbin/lib/Sabre/RootCollection.php +++ b/apps/files_trashbin/lib/Sabre/RootCollection.php @@ -10,6 +10,8 @@ namespace OCA\Files_Trashbin\Sabre; use OCA\Files_Trashbin\Trash\ITrashManager; use OCP\IConfig; +use OCP\IUserSession; +use OCP\Server; use Sabre\DAV\INode; use Sabre\DAVACL\AbstractPrincipalCollection; use Sabre\DAVACL\PrincipalBackend; @@ -36,7 +38,7 @@ class RootCollection extends AbstractPrincipalCollection { */ public function getChildForPrincipal(array $principalInfo): TrashHome { [, $name] = \Sabre\Uri\split($principalInfo['uri']); - $user = \OC::$server->getUserSession()->getUser(); + $user = Server::get(IUserSession::class)->getUser(); if (is_null($user) || $name !== $user->getUID()) { throw new \Sabre\DAV\Exception\Forbidden(); } diff --git a/apps/files_trashbin/lib/Storage.php b/apps/files_trashbin/lib/Storage.php index a2855a97ac9..9ddb8e791fa 100644 --- a/apps/files_trashbin/lib/Storage.php +++ b/apps/files_trashbin/lib/Storage.php @@ -148,12 +148,12 @@ class Storage extends Wrapper { * Setup the storage wrapper callback */ public static function setupStorage(): void { - $trashManager = \OC::$server->get(ITrashManager::class); - $userManager = \OC::$server->get(IUserManager::class); - $logger = \OC::$server->get(LoggerInterface::class); - $eventDispatcher = \OC::$server->get(IEventDispatcher::class); - $rootFolder = \OC::$server->get(IRootFolder::class); - $request = \OC::$server->get(IRequest::class); + $trashManager = Server::get(ITrashManager::class); + $userManager = Server::get(IUserManager::class); + $logger = Server::get(LoggerInterface::class); + $eventDispatcher = Server::get(IEventDispatcher::class); + $rootFolder = Server::get(IRootFolder::class); + $request = Server::get(IRequest::class); Filesystem::addStorageWrapper( 'oc_trashbin', function (string $mountPoint, IStorage $storage) use ($trashManager, $userManager, $logger, $eventDispatcher, $rootFolder, $request) { diff --git a/apps/files_trashbin/lib/Trashbin.php b/apps/files_trashbin/lib/Trashbin.php index 32fd81465fa..e79fa2c9def 100644 --- a/apps/files_trashbin/lib/Trashbin.php +++ b/apps/files_trashbin/lib/Trashbin.php @@ -24,12 +24,14 @@ use OCA\Files_Trashbin\Exceptions\CopyRecursiveException; use OCA\Files_Versions\Storage; use OCP\App\IAppManager; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\Command\IBus; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventDispatcher; use OCP\EventDispatcher\IEventListener; use OCP\Files\Events\Node\BeforeNodeDeletedEvent; use OCP\Files\File; use OCP\Files\Folder; +use OCP\Files\IMimeTypeLoader; use OCP\Files\IRootFolder; use OCP\Files\Node; use OCP\Files\NotFoundException; @@ -39,6 +41,8 @@ use OCP\Files\Storage\IStorage; use OCP\FilesMetadata\IFilesMetadataManager; use OCP\IConfig; use OCP\IDBConnection; +use OCP\IURLGenerator; +use OCP\IUserManager; use OCP\Lock\ILockingProvider; use OCP\Lock\LockedException; use OCP\Server; @@ -72,7 +76,7 @@ class Trashbin implements IEventListener { */ public static function getUidAndFilename($filename) { $uid = Filesystem::getOwner($filename); - $userManager = \OC::$server->getUserManager(); + $userManager = Server::get(IUserManager::class); // if the user with the UID doesn't exists, e.g. because the UID points // to a remote user with a federated cloud ID we use the current logged-in // user. We need a valid local user to move the file to the right trash bin @@ -103,7 +107,7 @@ class Trashbin implements IEventListener { * @return array<string, array<string, array{location: string, deletedBy: string}>> */ public static function getExtraData($user) { - $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $query = Server::get(IDBConnection::class)->getQueryBuilder(); $query->select('id', 'timestamp', 'location', 'deleted_by') ->from('files_trash') ->where($query->expr()->eq('user', $query->createNamedParameter($user))); @@ -128,7 +132,7 @@ class Trashbin implements IEventListener { * @return string|false original location */ public static function getLocation($user, $filename, $timestamp) { - $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $query = Server::get(IDBConnection::class)->getQueryBuilder(); $query->select('location') ->from('files_trash') ->where($query->expr()->eq('user', $query->createNamedParameter($user))) @@ -194,7 +198,7 @@ class Trashbin implements IEventListener { if ($view->file_exists($target)) { - $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $query = Server::get(IDBConnection::class)->getQueryBuilder(); $query->insert('files_trash') ->setValue('id', $query->createNamedParameter($targetFilename)) ->setValue('timestamp', $query->createNamedParameter($timestamp)) @@ -203,7 +207,7 @@ class Trashbin implements IEventListener { ->setValue('deleted_by', $query->createNamedParameter($user)); $result = $query->executeStatement(); if (!$result) { - \OC::$server->get(LoggerInterface::class)->error('trash bin database couldn\'t be updated for the files owner', ['app' => 'files_trashbin']); + Server::get(LoggerInterface::class)->error('trash bin database couldn\'t be updated for the files owner', ['app' => 'files_trashbin']); } } } @@ -253,10 +257,10 @@ class Trashbin implements IEventListener { $filename = $path_parts['basename']; $location = $path_parts['dirname']; /** @var ITimeFactory $timeFactory */ - $timeFactory = \OC::$server->query(ITimeFactory::class); + $timeFactory = Server::get(ITimeFactory::class); $timestamp = $timeFactory->getTime(); - $lockingProvider = \OC::$server->getLockingProvider(); + $lockingProvider = Server::get(ILockingProvider::class); // disable proxy to prevent recursive calls $trashPath = '/files_trashbin/files/' . static::getTrashFilename($filename, $timestamp); @@ -302,7 +306,7 @@ class Trashbin implements IEventListener { if ($trashStorage->file_exists($trashInternalPath)) { $trashStorage->unlink($trashInternalPath); } - \OC::$server->get(LoggerInterface::class)->error('Couldn\'t move ' . $file_path . ' to the trash bin', ['app' => 'files_trashbin']); + Server::get(LoggerInterface::class)->error('Couldn\'t move ' . $file_path . ' to the trash bin', ['app' => 'files_trashbin']); } if ($sourceStorage->file_exists($sourceInternalPath)) { // failed to delete the original file, abort @@ -322,7 +326,7 @@ class Trashbin implements IEventListener { } if ($moveSuccessful) { - $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $query = Server::get(IDBConnection::class)->getQueryBuilder(); $query->insert('files_trash') ->setValue('id', $query->createNamedParameter($filename)) ->setValue('timestamp', $query->createNamedParameter($timestamp)) @@ -331,7 +335,7 @@ class Trashbin implements IEventListener { ->setValue('deleted_by', $query->createNamedParameter($user)); $result = $query->executeStatement(); if (!$result) { - \OC::$server->get(LoggerInterface::class)->error('trash bin database couldn\'t be updated', ['app' => 'files_trashbin']); + Server::get(LoggerInterface::class)->error('trash bin database couldn\'t be updated', ['app' => 'files_trashbin']); } Util::emitHook('\OCA\Files_Trashbin\Trashbin', 'post_moveToTrash', ['filePath' => Filesystem::normalizePath($file_path), 'trashPath' => Filesystem::normalizePath(static::getTrashFilename($filename, $timestamp))]); @@ -357,7 +361,7 @@ class Trashbin implements IEventListener { } private static function getConfiguredTrashbinSize(string $user): int|float { - $config = \OC::$server->get(IConfig::class); + $config = Server::get(IConfig::class); $userTrashbinSize = $config->getUserValue($user, 'files_trashbin', 'trashbin_size', '-1'); if (is_numeric($userTrashbinSize) && ($userTrashbinSize > -1)) { return Util::numericToNumber($userTrashbinSize); @@ -460,7 +464,7 @@ class Trashbin implements IEventListener { if ($timestamp) { $location = self::getLocation($user, $filename, $timestamp); if ($location === false) { - \OC::$server->get(LoggerInterface::class)->error('trash bin database inconsistent! ($user: ' . $user . ' $filename: ' . $filename . ', $timestamp: ' . $timestamp . ')', ['app' => 'files_trashbin']); + Server::get(LoggerInterface::class)->error('trash bin database inconsistent! ($user: ' . $user . ' $filename: ' . $filename . ', $timestamp: ' . $timestamp . ')', ['app' => 'files_trashbin']); } else { // if location no longer exists, restore file in the root directory if ($location !== '/' && @@ -494,7 +498,7 @@ class Trashbin implements IEventListener { $targetNode = self::getNodeForPath($targetPath); $run = true; $event = new BeforeNodeRestoredEvent($sourceNode, $targetNode, $run); - $dispatcher = \OC::$server->get(IEventDispatcher::class); + $dispatcher = Server::get(IEventDispatcher::class); $dispatcher->dispatchTyped($event); if (!$run) { @@ -514,13 +518,13 @@ class Trashbin implements IEventListener { $sourceNode = self::getNodeForPath($sourcePath); $targetNode = self::getNodeForPath($targetPath); $event = new NodeRestoredEvent($sourceNode, $targetNode); - $dispatcher = \OC::$server->get(IEventDispatcher::class); + $dispatcher = Server::get(IEventDispatcher::class); $dispatcher->dispatchTyped($event); self::restoreVersions($view, $file, $filename, $uniqueFilename, $location, $timestamp); if ($timestamp) { - $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $query = Server::get(IDBConnection::class)->getQueryBuilder(); $query->delete('files_trash') ->where($query->expr()->eq('user', $query->createNamedParameter($user))) ->andWhere($query->expr()->eq('id', $query->createNamedParameter($filename))) @@ -612,7 +616,7 @@ class Trashbin implements IEventListener { // actual file deletion $trash->delete(); - $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $query = Server::get(IDBConnection::class)->getQueryBuilder(); $query->delete('files_trash') ->where($query->expr()->eq('user', $query->createNamedParameter($user))); $query->executeStatement(); @@ -664,7 +668,7 @@ class Trashbin implements IEventListener { $size = 0; if ($timestamp) { - $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $query = Server::get(IDBConnection::class)->getQueryBuilder(); $query->delete('files_trash') ->where($query->expr()->eq('user', $query->createNamedParameter($user))) ->andWhere($query->expr()->eq('id', $query->createNamedParameter($filename))) @@ -749,7 +753,7 @@ class Trashbin implements IEventListener { * @return bool result of db delete operation */ public static function deleteUser($uid) { - $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $query = Server::get(IDBConnection::class)->getQueryBuilder(); $query->delete('files_trash') ->where($query->expr()->eq('user', $query->createNamedParameter($uid))); return (bool)$query->executeStatement(); @@ -768,7 +772,7 @@ class Trashbin implements IEventListener { return $configuredTrashbinSize - $trashbinSize; } - $userObject = \OC::$server->getUserManager()->get($user); + $userObject = Server::get(IUserManager::class)->get($user); if (is_null($userObject)) { return 0; } @@ -850,10 +854,10 @@ class Trashbin implements IEventListener { private static function scheduleExpire($user) { // let the admin disable auto expire /** @var Application $application */ - $application = \OC::$server->query(Application::class); + $application = Server::get(Application::class); $expiration = $application->getContainer()->query('Expiration'); if ($expiration->isEnabled()) { - \OC::$server->getCommandBus()->push(new Expire($user)); + Server::get(IBus::class)->push(new Expire($user)); } } @@ -868,7 +872,7 @@ class Trashbin implements IEventListener { */ protected static function deleteFiles(array $files, string $user, int|float $availableSpace): int|float { /** @var Application $application */ - $application = \OC::$server->query(Application::class); + $application = Server::get(Application::class); $expiration = $application->getContainer()->query('Expiration'); $size = 0; @@ -876,7 +880,7 @@ class Trashbin implements IEventListener { foreach ($files as $file) { if ($availableSpace < 0 && $expiration->isExpired($file['mtime'], true)) { $tmp = self::delete($file['name'], $user, $file['mtime']); - \OC::$server->get(LoggerInterface::class)->info('remove "' . $file['name'] . '" (' . $tmp . 'B) to meet the limit of trash bin size (50% of available quota)', ['app' => 'files_trashbin']); + Server::get(LoggerInterface::class)->info('remove "' . $file['name'] . '" (' . $tmp . 'B) to meet the limit of trash bin size (50% of available quota)', ['app' => 'files_trashbin']); $availableSpace += $tmp; $size += $tmp; } else { @@ -896,7 +900,7 @@ class Trashbin implements IEventListener { */ public static function deleteExpiredFiles($files, $user) { /** @var Expiration $expiration */ - $expiration = \OC::$server->query(Expiration::class); + $expiration = Server::get(Expiration::class); $size = 0; $count = 0; foreach ($files as $file) { @@ -907,14 +911,14 @@ class Trashbin implements IEventListener { $size += self::delete($filename, $user, $timestamp); $count++; } catch (NotPermittedException $e) { - \OC::$server->get(LoggerInterface::class)->warning('Removing "' . $filename . '" from trashbin failed.', + Server::get(LoggerInterface::class)->warning('Removing "' . $filename . '" from trashbin failed.', [ 'exception' => $e, 'app' => 'files_trashbin', ] ); } - \OC::$server->get(LoggerInterface::class)->info( + Server::get(LoggerInterface::class)->info( 'Remove "' . $filename . '" from trashbin because it exceeds max retention obligation term.', ['app' => 'files_trashbin'] ); @@ -977,10 +981,10 @@ class Trashbin implements IEventListener { /** @var \OC\Files\Storage\Storage $storage */ [$storage,] = $view->resolvePath('/'); - $pattern = \OC::$server->getDatabaseConnection()->escapeLikeParameter(basename($filename)); + $pattern = Server::get(IDBConnection::class)->escapeLikeParameter(basename($filename)); if ($timestamp) { // fetch for old versions - $escapedTimestamp = \OC::$server->getDatabaseConnection()->escapeLikeParameter((string)$timestamp); + $escapedTimestamp = Server::get(IDBConnection::class)->escapeLikeParameter((string)$timestamp); $pattern .= '.v%.d' . $escapedTimestamp; $offset = -strlen($escapedTimestamp) - 2; } else { @@ -1010,7 +1014,7 @@ class Trashbin implements IEventListener { /** @var CacheEntry[] $matches */ $matches = array_map(function (array $data) { - return Cache::cacheEntryFromData($data, \OC::$server->getMimeTypeLoader()); + return Cache::cacheEntryFromData($data, Server::get(IMimeTypeLoader::class)); }, $entries); foreach ($matches as $ma) { @@ -1067,7 +1071,7 @@ class Trashbin implements IEventListener { * @return int|float size of the folder */ private static function calculateSize(View $view): int|float { - $root = \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . $view->getAbsolutePath(''); + $root = Server::get(IConfig::class)->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . $view->getAbsolutePath(''); if (!file_exists($root)) { return 0; } @@ -1126,7 +1130,7 @@ class Trashbin implements IEventListener { * @return string */ public static function preview_icon($path) { - return \OC::$server->getURLGenerator()->linkToRoute('core_ajax_trashbin_preview', ['x' => 32, 'y' => 32, 'file' => $path]); + return Server::get(IURLGenerator::class)->linkToRoute('core_ajax_trashbin_preview', ['x' => 32, 'y' => 32, 'file' => $path]); } /** @@ -1150,7 +1154,7 @@ class Trashbin implements IEventListener { private static function getNodeForPath(string $path): Node { $user = OC_User::getUser(); - $rootFolder = \OC::$server->get(IRootFolder::class); + $rootFolder = Server::get(IRootFolder::class); if ($user !== false) { $userFolder = $rootFolder->getUserFolder($user); @@ -1162,7 +1166,7 @@ class Trashbin implements IEventListener { } } - $view = \OC::$server->get(View::class); + $view = Server::get(View::class); $fsView = Filesystem::getView(); if ($fsView === null) { throw new Exception('View should not be null'); |