1
0

PersonalMount.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. /**
  13. * Person mount points can be moved by the user
  14. */
  15. class PersonalMount extends ExternalMountPoint implements MoveableMount {
  16. /** @var UserStoragesService */
  17. protected $storagesService;
  18. /** @var int id of the external storage (mount) (not the numeric id of the resulting storage!) */
  19. protected $numericExternalStorageId;
  20. /**
  21. * @param UserStoragesService $storagesService
  22. * @param int $storageId
  23. * @param IStorage $storage
  24. * @param string $mountpoint
  25. * @param array $arguments (optional) configuration for the storage backend
  26. * @param \OCP\Files\Storage\IStorageFactory $loader
  27. * @param array $mountOptions mount specific options
  28. */
  29. public function __construct(
  30. UserStoragesService $storagesService,
  31. StorageConfig $storageConfig,
  32. $externalStorageId,
  33. $storage,
  34. $mountpoint,
  35. $arguments = null,
  36. $loader = null,
  37. $mountOptions = null,
  38. $mountId = null
  39. ) {
  40. parent::__construct($storageConfig, $storage, $mountpoint, $arguments, $loader, $mountOptions, $mountId);
  41. $this->storagesService = $storagesService;
  42. $this->numericExternalStorageId = $externalStorageId;
  43. }
  44. /**
  45. * Move the mount point to $target
  46. *
  47. * @param string $target the target mount point
  48. * @return bool
  49. */
  50. public function moveMount($target) {
  51. $storage = $this->storagesService->getStorage($this->numericExternalStorageId);
  52. // remove "/$user/files" prefix
  53. $targetParts = explode('/', trim($target, '/'), 3);
  54. $storage->setMountPoint($targetParts[2]);
  55. $this->storagesService->updateStorage($storage);
  56. $this->setMountPoint($target);
  57. return true;
  58. }
  59. /**
  60. * Remove the mount points
  61. *
  62. * @return bool
  63. */
  64. public function removeMount() {
  65. $this->storagesService->removeStorage($this->numericExternalStorageId);
  66. return true;
  67. }
  68. }