2014-10-31 10:41:07 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2015-03-26 10:44:34 +00:00
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
|
|
|
*
|
|
|
|
* @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-10-31 10:41:07 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Files_external\Lib;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* External storage configuration
|
|
|
|
*/
|
|
|
|
class StorageConfig implements \JsonSerializable {
|
|
|
|
|
|
|
|
/**
|
2015-03-17 10:42:52 +00:00
|
|
|
* Storage config id
|
|
|
|
*
|
2014-10-31 10:41:07 +00:00
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
/**
|
2015-03-17 10:42:52 +00:00
|
|
|
* Backend class name
|
|
|
|
*
|
2014-10-31 10:41:07 +00:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $backendClass;
|
|
|
|
|
|
|
|
/**
|
2015-03-17 10:42:52 +00:00
|
|
|
* Backend options
|
|
|
|
*
|
2014-10-31 10:41:07 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private $backendOptions = [];
|
|
|
|
|
|
|
|
/**
|
2015-03-17 10:42:52 +00:00
|
|
|
* Mount point path, relative to the user's "files" folder
|
|
|
|
*
|
2014-10-31 10:41:07 +00:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $mountPoint;
|
|
|
|
|
|
|
|
/**
|
2015-03-17 10:42:52 +00:00
|
|
|
* Storage status
|
|
|
|
*
|
2014-10-31 10:41:07 +00:00
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
private $status;
|
|
|
|
|
|
|
|
/**
|
2015-03-17 10:42:52 +00:00
|
|
|
* Priority
|
|
|
|
*
|
2014-10-31 10:41:07 +00:00
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
private $priority;
|
|
|
|
|
|
|
|
/**
|
2015-03-17 10:42:52 +00:00
|
|
|
* List of users who have access to this storage
|
|
|
|
*
|
2014-10-31 10:41:07 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private $applicableUsers = [];
|
|
|
|
|
|
|
|
/**
|
2015-03-17 10:42:52 +00:00
|
|
|
* List of groups that have access to this storage
|
|
|
|
*
|
2014-10-31 10:41:07 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private $applicableGroups = [];
|
|
|
|
|
2015-03-13 11:49:11 +00:00
|
|
|
/**
|
2015-03-17 10:42:52 +00:00
|
|
|
* Mount-specific options
|
|
|
|
*
|
2015-03-13 11:49:11 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private $mountOptions = [];
|
|
|
|
|
2014-10-31 10:41:07 +00:00
|
|
|
/**
|
2015-03-17 10:42:52 +00:00
|
|
|
* Creates a storage config
|
|
|
|
*
|
2014-10-31 10:41:07 +00:00
|
|
|
* @param int|null $id config id or null for a new config
|
|
|
|
*/
|
|
|
|
public function __construct($id = null) {
|
|
|
|
$this->id = $id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the configuration id
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getId() {
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the configuration id
|
|
|
|
*
|
2015-03-17 10:42:52 +00:00
|
|
|
* @param int $id configuration id
|
2014-10-31 10:41:07 +00:00
|
|
|
*/
|
|
|
|
public function setId($id) {
|
|
|
|
$this->id = $id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns mount point path relative to the user's
|
|
|
|
* "files" folder.
|
|
|
|
*
|
|
|
|
* @return string path
|
|
|
|
*/
|
|
|
|
public function getMountPoint() {
|
|
|
|
return $this->mountPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets mount point path relative to the user's
|
|
|
|
* "files" folder.
|
|
|
|
* The path will be normalized.
|
|
|
|
*
|
2015-03-17 10:42:52 +00:00
|
|
|
* @param string $mountPoint path
|
2014-10-31 10:41:07 +00:00
|
|
|
*/
|
|
|
|
public function setMountPoint($mountPoint) {
|
|
|
|
$this->mountPoint = \OC\Files\Filesystem::normalizePath($mountPoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the external storage backend class name
|
|
|
|
*
|
|
|
|
* @return string external storage backend class name
|
|
|
|
*/
|
|
|
|
public function getBackendClass() {
|
|
|
|
return $this->backendClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the external storage backend class name
|
|
|
|
*
|
|
|
|
* @param string external storage backend class name
|
|
|
|
*/
|
|
|
|
public function setBackendClass($backendClass) {
|
|
|
|
$this->backendClass = $backendClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the external storage backend-specific options
|
|
|
|
*
|
|
|
|
* @return array backend options
|
|
|
|
*/
|
|
|
|
public function getBackendOptions() {
|
|
|
|
return $this->backendOptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the external storage backend-specific options
|
|
|
|
*
|
2015-03-17 10:42:52 +00:00
|
|
|
* @param array $backendOptions backend options
|
2014-10-31 10:41:07 +00:00
|
|
|
*/
|
|
|
|
public function setBackendOptions($backendOptions) {
|
|
|
|
$this->backendOptions = $backendOptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the mount priority
|
|
|
|
*
|
|
|
|
* @return int priority
|
|
|
|
*/
|
|
|
|
public function getPriority() {
|
|
|
|
return $this->priority;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the mount priotity
|
|
|
|
*
|
2015-03-17 10:42:52 +00:00
|
|
|
* @param int $priority priority
|
2014-10-31 10:41:07 +00:00
|
|
|
*/
|
|
|
|
public function setPriority($priority) {
|
|
|
|
$this->priority = $priority;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the users for which to mount this storage
|
|
|
|
*
|
|
|
|
* @return array applicable users
|
|
|
|
*/
|
|
|
|
public function getApplicableUsers() {
|
|
|
|
return $this->applicableUsers;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the users for which to mount this storage
|
|
|
|
*
|
2015-03-17 10:42:52 +00:00
|
|
|
* @param array|null $applicableUsers applicable users
|
2014-10-31 10:41:07 +00:00
|
|
|
*/
|
|
|
|
public function setApplicableUsers($applicableUsers) {
|
|
|
|
if (is_null($applicableUsers)) {
|
|
|
|
$applicableUsers = [];
|
|
|
|
}
|
|
|
|
$this->applicableUsers = $applicableUsers;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the groups for which to mount this storage
|
|
|
|
*
|
|
|
|
* @return array applicable groups
|
|
|
|
*/
|
|
|
|
public function getApplicableGroups() {
|
|
|
|
return $this->applicableGroups;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the groups for which to mount this storage
|
|
|
|
*
|
2015-03-17 10:42:52 +00:00
|
|
|
* @param array|null $applicableGroups applicable groups
|
2014-10-31 10:41:07 +00:00
|
|
|
*/
|
|
|
|
public function setApplicableGroups($applicableGroups) {
|
|
|
|
if (is_null($applicableGroups)) {
|
|
|
|
$applicableGroups = [];
|
|
|
|
}
|
|
|
|
$this->applicableGroups = $applicableGroups;
|
|
|
|
}
|
|
|
|
|
2015-03-13 11:49:11 +00:00
|
|
|
/**
|
|
|
|
* Returns the mount-specific options
|
|
|
|
*
|
|
|
|
* @return array mount specific options
|
|
|
|
*/
|
|
|
|
public function getMountOptions() {
|
|
|
|
return $this->mountOptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the mount-specific options
|
|
|
|
*
|
2015-03-17 10:42:52 +00:00
|
|
|
* @param array $mountOptions applicable groups
|
2015-03-13 11:49:11 +00:00
|
|
|
*/
|
|
|
|
public function setMountOptions($mountOptions) {
|
|
|
|
if (is_null($mountOptions)) {
|
|
|
|
$mountOptions = [];
|
|
|
|
}
|
|
|
|
$this->mountOptions = $mountOptions;
|
|
|
|
}
|
|
|
|
|
2014-10-31 10:41:07 +00:00
|
|
|
/**
|
|
|
|
* Sets the storage status, whether the config worked last time
|
|
|
|
*
|
|
|
|
* @return int $status status
|
|
|
|
*/
|
|
|
|
public function getStatus() {
|
|
|
|
return $this->status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the storage status, whether the config worked last time
|
|
|
|
*
|
|
|
|
* @param int $status status
|
|
|
|
*/
|
|
|
|
public function setStatus($status) {
|
|
|
|
$this->status = $status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Serialize config to JSON
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function jsonSerialize() {
|
|
|
|
$result = [];
|
|
|
|
if (!is_null($this->id)) {
|
|
|
|
$result['id'] = $this->id;
|
|
|
|
}
|
|
|
|
$result['mountPoint'] = $this->mountPoint;
|
|
|
|
$result['backendClass'] = $this->backendClass;
|
|
|
|
$result['backendOptions'] = $this->backendOptions;
|
|
|
|
if (!is_null($this->priority)) {
|
|
|
|
$result['priority'] = $this->priority;
|
|
|
|
}
|
|
|
|
if (!empty($this->applicableUsers)) {
|
|
|
|
$result['applicableUsers'] = $this->applicableUsers;
|
|
|
|
}
|
|
|
|
if (!empty($this->applicableGroups)) {
|
|
|
|
$result['applicableGroups'] = $this->applicableGroups;
|
|
|
|
}
|
2015-03-13 11:49:11 +00:00
|
|
|
if (!empty($this->mountOptions)) {
|
|
|
|
$result['mountOptions'] = $this->mountOptions;
|
|
|
|
}
|
2014-10-31 10:41:07 +00:00
|
|
|
if (!is_null($this->status)) {
|
|
|
|
$result['status'] = $this->status;
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|