You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

storageconfig.php 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <?php
  2. /**
  3. * @author Vincent Petry <pvince81@owncloud.com>
  4. *
  5. * @copyright Copyright (c) 2015, ownCloud, Inc.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace OCA\Files_external\Lib;
  22. /**
  23. * External storage configuration
  24. */
  25. class StorageConfig implements \JsonSerializable {
  26. /**
  27. * Storage config id
  28. *
  29. * @var int
  30. */
  31. private $id;
  32. /**
  33. * Backend class name
  34. *
  35. * @var string
  36. */
  37. private $backendClass;
  38. /**
  39. * Backend options
  40. *
  41. * @var array
  42. */
  43. private $backendOptions = [];
  44. /**
  45. * Mount point path, relative to the user's "files" folder
  46. *
  47. * @var string
  48. */
  49. private $mountPoint;
  50. /**
  51. * Storage status
  52. *
  53. * @var int
  54. */
  55. private $status;
  56. /**
  57. * Priority
  58. *
  59. * @var int
  60. */
  61. private $priority;
  62. /**
  63. * List of users who have access to this storage
  64. *
  65. * @var array
  66. */
  67. private $applicableUsers = [];
  68. /**
  69. * List of groups that have access to this storage
  70. *
  71. * @var array
  72. */
  73. private $applicableGroups = [];
  74. /**
  75. * Mount-specific options
  76. *
  77. * @var array
  78. */
  79. private $mountOptions = [];
  80. /**
  81. * Creates a storage config
  82. *
  83. * @param int|null $id config id or null for a new config
  84. */
  85. public function __construct($id = null) {
  86. $this->id = $id;
  87. }
  88. /**
  89. * Returns the configuration id
  90. *
  91. * @return int
  92. */
  93. public function getId() {
  94. return $this->id;
  95. }
  96. /**
  97. * Sets the configuration id
  98. *
  99. * @param int $id configuration id
  100. */
  101. public function setId($id) {
  102. $this->id = $id;
  103. }
  104. /**
  105. * Returns mount point path relative to the user's
  106. * "files" folder.
  107. *
  108. * @return string path
  109. */
  110. public function getMountPoint() {
  111. return $this->mountPoint;
  112. }
  113. /**
  114. * Sets mount point path relative to the user's
  115. * "files" folder.
  116. * The path will be normalized.
  117. *
  118. * @param string $mountPoint path
  119. */
  120. public function setMountPoint($mountPoint) {
  121. $this->mountPoint = \OC\Files\Filesystem::normalizePath($mountPoint);
  122. }
  123. /**
  124. * Returns the external storage backend class name
  125. *
  126. * @return string external storage backend class name
  127. */
  128. public function getBackendClass() {
  129. return $this->backendClass;
  130. }
  131. /**
  132. * Sets the external storage backend class name
  133. *
  134. * @param string external storage backend class name
  135. */
  136. public function setBackendClass($backendClass) {
  137. $this->backendClass = $backendClass;
  138. }
  139. /**
  140. * Returns the external storage backend-specific options
  141. *
  142. * @return array backend options
  143. */
  144. public function getBackendOptions() {
  145. return $this->backendOptions;
  146. }
  147. /**
  148. * Sets the external storage backend-specific options
  149. *
  150. * @param array $backendOptions backend options
  151. */
  152. public function setBackendOptions($backendOptions) {
  153. $this->backendOptions = $backendOptions;
  154. }
  155. /**
  156. * Returns the mount priority
  157. *
  158. * @return int priority
  159. */
  160. public function getPriority() {
  161. return $this->priority;
  162. }
  163. /**
  164. * Sets the mount priotity
  165. *
  166. * @param int $priority priority
  167. */
  168. public function setPriority($priority) {
  169. $this->priority = $priority;
  170. }
  171. /**
  172. * Returns the users for which to mount this storage
  173. *
  174. * @return array applicable users
  175. */
  176. public function getApplicableUsers() {
  177. return $this->applicableUsers;
  178. }
  179. /**
  180. * Sets the users for which to mount this storage
  181. *
  182. * @param array|null $applicableUsers applicable users
  183. */
  184. public function setApplicableUsers($applicableUsers) {
  185. if (is_null($applicableUsers)) {
  186. $applicableUsers = [];
  187. }
  188. $this->applicableUsers = $applicableUsers;
  189. }
  190. /**
  191. * Returns the groups for which to mount this storage
  192. *
  193. * @return array applicable groups
  194. */
  195. public function getApplicableGroups() {
  196. return $this->applicableGroups;
  197. }
  198. /**
  199. * Sets the groups for which to mount this storage
  200. *
  201. * @param array|null $applicableGroups applicable groups
  202. */
  203. public function setApplicableGroups($applicableGroups) {
  204. if (is_null($applicableGroups)) {
  205. $applicableGroups = [];
  206. }
  207. $this->applicableGroups = $applicableGroups;
  208. }
  209. /**
  210. * Returns the mount-specific options
  211. *
  212. * @return array mount specific options
  213. */
  214. public function getMountOptions() {
  215. return $this->mountOptions;
  216. }
  217. /**
  218. * Sets the mount-specific options
  219. *
  220. * @param array $mountOptions applicable groups
  221. */
  222. public function setMountOptions($mountOptions) {
  223. if (is_null($mountOptions)) {
  224. $mountOptions = [];
  225. }
  226. $this->mountOptions = $mountOptions;
  227. }
  228. /**
  229. * Sets the storage status, whether the config worked last time
  230. *
  231. * @return int $status status
  232. */
  233. public function getStatus() {
  234. return $this->status;
  235. }
  236. /**
  237. * Sets the storage status, whether the config worked last time
  238. *
  239. * @param int $status status
  240. */
  241. public function setStatus($status) {
  242. $this->status = $status;
  243. }
  244. /**
  245. * Serialize config to JSON
  246. *
  247. * @return array
  248. */
  249. public function jsonSerialize() {
  250. $result = [];
  251. if (!is_null($this->id)) {
  252. $result['id'] = $this->id;
  253. }
  254. $result['mountPoint'] = $this->mountPoint;
  255. $result['backendClass'] = $this->backendClass;
  256. $result['backendOptions'] = $this->backendOptions;
  257. if (!is_null($this->priority)) {
  258. $result['priority'] = $this->priority;
  259. }
  260. if (!empty($this->applicableUsers)) {
  261. $result['applicableUsers'] = $this->applicableUsers;
  262. }
  263. if (!empty($this->applicableGroups)) {
  264. $result['applicableGroups'] = $this->applicableGroups;
  265. }
  266. if (!empty($this->mountOptions)) {
  267. $result['mountOptions'] = $this->mountOptions;
  268. }
  269. if (!is_null($this->status)) {
  270. $result['status'] = $this->status;
  271. }
  272. return $result;
  273. }
  274. }