1
0

PersonalMount.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\Files_External\Lib;
  8. use OC\Files\Mount\MoveableMount;
  9. use OCA\Files_External\Config\ExternalMountPoint;
  10. use OCA\Files_External\Service\UserStoragesService;
  11. use OCP\Files\Storage\IStorage;
  12. use OCP\Files\Storage\IStorageFactory;
  13. /**
  14. * Person mount points can be moved by the user
  15. */
  16. class PersonalMount extends ExternalMountPoint implements MoveableMount {
  17. /**
  18. * @param UserStoragesService $storagesService
  19. * @param int $storageId
  20. * @param IStorage $storage
  21. * @param string $mountpoint
  22. * @param array $arguments (optional) configuration for the storage backend
  23. * @param IStorageFactory $loader
  24. * @param array $mountOptions mount specific options
  25. * @param int $externalStorageId
  26. */
  27. public function __construct(
  28. protected UserStoragesService $storagesService,
  29. StorageConfig $storageConfig,
  30. /** @var int id of the external storage (mount) (not the numeric id of the resulting storage!) */
  31. protected $numericExternalStorageId,
  32. $storage,
  33. $mountpoint,
  34. $arguments = null,
  35. $loader = null,
  36. $mountOptions = null,
  37. $mountId = null,
  38. ) {
  39. parent::__construct($storageConfig, $storage, $mountpoint, $arguments, $loader, $mountOptions, $mountId);
  40. }
  41. /**
  42. * Move the mount point to $target
  43. *
  44. * @param string $target the target mount point
  45. * @return bool
  46. */
  47. public function moveMount($target) {
  48. $storage = $this->storagesService->getStorage($this->numericExternalStorageId);
  49. // remove "/$user/files" prefix
  50. $targetParts = explode('/', trim($target, '/'), 3);
  51. $storage->setMountPoint($targetParts[2]);
  52. $this->storagesService->updateStorage($storage);
  53. $this->setMountPoint($target);
  54. return true;
  55. }
  56. /**
  57. * Remove the mount points
  58. *
  59. * @return bool
  60. */
  61. public function removeMount() {
  62. $this->storagesService->removeStorage($this->numericExternalStorageId);
  63. return true;
  64. }
  65. }