2015-03-21 22:12:55 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2020-04-29 12:57:22 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Georg Ehrke <oc.list@georgehrke.com>
|
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2015-07-30 22:31:18 +03:00
|
|
|
* @author Victor Dubiniuk <dubiniuk@owncloud.com>
|
2015-03-21 22:12:55 +03:00
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2015-03-21 22:12:55 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Files_Trashbin\AppInfo;
|
|
|
|
|
2018-04-16 15:14:31 +03:00
|
|
|
use OCA\DAV\Connector\Sabre\Principal;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCA\Files_Trashbin\Capabilities;
|
|
|
|
use OCA\Files_Trashbin\Expiration;
|
2018-09-10 15:40:35 +03:00
|
|
|
use OCA\Files_Trashbin\Trash\ITrashManager;
|
|
|
|
use OCA\Files_Trashbin\Trash\TrashManager;
|
2020-07-22 23:11:01 +03:00
|
|
|
use OCP\App\IAppManager;
|
2015-03-21 22:12:55 +03:00
|
|
|
use OCP\AppFramework\App;
|
2020-07-22 23:11:01 +03:00
|
|
|
use OCP\AppFramework\Bootstrap\IBootContext;
|
|
|
|
use OCP\AppFramework\Bootstrap\IBootstrap;
|
|
|
|
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
|
|
|
use OCP\ILogger;
|
|
|
|
use OCP\IServerContainer;
|
2015-03-21 22:12:55 +03:00
|
|
|
|
2020-07-22 23:11:01 +03:00
|
|
|
class Application extends App implements IBootstrap {
|
2020-04-09 14:53:40 +03:00
|
|
|
public function __construct(array $urlParams = []) {
|
2015-03-21 22:12:55 +03:00
|
|
|
parent::__construct('files_trashbin', $urlParams);
|
2020-07-22 23:11:01 +03:00
|
|
|
}
|
2015-03-21 22:12:55 +03:00
|
|
|
|
2020-07-22 23:11:01 +03:00
|
|
|
public function register(IRegistrationContext $context): void {
|
|
|
|
$context->registerCapability(Capabilities::class);
|
2015-07-30 22:31:18 +03:00
|
|
|
|
2020-07-22 23:11:01 +03:00
|
|
|
$context->registerServiceAlias('Expiration', Expiration::class);
|
|
|
|
$context->registerServiceAlias(ITrashManager::class, TrashManager::class);
|
|
|
|
/** Register $principalBackend for the DAV collection */
|
|
|
|
$context->registerServiceAlias('principalBackend', Principal::class);
|
|
|
|
}
|
2018-04-16 15:14:31 +03:00
|
|
|
|
2020-07-22 23:11:01 +03:00
|
|
|
public function boot(IBootContext $context): void {
|
|
|
|
$context->injectFn([$this, 'registerTrashBackends']);
|
2018-09-10 15:40:35 +03:00
|
|
|
|
2020-07-22 23:11:01 +03:00
|
|
|
// create storage wrapper on setup
|
|
|
|
\OCP\Util::connectHook('OC_Filesystem', 'preSetup', 'OCA\Files_Trashbin\Storage', 'setupStorage');
|
|
|
|
//Listen to delete user signal
|
|
|
|
\OCP\Util::connectHook('OC_User', 'pre_deleteUser', 'OCA\Files_Trashbin\Hooks', 'deleteUser_hook');
|
|
|
|
//Listen to post write hook
|
|
|
|
\OCP\Util::connectHook('OC_Filesystem', 'post_write', 'OCA\Files_Trashbin\Hooks', 'post_write_hook');
|
|
|
|
// pre and post-rename, disable trash logic for the copy+unlink case
|
|
|
|
\OCP\Util::connectHook('OC_Filesystem', 'delete', 'OCA\Files_Trashbin\Trashbin', 'ensureFileScannedHook');
|
2018-09-10 15:40:35 +03:00
|
|
|
|
2020-07-22 23:11:01 +03:00
|
|
|
\OCA\Files\App::getNavigationManager()->add(function () {
|
|
|
|
$l = \OC::$server->getL10N('files_trashbin');
|
|
|
|
return [
|
|
|
|
'id' => 'trashbin',
|
|
|
|
'appname' => 'files_trashbin',
|
|
|
|
'script' => 'list.php',
|
|
|
|
'order' => 50,
|
|
|
|
'name' => $l->t('Deleted files'),
|
|
|
|
'classes' => 'pinned',
|
|
|
|
];
|
|
|
|
});
|
2018-09-10 15:40:35 +03:00
|
|
|
}
|
|
|
|
|
2020-07-22 23:11:01 +03:00
|
|
|
public function registerTrashBackends(IServerContainer $serverContainer, ILogger $logger, IAppManager $appManager, ITrashManager $trashManager) {
|
2020-04-10 15:19:56 +03:00
|
|
|
foreach ($appManager->getInstalledApps() as $app) {
|
2018-09-10 15:40:35 +03:00
|
|
|
$appInfo = $appManager->getAppInfo($app);
|
|
|
|
if (isset($appInfo['trash'])) {
|
|
|
|
$backends = $appInfo['trash'];
|
2020-04-10 15:19:56 +03:00
|
|
|
foreach ($backends as $backend) {
|
2018-09-10 15:40:35 +03:00
|
|
|
$class = $backend['@value'];
|
|
|
|
$for = $backend['@attributes']['for'];
|
|
|
|
|
|
|
|
try {
|
2020-07-22 23:11:01 +03:00
|
|
|
$backendObject = $serverContainer->query($class);
|
2018-09-10 15:40:35 +03:00
|
|
|
$trashManager->registerBackend($for, $backendObject);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
$logger->logException($e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-03-21 22:12:55 +03:00
|
|
|
}
|
|
|
|
}
|