personalmount.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * @author Morris Jobke <hey@morrisjobke.de>
  4. * @author Robin Appelman <icewind@owncloud.com>
  5. *
  6. * @copyright Copyright (c) 2015, ownCloud, Inc.
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OCA\Files_External\Lib;
  23. use OC\Files\Mount\MountPoint;
  24. use OC\Files\Mount\MoveableMount;
  25. use OCA\Files_External\Service\UserStoragesService;
  26. /**
  27. * Person mount points can be moved by the user
  28. */
  29. class PersonalMount extends MountPoint implements MoveableMount {
  30. /** @var UserStoragesService */
  31. protected $storagesService;
  32. /** @var int */
  33. protected $storageId;
  34. /**
  35. * @param UserStoragesService $storagesService
  36. * @param int $storageId
  37. * @param string|\OC\Files\Storage\Storage $storage
  38. * @param string $mountpoint
  39. * @param array $arguments (optional) configuration for the storage backend
  40. * @param \OCP\Files\Storage\IStorageFactory $loader
  41. * @param array $mountOptions mount specific options
  42. */
  43. public function __construct(
  44. UserStoragesService $storagesService,
  45. $storageId,
  46. $storage,
  47. $mountpoint,
  48. $arguments = null,
  49. $loader = null,
  50. $mountOptions = null
  51. ) {
  52. parent::__construct($storage, $mountpoint, $arguments, $loader, $mountOptions);
  53. $this->storagesService = $storagesService;
  54. $this->storageId = $storageId;
  55. }
  56. /**
  57. * Move the mount point to $target
  58. *
  59. * @param string $target the target mount point
  60. * @return bool
  61. */
  62. public function moveMount($target) {
  63. $storage = $this->storagesService->getStorage($this->storageId);
  64. // remove "/$user/files" prefix
  65. $targetParts = explode('/', trim($target, '/'), 3);
  66. $storage->setMountPoint($targetParts[2]);
  67. $this->storagesService->updateStorage($storage);
  68. $this->setMountPoint($target);
  69. return true;
  70. }
  71. /**
  72. * Remove the mount points
  73. *
  74. * @return bool
  75. */
  76. public function removeMount() {
  77. $this->storagesService->removeStorage($this->storageId);
  78. return true;
  79. }
  80. }