1
0

Application.php 3.6 KB

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