-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Refactor files trashbin app #39883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
danialRahimy
wants to merge
14
commits into
nextcloud:master
from
danialRahimy:app_files_trashbin_refactor
Closed
Refactor files trashbin app #39883
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
558c146
Files trashbin app: Return early in method retainVersions
danialRahimy 81c4780
Files trashbin app: Change the const name for more readability
danialRahimy 2c298c0
Files trashbin app: Adding functions' return type
danialRahimy 36338e8
Files trashbin app: Return early
danialRahimy dfceb76
Files trashbin app: Remove extra spaces between methods
danialRahimy a531255
Files trashbin app: Update doc types
danialRahimy 82dd6fa
Files trashbin app: Add remaining return type.
danialRahimy 8bd6a2f
Files trashbin app: Add parameter type to the methods according to th…
danialRahimy dcfcce8
Files trashbin app: Remove unrelated throw tag for clarification exc…
danialRahimy e1fa130
Update apps/files_trashbin/lib/Trashbin.php
danialRahimy b55f595
Update apps/files_trashbin/lib/Trashbin.php
danialRahimy 863dd39
Update apps/files_trashbin/lib/Trashbin.php
danialRahimy a766334
Update apps/files_trashbin/lib/Trashbin.php
danialRahimy 2186f0d
Update apps/files_trashbin/lib/Trashbin.php
danialRahimy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Files trashbin app: Adding functions' return type
Signed-off-by: Danial Rahimi <[email protected]>
- Loading branch information
commit 2c298c0d2a8b96448108bddbdd1a4c6e6ca56857
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -74,7 +74,7 @@ class Trashbin { | |||||
| * | ||||||
| * @param array $params | ||||||
| */ | ||||||
| public static function ensureFileScannedHook($params) { | ||||||
| public static function ensureFileScannedHook($params): void { | ||||||
| try { | ||||||
| self::getUidAndFilename($params['path']); | ||||||
| } catch (NotFoundException $e) { | ||||||
|
|
@@ -90,7 +90,7 @@ public static function ensureFileScannedHook($params) { | |||||
| * @return array | ||||||
| * @throws \OC\User\NoUserException | ||||||
| */ | ||||||
| public static function getUidAndFilename($filename) { | ||||||
| public static function getUidAndFilename($filename): array { | ||||||
danialRahimy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| $uid = Filesystem::getOwner($filename); | ||||||
| $userManager = \OC::$server->getUserManager(); | ||||||
| // if the user with the UID doesn't exists, e.g. because the UID points | ||||||
|
|
@@ -122,7 +122,7 @@ public static function getUidAndFilename($filename) { | |||||
| * @param string $user | ||||||
| * @return array (filename => array (timestamp => original location)) | ||||||
| */ | ||||||
| public static function getLocations($user) { | ||||||
| public static function getLocations($user): array { | ||||||
danialRahimy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); | ||||||
| $query->select('id', 'timestamp', 'location') | ||||||
| ->from('files_trash') | ||||||
|
|
@@ -146,9 +146,9 @@ public static function getLocations($user) { | |||||
| * @param string $user | ||||||
| * @param string $filename | ||||||
| * @param string $timestamp | ||||||
| * @return string original location | ||||||
| * @return bool|string original location | ||||||
| */ | ||||||
| public static function getLocation($user, $filename, $timestamp) { | ||||||
| public static function getLocation($user, $filename, $timestamp): bool|string { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); | ||||||
| $query->select('location') | ||||||
| ->from('files_trash') | ||||||
|
|
@@ -167,7 +167,7 @@ public static function getLocation($user, $filename, $timestamp) { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| private static function setUpTrash($user) { | ||||||
| private static function setUpTrash($user): void { | ||||||
|
||||||
| $view = new View('/' . $user); | ||||||
| if (!$view->is_dir('files_trashbin')) { | ||||||
| $view->mkdir('files_trashbin'); | ||||||
|
|
@@ -193,7 +193,7 @@ private static function setUpTrash($user) { | |||||
| * @param $user | ||||||
| * @param int $timestamp | ||||||
| */ | ||||||
| private static function copyFilesToUser($sourcePath, $owner, $targetPath, $user, $timestamp) { | ||||||
| private static function copyFilesToUser($sourcePath, $owner, $targetPath, $user, $timestamp): void { | ||||||
|
||||||
| self::setUpTrash($owner); | ||||||
|
|
||||||
| $targetFilename = basename($targetPath); | ||||||
|
|
@@ -236,7 +236,7 @@ private static function copyFilesToUser($sourcePath, $owner, $targetPath, $user, | |||||
| * | ||||||
| * @return bool | ||||||
| */ | ||||||
| public static function move2trash($file_path, $ownerOnly = false) { | ||||||
| public static function move2trash($file_path, $ownerOnly = false): bool { | ||||||
| // get the user for which the filesystem is setup | ||||||
| $root = Filesystem::getRoot(); | ||||||
| [, $user] = explode('/', $root); | ||||||
|
|
@@ -398,9 +398,9 @@ private static function getConfiguredTrashbinSize(string $user): int|float { | |||||
| * @param string $ownerPath path relative to the owner's home storage | ||||||
| * @param int $timestamp when the file was deleted | ||||||
| */ | ||||||
| private static function retainVersions($filename, $owner, $ownerPath, $timestamp) { | ||||||
| private static function retainVersions($filename, $owner, $ownerPath, $timestamp): void { | ||||||
| if (!\OCP\Server::get(IAppManager::class)->isEnabledForUser('files_versions') || empty($ownerPath)) { | ||||||
| return null; | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
| $user = OC_User::getUser(); | ||||||
|
|
@@ -475,7 +475,7 @@ private static function copy(View $view, $source, $target) { | |||||
| * | ||||||
| * @return bool true on success, false otherwise | ||||||
| */ | ||||||
| public static function restore($file, $filename, $timestamp) { | ||||||
| public static function restore($file, $filename, $timestamp): bool { | ||||||
| $user = OC_User::getUser(); | ||||||
| $view = new View('/' . $user); | ||||||
|
|
||||||
|
|
@@ -548,7 +548,7 @@ public static function restore($file, $filename, $timestamp) { | |||||
| * @param int $timestamp deletion time | ||||||
| * @return false|null | ||||||
| */ | ||||||
| private static function restoreVersions(View $view, $file, $filename, $uniqueFilename, $location, $timestamp) { | ||||||
| private static function restoreVersions(View $view, $file, $filename, $uniqueFilename, $location, $timestamp): ?bool { | ||||||
| if (\OCP\Server::get(IAppManager::class)->isEnabledForUser('files_versions')) { | ||||||
| $user = OC_User::getUser(); | ||||||
| $rootView = new View('/'); | ||||||
|
|
@@ -580,12 +580,14 @@ private static function restoreVersions(View $view, $file, $filename, $uniqueFil | |||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| return null; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * delete all files from the trash | ||||||
| */ | ||||||
| public static function deleteAll() { | ||||||
| public static function deleteAll(): bool { | ||||||
| $user = OC_User::getUser(); | ||||||
| $userRoot = \OC::$server->getUserFolder($user)->getParent(); | ||||||
| $view = new View('/' . $user); | ||||||
|
|
@@ -639,7 +641,7 @@ public static function deleteAll() { | |||||
| * | ||||||
| * @param string $path | ||||||
| */ | ||||||
| protected static function emitTrashbinPreDelete($path) { | ||||||
| protected static function emitTrashbinPreDelete($path): void { | ||||||
| \OC_Hook::emit('\OCP\Trashbin', 'preDelete', ['path' => $path]); | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -648,7 +650,7 @@ protected static function emitTrashbinPreDelete($path) { | |||||
| * | ||||||
| * @param string $path | ||||||
| */ | ||||||
| protected static function emitTrashbinPostDelete($path) { | ||||||
| protected static function emitTrashbinPostDelete($path): void { | ||||||
| \OC_Hook::emit('\OCP\Trashbin', 'delete', ['path' => $path]); | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -661,7 +663,7 @@ protected static function emitTrashbinPostDelete($path) { | |||||
| * | ||||||
| * @return int|float size of deleted files | ||||||
| */ | ||||||
| public static function delete($filename, $user, $timestamp = null) { | ||||||
| public static function delete($filename, $user, $timestamp = null): float|int { | ||||||
| $userRoot = \OC::$server->getUserFolder($user)->getParent(); | ||||||
| $view = new View('/' . $user); | ||||||
| $size = 0; | ||||||
|
|
@@ -751,7 +753,7 @@ public static function file_exists($filename, $timestamp = null) { | |||||
| * @param string $uid id of deleted user | ||||||
| * @return bool result of db delete operation | ||||||
| */ | ||||||
| public static function deleteUser($uid) { | ||||||
| public static function deleteUser($uid): bool { | ||||||
| $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); | ||||||
| $query->delete('files_trash') | ||||||
| ->where($query->expr()->eq('user', $query->createNamedParameter($uid))); | ||||||
|
|
@@ -817,7 +819,7 @@ private static function calculateFreeSpace(int|float $trashbinSize, string $user | |||||
| * | ||||||
| * @param string $user user id | ||||||
| */ | ||||||
| public static function resizeTrash($user) { | ||||||
| public static function resizeTrash($user): void { | ||||||
| $size = self::getTrashbinSize($user); | ||||||
|
|
||||||
| $freeSpace = self::calculateFreeSpace($size, $user); | ||||||
|
|
@@ -832,7 +834,7 @@ public static function resizeTrash($user) { | |||||
| * | ||||||
| * @param string $user | ||||||
| */ | ||||||
| public static function expire($user) { | ||||||
| public static function expire($user): void { | ||||||
| $trashBinSize = self::getTrashbinSize($user); | ||||||
| $availableSpace = self::calculateFreeSpace($trashBinSize, $user); | ||||||
|
|
||||||
|
|
@@ -850,7 +852,7 @@ public static function expire($user) { | |||||
| /** | ||||||
| * @param string $user | ||||||
| */ | ||||||
| private static function scheduleExpire($user) { | ||||||
| private static function scheduleExpire($user): void { | ||||||
| // let the admin disable auto expire | ||||||
| /** @var Application $application */ | ||||||
| $application = \OC::$server->query(Application::class); | ||||||
|
|
@@ -897,7 +899,7 @@ protected static function deleteFiles(array $files, string $user, int|float $ava | |||||
| * @param string $user | ||||||
| * @return array{int|float, int} size of deleted files and number of deleted files | ||||||
| */ | ||||||
| public static function deleteExpiredFiles($files, $user) { | ||||||
| public static function deleteExpiredFiles($files, $user): array { | ||||||
| /** @var Expiration $expiration */ | ||||||
| $expiration = \OC::$server->query(Expiration::class); | ||||||
| $size = 0; | ||||||
|
|
@@ -1038,7 +1040,7 @@ private static function getVersionsFromTrash($filename, $timestamp, string $user | |||||
| * @param View $view filesystem view relative to users root directory | ||||||
| * @return string with unique extension | ||||||
| */ | ||||||
| private static function getUniqueFilename($location, $filename, View $view) { | ||||||
| private static function getUniqueFilename($location, $filename, View $view): string { | ||||||
| $ext = pathinfo($filename, PATHINFO_EXTENSION); | ||||||
| $name = pathinfo($filename, PATHINFO_FILENAME); | ||||||
| $l = \OC::$server->getL10N('files_trashbin'); | ||||||
|
|
@@ -1113,7 +1115,7 @@ private static function getTrashbinSize(string $user): int|float { | |||||
| * @param string $user | ||||||
| * @return bool | ||||||
| */ | ||||||
| public static function isEmpty($user) { | ||||||
| public static function isEmpty($user): bool { | ||||||
| $view = new View('/' . $user . '/files_trashbin'); | ||||||
| if ($view->is_dir('/files') && $dh = $view->opendir('/files')) { | ||||||
| while ($file = readdir($dh)) { | ||||||
|
|
@@ -1129,7 +1131,7 @@ public static function isEmpty($user) { | |||||
| * @param $path | ||||||
| * @return string | ||||||
| */ | ||||||
| public static function preview_icon($path) { | ||||||
| public static function preview_icon($path): string { | ||||||
|
||||||
| return \OC::$server->getURLGenerator()->linkToRoute('core_ajax_trashbin_preview', ['x' => 32, 'y' => 32, 'file' => $path]); | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.