|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Joas Schilling <[email protected]> |
|
6
|
|
|
* @author Morris Jobke <[email protected]> |
|
7
|
|
|
* @author Robin Appelman <[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\Command; |
|
26
|
|
|
|
|
27
|
|
|
use OC\Command\FileAccess; |
|
28
|
|
|
use OCA\Files_Versions\Storage; |
|
29
|
|
|
use OCP\Command\ICommand; |
|
30
|
|
|
|
|
31
|
|
View Code Duplication |
class Expire implements ICommand { |
|
|
|
|
|
|
32
|
|
|
use FileAccess; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
private $fileName; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var string |
|
41
|
|
|
*/ |
|
42
|
|
|
private $user; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param string $user |
|
46
|
|
|
* @param string $fileName |
|
47
|
|
|
*/ |
|
48
|
|
|
function __construct($user, $fileName) { |
|
|
|
|
|
|
49
|
|
|
$this->user = $user; |
|
50
|
|
|
$this->fileName = $fileName; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
public function handle() { |
|
55
|
|
|
$userManager = \OC::$server->getUserManager(); |
|
56
|
|
|
if (!$userManager->userExists($this->user)) { |
|
57
|
|
|
// User has been deleted already |
|
58
|
|
|
return; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
\OC_Util::setupFS($this->user); |
|
62
|
|
|
Storage::expire($this->fileName); |
|
63
|
|
|
\OC_Util::tearDownFS(); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.