Application.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Roeland Jago Douma <roeland@famdouma.nl>
  6. * @author Victor Dubiniuk <dubiniuk@owncloud.com>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OCA\Files_Trashbin\AppInfo;
  24. use OCA\DAV\CalDAV\Proxy\ProxyMapper;
  25. use OCA\DAV\Connector\Sabre\Principal;
  26. use OCA\Files_Trashbin\Trash\ITrashManager;
  27. use OCA\Files_Trashbin\Trash\TrashManager;
  28. use OCP\AppFramework\App;
  29. use OCA\Files_Trashbin\Expiration;
  30. use OCP\AppFramework\IAppContainer;
  31. use OCP\AppFramework\Utility\ITimeFactory;
  32. use OCA\Files_Trashbin\Capabilities;
  33. class Application extends App {
  34. public function __construct (array $urlParams = []) {
  35. parent::__construct('files_trashbin', $urlParams);
  36. $container = $this->getContainer();
  37. /*
  38. * Register capabilities
  39. */
  40. $container->registerCapability(Capabilities::class);
  41. /*
  42. * Register expiration
  43. */
  44. $container->registerService('Expiration', function($c) {
  45. return new Expiration(
  46. $c->query('ServerContainer')->getConfig(),
  47. $c->query(ITimeFactory::class)
  48. );
  49. });
  50. /*
  51. * Register $principalBackend for the DAV collection
  52. */
  53. $container->registerService('principalBackend', function () {
  54. return new Principal(
  55. \OC::$server->getUserManager(),
  56. \OC::$server->getGroupManager(),
  57. \OC::$server->getShareManager(),
  58. \OC::$server->getUserSession(),
  59. \OC::$server->getAppManager(),
  60. \OC::$server->query(ProxyMapper::class)
  61. );
  62. });
  63. $container->registerService(ITrashManager::class, function(IAppContainer $c) {
  64. return new TrashManager();
  65. });
  66. $this->registerTrashBackends();
  67. }
  68. public function registerTrashBackends() {
  69. $server = $this->getContainer()->getServer();
  70. $logger = $server->getLogger();
  71. $appManager = $server->getAppManager();
  72. /** @var ITrashManager $trashManager */
  73. $trashManager = $this->getContainer()->getServer()->query(ITrashManager::class);
  74. foreach($appManager->getInstalledApps() as $app) {
  75. $appInfo = $appManager->getAppInfo($app);
  76. if (isset($appInfo['trash'])) {
  77. $backends = $appInfo['trash'];
  78. foreach($backends as $backend) {
  79. $class = $backend['@value'];
  80. $for = $backend['@attributes']['for'];
  81. try {
  82. $backendObject = $server->query($class);
  83. $trashManager->registerBackend($for, $backendObject);
  84. } catch (\Exception $e) {
  85. $logger->logException($e);
  86. }
  87. }
  88. }
  89. }
  90. }
  91. }