@@ -33,93 +33,93 @@ |
||
33 | 33 | |
34 | 34 | class ExpireVersions extends Command { |
35 | 35 | |
36 | - /** |
|
37 | - * @var Expiration |
|
38 | - */ |
|
39 | - private $expiration; |
|
36 | + /** |
|
37 | + * @var Expiration |
|
38 | + */ |
|
39 | + private $expiration; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @var IUserManager |
|
43 | - */ |
|
44 | - private $userManager; |
|
41 | + /** |
|
42 | + * @var IUserManager |
|
43 | + */ |
|
44 | + private $userManager; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @param IUserManager|null $userManager |
|
48 | - * @param Expiration|null $expiration |
|
49 | - */ |
|
50 | - public function __construct(IUserManager $userManager = null, |
|
51 | - Expiration $expiration = null) { |
|
52 | - parent::__construct(); |
|
46 | + /** |
|
47 | + * @param IUserManager|null $userManager |
|
48 | + * @param Expiration|null $expiration |
|
49 | + */ |
|
50 | + public function __construct(IUserManager $userManager = null, |
|
51 | + Expiration $expiration = null) { |
|
52 | + parent::__construct(); |
|
53 | 53 | |
54 | - $this->userManager = $userManager; |
|
55 | - $this->expiration = $expiration; |
|
56 | - } |
|
54 | + $this->userManager = $userManager; |
|
55 | + $this->expiration = $expiration; |
|
56 | + } |
|
57 | 57 | |
58 | - protected function configure() { |
|
59 | - $this |
|
60 | - ->setName('versions:expire') |
|
61 | - ->setDescription('Expires the users file versions') |
|
62 | - ->addArgument( |
|
63 | - 'user_id', |
|
64 | - InputArgument::OPTIONAL | InputArgument::IS_ARRAY, |
|
65 | - 'expire file versions of the given user(s), if no user is given file versions for all users will be expired.' |
|
66 | - ); |
|
67 | - } |
|
58 | + protected function configure() { |
|
59 | + $this |
|
60 | + ->setName('versions:expire') |
|
61 | + ->setDescription('Expires the users file versions') |
|
62 | + ->addArgument( |
|
63 | + 'user_id', |
|
64 | + InputArgument::OPTIONAL | InputArgument::IS_ARRAY, |
|
65 | + 'expire file versions of the given user(s), if no user is given file versions for all users will be expired.' |
|
66 | + ); |
|
67 | + } |
|
68 | 68 | |
69 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
69 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
70 | 70 | |
71 | - $maxAge = $this->expiration->getMaxAgeAsTimestamp(); |
|
72 | - if (!$maxAge) { |
|
73 | - $output->writeln("No expiry configured."); |
|
74 | - return; |
|
75 | - } |
|
71 | + $maxAge = $this->expiration->getMaxAgeAsTimestamp(); |
|
72 | + if (!$maxAge) { |
|
73 | + $output->writeln("No expiry configured."); |
|
74 | + return; |
|
75 | + } |
|
76 | 76 | |
77 | - $users = $input->getArgument('user_id'); |
|
78 | - if (!empty($users)) { |
|
79 | - foreach ($users as $user) { |
|
80 | - if ($this->userManager->userExists($user)) { |
|
81 | - $output->writeln("Remove deleted files of <info>$user</info>"); |
|
82 | - $userObject = $this->userManager->get($user); |
|
83 | - $this->expireVersionsForUser($userObject); |
|
84 | - } else { |
|
85 | - $output->writeln("<error>Unknown user $user</error>"); |
|
86 | - } |
|
87 | - } |
|
88 | - } else { |
|
89 | - $p = new ProgressBar($output); |
|
90 | - $p->start(); |
|
91 | - $this->userManager->callForSeenUsers(function(IUser $user) use ($p) { |
|
92 | - $p->advance(); |
|
93 | - $this->expireVersionsForUser($user); |
|
94 | - }); |
|
95 | - $p->finish(); |
|
96 | - $output->writeln(''); |
|
97 | - } |
|
98 | - } |
|
77 | + $users = $input->getArgument('user_id'); |
|
78 | + if (!empty($users)) { |
|
79 | + foreach ($users as $user) { |
|
80 | + if ($this->userManager->userExists($user)) { |
|
81 | + $output->writeln("Remove deleted files of <info>$user</info>"); |
|
82 | + $userObject = $this->userManager->get($user); |
|
83 | + $this->expireVersionsForUser($userObject); |
|
84 | + } else { |
|
85 | + $output->writeln("<error>Unknown user $user</error>"); |
|
86 | + } |
|
87 | + } |
|
88 | + } else { |
|
89 | + $p = new ProgressBar($output); |
|
90 | + $p->start(); |
|
91 | + $this->userManager->callForSeenUsers(function(IUser $user) use ($p) { |
|
92 | + $p->advance(); |
|
93 | + $this->expireVersionsForUser($user); |
|
94 | + }); |
|
95 | + $p->finish(); |
|
96 | + $output->writeln(''); |
|
97 | + } |
|
98 | + } |
|
99 | 99 | |
100 | - function expireVersionsForUser(IUser $user) { |
|
101 | - $uid = $user->getUID(); |
|
102 | - if (!$this->setupFS($uid)) { |
|
103 | - return; |
|
104 | - } |
|
105 | - Storage::expireOlderThanMaxForUser($uid); |
|
106 | - } |
|
100 | + function expireVersionsForUser(IUser $user) { |
|
101 | + $uid = $user->getUID(); |
|
102 | + if (!$this->setupFS($uid)) { |
|
103 | + return; |
|
104 | + } |
|
105 | + Storage::expireOlderThanMaxForUser($uid); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * Act on behalf on versions item owner |
|
110 | - * @param string $user |
|
111 | - * @return boolean |
|
112 | - */ |
|
113 | - protected function setupFS($user) { |
|
114 | - \OC_Util::tearDownFS(); |
|
115 | - \OC_Util::setupFS($user); |
|
108 | + /** |
|
109 | + * Act on behalf on versions item owner |
|
110 | + * @param string $user |
|
111 | + * @return boolean |
|
112 | + */ |
|
113 | + protected function setupFS($user) { |
|
114 | + \OC_Util::tearDownFS(); |
|
115 | + \OC_Util::setupFS($user); |
|
116 | 116 | |
117 | - // Check if this user has a version directory |
|
118 | - $view = new \OC\Files\View('/' . $user); |
|
119 | - if (!$view->is_dir('/files_versions')) { |
|
120 | - return false; |
|
121 | - } |
|
117 | + // Check if this user has a version directory |
|
118 | + $view = new \OC\Files\View('/' . $user); |
|
119 | + if (!$view->is_dir('/files_versions')) { |
|
120 | + return false; |
|
121 | + } |
|
122 | 122 | |
123 | - return true; |
|
124 | - } |
|
123 | + return true; |
|
124 | + } |
|
125 | 125 | } |
@@ -33,83 +33,83 @@ |
||
33 | 33 | |
34 | 34 | class CleanUp extends Command { |
35 | 35 | |
36 | - /** @var IUserManager */ |
|
37 | - protected $userManager; |
|
38 | - |
|
39 | - /** @var IRootFolder */ |
|
40 | - protected $rootFolder; |
|
41 | - |
|
42 | - /** |
|
43 | - * @param IRootFolder $rootFolder |
|
44 | - * @param IUserManager $userManager |
|
45 | - */ |
|
46 | - function __construct(IRootFolder $rootFolder, IUserManager $userManager) { |
|
47 | - parent::__construct(); |
|
48 | - $this->userManager = $userManager; |
|
49 | - $this->rootFolder = $rootFolder; |
|
50 | - } |
|
51 | - |
|
52 | - protected function configure() { |
|
53 | - $this |
|
54 | - ->setName('versions:cleanup') |
|
55 | - ->setDescription('Delete versions') |
|
56 | - ->addArgument( |
|
57 | - 'user_id', |
|
58 | - InputArgument::OPTIONAL | InputArgument::IS_ARRAY, |
|
59 | - 'delete versions of the given user(s), if no user is given all versions will be deleted' |
|
60 | - ); |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
65 | - |
|
66 | - $users = $input->getArgument('user_id'); |
|
67 | - if (!empty($users)) { |
|
68 | - foreach ($users as $user) { |
|
69 | - if ($this->userManager->userExists($user)) { |
|
70 | - $output->writeln("Delete versions of <info>$user</info>"); |
|
71 | - $this->deleteVersions($user); |
|
72 | - } else { |
|
73 | - $output->writeln("<error>Unknown user $user</error>"); |
|
74 | - } |
|
75 | - } |
|
76 | - } else { |
|
77 | - $output->writeln('Delete all versions'); |
|
78 | - foreach ($this->userManager->getBackends() as $backend) { |
|
79 | - $name = get_class($backend); |
|
80 | - |
|
81 | - if ($backend instanceof IUserBackend) { |
|
82 | - $name = $backend->getBackendName(); |
|
83 | - } |
|
84 | - |
|
85 | - $output->writeln("Delete versions for users on backend <info>$name</info>"); |
|
86 | - |
|
87 | - $limit = 500; |
|
88 | - $offset = 0; |
|
89 | - do { |
|
90 | - $users = $backend->getUsers('', $limit, $offset); |
|
91 | - foreach ($users as $user) { |
|
92 | - $output->writeln(" <info>$user</info>"); |
|
93 | - $this->deleteVersions($user); |
|
94 | - } |
|
95 | - $offset += $limit; |
|
96 | - } while (count($users) >= $limit); |
|
97 | - } |
|
98 | - } |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * delete versions for the given user |
|
104 | - * |
|
105 | - * @param string $user |
|
106 | - */ |
|
107 | - protected function deleteVersions($user) { |
|
108 | - \OC_Util::tearDownFS(); |
|
109 | - \OC_Util::setupFS($user); |
|
110 | - if ($this->rootFolder->nodeExists('/' . $user . '/files_versions')) { |
|
111 | - $this->rootFolder->get('/' . $user . '/files_versions')->delete(); |
|
112 | - } |
|
113 | - } |
|
36 | + /** @var IUserManager */ |
|
37 | + protected $userManager; |
|
38 | + |
|
39 | + /** @var IRootFolder */ |
|
40 | + protected $rootFolder; |
|
41 | + |
|
42 | + /** |
|
43 | + * @param IRootFolder $rootFolder |
|
44 | + * @param IUserManager $userManager |
|
45 | + */ |
|
46 | + function __construct(IRootFolder $rootFolder, IUserManager $userManager) { |
|
47 | + parent::__construct(); |
|
48 | + $this->userManager = $userManager; |
|
49 | + $this->rootFolder = $rootFolder; |
|
50 | + } |
|
51 | + |
|
52 | + protected function configure() { |
|
53 | + $this |
|
54 | + ->setName('versions:cleanup') |
|
55 | + ->setDescription('Delete versions') |
|
56 | + ->addArgument( |
|
57 | + 'user_id', |
|
58 | + InputArgument::OPTIONAL | InputArgument::IS_ARRAY, |
|
59 | + 'delete versions of the given user(s), if no user is given all versions will be deleted' |
|
60 | + ); |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
65 | + |
|
66 | + $users = $input->getArgument('user_id'); |
|
67 | + if (!empty($users)) { |
|
68 | + foreach ($users as $user) { |
|
69 | + if ($this->userManager->userExists($user)) { |
|
70 | + $output->writeln("Delete versions of <info>$user</info>"); |
|
71 | + $this->deleteVersions($user); |
|
72 | + } else { |
|
73 | + $output->writeln("<error>Unknown user $user</error>"); |
|
74 | + } |
|
75 | + } |
|
76 | + } else { |
|
77 | + $output->writeln('Delete all versions'); |
|
78 | + foreach ($this->userManager->getBackends() as $backend) { |
|
79 | + $name = get_class($backend); |
|
80 | + |
|
81 | + if ($backend instanceof IUserBackend) { |
|
82 | + $name = $backend->getBackendName(); |
|
83 | + } |
|
84 | + |
|
85 | + $output->writeln("Delete versions for users on backend <info>$name</info>"); |
|
86 | + |
|
87 | + $limit = 500; |
|
88 | + $offset = 0; |
|
89 | + do { |
|
90 | + $users = $backend->getUsers('', $limit, $offset); |
|
91 | + foreach ($users as $user) { |
|
92 | + $output->writeln(" <info>$user</info>"); |
|
93 | + $this->deleteVersions($user); |
|
94 | + } |
|
95 | + $offset += $limit; |
|
96 | + } while (count($users) >= $limit); |
|
97 | + } |
|
98 | + } |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * delete versions for the given user |
|
104 | + * |
|
105 | + * @param string $user |
|
106 | + */ |
|
107 | + protected function deleteVersions($user) { |
|
108 | + \OC_Util::tearDownFS(); |
|
109 | + \OC_Util::setupFS($user); |
|
110 | + if ($this->rootFolder->nodeExists('/' . $user . '/files_versions')) { |
|
111 | + $this->rootFolder->get('/' . $user . '/files_versions')->delete(); |
|
112 | + } |
|
113 | + } |
|
114 | 114 | |
115 | 115 | } |
@@ -29,16 +29,16 @@ |
||
29 | 29 | |
30 | 30 | class Capabilities implements ICapability { |
31 | 31 | |
32 | - /** |
|
33 | - * Return this classes capabilities |
|
34 | - * |
|
35 | - * @return array |
|
36 | - */ |
|
37 | - public function getCapabilities() { |
|
38 | - return [ |
|
39 | - 'files' => [ |
|
40 | - 'versioning' => true |
|
41 | - ] |
|
42 | - ]; |
|
43 | - } |
|
32 | + /** |
|
33 | + * Return this classes capabilities |
|
34 | + * |
|
35 | + * @return array |
|
36 | + */ |
|
37 | + public function getCapabilities() { |
|
38 | + return [ |
|
39 | + 'files' => [ |
|
40 | + 'versioning' => true |
|
41 | + ] |
|
42 | + ]; |
|
43 | + } |
|
44 | 44 | } |
@@ -31,66 +31,66 @@ |
||
31 | 31 | |
32 | 32 | class ExpireVersions extends \OC\BackgroundJob\TimedJob { |
33 | 33 | |
34 | - const ITEMS_PER_SESSION = 1000; |
|
34 | + const ITEMS_PER_SESSION = 1000; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @var Expiration |
|
38 | - */ |
|
39 | - private $expiration; |
|
36 | + /** |
|
37 | + * @var Expiration |
|
38 | + */ |
|
39 | + private $expiration; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @var IUserManager |
|
43 | - */ |
|
44 | - private $userManager; |
|
41 | + /** |
|
42 | + * @var IUserManager |
|
43 | + */ |
|
44 | + private $userManager; |
|
45 | 45 | |
46 | - public function __construct(IUserManager $userManager = null, Expiration $expiration = null) { |
|
47 | - // Run once per 30 minutes |
|
48 | - $this->setInterval(60 * 30); |
|
46 | + public function __construct(IUserManager $userManager = null, Expiration $expiration = null) { |
|
47 | + // Run once per 30 minutes |
|
48 | + $this->setInterval(60 * 30); |
|
49 | 49 | |
50 | - if (is_null($expiration) || is_null($userManager)) { |
|
51 | - $this->fixDIForJobs(); |
|
52 | - } else { |
|
53 | - $this->expiration = $expiration; |
|
54 | - $this->userManager = $userManager; |
|
55 | - } |
|
56 | - } |
|
50 | + if (is_null($expiration) || is_null($userManager)) { |
|
51 | + $this->fixDIForJobs(); |
|
52 | + } else { |
|
53 | + $this->expiration = $expiration; |
|
54 | + $this->userManager = $userManager; |
|
55 | + } |
|
56 | + } |
|
57 | 57 | |
58 | - protected function fixDIForJobs() { |
|
59 | - $application = new Application(); |
|
60 | - $this->expiration = $application->getContainer()->query('Expiration'); |
|
61 | - $this->userManager = \OC::$server->getUserManager(); |
|
62 | - } |
|
58 | + protected function fixDIForJobs() { |
|
59 | + $application = new Application(); |
|
60 | + $this->expiration = $application->getContainer()->query('Expiration'); |
|
61 | + $this->userManager = \OC::$server->getUserManager(); |
|
62 | + } |
|
63 | 63 | |
64 | - protected function run($argument) { |
|
65 | - $maxAge = $this->expiration->getMaxAgeAsTimestamp(); |
|
66 | - if (!$maxAge) { |
|
67 | - return; |
|
68 | - } |
|
64 | + protected function run($argument) { |
|
65 | + $maxAge = $this->expiration->getMaxAgeAsTimestamp(); |
|
66 | + if (!$maxAge) { |
|
67 | + return; |
|
68 | + } |
|
69 | 69 | |
70 | - $this->userManager->callForSeenUsers(function(IUser $user) { |
|
71 | - $uid = $user->getUID(); |
|
72 | - if (!$this->setupFS($uid)) { |
|
73 | - return; |
|
74 | - } |
|
75 | - Storage::expireOlderThanMaxForUser($uid); |
|
76 | - }); |
|
77 | - } |
|
70 | + $this->userManager->callForSeenUsers(function(IUser $user) { |
|
71 | + $uid = $user->getUID(); |
|
72 | + if (!$this->setupFS($uid)) { |
|
73 | + return; |
|
74 | + } |
|
75 | + Storage::expireOlderThanMaxForUser($uid); |
|
76 | + }); |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * Act on behalf on trash item owner |
|
81 | - * @param string $user |
|
82 | - * @return boolean |
|
83 | - */ |
|
84 | - protected function setupFS($user) { |
|
85 | - \OC_Util::tearDownFS(); |
|
86 | - \OC_Util::setupFS($user); |
|
79 | + /** |
|
80 | + * Act on behalf on trash item owner |
|
81 | + * @param string $user |
|
82 | + * @return boolean |
|
83 | + */ |
|
84 | + protected function setupFS($user) { |
|
85 | + \OC_Util::tearDownFS(); |
|
86 | + \OC_Util::setupFS($user); |
|
87 | 87 | |
88 | - // Check if this user has a versions directory |
|
89 | - $view = new \OC\Files\View('/' . $user); |
|
90 | - if (!$view->is_dir('/files_versions')) { |
|
91 | - return false; |
|
92 | - } |
|
88 | + // Check if this user has a versions directory |
|
89 | + $view = new \OC\Files\View('/' . $user); |
|
90 | + if (!$view->is_dir('/files_versions')) { |
|
91 | + return false; |
|
92 | + } |
|
93 | 93 | |
94 | - return true; |
|
95 | - } |
|
94 | + return true; |
|
95 | + } |
|
96 | 96 | } |
@@ -27,173 +27,173 @@ |
||
27 | 27 | |
28 | 28 | class Expiration { |
29 | 29 | |
30 | - // how long do we keep files a version if no other value is defined in the config file (unit: days) |
|
31 | - const NO_OBLIGATION = -1; |
|
32 | - |
|
33 | - /** @var ITimeFactory */ |
|
34 | - private $timeFactory; |
|
35 | - |
|
36 | - /** @var string */ |
|
37 | - private $retentionObligation; |
|
38 | - |
|
39 | - /** @var int */ |
|
40 | - private $minAge; |
|
41 | - |
|
42 | - /** @var int */ |
|
43 | - private $maxAge; |
|
44 | - |
|
45 | - /** @var bool */ |
|
46 | - private $canPurgeToSaveSpace; |
|
47 | - |
|
48 | - public function __construct(IConfig $config,ITimeFactory $timeFactory){ |
|
49 | - $this->timeFactory = $timeFactory; |
|
50 | - $this->retentionObligation = $config->getSystemValue('versions_retention_obligation', 'auto'); |
|
51 | - |
|
52 | - if ($this->retentionObligation !== 'disabled') { |
|
53 | - $this->parseRetentionObligation(); |
|
54 | - } |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Is versions expiration enabled |
|
59 | - * @return bool |
|
60 | - */ |
|
61 | - public function isEnabled(){ |
|
62 | - return $this->retentionObligation !== 'disabled'; |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * Is default expiration active |
|
67 | - */ |
|
68 | - public function shouldAutoExpire(){ |
|
69 | - return $this->minAge === self::NO_OBLIGATION |
|
70 | - || $this->maxAge === self::NO_OBLIGATION; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Check if given timestamp in expiration range |
|
75 | - * @param int $timestamp |
|
76 | - * @param bool $quotaExceeded |
|
77 | - * @return bool |
|
78 | - */ |
|
79 | - public function isExpired($timestamp, $quotaExceeded = false){ |
|
80 | - // No expiration if disabled |
|
81 | - if (!$this->isEnabled()) { |
|
82 | - return false; |
|
83 | - } |
|
84 | - |
|
85 | - // Purge to save space (if allowed) |
|
86 | - if ($quotaExceeded && $this->canPurgeToSaveSpace) { |
|
87 | - return true; |
|
88 | - } |
|
89 | - |
|
90 | - $time = $this->timeFactory->getTime(); |
|
91 | - // Never expire dates in future e.g. misconfiguration or negative time |
|
92 | - // adjustment |
|
93 | - if ($time<$timestamp) { |
|
94 | - return false; |
|
95 | - } |
|
96 | - |
|
97 | - // Purge as too old |
|
98 | - if ($this->maxAge !== self::NO_OBLIGATION) { |
|
99 | - $maxTimestamp = $time - ($this->maxAge * 86400); |
|
100 | - $isOlderThanMax = $timestamp < $maxTimestamp; |
|
101 | - } else { |
|
102 | - $isOlderThanMax = false; |
|
103 | - } |
|
104 | - |
|
105 | - if ($this->minAge !== self::NO_OBLIGATION) { |
|
106 | - // older than Min obligation and we are running out of quota? |
|
107 | - $minTimestamp = $time - ($this->minAge * 86400); |
|
108 | - $isMinReached = ($timestamp < $minTimestamp) && $quotaExceeded; |
|
109 | - } else { |
|
110 | - $isMinReached = false; |
|
111 | - } |
|
112 | - |
|
113 | - return $isOlderThanMax || $isMinReached; |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Get maximal retention obligation as a timestamp |
|
118 | - * @return int |
|
119 | - */ |
|
120 | - public function getMaxAgeAsTimestamp(){ |
|
121 | - $maxAge = false; |
|
122 | - if ($this->isEnabled() && $this->maxAge !== self::NO_OBLIGATION) { |
|
123 | - $time = $this->timeFactory->getTime(); |
|
124 | - $maxAge = $time - ($this->maxAge * 86400); |
|
125 | - } |
|
126 | - return $maxAge; |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * Read versions_retention_obligation, validate it |
|
131 | - * and set private members accordingly |
|
132 | - */ |
|
133 | - private function parseRetentionObligation(){ |
|
134 | - $splitValues = explode(',', $this->retentionObligation); |
|
135 | - if (!isset($splitValues[0])) { |
|
136 | - $minValue = 'auto'; |
|
137 | - } else { |
|
138 | - $minValue = trim($splitValues[0]); |
|
139 | - } |
|
140 | - |
|
141 | - if (!isset($splitValues[1])) { |
|
142 | - $maxValue = 'auto'; |
|
143 | - } else { |
|
144 | - $maxValue = trim($splitValues[1]); |
|
145 | - } |
|
146 | - |
|
147 | - $isValid = true; |
|
148 | - // Validate |
|
149 | - if (!ctype_digit($minValue) && $minValue !== 'auto') { |
|
150 | - $isValid = false; |
|
151 | - \OC::$server->getLogger()->warning( |
|
152 | - $minValue . ' is not a valid value for minimal versions retention obligation. Check versions_retention_obligation in your config.php. Falling back to auto.', |
|
153 | - ['app'=>'files_versions'] |
|
154 | - ); |
|
155 | - } |
|
156 | - |
|
157 | - if (!ctype_digit($maxValue) && $maxValue !== 'auto') { |
|
158 | - $isValid = false; |
|
159 | - \OC::$server->getLogger()->warning( |
|
160 | - $maxValue . ' is not a valid value for maximal versions retention obligation. Check versions_retention_obligation in your config.php. Falling back to auto.', |
|
161 | - ['app'=>'files_versions'] |
|
162 | - ); |
|
163 | - } |
|
164 | - |
|
165 | - if (!$isValid){ |
|
166 | - $minValue = 'auto'; |
|
167 | - $maxValue = 'auto'; |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - if ($minValue === 'auto' && $maxValue === 'auto') { |
|
172 | - // Default: Delete anytime if space needed |
|
173 | - $this->minAge = self::NO_OBLIGATION; |
|
174 | - $this->maxAge = self::NO_OBLIGATION; |
|
175 | - $this->canPurgeToSaveSpace = true; |
|
176 | - } elseif ($minValue !== 'auto' && $maxValue === 'auto') { |
|
177 | - // Keep for X days but delete anytime if space needed |
|
178 | - $this->minAge = intval($minValue); |
|
179 | - $this->maxAge = self::NO_OBLIGATION; |
|
180 | - $this->canPurgeToSaveSpace = true; |
|
181 | - } elseif ($minValue === 'auto' && $maxValue !== 'auto') { |
|
182 | - // Delete anytime if space needed, Delete all older than max automatically |
|
183 | - $this->minAge = self::NO_OBLIGATION; |
|
184 | - $this->maxAge = intval($maxValue); |
|
185 | - $this->canPurgeToSaveSpace = true; |
|
186 | - } elseif ($minValue !== 'auto' && $maxValue !== 'auto') { |
|
187 | - // Delete all older than max OR older than min if space needed |
|
188 | - |
|
189 | - // Max < Min as per https://github.com/owncloud/core/issues/16301 |
|
190 | - if ($maxValue < $minValue) { |
|
191 | - $maxValue = $minValue; |
|
192 | - } |
|
193 | - |
|
194 | - $this->minAge = intval($minValue); |
|
195 | - $this->maxAge = intval($maxValue); |
|
196 | - $this->canPurgeToSaveSpace = false; |
|
197 | - } |
|
198 | - } |
|
30 | + // how long do we keep files a version if no other value is defined in the config file (unit: days) |
|
31 | + const NO_OBLIGATION = -1; |
|
32 | + |
|
33 | + /** @var ITimeFactory */ |
|
34 | + private $timeFactory; |
|
35 | + |
|
36 | + /** @var string */ |
|
37 | + private $retentionObligation; |
|
38 | + |
|
39 | + /** @var int */ |
|
40 | + private $minAge; |
|
41 | + |
|
42 | + /** @var int */ |
|
43 | + private $maxAge; |
|
44 | + |
|
45 | + /** @var bool */ |
|
46 | + private $canPurgeToSaveSpace; |
|
47 | + |
|
48 | + public function __construct(IConfig $config,ITimeFactory $timeFactory){ |
|
49 | + $this->timeFactory = $timeFactory; |
|
50 | + $this->retentionObligation = $config->getSystemValue('versions_retention_obligation', 'auto'); |
|
51 | + |
|
52 | + if ($this->retentionObligation !== 'disabled') { |
|
53 | + $this->parseRetentionObligation(); |
|
54 | + } |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Is versions expiration enabled |
|
59 | + * @return bool |
|
60 | + */ |
|
61 | + public function isEnabled(){ |
|
62 | + return $this->retentionObligation !== 'disabled'; |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * Is default expiration active |
|
67 | + */ |
|
68 | + public function shouldAutoExpire(){ |
|
69 | + return $this->minAge === self::NO_OBLIGATION |
|
70 | + || $this->maxAge === self::NO_OBLIGATION; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Check if given timestamp in expiration range |
|
75 | + * @param int $timestamp |
|
76 | + * @param bool $quotaExceeded |
|
77 | + * @return bool |
|
78 | + */ |
|
79 | + public function isExpired($timestamp, $quotaExceeded = false){ |
|
80 | + // No expiration if disabled |
|
81 | + if (!$this->isEnabled()) { |
|
82 | + return false; |
|
83 | + } |
|
84 | + |
|
85 | + // Purge to save space (if allowed) |
|
86 | + if ($quotaExceeded && $this->canPurgeToSaveSpace) { |
|
87 | + return true; |
|
88 | + } |
|
89 | + |
|
90 | + $time = $this->timeFactory->getTime(); |
|
91 | + // Never expire dates in future e.g. misconfiguration or negative time |
|
92 | + // adjustment |
|
93 | + if ($time<$timestamp) { |
|
94 | + return false; |
|
95 | + } |
|
96 | + |
|
97 | + // Purge as too old |
|
98 | + if ($this->maxAge !== self::NO_OBLIGATION) { |
|
99 | + $maxTimestamp = $time - ($this->maxAge * 86400); |
|
100 | + $isOlderThanMax = $timestamp < $maxTimestamp; |
|
101 | + } else { |
|
102 | + $isOlderThanMax = false; |
|
103 | + } |
|
104 | + |
|
105 | + if ($this->minAge !== self::NO_OBLIGATION) { |
|
106 | + // older than Min obligation and we are running out of quota? |
|
107 | + $minTimestamp = $time - ($this->minAge * 86400); |
|
108 | + $isMinReached = ($timestamp < $minTimestamp) && $quotaExceeded; |
|
109 | + } else { |
|
110 | + $isMinReached = false; |
|
111 | + } |
|
112 | + |
|
113 | + return $isOlderThanMax || $isMinReached; |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Get maximal retention obligation as a timestamp |
|
118 | + * @return int |
|
119 | + */ |
|
120 | + public function getMaxAgeAsTimestamp(){ |
|
121 | + $maxAge = false; |
|
122 | + if ($this->isEnabled() && $this->maxAge !== self::NO_OBLIGATION) { |
|
123 | + $time = $this->timeFactory->getTime(); |
|
124 | + $maxAge = $time - ($this->maxAge * 86400); |
|
125 | + } |
|
126 | + return $maxAge; |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * Read versions_retention_obligation, validate it |
|
131 | + * and set private members accordingly |
|
132 | + */ |
|
133 | + private function parseRetentionObligation(){ |
|
134 | + $splitValues = explode(',', $this->retentionObligation); |
|
135 | + if (!isset($splitValues[0])) { |
|
136 | + $minValue = 'auto'; |
|
137 | + } else { |
|
138 | + $minValue = trim($splitValues[0]); |
|
139 | + } |
|
140 | + |
|
141 | + if (!isset($splitValues[1])) { |
|
142 | + $maxValue = 'auto'; |
|
143 | + } else { |
|
144 | + $maxValue = trim($splitValues[1]); |
|
145 | + } |
|
146 | + |
|
147 | + $isValid = true; |
|
148 | + // Validate |
|
149 | + if (!ctype_digit($minValue) && $minValue !== 'auto') { |
|
150 | + $isValid = false; |
|
151 | + \OC::$server->getLogger()->warning( |
|
152 | + $minValue . ' is not a valid value for minimal versions retention obligation. Check versions_retention_obligation in your config.php. Falling back to auto.', |
|
153 | + ['app'=>'files_versions'] |
|
154 | + ); |
|
155 | + } |
|
156 | + |
|
157 | + if (!ctype_digit($maxValue) && $maxValue !== 'auto') { |
|
158 | + $isValid = false; |
|
159 | + \OC::$server->getLogger()->warning( |
|
160 | + $maxValue . ' is not a valid value for maximal versions retention obligation. Check versions_retention_obligation in your config.php. Falling back to auto.', |
|
161 | + ['app'=>'files_versions'] |
|
162 | + ); |
|
163 | + } |
|
164 | + |
|
165 | + if (!$isValid){ |
|
166 | + $minValue = 'auto'; |
|
167 | + $maxValue = 'auto'; |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + if ($minValue === 'auto' && $maxValue === 'auto') { |
|
172 | + // Default: Delete anytime if space needed |
|
173 | + $this->minAge = self::NO_OBLIGATION; |
|
174 | + $this->maxAge = self::NO_OBLIGATION; |
|
175 | + $this->canPurgeToSaveSpace = true; |
|
176 | + } elseif ($minValue !== 'auto' && $maxValue === 'auto') { |
|
177 | + // Keep for X days but delete anytime if space needed |
|
178 | + $this->minAge = intval($minValue); |
|
179 | + $this->maxAge = self::NO_OBLIGATION; |
|
180 | + $this->canPurgeToSaveSpace = true; |
|
181 | + } elseif ($minValue === 'auto' && $maxValue !== 'auto') { |
|
182 | + // Delete anytime if space needed, Delete all older than max automatically |
|
183 | + $this->minAge = self::NO_OBLIGATION; |
|
184 | + $this->maxAge = intval($maxValue); |
|
185 | + $this->canPurgeToSaveSpace = true; |
|
186 | + } elseif ($minValue !== 'auto' && $maxValue !== 'auto') { |
|
187 | + // Delete all older than max OR older than min if space needed |
|
188 | + |
|
189 | + // Max < Min as per https://github.com/owncloud/core/issues/16301 |
|
190 | + if ($maxValue < $minValue) { |
|
191 | + $maxValue = $minValue; |
|
192 | + } |
|
193 | + |
|
194 | + $this->minAge = intval($minValue); |
|
195 | + $this->maxAge = intval($maxValue); |
|
196 | + $this->canPurgeToSaveSpace = false; |
|
197 | + } |
|
198 | + } |
|
199 | 199 | } |
@@ -32,13 +32,13 @@ |
||
32 | 32 | $revision=(int)$_GET['revision']; |
33 | 33 | |
34 | 34 | try { |
35 | - list($uid, $filename) = OCA\Files_Versions\Storage::getUidAndFilename($file); |
|
35 | + list($uid, $filename) = OCA\Files_Versions\Storage::getUidAndFilename($file); |
|
36 | 36 | } catch(\OCP\Files\NotFoundException $e) { |
37 | - header("HTTP/1.1 404 Not Found"); |
|
38 | - $tmpl = new OCP\Template('', '404', 'guest'); |
|
39 | - $tmpl->assign('file', ''); |
|
40 | - $tmpl->printPage(); |
|
41 | - exit(); |
|
37 | + header("HTTP/1.1 404 Not Found"); |
|
38 | + $tmpl = new OCP\Template('', '404', 'guest'); |
|
39 | + $tmpl->assign('file', ''); |
|
40 | + $tmpl->printPage(); |
|
41 | + exit(); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | $versionName = '/'.$uid.'/files_versions/'.$filename.'.v'.$revision; |
@@ -31,20 +31,20 @@ |
||
31 | 31 | |
32 | 32 | $application = new Application(); |
33 | 33 | $application->registerRoutes($this, [ |
34 | - 'routes' => [ |
|
35 | - [ |
|
36 | - 'name' => 'Preview#getPreview', |
|
37 | - 'url' => '/preview', |
|
38 | - 'verb' => 'GET', |
|
39 | - ], |
|
40 | - ], |
|
34 | + 'routes' => [ |
|
35 | + [ |
|
36 | + 'name' => 'Preview#getPreview', |
|
37 | + 'url' => '/preview', |
|
38 | + 'verb' => 'GET', |
|
39 | + ], |
|
40 | + ], |
|
41 | 41 | ]); |
42 | 42 | |
43 | 43 | /** @var $this \OCP\Route\IRouter */ |
44 | 44 | $this->create('files_versions_download', 'download.php') |
45 | - ->actionInclude('files_versions/download.php'); |
|
45 | + ->actionInclude('files_versions/download.php'); |
|
46 | 46 | $this->create('files_versions_ajax_getVersions', 'ajax/getVersions.php') |
47 | - ->actionInclude('files_versions/ajax/getVersions.php'); |
|
47 | + ->actionInclude('files_versions/ajax/getVersions.php'); |
|
48 | 48 | $this->create('files_versions_ajax_rollbackVersion', 'ajax/rollbackVersion.php') |
49 | - ->actionInclude('files_versions/ajax/rollbackVersion.php'); |
|
49 | + ->actionInclude('files_versions/ajax/rollbackVersion.php'); |
|
50 | 50 |
@@ -38,28 +38,28 @@ |
||
38 | 38 | */ |
39 | 39 | interface IApacheBackend { |
40 | 40 | |
41 | - /** |
|
42 | - * In case the user has been authenticated by Apache true is returned. |
|
43 | - * |
|
44 | - * @return boolean whether Apache reports a user as currently logged in. |
|
45 | - * @since 6.0.0 |
|
46 | - */ |
|
47 | - public function isSessionActive(); |
|
41 | + /** |
|
42 | + * In case the user has been authenticated by Apache true is returned. |
|
43 | + * |
|
44 | + * @return boolean whether Apache reports a user as currently logged in. |
|
45 | + * @since 6.0.0 |
|
46 | + */ |
|
47 | + public function isSessionActive(); |
|
48 | 48 | |
49 | - /** |
|
50 | - * Creates an attribute which is added to the logout hyperlink. It can |
|
51 | - * supply any attribute(s) which are valid for <a>. |
|
52 | - * |
|
53 | - * @return string with one or more HTML attributes. |
|
54 | - * @since 6.0.0 |
|
55 | - */ |
|
56 | - public function getLogoutAttribute(); |
|
49 | + /** |
|
50 | + * Creates an attribute which is added to the logout hyperlink. It can |
|
51 | + * supply any attribute(s) which are valid for <a>. |
|
52 | + * |
|
53 | + * @return string with one or more HTML attributes. |
|
54 | + * @since 6.0.0 |
|
55 | + */ |
|
56 | + public function getLogoutAttribute(); |
|
57 | 57 | |
58 | - /** |
|
59 | - * Return the id of the current user |
|
60 | - * @return string |
|
61 | - * @since 6.0.0 |
|
62 | - */ |
|
63 | - public function getCurrentUserId(); |
|
58 | + /** |
|
59 | + * Return the id of the current user |
|
60 | + * @return string |
|
61 | + * @since 6.0.0 |
|
62 | + */ |
|
63 | + public function getCurrentUserId(); |
|
64 | 64 | |
65 | 65 | } |
@@ -31,14 +31,14 @@ |
||
31 | 31 | */ |
32 | 32 | interface IStore { |
33 | 33 | |
34 | - /** |
|
35 | - * Get login credentials of the currently logged in user |
|
36 | - * |
|
37 | - * @since 12 |
|
38 | - * |
|
39 | - * @throws CredentialsUnavailableException |
|
40 | - * @return ICredentials the login credentials of the current user |
|
41 | - */ |
|
42 | - public function getLoginCredentials(); |
|
34 | + /** |
|
35 | + * Get login credentials of the currently logged in user |
|
36 | + * |
|
37 | + * @since 12 |
|
38 | + * |
|
39 | + * @throws CredentialsUnavailableException |
|
40 | + * @return ICredentials the login credentials of the current user |
|
41 | + */ |
|
42 | + public function getLoginCredentials(); |
|
43 | 43 | |
44 | 44 | } |