You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Application.php 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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\Event\LoadAdditionalScriptsEvent;
  29. use OCA\Files_Trashbin\Capabilities;
  30. use OCA\Files_Trashbin\Expiration;
  31. use OCA\Files_Trashbin\Listeners\LoadAdditionalScripts;
  32. use OCA\Files_Trashbin\Trash\ITrashManager;
  33. use OCA\Files_Trashbin\Trash\TrashManager;
  34. use OCA\Files_Trashbin\UserMigration\TrashbinMigrator;
  35. use OCP\AppFramework\App;
  36. use OCP\AppFramework\Bootstrap\IBootContext;
  37. use OCP\AppFramework\Bootstrap\IBootstrap;
  38. use OCP\AppFramework\Bootstrap\IRegistrationContext;
  39. use OCP\App\IAppManager;
  40. use OCP\ILogger;
  41. use OCP\IServerContainer;
  42. class Application extends App implements IBootstrap {
  43. public const APP_ID = 'files_trashbin';
  44. public function __construct(array $urlParams = []) {
  45. parent::__construct(self::APP_ID, $urlParams);
  46. }
  47. public function register(IRegistrationContext $context): void {
  48. $context->registerCapability(Capabilities::class);
  49. $context->registerServiceAlias('Expiration', Expiration::class);
  50. $context->registerServiceAlias(ITrashManager::class, TrashManager::class);
  51. /** Register $principalBackend for the DAV collection */
  52. $context->registerServiceAlias('principalBackend', Principal::class);
  53. $context->registerUserMigrator(TrashbinMigrator::class);
  54. $context->registerEventListener(
  55. LoadAdditionalScriptsEvent::class,
  56. LoadAdditionalScripts::class
  57. );
  58. }
  59. public function boot(IBootContext $context): void {
  60. $context->injectFn([$this, 'registerTrashBackends']);
  61. // create storage wrapper on setup
  62. \OCP\Util::connectHook('OC_Filesystem', 'preSetup', 'OCA\Files_Trashbin\Storage', 'setupStorage');
  63. //Listen to delete user signal
  64. \OCP\Util::connectHook('OC_User', 'pre_deleteUser', 'OCA\Files_Trashbin\Hooks', 'deleteUser_hook');
  65. //Listen to post write hook
  66. \OCP\Util::connectHook('OC_Filesystem', 'post_write', 'OCA\Files_Trashbin\Hooks', 'post_write_hook');
  67. // pre and post-rename, disable trash logic for the copy+unlink case
  68. \OCP\Util::connectHook('OC_Filesystem', 'delete', 'OCA\Files_Trashbin\Trashbin', 'ensureFileScannedHook');
  69. }
  70. public function registerTrashBackends(IServerContainer $serverContainer, ILogger $logger, IAppManager $appManager, ITrashManager $trashManager) {
  71. foreach ($appManager->getInstalledApps() as $app) {
  72. $appInfo = $appManager->getAppInfo($app);
  73. if (isset($appInfo['trash'])) {
  74. $backends = $appInfo['trash'];
  75. foreach ($backends as $backend) {
  76. $class = $backend['@value'];
  77. $for = $backend['@attributes']['for'];
  78. try {
  79. $backendObject = $serverContainer->query($class);
  80. $trashManager->registerBackend($for, $backendObject);
  81. } catch (\Exception $e) {
  82. $logger->logException($e);
  83. }
  84. }
  85. }
  86. }
  87. }
  88. }