diff options
author | Robin Appelman <icewind@owncloud.com> | 2015-03-02 15:25:50 +0100 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2015-03-02 15:25:50 +0100 |
commit | c80522ed63e3225ce1f1353581220c3296ed0590 (patch) | |
tree | 1c95536318918ac24332672d00162b2fb1e7d3e9 /apps/files_trashbin/lib/trashbin.php | |
parent | 00568af74d8b392ea9f991e3d4069cd50e030030 (diff) | |
download | nextcloud-server-c80522ed63e3225ce1f1353581220c3296ed0590.tar.gz nextcloud-server-c80522ed63e3225ce1f1353581220c3296ed0590.zip |
Expire files from the trash in the background
Diffstat (limited to 'apps/files_trashbin/lib/trashbin.php')
-rw-r--r-- | apps/files_trashbin/lib/trashbin.php | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/apps/files_trashbin/lib/trashbin.php b/apps/files_trashbin/lib/trashbin.php index 8ce6d668d66..76395cc95d0 100644 --- a/apps/files_trashbin/lib/trashbin.php +++ b/apps/files_trashbin/lib/trashbin.php @@ -23,6 +23,7 @@ namespace OCA\Files_Trashbin; use OC\Files\Filesystem; +use OCA\Files_Trashbin\Command\Expire; class Trashbin { // how long do we keep files in the trash bin if no other value is defined in the config file (unit: days) @@ -204,13 +205,13 @@ class Trashbin { } $userTrashSize += $size; - $userTrashSize -= self::expire($userTrashSize, $user); + self::scheduleExpire($userTrashSize, $user); // if owner !== user we also need to update the owners trash size if ($owner !== $user) { $ownerTrashSize = self::getTrashbinSize($owner); $ownerTrashSize += $size; - $ownerTrashSize -= self::expire($ownerTrashSize, $owner); + self::scheduleExpire($ownerTrashSize, $owner); } return ($sizeOfAddedFiles === false) ? false : true; @@ -682,26 +683,18 @@ class Trashbin { $freeSpace = self::calculateFreeSpace($size, $user); if ($freeSpace < 0) { - self::expire($size, $user); + self::scheduleExpire($size, $user); } } /** * clean up the trash bin * - * @param int $trashbinSize current size of the trash bin + * @param int $trashBinSize current size of the trash bin * @param string $user - * @return int size of expired files */ - private static function expire($trashbinSize, $user) { - - // let the admin disable auto expire - $autoExpire = \OC_Config::getValue('trashbin_auto_expire', true); - if ($autoExpire === false) { - return 0; - } - - $availableSpace = self::calculateFreeSpace($trashbinSize, $user); + public static function expire($trashBinSize, $user) { + $availableSpace = self::calculateFreeSpace($trashBinSize, $user); $size = 0; $retention_obligation = \OC_Config::getValue('trashbin_retention_obligation', self::DEFAULT_RETENTION_OBLIGATION); @@ -718,8 +711,18 @@ class Trashbin { // delete files from trash until we meet the trash bin size limit again $size += self::deleteFiles(array_slice($dirContent, $count), $user, $availableSpace); + } - return $size; + /**@param int $trashBinSize current size of the trash bin + * @param string $user + */ + private static function scheduleExpire($trashBinSize, $user) { + // let the admin disable auto expire + $autoExpire = \OC_Config::getValue('trashbin_auto_expire', true); + if ($autoExpire === false) { + return; + } + \OC::$server->getCommandBus()->push(new Expire($user, $trashBinSize)); } /** |