2014-12-03 16:14:31 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
* @author Robin Appelman <icewind@owncloud.com>
|
2015-08-12 16:22:27 +03:00
|
|
|
* @author Robin McCorkell <rmccorkell@owncloud.com>
|
2015-03-26 13:44:34 +03:00
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
2014-12-03 16:14:31 +03:00
|
|
|
*/
|
2015-02-26 13:37:37 +03:00
|
|
|
|
2014-12-03 16:14:31 +03:00
|
|
|
namespace OCA\Files_External\Config;
|
|
|
|
|
2015-08-12 16:22:27 +03:00
|
|
|
use OCP\Files\Storage;
|
2014-12-03 16:14:31 +03:00
|
|
|
use OC\Files\Mount\MountPoint;
|
|
|
|
use OCP\Files\Storage\IStorageFactory;
|
2015-08-11 20:45:07 +03:00
|
|
|
use OCA\Files_External\Lib\PersonalMount;
|
2014-12-03 16:14:31 +03:00
|
|
|
use OCP\Files\Config\IMountProvider;
|
|
|
|
use OCP\IUser;
|
2015-08-11 20:45:07 +03:00
|
|
|
use OCA\Files_external\Service\UserStoragesService;
|
2015-08-12 16:22:27 +03:00
|
|
|
use OCA\Files_External\Service\UserGlobalStoragesService;
|
|
|
|
use OCA\Files_External\Lib\StorageConfig;
|
2014-12-03 16:14:31 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Make the old files_external config work with the new public mount config api
|
|
|
|
*/
|
|
|
|
class ConfigAdapter implements IMountProvider {
|
2015-08-11 20:45:07 +03:00
|
|
|
|
2015-08-12 16:22:27 +03:00
|
|
|
/** @var UserStoragesService */
|
|
|
|
private $userStoragesService;
|
|
|
|
|
|
|
|
/** @var UserGlobalStoragesService */
|
|
|
|
private $userGlobalStoragesService;
|
|
|
|
|
2015-08-11 20:45:07 +03:00
|
|
|
/**
|
|
|
|
* @param UserStoragesService $userStoragesService
|
2015-08-12 16:22:27 +03:00
|
|
|
* @param UserGlobalStoragesService $userGlobalStoragesService
|
2015-08-11 20:45:07 +03:00
|
|
|
*/
|
2015-08-12 16:22:27 +03:00
|
|
|
public function __construct(
|
|
|
|
UserStoragesService $userStoragesService,
|
|
|
|
UserGlobalStoragesService $userGlobalStoragesService
|
|
|
|
) {
|
2015-08-11 20:45:07 +03:00
|
|
|
$this->userStoragesService = $userStoragesService;
|
2015-08-12 16:22:27 +03:00
|
|
|
$this->userGlobalStoragesService = $userGlobalStoragesService;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process storage ready for mounting
|
|
|
|
*
|
|
|
|
* @param StorageConfig $storage
|
|
|
|
*/
|
|
|
|
private function prepareStorageConfig(StorageConfig &$storage) {
|
|
|
|
$objectStore = $storage->getBackendOption('objectstore');
|
|
|
|
if ($objectStore) {
|
|
|
|
$objectClass = $objectStore['class'];
|
|
|
|
$storage->setBackendOption('objectstore', new $objectClass($objectStore));
|
|
|
|
}
|
|
|
|
|
|
|
|
$storage->getBackend()->manipulateStorageConfig($storage);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct the storage implementation
|
|
|
|
*
|
|
|
|
* @param StorageConfig $storageConfig
|
|
|
|
* @return Storage
|
|
|
|
*/
|
|
|
|
private function constructStorage(StorageConfig $storageConfig) {
|
|
|
|
$class = $storageConfig->getBackend()->getStorageClass();
|
|
|
|
$storage = new $class($storageConfig->getBackendOptions());
|
|
|
|
|
|
|
|
$storage = $storageConfig->getBackend()->wrapStorage($storage);
|
|
|
|
|
|
|
|
return $storage;
|
2015-08-11 20:45:07 +03:00
|
|
|
}
|
|
|
|
|
2014-12-03 16:14:31 +03:00
|
|
|
/**
|
|
|
|
* Get all mountpoints applicable for the user
|
|
|
|
*
|
|
|
|
* @param \OCP\IUser $user
|
|
|
|
* @param \OCP\Files\Storage\IStorageFactory $loader
|
|
|
|
* @return \OCP\Files\Mount\IMountPoint[]
|
|
|
|
*/
|
|
|
|
public function getMountsForUser(IUser $user, IStorageFactory $loader) {
|
2015-08-12 16:22:27 +03:00
|
|
|
$mounts = [];
|
|
|
|
|
|
|
|
$this->userStoragesService->setUser($user);
|
|
|
|
$this->userGlobalStoragesService->setUser($user);
|
|
|
|
|
|
|
|
foreach ($this->userGlobalStoragesService->getAllStorages() as $storage) {
|
|
|
|
$this->prepareStorageConfig($storage);
|
|
|
|
$impl = $this->constructStorage($storage);
|
|
|
|
|
|
|
|
$mount = new MountPoint(
|
|
|
|
$impl,
|
|
|
|
'/'.$user->getUID().'/files' . $storage->getMountPoint(),
|
|
|
|
null,
|
|
|
|
$loader,
|
|
|
|
$storage->getMountOptions()
|
|
|
|
);
|
|
|
|
$mounts[$storage->getMountPoint()] = $mount;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($this->userStoragesService->getAllStorages() as $storage) {
|
|
|
|
$this->prepareStorageConfig($storage);
|
|
|
|
$impl = $this->constructStorage($storage);
|
|
|
|
|
|
|
|
$mount = new PersonalMount(
|
|
|
|
$this->userStoragesService,
|
|
|
|
$storage->getId(),
|
|
|
|
$impl,
|
|
|
|
'/'.$user->getUID().'/files' . $storage->getMountPoint(),
|
|
|
|
null,
|
|
|
|
$loader,
|
|
|
|
$storage->getMountOptions()
|
|
|
|
);
|
|
|
|
$mounts[$storage->getMountPoint()] = $mount;
|
2014-12-03 16:14:31 +03:00
|
|
|
}
|
2015-08-12 16:22:27 +03:00
|
|
|
|
|
|
|
$this->userStoragesService->resetUser();
|
|
|
|
$this->userGlobalStoragesService->resetUser();
|
|
|
|
|
2014-12-03 16:14:31 +03:00
|
|
|
return $mounts;
|
|
|
|
}
|
|
|
|
}
|