summaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin/lib
diff options
context:
space:
mode:
authorVictor Dubiniuk <victor.dubiniuk@gmail.com>2015-09-11 00:24:19 +0300
committerVictor Dubiniuk <victor.dubiniuk@gmail.com>2015-09-16 17:37:21 +0300
commit764726ce0128054a036f8c515cc62d3ca2e490cd (patch)
treef2737a25c0937b22cd7e0de8327a221e947a2138 /apps/files_trashbin/lib
parent867ed67aa501f11f363a44a40c3b046bbaf08917 (diff)
downloadnextcloud-server-764726ce0128054a036f8c515cc62d3ca2e490cd.tar.gz
nextcloud-server-764726ce0128054a036f8c515cc62d3ca2e490cd.zip
Updates according to review
Diffstat (limited to 'apps/files_trashbin/lib')
-rw-r--r--apps/files_trashbin/lib/backgroundjob/expiretrash.php32
1 files changed, 22 insertions, 10 deletions
diff --git a/apps/files_trashbin/lib/backgroundjob/expiretrash.php b/apps/files_trashbin/lib/backgroundjob/expiretrash.php
index 350628444cf..07bcce0659b 100644
--- a/apps/files_trashbin/lib/backgroundjob/expiretrash.php
+++ b/apps/files_trashbin/lib/backgroundjob/expiretrash.php
@@ -21,7 +21,7 @@
namespace OCA\Files_Trashbin\BackgroundJob;
-use OCP\IDBConnection;
+use OCP\IConfig;
use OCP\IUserManager;
use OCA\Files_Trashbin\AppInfo\Application;
use OCA\Files_Trashbin\Expiration;
@@ -38,23 +38,25 @@ class ExpireTrash extends \OC\BackgroundJob\TimedJob {
private $expiration;
/**
- * @var IDBConnection
+ * @var IConfig
*/
- private $dbConnection;
+ private $config;
/**
* @var IUserManager
*/
private $userManager;
+
+ const USERS_PER_SESSION = 1000;
- public function __construct(IDBConnection $dbConnection = null, IUserManager $userManager = null, Expiration $expiration = null) {
+ public function __construct(IConfig $config = null, IUserManager $userManager = null, Expiration $expiration = null) {
// Run once per 30 minutes
$this->setInterval(60 * 30);
- if (is_null($expiration) || is_null($userManager) || is_null($dbConnection)) {
+ if (is_null($expiration) || is_null($userManager) || is_null($config)) {
$this->fixDIForJobs();
} else {
- $this->dbConnection = $dbConnection;
+ $this->config = $config;
$this->userManager = $userManager;
$this->expiration = $expiration;
}
@@ -62,7 +64,7 @@ class ExpireTrash extends \OC\BackgroundJob\TimedJob {
protected function fixDIForJobs() {
$application = new Application();
- $this->dbConnection = \OC::$server->getDatabaseConnection();
+ $this->config = \OC::$server->getConfig();
$this->userManager = \OC::$server->getUserManager();
$this->expiration = $application->getContainer()->query('Expiration');
}
@@ -72,17 +74,27 @@ class ExpireTrash extends \OC\BackgroundJob\TimedJob {
if (!$maxAge) {
return;
}
- $users = $this->userManager->search('');
+
+ $offset = $this->config->getAppValue('files_trashbin', 'cronjob_user_offset', 0);
+ $users = $this->userManager->search('', self::USERS_PER_SESSION, $offset);
+ if (!count($users)) {
+ // No users found, reset offset and retry
+ $offset = 0;
+ $users = $this->userManager->search('', self::USERS_PER_SESSION);
+ }
+
+ $offset += self::USERS_PER_SESSION;
+ $this->config->setAppValue('files_trashbin', 'cronjob_user_offset', $offset);
+
foreach ($users as $user) {
$uid = $user->getUID();
if (!$this->setupFS($uid)) {
continue;
}
$dirContent = Helper::getTrashFiles('/', $uid, 'mtime');
- var_dump($dirContent);
Trashbin::deleteExpiredFiles($dirContent, $uid);
}
-
+
\OC_Util::tearDownFS();
}