1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
4
|
|
|
* |
5
|
|
|
* @author Roeland Jago Douma <[email protected]> |
6
|
|
|
* @author Victor Dubiniuk <[email protected]> |
7
|
|
|
* |
8
|
|
|
* @license AGPL-3.0 |
9
|
|
|
* |
10
|
|
|
* This code is free software: you can redistribute it and/or modify |
11
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
12
|
|
|
* as published by the Free Software Foundation. |
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, version 3, |
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
21
|
|
|
* |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace OCA\Files_Versions\AppInfo; |
25
|
|
|
|
26
|
|
|
use OCA\DAV\Connector\Sabre\Principal; |
27
|
|
|
use OCA\Files_Versions\Versions\IVersionManager; |
28
|
|
|
use OCA\Files_Versions\Versions\VersionManager; |
29
|
|
|
use OCP\AppFramework\App; |
30
|
|
|
use OCP\AppFramework\IAppContainer; |
31
|
|
|
use OCA\Files_Versions\Capabilities; |
32
|
|
|
|
33
|
|
|
class Application extends App { |
34
|
|
|
public function __construct(array $urlParams = array()) { |
35
|
|
|
parent::__construct('files_versions', $urlParams); |
36
|
|
|
|
37
|
|
|
$container = $this->getContainer(); |
38
|
|
|
|
39
|
|
|
/* |
40
|
|
|
* Register capabilities |
41
|
|
|
*/ |
42
|
|
|
$container->registerCapability(Capabilities::class); |
43
|
|
|
|
44
|
|
|
/* |
45
|
|
|
* Register $principalBackend for the DAV collection |
46
|
|
|
*/ |
47
|
|
|
$container->registerService('principalBackend', function (IAppContainer $c) { |
48
|
|
|
$server = $c->getServer(); |
49
|
|
|
return new Principal( |
50
|
|
|
$server->getUserManager(), |
51
|
|
|
$server->getGroupManager(), |
52
|
|
|
$server->getShareManager(), |
53
|
|
|
$server->getUserSession(), |
54
|
|
|
$server->getConfig(), |
55
|
|
|
$server->getAppManager() |
56
|
|
|
); |
57
|
|
|
}); |
58
|
|
|
|
59
|
|
|
$container->registerService(IVersionManager::class, function(IAppContainer $c) { |
|
|
|
|
60
|
|
|
return new VersionManager(); |
61
|
|
|
}); |
62
|
|
|
|
63
|
|
|
$this->registerVersionBackends(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function registerVersionBackends() { |
67
|
|
|
$server = $this->getContainer()->getServer(); |
68
|
|
|
$appManager = $server->getAppManager(); |
69
|
|
|
foreach($appManager->getInstalledApps() as $app) { |
70
|
|
|
$appInfo = $appManager->getAppInfo($app); |
71
|
|
|
if (isset($appInfo['versions'])) { |
72
|
|
|
$backends = $appInfo['versions']; |
73
|
|
|
foreach($backends as $backend) { |
74
|
|
|
if (isset($backend['@value'])) { |
75
|
|
|
$this->loadBackend($backend); |
76
|
|
|
} else { |
77
|
|
|
foreach ($backend as $singleBackend) { |
78
|
|
|
$this->loadBackend($singleBackend); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
private function loadBackend(array $backend) { |
87
|
|
|
$server = $this->getContainer()->getServer(); |
88
|
|
|
$logger = $server->getLogger(); |
89
|
|
|
/** @var IVersionManager $versionManager */ |
90
|
|
|
$versionManager = $this->getContainer()->getServer()->query(IVersionManager::class); |
91
|
|
|
$class = $backend['@value']; |
92
|
|
|
$for = $backend['@attributes']['for']; |
93
|
|
|
try { |
94
|
|
|
$backendObject = $server->query($class); |
95
|
|
|
$versionManager->registerBackend($for, $backendObject); |
96
|
|
|
} catch (\Exception $e) { |
97
|
|
|
$logger->logException($e); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.