1
0

PersonalMount.php 2.5 KB

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