2014-10-31 13:41:07 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
|
|
|
* @author Juan Pablo Villafáñez <jvillafanez@solidgear.es>
|
2016-07-21 19:13:36 +03:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2016-01-12 17:02:16 +03:00
|
|
|
* @author Robin McCorkell <robin@mccorkell.me.uk>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
2014-10-31 13:41:07 +03:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* @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,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2014-10-31 13:41:07 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Files_External\Controller;
|
|
|
|
|
|
|
|
|
2016-05-13 12:56:47 +03:00
|
|
|
use OCA\Files_External\NotFoundException;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCA\Files_External\Service\GlobalStoragesService;
|
|
|
|
use OCP\AppFramework\Http;
|
|
|
|
use OCP\AppFramework\Http\DataResponse;
|
|
|
|
use OCP\IL10N;
|
|
|
|
use OCP\ILogger;
|
|
|
|
use OCP\IRequest;
|
2014-10-31 13:41:07 +03:00
|
|
|
|
2015-03-17 13:42:52 +03:00
|
|
|
/**
|
|
|
|
* Global storages controller
|
|
|
|
*/
|
2014-10-31 13:41:07 +03:00
|
|
|
class GlobalStoragesController extends StoragesController {
|
|
|
|
/**
|
2015-03-16 14:18:01 +03:00
|
|
|
* Creates a new global storages controller.
|
|
|
|
*
|
|
|
|
* @param string $AppName application name
|
|
|
|
* @param IRequest $request request object
|
|
|
|
* @param IL10N $l10n l10n service
|
|
|
|
* @param GlobalStoragesService $globalStoragesService storage service
|
2016-01-28 15:07:19 +03:00
|
|
|
* @param ILogger $logger
|
2014-10-31 13:41:07 +03:00
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
$AppName,
|
|
|
|
IRequest $request,
|
2015-03-16 14:18:01 +03:00
|
|
|
IL10N $l10n,
|
2016-01-28 15:07:19 +03:00
|
|
|
GlobalStoragesService $globalStoragesService,
|
|
|
|
ILogger $logger
|
2015-03-17 13:42:52 +03:00
|
|
|
) {
|
2014-10-31 13:41:07 +03:00
|
|
|
parent::__construct(
|
|
|
|
$AppName,
|
|
|
|
$request,
|
|
|
|
$l10n,
|
2016-01-28 15:07:19 +03:00
|
|
|
$globalStoragesService,
|
|
|
|
$logger
|
2014-10-31 13:41:07 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an external storage entry.
|
|
|
|
*
|
|
|
|
* @param string $mountPoint storage mount point
|
2015-08-12 22:03:11 +03:00
|
|
|
* @param string $backend backend identifier
|
|
|
|
* @param string $authMechanism authentication mechanism identifier
|
2014-10-31 13:41:07 +03:00
|
|
|
* @param array $backendOptions backend-specific options
|
2015-03-13 14:49:11 +03:00
|
|
|
* @param array $mountOptions mount-specific options
|
2014-10-31 13:41:07 +03:00
|
|
|
* @param array $applicableUsers users for which to mount the storage
|
|
|
|
* @param array $applicableGroups groups for which to mount the storage
|
|
|
|
* @param int $priority priority
|
|
|
|
*
|
|
|
|
* @return DataResponse
|
|
|
|
*/
|
|
|
|
public function create(
|
|
|
|
$mountPoint,
|
2015-08-12 22:03:11 +03:00
|
|
|
$backend,
|
|
|
|
$authMechanism,
|
2014-10-31 13:41:07 +03:00
|
|
|
$backendOptions,
|
2015-03-13 14:49:11 +03:00
|
|
|
$mountOptions,
|
2014-10-31 13:41:07 +03:00
|
|
|
$applicableUsers,
|
|
|
|
$applicableGroups,
|
|
|
|
$priority
|
|
|
|
) {
|
2015-08-11 20:45:07 +03:00
|
|
|
$newStorage = $this->createStorage(
|
|
|
|
$mountPoint,
|
2015-08-12 22:03:11 +03:00
|
|
|
$backend,
|
|
|
|
$authMechanism,
|
2015-08-11 20:45:07 +03:00
|
|
|
$backendOptions,
|
|
|
|
$mountOptions,
|
|
|
|
$applicableUsers,
|
|
|
|
$applicableGroups,
|
|
|
|
$priority
|
|
|
|
);
|
|
|
|
if ($newStorage instanceof DataResponse) {
|
|
|
|
return $newStorage;
|
|
|
|
}
|
2014-10-31 13:41:07 +03:00
|
|
|
|
2015-09-17 12:24:19 +03:00
|
|
|
$response = $this->validate($newStorage);
|
2014-10-31 13:41:07 +03:00
|
|
|
if (!empty($response)) {
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
$newStorage = $this->service->addStorage($newStorage);
|
|
|
|
|
|
|
|
$this->updateStorageStatus($newStorage);
|
|
|
|
|
|
|
|
return new DataResponse(
|
2020-03-12 21:45:23 +03:00
|
|
|
$this->formatStorageForUI($newStorage),
|
2014-10-31 13:41:07 +03:00
|
|
|
Http::STATUS_CREATED
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update an external storage entry.
|
|
|
|
*
|
|
|
|
* @param int $id storage id
|
|
|
|
* @param string $mountPoint storage mount point
|
2015-08-12 22:03:11 +03:00
|
|
|
* @param string $backend backend identifier
|
|
|
|
* @param string $authMechanism authentication mechansim identifier
|
2014-10-31 13:41:07 +03:00
|
|
|
* @param array $backendOptions backend-specific options
|
2015-03-13 14:49:11 +03:00
|
|
|
* @param array $mountOptions mount-specific options
|
2014-10-31 13:41:07 +03:00
|
|
|
* @param array $applicableUsers users for which to mount the storage
|
|
|
|
* @param array $applicableGroups groups for which to mount the storage
|
|
|
|
* @param int $priority priority
|
2016-06-17 15:25:29 +03:00
|
|
|
* @param bool $testOnly whether to storage should only test the connection or do more things
|
2014-10-31 13:41:07 +03:00
|
|
|
*
|
|
|
|
* @return DataResponse
|
|
|
|
*/
|
|
|
|
public function update(
|
|
|
|
$id,
|
|
|
|
$mountPoint,
|
2015-08-12 22:03:11 +03:00
|
|
|
$backend,
|
|
|
|
$authMechanism,
|
2014-10-31 13:41:07 +03:00
|
|
|
$backendOptions,
|
2015-03-13 14:49:11 +03:00
|
|
|
$mountOptions,
|
2014-10-31 13:41:07 +03:00
|
|
|
$applicableUsers,
|
|
|
|
$applicableGroups,
|
2016-06-07 17:53:16 +03:00
|
|
|
$priority,
|
2016-06-08 13:48:33 +03:00
|
|
|
$testOnly = true
|
2014-10-31 13:41:07 +03:00
|
|
|
) {
|
2015-08-11 20:45:07 +03:00
|
|
|
$storage = $this->createStorage(
|
|
|
|
$mountPoint,
|
2015-08-12 22:03:11 +03:00
|
|
|
$backend,
|
|
|
|
$authMechanism,
|
2015-08-11 20:45:07 +03:00
|
|
|
$backendOptions,
|
|
|
|
$mountOptions,
|
|
|
|
$applicableUsers,
|
|
|
|
$applicableGroups,
|
|
|
|
$priority
|
|
|
|
);
|
|
|
|
if ($storage instanceof DataResponse) {
|
|
|
|
return $storage;
|
|
|
|
}
|
|
|
|
$storage->setId($id);
|
2014-10-31 13:41:07 +03:00
|
|
|
|
2015-09-17 12:24:19 +03:00
|
|
|
$response = $this->validate($storage);
|
2014-10-31 13:41:07 +03:00
|
|
|
if (!empty($response)) {
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
$storage = $this->service->updateStorage($storage);
|
|
|
|
} catch (NotFoundException $e) {
|
|
|
|
return new DataResponse(
|
|
|
|
[
|
2020-03-26 11:30:18 +03:00
|
|
|
'message' => (string)$this->l10n->t('Storage with ID "%d" not found', [$id])
|
2014-10-31 13:41:07 +03:00
|
|
|
],
|
|
|
|
Http::STATUS_NOT_FOUND
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-06-07 19:25:17 +03:00
|
|
|
$this->updateStorageStatus($storage, $testOnly);
|
2014-10-31 13:41:07 +03:00
|
|
|
|
|
|
|
return new DataResponse(
|
2020-03-12 21:45:23 +03:00
|
|
|
$this->formatStorageForUI($storage),
|
2014-10-31 13:41:07 +03:00
|
|
|
Http::STATUS_OK
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-08-28 18:15:21 +03:00
|
|
|
|
2014-10-31 13:41:07 +03:00
|
|
|
}
|