|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Joas Schilling <[email protected]> |
|
6
|
|
|
* @author Jörn Friedrich Dreyer <[email protected]> |
|
7
|
|
|
* @author Victor Dubiniuk <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* @license AGPL-3.0 |
|
10
|
|
|
* |
|
11
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
12
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
13
|
|
|
* as published by the Free Software Foundation. |
|
14
|
|
|
* |
|
15
|
|
|
* This program is distributed in the hope that it will be useful, |
|
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18
|
|
|
* GNU Affero General Public License for more details. |
|
19
|
|
|
* |
|
20
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
21
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
22
|
|
|
* |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
namespace OCA\Files_Versions\BackgroundJob; |
|
26
|
|
|
|
|
27
|
|
|
use OCP\IUser; |
|
28
|
|
|
use OCP\IUserManager; |
|
29
|
|
|
use OCA\Files_Versions\AppInfo\Application; |
|
30
|
|
|
use OCA\Files_Versions\Storage; |
|
31
|
|
|
use OCA\Files_Versions\Expiration; |
|
32
|
|
|
|
|
33
|
|
|
class ExpireVersions extends \OC\BackgroundJob\TimedJob { |
|
34
|
|
|
|
|
35
|
|
|
const ITEMS_PER_SESSION = 1000; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var Expiration |
|
39
|
|
|
*/ |
|
40
|
|
|
private $expiration; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var IUserManager |
|
44
|
|
|
*/ |
|
45
|
|
|
private $userManager; |
|
46
|
|
|
|
|
47
|
|
|
public function __construct(IUserManager $userManager, Expiration $expiration) { |
|
48
|
|
|
// Run once per 30 minutes |
|
49
|
|
|
$this->setInterval(60 * 30); |
|
50
|
|
|
|
|
51
|
|
|
$this->expiration = $expiration; |
|
52
|
|
|
$this->userManager = $userManager; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
protected function run($argument) { |
|
56
|
|
|
$maxAge = $this->expiration->getMaxAgeAsTimestamp(); |
|
57
|
|
|
if (!$maxAge) { |
|
|
|
|
|
|
58
|
|
|
return; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$this->userManager->callForSeenUsers(function(IUser $user) { |
|
62
|
|
|
$uid = $user->getUID(); |
|
63
|
|
|
if (!$this->setupFS($uid)) { |
|
64
|
|
|
return; |
|
65
|
|
|
} |
|
66
|
|
|
Storage::expireOlderThanMaxForUser($uid); |
|
67
|
|
|
}); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Act on behalf on trash item owner |
|
72
|
|
|
* @param string $user |
|
73
|
|
|
* @return boolean |
|
74
|
|
|
*/ |
|
75
|
|
View Code Duplication |
protected function setupFS($user) { |
|
76
|
|
|
\OC_Util::tearDownFS(); |
|
77
|
|
|
\OC_Util::setupFS($user); |
|
78
|
|
|
|
|
79
|
|
|
// Check if this user has a versions directory |
|
80
|
|
|
$view = new \OC\Files\View('/' . $user); |
|
81
|
|
|
if (!$view->is_dir('/files_versions')) { |
|
82
|
|
|
return false; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
return true; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: