1
0

MountProvider.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Lukas Reschke <lukas@statuscode.ch>
  6. * @author Robin Appelman <robin@icewind.nl>
  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_Sharing\External;
  24. use OCP\Federation\ICloudIdManager;
  25. use OCP\Files\Config\IMountProvider;
  26. use OCP\Files\Storage\IStorageFactory;
  27. use OCP\IDBConnection;
  28. use OCP\IUser;
  29. class MountProvider implements IMountProvider {
  30. const STORAGE = '\OCA\Files_Sharing\External\Storage';
  31. /**
  32. * @var \OCP\IDBConnection
  33. */
  34. private $connection;
  35. /**
  36. * @var callable
  37. */
  38. private $managerProvider;
  39. /**
  40. * @var ICloudIdManager
  41. */
  42. private $cloudIdManager;
  43. /**
  44. * @param \OCP\IDBConnection $connection
  45. * @param callable $managerProvider due to setup order we need a callable that return the manager instead of the manager itself
  46. * @param ICloudIdManager $cloudIdManager
  47. */
  48. public function __construct(IDBConnection $connection, callable $managerProvider, ICloudIdManager $cloudIdManager) {
  49. $this->connection = $connection;
  50. $this->managerProvider = $managerProvider;
  51. $this->cloudIdManager = $cloudIdManager;
  52. }
  53. public function getMount(IUser $user, $data, IStorageFactory $storageFactory) {
  54. $managerProvider = $this->managerProvider;
  55. $manager = $managerProvider();
  56. $data['manager'] = $manager;
  57. $mountPoint = '/' . $user->getUID() . '/files/' . ltrim($data['mountpoint'], '/');
  58. $data['mountpoint'] = $mountPoint;
  59. $data['cloudId'] = $this->cloudIdManager->getCloudId($data['owner'], $data['remote']);
  60. $data['certificateManager'] = \OC::$server->getCertificateManager($user->getUID());
  61. $data['HttpClientService'] = \OC::$server->getHTTPClientService();
  62. return new Mount(self::STORAGE, $mountPoint, $data, $manager, $storageFactory);
  63. }
  64. public function getMountsForUser(IUser $user, IStorageFactory $loader) {
  65. $query = $this->connection->prepare('
  66. SELECT `remote`, `share_token`, `password`, `mountpoint`, `owner`
  67. FROM `*PREFIX*share_external`
  68. WHERE `user` = ? AND `accepted` = ?
  69. ');
  70. $query->execute([$user->getUID(), 1]);
  71. $mounts = [];
  72. while ($row = $query->fetch()) {
  73. $row['manager'] = $this;
  74. $row['token'] = $row['share_token'];
  75. $mounts[] = $this->getMount($user, $row, $loader);
  76. }
  77. return $mounts;
  78. }
  79. }