2014-05-21 23:40:42 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2024-06-06 07:55:47 +00:00
|
|
|
* SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2014-05-21 23:40:42 +00:00
|
|
|
*/
|
2015-08-11 17:45:07 +00:00
|
|
|
namespace OCA\Files_External\Lib;
|
2014-05-21 23:40:42 +00:00
|
|
|
|
|
|
|
use OC\Files\Mount\MoveableMount;
|
2018-02-20 14:51:12 +00:00
|
|
|
use OCA\Files_External\Config\ExternalMountPoint;
|
2015-08-11 17:45:07 +00:00
|
|
|
use OCA\Files_External\Service\UserStoragesService;
|
2020-10-07 13:31:03 +00:00
|
|
|
use OCP\Files\Storage\IStorage;
|
2024-10-18 10:04:22 +00:00
|
|
|
use OCP\Files\Storage\IStorageFactory;
|
2014-05-21 23:40:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Person mount points can be moved by the user
|
|
|
|
*/
|
2018-02-20 14:51:12 +00:00
|
|
|
class PersonalMount extends ExternalMountPoint implements MoveableMount {
|
2015-08-11 17:45:07 +00:00
|
|
|
/**
|
|
|
|
* @param UserStoragesService $storagesService
|
|
|
|
* @param int $storageId
|
2020-10-07 13:31:03 +00:00
|
|
|
* @param IStorage $storage
|
2015-08-11 17:45:07 +00:00
|
|
|
* @param string $mountpoint
|
|
|
|
* @param array $arguments (optional) configuration for the storage backend
|
2024-10-18 10:04:22 +00:00
|
|
|
* @param IStorageFactory $loader
|
2015-08-11 17:45:07 +00:00
|
|
|
* @param array $mountOptions mount specific options
|
2024-10-18 10:04:22 +00:00
|
|
|
* @param int $externalStorageId
|
2015-08-11 17:45:07 +00:00
|
|
|
*/
|
|
|
|
public function __construct(
|
2024-10-18 10:04:22 +00:00
|
|
|
protected UserStoragesService $storagesService,
|
2020-10-07 13:31:03 +00:00
|
|
|
StorageConfig $storageConfig,
|
2024-10-18 10:04:22 +00:00
|
|
|
/** @var int id of the external storage (mount) (not the numeric id of the resulting storage!) */
|
|
|
|
protected $numericExternalStorageId,
|
2015-08-11 17:45:07 +00:00
|
|
|
$storage,
|
|
|
|
$mountpoint,
|
|
|
|
$arguments = null,
|
|
|
|
$loader = null,
|
2020-12-02 13:25:48 +00:00
|
|
|
$mountOptions = null,
|
|
|
|
$mountId = null,
|
2015-08-11 17:45:07 +00:00
|
|
|
) {
|
2020-10-07 13:31:03 +00:00
|
|
|
parent::__construct($storageConfig, $storage, $mountpoint, $arguments, $loader, $mountOptions, $mountId);
|
2015-08-11 17:45:07 +00:00
|
|
|
}
|
|
|
|
|
2014-05-21 23:40:42 +00:00
|
|
|
/**
|
|
|
|
* Move the mount point to $target
|
|
|
|
*
|
|
|
|
* @param string $target the target mount point
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function moveMount($target) {
|
2023-05-07 02:47:44 +00:00
|
|
|
$storage = $this->storagesService->getStorage($this->numericExternalStorageId);
|
2015-08-11 17:45:07 +00:00
|
|
|
// remove "/$user/files" prefix
|
|
|
|
$targetParts = explode('/', trim($target, '/'), 3);
|
|
|
|
$storage->setMountPoint($targetParts[2]);
|
|
|
|
$this->storagesService->updateStorage($storage);
|
2014-05-21 23:40:42 +00:00
|
|
|
$this->setMountPoint($target);
|
2015-08-11 17:45:07 +00:00
|
|
|
return true;
|
2014-05-21 23:40:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the mount points
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function removeMount() {
|
2023-05-07 02:47:44 +00:00
|
|
|
$this->storagesService->removeStorage($this->numericExternalStorageId);
|
2015-08-11 17:45:07 +00:00
|
|
|
return true;
|
2014-05-21 23:40:42 +00:00
|
|
|
}
|
|
|
|
}
|