PersonalMount.php 2.7 KB

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