Application.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Georg Ehrke <oc.list@georgehrke.com>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Robin Appelman <robin@icewind.nl>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. * @author Victor Dubiniuk <dubiniuk@owncloud.com>
  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. namespace OCA\Files_Trashbin\AppInfo;
  28. use OCA\DAV\CalDAV\Proxy\ProxyMapper;
  29. use OCA\DAV\Connector\Sabre\Principal;
  30. use OCA\Files_Trashbin\Capabilities;
  31. use OCA\Files_Trashbin\Expiration;
  32. use OCA\Files_Trashbin\Trash\ITrashManager;
  33. use OCA\Files_Trashbin\Trash\TrashManager;
  34. use OCP\AppFramework\App;
  35. use OCP\AppFramework\IAppContainer;
  36. class Application extends App {
  37. public function __construct(array $urlParams = []) {
  38. parent::__construct('files_trashbin', $urlParams);
  39. $container = $this->getContainer();
  40. /*
  41. * Register capabilities
  42. */
  43. $container->registerCapability(Capabilities::class);
  44. /*
  45. * Register expiration
  46. */
  47. $container->registerAlias('Expiration', Expiration::class);
  48. /*
  49. * Register $principalBackend for the DAV collection
  50. */
  51. $container->registerService('principalBackend', function () {
  52. return new Principal(
  53. \OC::$server->getUserManager(),
  54. \OC::$server->getGroupManager(),
  55. \OC::$server->getShareManager(),
  56. \OC::$server->getUserSession(),
  57. \OC::$server->getAppManager(),
  58. \OC::$server->query(ProxyMapper::class),
  59. \OC::$server->getConfig()
  60. );
  61. });
  62. $container->registerService(ITrashManager::class, function (IAppContainer $c) {
  63. return new TrashManager();
  64. });
  65. $this->registerTrashBackends();
  66. }
  67. public function registerTrashBackends() {
  68. $server = $this->getContainer()->getServer();
  69. $logger = $server->getLogger();
  70. $appManager = $server->getAppManager();
  71. /** @var ITrashManager $trashManager */
  72. $trashManager = $this->getContainer()->getServer()->query(ITrashManager::class);
  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 = $server->query($class);
  82. $trashManager->registerBackend($for, $backendObject);
  83. } catch (\Exception $e) {
  84. $logger->logException($e);
  85. }
  86. }
  87. }
  88. }
  89. }
  90. }