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.

MountProvider.php 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Lukas Reschke <lukas@statuscode.ch>
  7. * @author Robin Appelman <robin@icewind.nl>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OCA\Files_Sharing\External;
  25. use OCP\Federation\ICloudIdManager;
  26. use OCP\Files\Config\IMountProvider;
  27. use OCP\Files\Storage\IStorageFactory;
  28. use OCP\IDBConnection;
  29. use OCP\IUser;
  30. class MountProvider implements IMountProvider {
  31. public const STORAGE = '\OCA\Files_Sharing\External\Storage';
  32. /**
  33. * @var \OCP\IDBConnection
  34. */
  35. private $connection;
  36. /**
  37. * @var callable
  38. */
  39. private $managerProvider;
  40. /**
  41. * @var ICloudIdManager
  42. */
  43. private $cloudIdManager;
  44. /**
  45. * @param \OCP\IDBConnection $connection
  46. * @param callable $managerProvider due to setup order we need a callable that return the manager instead of the manager itself
  47. * @param ICloudIdManager $cloudIdManager
  48. */
  49. public function __construct(IDBConnection $connection, callable $managerProvider, ICloudIdManager $cloudIdManager) {
  50. $this->connection = $connection;
  51. $this->managerProvider = $managerProvider;
  52. $this->cloudIdManager = $cloudIdManager;
  53. }
  54. public function getMount(IUser $user, $data, IStorageFactory $storageFactory) {
  55. $managerProvider = $this->managerProvider;
  56. $manager = $managerProvider();
  57. $data['manager'] = $manager;
  58. $mountPoint = '/' . $user->getUID() . '/files/' . ltrim($data['mountpoint'], '/');
  59. $data['mountpoint'] = $mountPoint;
  60. $data['cloudId'] = $this->cloudIdManager->getCloudId($data['owner'], $data['remote']);
  61. $data['certificateManager'] = \OC::$server->getCertificateManager($user->getUID());
  62. $data['HttpClientService'] = \OC::$server->getHTTPClientService();
  63. return new Mount(self::STORAGE, $mountPoint, $data, $manager, $storageFactory);
  64. }
  65. public function getMountsForUser(IUser $user, IStorageFactory $loader) {
  66. $query = $this->connection->prepare('
  67. SELECT `remote`, `share_token`, `password`, `mountpoint`, `owner`
  68. FROM `*PREFIX*share_external`
  69. WHERE `user` = ? AND `accepted` = ?
  70. ');
  71. $query->execute([$user->getUID(), 1]);
  72. $mounts = [];
  73. while ($row = $query->fetch()) {
  74. $row['manager'] = $this;
  75. $row['token'] = $row['share_token'];
  76. $mounts[] = $this->getMount($user, $row, $loader);
  77. }
  78. return $mounts;
  79. }
  80. }