|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Christoph Wurst <[email protected]> |
|
6
|
|
|
* @author Georg Ehrke <[email protected]> |
|
7
|
|
|
* @author Morris Jobke <[email protected]> |
|
8
|
|
|
* @author Robin Appelman <[email protected]> |
|
9
|
|
|
* @author Roeland Jago Douma <[email protected]> |
|
10
|
|
|
* @author Victor Dubiniuk <[email protected]> |
|
11
|
|
|
* |
|
12
|
|
|
* @license AGPL-3.0 |
|
13
|
|
|
* |
|
14
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
15
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
16
|
|
|
* as published by the Free Software Foundation. |
|
17
|
|
|
* |
|
18
|
|
|
* This program is distributed in the hope that it will be useful, |
|
19
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
20
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
21
|
|
|
* GNU Affero General Public License for more details. |
|
22
|
|
|
* |
|
23
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
24
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
25
|
|
|
* |
|
26
|
|
|
*/ |
|
27
|
|
|
|
|
28
|
|
|
namespace OCA\Files_Trashbin\AppInfo; |
|
29
|
|
|
|
|
30
|
|
|
use OCA\DAV\Connector\Sabre\Principal; |
|
31
|
|
|
use OCA\Files_Trashbin\Capabilities; |
|
32
|
|
|
use OCA\Files_Trashbin\Expiration; |
|
33
|
|
|
use OCA\Files_Trashbin\Trash\ITrashManager; |
|
34
|
|
|
use OCA\Files_Trashbin\Trash\TrashManager; |
|
35
|
|
|
use OCP\App\IAppManager; |
|
36
|
|
|
use OCP\AppFramework\App; |
|
37
|
|
|
use OCP\AppFramework\Bootstrap\IBootContext; |
|
38
|
|
|
use OCP\AppFramework\Bootstrap\IBootstrap; |
|
39
|
|
|
use OCP\AppFramework\Bootstrap\IRegistrationContext; |
|
40
|
|
|
use OCP\ILogger; |
|
41
|
|
|
use OCP\IServerContainer; |
|
42
|
|
|
|
|
43
|
|
|
class Application extends App implements IBootstrap { |
|
44
|
|
|
public function __construct(array $urlParams = []) { |
|
45
|
|
|
parent::__construct('files_trashbin', $urlParams); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function register(IRegistrationContext $context): void { |
|
49
|
|
|
$context->registerCapability(Capabilities::class); |
|
50
|
|
|
|
|
51
|
|
|
$context->registerServiceAlias('Expiration', Expiration::class); |
|
52
|
|
|
$context->registerServiceAlias(ITrashManager::class, TrashManager::class); |
|
53
|
|
|
/** Register $principalBackend for the DAV collection */ |
|
54
|
|
|
$context->registerServiceAlias('principalBackend', Principal::class); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function boot(IBootContext $context): void { |
|
58
|
|
|
$context->injectFn([$this, 'registerTrashBackends']); |
|
59
|
|
|
|
|
60
|
|
|
// create storage wrapper on setup |
|
61
|
|
|
\OCP\Util::connectHook('OC_Filesystem', 'preSetup', 'OCA\Files_Trashbin\Storage', 'setupStorage'); |
|
62
|
|
|
//Listen to delete user signal |
|
63
|
|
|
\OCP\Util::connectHook('OC_User', 'pre_deleteUser', 'OCA\Files_Trashbin\Hooks', 'deleteUser_hook'); |
|
64
|
|
|
//Listen to post write hook |
|
65
|
|
|
\OCP\Util::connectHook('OC_Filesystem', 'post_write', 'OCA\Files_Trashbin\Hooks', 'post_write_hook'); |
|
66
|
|
|
// pre and post-rename, disable trash logic for the copy+unlink case |
|
67
|
|
|
\OCP\Util::connectHook('OC_Filesystem', 'delete', 'OCA\Files_Trashbin\Trashbin', 'ensureFileScannedHook'); |
|
68
|
|
|
|
|
69
|
|
|
\OCA\Files\App::getNavigationManager()->add(function () { |
|
70
|
|
|
$l = \OC::$server->getL10N('files_trashbin'); |
|
|
|
|
|
|
71
|
|
|
return [ |
|
72
|
|
|
'id' => 'trashbin', |
|
73
|
|
|
'appname' => 'files_trashbin', |
|
74
|
|
|
'script' => 'list.php', |
|
75
|
|
|
'order' => 50, |
|
76
|
|
|
'name' => $l->t('Deleted files'), |
|
77
|
|
|
'classes' => 'pinned', |
|
78
|
|
|
]; |
|
79
|
|
|
}); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function registerTrashBackends(IServerContainer $serverContainer, ILogger $logger, IAppManager $appManager, ITrashManager $trashManager) { |
|
83
|
|
|
foreach ($appManager->getInstalledApps() as $app) { |
|
84
|
|
|
$appInfo = $appManager->getAppInfo($app); |
|
85
|
|
|
if (isset($appInfo['trash'])) { |
|
86
|
|
|
$backends = $appInfo['trash']; |
|
87
|
|
|
foreach ($backends as $backend) { |
|
88
|
|
|
$class = $backend['@value']; |
|
89
|
|
|
$for = $backend['@attributes']['for']; |
|
90
|
|
|
|
|
91
|
|
|
try { |
|
92
|
|
|
$backendObject = $serverContainer->query($class); |
|
93
|
|
|
$trashManager->registerBackend($for, $backendObject); |
|
94
|
|
|
} catch (\Exception $e) { |
|
95
|
|
|
$logger->logException($e); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|