1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright 2018, Roeland Jago Douma <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @author Roeland Jago Douma <[email protected]> |
6
|
|
|
* |
7
|
|
|
* @license GNU AGPL version 3 or any later version |
8
|
|
|
* |
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
12
|
|
|
* License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU Affero General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
21
|
|
|
* |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace OCA\Files_Versions\Sabre; |
25
|
|
|
|
26
|
|
|
use OC\User\NoUserException; |
27
|
|
|
use OCA\Files_Versions\Versions\IVersionManager; |
28
|
|
|
use OCP\Files\IRootFolder; |
29
|
|
|
use OCP\IUserManager; |
30
|
|
|
use Sabre\DAV\Exception\Forbidden; |
31
|
|
|
use Sabre\DAV\ICollection; |
32
|
|
|
|
33
|
|
|
class VersionHome implements ICollection { |
34
|
|
|
|
35
|
|
|
/** @var array */ |
36
|
|
|
private $principalInfo; |
37
|
|
|
|
38
|
|
|
/** @var IRootFolder */ |
39
|
|
|
private $rootFolder; |
40
|
|
|
|
41
|
|
|
/** @var IUserManager */ |
42
|
|
|
private $userManager; |
43
|
|
|
|
44
|
|
|
/** @var IVersionManager */ |
45
|
|
|
private $versionManager; |
46
|
|
|
|
47
|
|
|
public function __construct(array $principalInfo, IRootFolder $rootFolder, IUserManager $userManager, IVersionManager $versionManager) { |
48
|
|
|
$this->principalInfo = $principalInfo; |
49
|
|
|
$this->rootFolder = $rootFolder; |
50
|
|
|
$this->userManager = $userManager; |
51
|
|
|
$this->versionManager = $versionManager; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
private function getUser() { |
55
|
|
|
list(, $name) = \Sabre\Uri\split($this->principalInfo['uri']); |
56
|
|
|
$user = $this->userManager->get($name); |
57
|
|
|
if (!$user) { |
58
|
|
|
throw new NoUserException(); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function delete() { |
63
|
|
|
throw new Forbidden(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function getName(): string { |
67
|
|
|
return $this->getUser()->getUID(); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function setName($name) { |
71
|
|
|
throw new Forbidden(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function createFile($name, $data = null) { |
75
|
|
|
throw new Forbidden(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function createDirectory($name) { |
79
|
|
|
throw new Forbidden(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function getChild($name) { |
83
|
|
|
$user = $this->getUser(); |
|
|
|
|
84
|
|
|
|
85
|
|
|
if ($name === 'versions') { |
86
|
|
|
return new VersionRoot($user, $this->rootFolder, $this->versionManager); |
|
|
|
|
87
|
|
|
} |
88
|
|
|
if ($name === 'restore') { |
89
|
|
|
return new RestoreFolder(); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function getChildren() { |
94
|
|
|
$user = $this->getUser(); |
|
|
|
|
95
|
|
|
|
96
|
|
|
return [ |
97
|
|
|
new VersionRoot($user, $this->rootFolder, $this->versionManager), |
|
|
|
|
98
|
|
|
new RestoreFolder(), |
99
|
|
|
]; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function childExists($name) { |
103
|
|
|
return $name === 'versions' || $name === 'restore'; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function getLastModified() { |
107
|
|
|
return 0; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.