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.

PersonalMount.php 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * @author Morris Jobke <hey@morrisjobke.de>
  4. * @author Robin Appelman <icewind@owncloud.com>
  5. * @author Robin McCorkell <robin@mccorkell.me.uk>
  6. *
  7. * @copyright Copyright (c) 2016, ownCloud, Inc.
  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_External\Lib;
  24. use OC\Files\Mount\MountPoint;
  25. use OC\Files\Mount\MoveableMount;
  26. use OCA\Files_External\Service\UserStoragesService;
  27. /**
  28. * Person mount points can be moved by the user
  29. */
  30. class PersonalMount extends MountPoint implements MoveableMount {
  31. /** @var UserStoragesService */
  32. protected $storagesService;
  33. /** @var int */
  34. protected $numericStorageId;
  35. /**
  36. * @param UserStoragesService $storagesService
  37. * @param int $storageId
  38. * @param \OCP\Files\Storage $storage
  39. * @param string $mountpoint
  40. * @param array $arguments (optional) configuration for the storage backend
  41. * @param \OCP\Files\Storage\IStorageFactory $loader
  42. * @param array $mountOptions mount specific options
  43. */
  44. public function __construct(
  45. UserStoragesService $storagesService,
  46. $storageId,
  47. $storage,
  48. $mountpoint,
  49. $arguments = null,
  50. $loader = null,
  51. $mountOptions = null
  52. ) {
  53. parent::__construct($storage, $mountpoint, $arguments, $loader, $mountOptions);
  54. $this->storagesService = $storagesService;
  55. $this->numericStorageId = $storageId;
  56. }
  57. /**
  58. * Move the mount point to $target
  59. *
  60. * @param string $target the target mount point
  61. * @return bool
  62. */
  63. public function moveMount($target) {
  64. $storage = $this->storagesService->getStorage($this->numericStorageId);
  65. // remove "/$user/files" prefix
  66. $targetParts = explode('/', trim($target, '/'), 3);
  67. $storage->setMountPoint($targetParts[2]);
  68. $this->storagesService->updateStorage($storage);
  69. $this->setMountPoint($target);
  70. return true;
  71. }
  72. /**
  73. * Remove the mount points
  74. *
  75. * @return bool
  76. */
  77. public function removeMount() {
  78. $this->storagesService->removeStorage($this->numericStorageId);
  79. return true;
  80. }
  81. }