@@ -370,18 +370,18 @@ discard block |
||
370 | 370 | private function findFileWithExtension($class, $ext) |
371 | 371 | { |
372 | 372 | // PSR-4 lookup |
373 | - $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; |
|
373 | + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR).$ext; |
|
374 | 374 | |
375 | 375 | $first = $class[0]; |
376 | 376 | if (isset($this->prefixLengthsPsr4[$first])) { |
377 | 377 | $subPath = $class; |
378 | 378 | while (false !== $lastPos = strrpos($subPath, '\\')) { |
379 | 379 | $subPath = substr($subPath, 0, $lastPos); |
380 | - $search = $subPath . '\\'; |
|
380 | + $search = $subPath.'\\'; |
|
381 | 381 | if (isset($this->prefixDirsPsr4[$search])) { |
382 | - $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); |
|
382 | + $pathEnd = DIRECTORY_SEPARATOR.substr($logicalPathPsr4, $lastPos + 1); |
|
383 | 383 | foreach ($this->prefixDirsPsr4[$search] as $dir) { |
384 | - if (file_exists($file = $dir . $pathEnd)) { |
|
384 | + if (file_exists($file = $dir.$pathEnd)) { |
|
385 | 385 | return $file; |
386 | 386 | } |
387 | 387 | } |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | |
392 | 392 | // PSR-4 fallback dirs |
393 | 393 | foreach ($this->fallbackDirsPsr4 as $dir) { |
394 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { |
|
394 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr4)) { |
|
395 | 395 | return $file; |
396 | 396 | } |
397 | 397 | } |
@@ -403,14 +403,14 @@ discard block |
||
403 | 403 | . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); |
404 | 404 | } else { |
405 | 405 | // PEAR-like class name |
406 | - $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; |
|
406 | + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR).$ext; |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | if (isset($this->prefixesPsr0[$first])) { |
410 | 410 | foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { |
411 | 411 | if (0 === strpos($class, $prefix)) { |
412 | 412 | foreach ($dirs as $dir) { |
413 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
413 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
414 | 414 | return $file; |
415 | 415 | } |
416 | 416 | } |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | |
421 | 421 | // PSR-0 fallback dirs |
422 | 422 | foreach ($this->fallbackDirsPsr0 as $dir) { |
423 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
423 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
424 | 424 | return $file; |
425 | 425 | } |
426 | 426 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * @return string|null |
86 | 86 | * @since 20.0.0 |
87 | 87 | */ |
88 | - public function getMessage():?string; |
|
88 | + public function getMessage(): ?string; |
|
89 | 89 | |
90 | 90 | /** |
91 | 91 | * Get a custom icon provided by the user |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * @return string|null |
94 | 94 | * @since 20.0.0 |
95 | 95 | */ |
96 | - public function getIcon():?string; |
|
96 | + public function getIcon(): ?string; |
|
97 | 97 | |
98 | 98 | /** |
99 | 99 | * Gets the time that the custom status will be cleared at |
@@ -101,5 +101,5 @@ discard block |
||
101 | 101 | * @return DateTimeImmutable|null |
102 | 102 | * @since 20.0.0 |
103 | 103 | */ |
104 | - public function getClearAt():?DateTimeImmutable; |
|
104 | + public function getClearAt(): ?DateTimeImmutable; |
|
105 | 105 | } |
@@ -16,119 +16,119 @@ |
||
16 | 16 | * @since 20.0.0 |
17 | 17 | */ |
18 | 18 | interface IUserStatus { |
19 | - /** |
|
20 | - * @var string |
|
21 | - * @since 20.0.0 |
|
22 | - */ |
|
23 | - public const ONLINE = 'online'; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var string |
|
27 | - * @since 20.0.0 |
|
28 | - */ |
|
29 | - public const AWAY = 'away'; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var string |
|
33 | - * @since 20.0.0 |
|
34 | - */ |
|
35 | - public const DND = 'dnd'; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var string |
|
39 | - * @since 28.0.0 |
|
40 | - */ |
|
41 | - public const BUSY = 'busy'; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var string |
|
45 | - * @since 20.0.0 |
|
46 | - */ |
|
47 | - public const OFFLINE = 'offline'; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var string |
|
51 | - * @since 20.0.0 |
|
52 | - */ |
|
53 | - public const INVISIBLE = 'invisible'; |
|
54 | - |
|
55 | - /** |
|
56 | - * @var string |
|
57 | - * @since 25.0.0 |
|
58 | - */ |
|
59 | - public const MESSAGE_CALL = 'call'; |
|
60 | - |
|
61 | - /** |
|
62 | - * @var string |
|
63 | - * @since 25.0.0 |
|
64 | - */ |
|
65 | - public const MESSAGE_AVAILABILITY = 'availability'; |
|
66 | - |
|
67 | - /** |
|
68 | - * @var string |
|
69 | - * @since 28.0.1 |
|
70 | - */ |
|
71 | - public const MESSAGE_OUT_OF_OFFICE = 'out-of-office'; |
|
72 | - |
|
73 | - /** |
|
74 | - * @var string |
|
75 | - * @since 28.0.0 |
|
76 | - */ |
|
77 | - public const MESSAGE_VACATION = 'vacationing'; |
|
78 | - |
|
79 | - /** |
|
80 | - * @var string |
|
81 | - * @since 28.0.0 |
|
82 | - */ |
|
83 | - public const MESSAGE_CALENDAR_BUSY = 'meeting'; |
|
84 | - |
|
85 | - /** |
|
86 | - * @var string |
|
87 | - * @since 28.0.0 |
|
88 | - */ |
|
89 | - public const MESSAGE_CALENDAR_BUSY_TENTATIVE = 'busy-tentative'; |
|
90 | - |
|
91 | - /** |
|
92 | - * Get the user this status is connected to |
|
93 | - * |
|
94 | - * @return string |
|
95 | - * @since 20.0.0 |
|
96 | - */ |
|
97 | - public function getUserId():string; |
|
98 | - |
|
99 | - /** |
|
100 | - * Get the status |
|
101 | - * |
|
102 | - * It will return one of the constants defined above. |
|
103 | - * It will never return invisible. In case a user marked |
|
104 | - * themselves as invisible, it will return offline. |
|
105 | - * |
|
106 | - * @return string See IUserStatus constants |
|
107 | - * @since 20.0.0 |
|
108 | - */ |
|
109 | - public function getStatus():string; |
|
110 | - |
|
111 | - /** |
|
112 | - * Get a custom message provided by the user |
|
113 | - * |
|
114 | - * @return string|null |
|
115 | - * @since 20.0.0 |
|
116 | - */ |
|
117 | - public function getMessage():?string; |
|
118 | - |
|
119 | - /** |
|
120 | - * Get a custom icon provided by the user |
|
121 | - * |
|
122 | - * @return string|null |
|
123 | - * @since 20.0.0 |
|
124 | - */ |
|
125 | - public function getIcon():?string; |
|
126 | - |
|
127 | - /** |
|
128 | - * Gets the time that the custom status will be cleared at |
|
129 | - * |
|
130 | - * @return DateTimeImmutable|null |
|
131 | - * @since 20.0.0 |
|
132 | - */ |
|
133 | - public function getClearAt():?DateTimeImmutable; |
|
19 | + /** |
|
20 | + * @var string |
|
21 | + * @since 20.0.0 |
|
22 | + */ |
|
23 | + public const ONLINE = 'online'; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var string |
|
27 | + * @since 20.0.0 |
|
28 | + */ |
|
29 | + public const AWAY = 'away'; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var string |
|
33 | + * @since 20.0.0 |
|
34 | + */ |
|
35 | + public const DND = 'dnd'; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var string |
|
39 | + * @since 28.0.0 |
|
40 | + */ |
|
41 | + public const BUSY = 'busy'; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var string |
|
45 | + * @since 20.0.0 |
|
46 | + */ |
|
47 | + public const OFFLINE = 'offline'; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var string |
|
51 | + * @since 20.0.0 |
|
52 | + */ |
|
53 | + public const INVISIBLE = 'invisible'; |
|
54 | + |
|
55 | + /** |
|
56 | + * @var string |
|
57 | + * @since 25.0.0 |
|
58 | + */ |
|
59 | + public const MESSAGE_CALL = 'call'; |
|
60 | + |
|
61 | + /** |
|
62 | + * @var string |
|
63 | + * @since 25.0.0 |
|
64 | + */ |
|
65 | + public const MESSAGE_AVAILABILITY = 'availability'; |
|
66 | + |
|
67 | + /** |
|
68 | + * @var string |
|
69 | + * @since 28.0.1 |
|
70 | + */ |
|
71 | + public const MESSAGE_OUT_OF_OFFICE = 'out-of-office'; |
|
72 | + |
|
73 | + /** |
|
74 | + * @var string |
|
75 | + * @since 28.0.0 |
|
76 | + */ |
|
77 | + public const MESSAGE_VACATION = 'vacationing'; |
|
78 | + |
|
79 | + /** |
|
80 | + * @var string |
|
81 | + * @since 28.0.0 |
|
82 | + */ |
|
83 | + public const MESSAGE_CALENDAR_BUSY = 'meeting'; |
|
84 | + |
|
85 | + /** |
|
86 | + * @var string |
|
87 | + * @since 28.0.0 |
|
88 | + */ |
|
89 | + public const MESSAGE_CALENDAR_BUSY_TENTATIVE = 'busy-tentative'; |
|
90 | + |
|
91 | + /** |
|
92 | + * Get the user this status is connected to |
|
93 | + * |
|
94 | + * @return string |
|
95 | + * @since 20.0.0 |
|
96 | + */ |
|
97 | + public function getUserId():string; |
|
98 | + |
|
99 | + /** |
|
100 | + * Get the status |
|
101 | + * |
|
102 | + * It will return one of the constants defined above. |
|
103 | + * It will never return invisible. In case a user marked |
|
104 | + * themselves as invisible, it will return offline. |
|
105 | + * |
|
106 | + * @return string See IUserStatus constants |
|
107 | + * @since 20.0.0 |
|
108 | + */ |
|
109 | + public function getStatus():string; |
|
110 | + |
|
111 | + /** |
|
112 | + * Get a custom message provided by the user |
|
113 | + * |
|
114 | + * @return string|null |
|
115 | + * @since 20.0.0 |
|
116 | + */ |
|
117 | + public function getMessage():?string; |
|
118 | + |
|
119 | + /** |
|
120 | + * Get a custom icon provided by the user |
|
121 | + * |
|
122 | + * @return string|null |
|
123 | + * @since 20.0.0 |
|
124 | + */ |
|
125 | + public function getIcon():?string; |
|
126 | + |
|
127 | + /** |
|
128 | + * Gets the time that the custom status will be cleared at |
|
129 | + * |
|
130 | + * @return DateTimeImmutable|null |
|
131 | + * @since 20.0.0 |
|
132 | + */ |
|
133 | + public function getClearAt():?DateTimeImmutable; |
|
134 | 134 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | |
116 | 116 | $result = []; |
117 | 117 | foreach ($storagesByMountpoint as $storageList) { |
118 | - $storage = array_reduce($storageList, function ($carry, $item) { |
|
118 | + $storage = array_reduce($storageList, function($carry, $item) { |
|
119 | 119 | if (isset($carry)) { |
120 | 120 | $carryPriorityType = $this->getPriorityType($carry); |
121 | 121 | $itemPriorityType = $this->getPriorityType($item); |
@@ -191,11 +191,11 @@ discard block |
||
191 | 191 | $groupIds = $this->groupManager->getUserGroupIds($user); |
192 | 192 | $mounts = $this->dbConfig->getMountsForUser($user->getUID(), $groupIds); |
193 | 193 | $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts); |
194 | - $configs = array_filter($configs, function ($config) { |
|
194 | + $configs = array_filter($configs, function($config) { |
|
195 | 195 | return $config instanceof StorageConfig; |
196 | 196 | }); |
197 | 197 | |
198 | - $keys = array_map(function (StorageConfig $config) { |
|
198 | + $keys = array_map(function(StorageConfig $config) { |
|
199 | 199 | return $config->getId(); |
200 | 200 | }, $configs); |
201 | 201 |
@@ -18,169 +18,169 @@ |
||
18 | 18 | * Read-only access available, attempting to write will throw DomainException |
19 | 19 | */ |
20 | 20 | class UserGlobalStoragesService extends GlobalStoragesService { |
21 | - use UserTrait; |
|
22 | - |
|
23 | - /** |
|
24 | - * @param BackendService $backendService |
|
25 | - * @param DBConfigService $dbConfig |
|
26 | - * @param IUserSession $userSession |
|
27 | - * @param IGroupManager $groupManager |
|
28 | - * @param IUserMountCache $userMountCache |
|
29 | - * @param IEventDispatcher $eventDispatcher |
|
30 | - */ |
|
31 | - public function __construct( |
|
32 | - BackendService $backendService, |
|
33 | - DBConfigService $dbConfig, |
|
34 | - IUserSession $userSession, |
|
35 | - protected IGroupManager $groupManager, |
|
36 | - IUserMountCache $userMountCache, |
|
37 | - IEventDispatcher $eventDispatcher, |
|
38 | - ) { |
|
39 | - parent::__construct($backendService, $dbConfig, $userMountCache, $eventDispatcher); |
|
40 | - $this->userSession = $userSession; |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Replace config hash ID with real IDs, for migrating legacy storages |
|
45 | - * |
|
46 | - * @param StorageConfig[] $storages Storages with real IDs |
|
47 | - * @param StorageConfig[] $storagesWithConfigHash Storages with config hash IDs |
|
48 | - */ |
|
49 | - protected function setRealStorageIds(array &$storages, array $storagesWithConfigHash) { |
|
50 | - // as a read-only view, storage IDs don't need to be real |
|
51 | - foreach ($storagesWithConfigHash as $storage) { |
|
52 | - $storages[$storage->getId()] = $storage; |
|
53 | - } |
|
54 | - } |
|
55 | - |
|
56 | - protected function readDBConfig() { |
|
57 | - $userMounts = $this->dbConfig->getAdminMountsFor(DBConfigService::APPLICABLE_TYPE_USER, $this->getUser()->getUID()); |
|
58 | - $globalMounts = $this->dbConfig->getAdminMountsFor(DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
59 | - $groups = $this->groupManager->getUserGroupIds($this->getUser()); |
|
60 | - if (count($groups) !== 0) { |
|
61 | - $groupMounts = $this->dbConfig->getAdminMountsForMultiple(DBConfigService::APPLICABLE_TYPE_GROUP, $groups); |
|
62 | - } else { |
|
63 | - $groupMounts = []; |
|
64 | - } |
|
65 | - return array_merge($userMounts, $groupMounts, $globalMounts); |
|
66 | - } |
|
67 | - |
|
68 | - public function addStorage(StorageConfig $newStorage) { |
|
69 | - throw new \DomainException('UserGlobalStoragesService writing disallowed'); |
|
70 | - } |
|
71 | - |
|
72 | - public function updateStorage(StorageConfig $updatedStorage) { |
|
73 | - throw new \DomainException('UserGlobalStoragesService writing disallowed'); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @param integer $id |
|
78 | - */ |
|
79 | - public function removeStorage($id) { |
|
80 | - throw new \DomainException('UserGlobalStoragesService writing disallowed'); |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Get unique storages, in case two are defined with the same mountpoint |
|
85 | - * Higher priority storages take precedence |
|
86 | - * |
|
87 | - * @return StorageConfig[] |
|
88 | - */ |
|
89 | - public function getUniqueStorages() { |
|
90 | - $storages = $this->getStorages(); |
|
91 | - |
|
92 | - $storagesByMountpoint = []; |
|
93 | - foreach ($storages as $storage) { |
|
94 | - $storagesByMountpoint[$storage->getMountPoint()][] = $storage; |
|
95 | - } |
|
96 | - |
|
97 | - $result = []; |
|
98 | - foreach ($storagesByMountpoint as $storageList) { |
|
99 | - $storage = array_reduce($storageList, function ($carry, $item) { |
|
100 | - if (isset($carry)) { |
|
101 | - $carryPriorityType = $this->getPriorityType($carry); |
|
102 | - $itemPriorityType = $this->getPriorityType($item); |
|
103 | - if ($carryPriorityType > $itemPriorityType) { |
|
104 | - return $carry; |
|
105 | - } elseif ($carryPriorityType === $itemPriorityType) { |
|
106 | - if ($carry->getPriority() > $item->getPriority()) { |
|
107 | - return $carry; |
|
108 | - } |
|
109 | - } |
|
110 | - } |
|
111 | - return $item; |
|
112 | - }); |
|
113 | - $result[$storage->getID()] = $storage; |
|
114 | - } |
|
115 | - |
|
116 | - return $result; |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Get a priority 'type', where a bigger number means higher priority |
|
121 | - * user applicable > group applicable > 'all' |
|
122 | - * |
|
123 | - * @param StorageConfig $storage |
|
124 | - * @return int |
|
125 | - */ |
|
126 | - protected function getPriorityType(StorageConfig $storage) { |
|
127 | - $applicableUsers = $storage->getApplicableUsers(); |
|
128 | - $applicableGroups = $storage->getApplicableGroups(); |
|
129 | - |
|
130 | - if ($applicableUsers && $applicableUsers[0] !== 'all') { |
|
131 | - return 2; |
|
132 | - } |
|
133 | - if ($applicableGroups) { |
|
134 | - return 1; |
|
135 | - } |
|
136 | - return 0; |
|
137 | - } |
|
138 | - |
|
139 | - protected function isApplicable(StorageConfig $config) { |
|
140 | - $applicableUsers = $config->getApplicableUsers(); |
|
141 | - $applicableGroups = $config->getApplicableGroups(); |
|
142 | - |
|
143 | - if (count($applicableUsers) === 0 && count($applicableGroups) === 0) { |
|
144 | - return true; |
|
145 | - } |
|
146 | - if (in_array($this->getUser()->getUID(), $applicableUsers, true)) { |
|
147 | - return true; |
|
148 | - } |
|
149 | - $groupIds = $this->groupManager->getUserGroupIds($this->getUser()); |
|
150 | - foreach ($groupIds as $groupId) { |
|
151 | - if (in_array($groupId, $applicableGroups, true)) { |
|
152 | - return true; |
|
153 | - } |
|
154 | - } |
|
155 | - return false; |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * Gets all storages for the user, admin, personal, global, etc |
|
161 | - * |
|
162 | - * @param IUser|null $user user to get the storages for, if not set the currently logged in user will be used |
|
163 | - * @return StorageConfig[] array of storage configs |
|
164 | - */ |
|
165 | - public function getAllStoragesForUser(?IUser $user = null) { |
|
166 | - if (is_null($user)) { |
|
167 | - $user = $this->getUser(); |
|
168 | - } |
|
169 | - if (is_null($user)) { |
|
170 | - return []; |
|
171 | - } |
|
172 | - $groupIds = $this->groupManager->getUserGroupIds($user); |
|
173 | - $mounts = $this->dbConfig->getMountsForUser($user->getUID(), $groupIds); |
|
174 | - $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts); |
|
175 | - $configs = array_filter($configs, function ($config) { |
|
176 | - return $config instanceof StorageConfig; |
|
177 | - }); |
|
178 | - |
|
179 | - $keys = array_map(function (StorageConfig $config) { |
|
180 | - return $config->getId(); |
|
181 | - }, $configs); |
|
182 | - |
|
183 | - $storages = array_combine($keys, $configs); |
|
184 | - return array_filter($storages, [$this, 'validateStorage']); |
|
185 | - } |
|
21 | + use UserTrait; |
|
22 | + |
|
23 | + /** |
|
24 | + * @param BackendService $backendService |
|
25 | + * @param DBConfigService $dbConfig |
|
26 | + * @param IUserSession $userSession |
|
27 | + * @param IGroupManager $groupManager |
|
28 | + * @param IUserMountCache $userMountCache |
|
29 | + * @param IEventDispatcher $eventDispatcher |
|
30 | + */ |
|
31 | + public function __construct( |
|
32 | + BackendService $backendService, |
|
33 | + DBConfigService $dbConfig, |
|
34 | + IUserSession $userSession, |
|
35 | + protected IGroupManager $groupManager, |
|
36 | + IUserMountCache $userMountCache, |
|
37 | + IEventDispatcher $eventDispatcher, |
|
38 | + ) { |
|
39 | + parent::__construct($backendService, $dbConfig, $userMountCache, $eventDispatcher); |
|
40 | + $this->userSession = $userSession; |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Replace config hash ID with real IDs, for migrating legacy storages |
|
45 | + * |
|
46 | + * @param StorageConfig[] $storages Storages with real IDs |
|
47 | + * @param StorageConfig[] $storagesWithConfigHash Storages with config hash IDs |
|
48 | + */ |
|
49 | + protected function setRealStorageIds(array &$storages, array $storagesWithConfigHash) { |
|
50 | + // as a read-only view, storage IDs don't need to be real |
|
51 | + foreach ($storagesWithConfigHash as $storage) { |
|
52 | + $storages[$storage->getId()] = $storage; |
|
53 | + } |
|
54 | + } |
|
55 | + |
|
56 | + protected function readDBConfig() { |
|
57 | + $userMounts = $this->dbConfig->getAdminMountsFor(DBConfigService::APPLICABLE_TYPE_USER, $this->getUser()->getUID()); |
|
58 | + $globalMounts = $this->dbConfig->getAdminMountsFor(DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
59 | + $groups = $this->groupManager->getUserGroupIds($this->getUser()); |
|
60 | + if (count($groups) !== 0) { |
|
61 | + $groupMounts = $this->dbConfig->getAdminMountsForMultiple(DBConfigService::APPLICABLE_TYPE_GROUP, $groups); |
|
62 | + } else { |
|
63 | + $groupMounts = []; |
|
64 | + } |
|
65 | + return array_merge($userMounts, $groupMounts, $globalMounts); |
|
66 | + } |
|
67 | + |
|
68 | + public function addStorage(StorageConfig $newStorage) { |
|
69 | + throw new \DomainException('UserGlobalStoragesService writing disallowed'); |
|
70 | + } |
|
71 | + |
|
72 | + public function updateStorage(StorageConfig $updatedStorage) { |
|
73 | + throw new \DomainException('UserGlobalStoragesService writing disallowed'); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @param integer $id |
|
78 | + */ |
|
79 | + public function removeStorage($id) { |
|
80 | + throw new \DomainException('UserGlobalStoragesService writing disallowed'); |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Get unique storages, in case two are defined with the same mountpoint |
|
85 | + * Higher priority storages take precedence |
|
86 | + * |
|
87 | + * @return StorageConfig[] |
|
88 | + */ |
|
89 | + public function getUniqueStorages() { |
|
90 | + $storages = $this->getStorages(); |
|
91 | + |
|
92 | + $storagesByMountpoint = []; |
|
93 | + foreach ($storages as $storage) { |
|
94 | + $storagesByMountpoint[$storage->getMountPoint()][] = $storage; |
|
95 | + } |
|
96 | + |
|
97 | + $result = []; |
|
98 | + foreach ($storagesByMountpoint as $storageList) { |
|
99 | + $storage = array_reduce($storageList, function ($carry, $item) { |
|
100 | + if (isset($carry)) { |
|
101 | + $carryPriorityType = $this->getPriorityType($carry); |
|
102 | + $itemPriorityType = $this->getPriorityType($item); |
|
103 | + if ($carryPriorityType > $itemPriorityType) { |
|
104 | + return $carry; |
|
105 | + } elseif ($carryPriorityType === $itemPriorityType) { |
|
106 | + if ($carry->getPriority() > $item->getPriority()) { |
|
107 | + return $carry; |
|
108 | + } |
|
109 | + } |
|
110 | + } |
|
111 | + return $item; |
|
112 | + }); |
|
113 | + $result[$storage->getID()] = $storage; |
|
114 | + } |
|
115 | + |
|
116 | + return $result; |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Get a priority 'type', where a bigger number means higher priority |
|
121 | + * user applicable > group applicable > 'all' |
|
122 | + * |
|
123 | + * @param StorageConfig $storage |
|
124 | + * @return int |
|
125 | + */ |
|
126 | + protected function getPriorityType(StorageConfig $storage) { |
|
127 | + $applicableUsers = $storage->getApplicableUsers(); |
|
128 | + $applicableGroups = $storage->getApplicableGroups(); |
|
129 | + |
|
130 | + if ($applicableUsers && $applicableUsers[0] !== 'all') { |
|
131 | + return 2; |
|
132 | + } |
|
133 | + if ($applicableGroups) { |
|
134 | + return 1; |
|
135 | + } |
|
136 | + return 0; |
|
137 | + } |
|
138 | + |
|
139 | + protected function isApplicable(StorageConfig $config) { |
|
140 | + $applicableUsers = $config->getApplicableUsers(); |
|
141 | + $applicableGroups = $config->getApplicableGroups(); |
|
142 | + |
|
143 | + if (count($applicableUsers) === 0 && count($applicableGroups) === 0) { |
|
144 | + return true; |
|
145 | + } |
|
146 | + if (in_array($this->getUser()->getUID(), $applicableUsers, true)) { |
|
147 | + return true; |
|
148 | + } |
|
149 | + $groupIds = $this->groupManager->getUserGroupIds($this->getUser()); |
|
150 | + foreach ($groupIds as $groupId) { |
|
151 | + if (in_array($groupId, $applicableGroups, true)) { |
|
152 | + return true; |
|
153 | + } |
|
154 | + } |
|
155 | + return false; |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * Gets all storages for the user, admin, personal, global, etc |
|
161 | + * |
|
162 | + * @param IUser|null $user user to get the storages for, if not set the currently logged in user will be used |
|
163 | + * @return StorageConfig[] array of storage configs |
|
164 | + */ |
|
165 | + public function getAllStoragesForUser(?IUser $user = null) { |
|
166 | + if (is_null($user)) { |
|
167 | + $user = $this->getUser(); |
|
168 | + } |
|
169 | + if (is_null($user)) { |
|
170 | + return []; |
|
171 | + } |
|
172 | + $groupIds = $this->groupManager->getUserGroupIds($user); |
|
173 | + $mounts = $this->dbConfig->getMountsForUser($user->getUID(), $groupIds); |
|
174 | + $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts); |
|
175 | + $configs = array_filter($configs, function ($config) { |
|
176 | + return $config instanceof StorageConfig; |
|
177 | + }); |
|
178 | + |
|
179 | + $keys = array_map(function (StorageConfig $config) { |
|
180 | + return $config->getId(); |
|
181 | + }, $configs); |
|
182 | + |
|
183 | + $storages = array_combine($keys, $configs); |
|
184 | + return array_filter($storages, [$this, 'validateStorage']); |
|
185 | + } |
|
186 | 186 | } |
@@ -31,11 +31,11 @@ |
||
31 | 31 | * @since 20.0.0 |
32 | 32 | */ |
33 | 33 | interface IRootMountProvider { |
34 | - /** |
|
35 | - * Get all root mountpoints of this provider |
|
36 | - * |
|
37 | - * @return \OCP\Files\Mount\IMountPoint[] |
|
38 | - * @since 20.0.0 |
|
39 | - */ |
|
40 | - public function getRootMounts(IStorageFactory $loader): array; |
|
34 | + /** |
|
35 | + * Get all root mountpoints of this provider |
|
36 | + * |
|
37 | + * @return \OCP\Files\Mount\IMountPoint[] |
|
38 | + * @since 20.0.0 |
|
39 | + */ |
|
40 | + public function getRootMounts(IStorageFactory $loader): array; |
|
41 | 41 | } |
@@ -36,56 +36,56 @@ |
||
36 | 36 | * @since 18.0.0 |
37 | 37 | */ |
38 | 38 | interface IRuleMatcher extends IFileCheck { |
39 | - /** |
|
40 | - * This method is left for backwards compatibility and easier porting of |
|
41 | - * apps. Please use 'getFlows' instead (and setOperation if you implement |
|
42 | - * an IComplexOperation). |
|
43 | - * |
|
44 | - * @since 18.0.0 |
|
45 | - * @deprecated 18.0.0 |
|
46 | - */ |
|
47 | - public function getMatchingOperations(string $class, bool $returnFirstMatchingOperationOnly = true): array; |
|
39 | + /** |
|
40 | + * This method is left for backwards compatibility and easier porting of |
|
41 | + * apps. Please use 'getFlows' instead (and setOperation if you implement |
|
42 | + * an IComplexOperation). |
|
43 | + * |
|
44 | + * @since 18.0.0 |
|
45 | + * @deprecated 18.0.0 |
|
46 | + */ |
|
47 | + public function getMatchingOperations(string $class, bool $returnFirstMatchingOperationOnly = true): array; |
|
48 | 48 | |
49 | - /** |
|
50 | - * @throws RuntimeException |
|
51 | - * @since 18.0.0 |
|
52 | - */ |
|
53 | - public function getFlows(bool $returnFirstMatchingOperationOnly = true): array; |
|
49 | + /** |
|
50 | + * @throws RuntimeException |
|
51 | + * @since 18.0.0 |
|
52 | + */ |
|
53 | + public function getFlows(bool $returnFirstMatchingOperationOnly = true): array; |
|
54 | 54 | |
55 | - /** |
|
56 | - * this method can only be called once and is typically called by the |
|
57 | - * Flow engine, unless for IComplexOperations. |
|
58 | - * |
|
59 | - * @throws RuntimeException |
|
60 | - * @since 18.0.0 |
|
61 | - */ |
|
62 | - public function setOperation(IOperation $operation): void; |
|
55 | + /** |
|
56 | + * this method can only be called once and is typically called by the |
|
57 | + * Flow engine, unless for IComplexOperations. |
|
58 | + * |
|
59 | + * @throws RuntimeException |
|
60 | + * @since 18.0.0 |
|
61 | + */ |
|
62 | + public function setOperation(IOperation $operation): void; |
|
63 | 63 | |
64 | - /** |
|
65 | - * this method can only be called once and is typically called by the |
|
66 | - * Flow engine, unless for IComplexOperations. |
|
67 | - * |
|
68 | - * @throws RuntimeException |
|
69 | - * @since 18.0.0 |
|
70 | - */ |
|
71 | - public function setEntity(IEntity $entity): void; |
|
64 | + /** |
|
65 | + * this method can only be called once and is typically called by the |
|
66 | + * Flow engine, unless for IComplexOperations. |
|
67 | + * |
|
68 | + * @throws RuntimeException |
|
69 | + * @since 18.0.0 |
|
70 | + */ |
|
71 | + public function setEntity(IEntity $entity): void; |
|
72 | 72 | |
73 | - /** |
|
74 | - * returns the entity which might provide more information, depending on |
|
75 | - * the interfaces it implements |
|
76 | - * |
|
77 | - * @return IEntity |
|
78 | - * @since 18.0.0 |
|
79 | - */ |
|
80 | - public function getEntity(): IEntity; |
|
73 | + /** |
|
74 | + * returns the entity which might provide more information, depending on |
|
75 | + * the interfaces it implements |
|
76 | + * |
|
77 | + * @return IEntity |
|
78 | + * @since 18.0.0 |
|
79 | + */ |
|
80 | + public function getEntity(): IEntity; |
|
81 | 81 | |
82 | - /** |
|
83 | - * this method can be called once to set the event name that is currently |
|
84 | - * being processed. The workflow engine takes care of this usually, only an |
|
85 | - * IComplexOperation might want to make use of it. |
|
86 | - * |
|
87 | - * @throws RuntimeException |
|
88 | - * @since 20.0.0 |
|
89 | - */ |
|
90 | - public function setEventName(string $eventName): void; |
|
82 | + /** |
|
83 | + * this method can be called once to set the event name that is currently |
|
84 | + * being processed. The workflow engine takes care of this usually, only an |
|
85 | + * IComplexOperation might want to make use of it. |
|
86 | + * |
|
87 | + * @throws RuntimeException |
|
88 | + * @since 20.0.0 |
|
89 | + */ |
|
90 | + public function setEventName(string $eventName): void; |
|
91 | 91 | } |
@@ -36,22 +36,22 @@ |
||
36 | 36 | */ |
37 | 37 | class Version0002Date20200902144824 extends SimpleMigrationStep { |
38 | 38 | |
39 | - /** |
|
40 | - * @param IOutput $output |
|
41 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
42 | - * @param array $options |
|
43 | - * @return null|ISchemaWrapper |
|
44 | - * @since 20.0.0 |
|
45 | - */ |
|
46 | - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
47 | - /** @var ISchemaWrapper $schema */ |
|
48 | - $schema = $schemaClosure(); |
|
49 | - |
|
50 | - $statusTable = $schema->getTable('user_status'); |
|
51 | - |
|
52 | - $statusTable->addIndex(['status_timestamp'], 'user_status_tstmp_ix'); |
|
53 | - $statusTable->addIndex(['is_user_defined', 'status'], 'user_status_iud_ix'); |
|
54 | - |
|
55 | - return $schema; |
|
56 | - } |
|
39 | + /** |
|
40 | + * @param IOutput $output |
|
41 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
42 | + * @param array $options |
|
43 | + * @return null|ISchemaWrapper |
|
44 | + * @since 20.0.0 |
|
45 | + */ |
|
46 | + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
47 | + /** @var ISchemaWrapper $schema */ |
|
48 | + $schema = $schemaClosure(); |
|
49 | + |
|
50 | + $statusTable = $schema->getTable('user_status'); |
|
51 | + |
|
52 | + $statusTable->addIndex(['status_timestamp'], 'user_status_tstmp_ix'); |
|
53 | + $statusTable->addIndex(['is_user_defined', 'status'], 'user_status_iud_ix'); |
|
54 | + |
|
55 | + return $schema; |
|
56 | + } |
|
57 | 57 | } |
@@ -24,30 +24,30 @@ |
||
24 | 24 | namespace OC\Files\Cache; |
25 | 25 | |
26 | 26 | class NullWatcher extends Watcher { |
27 | - private $policy; |
|
27 | + private $policy; |
|
28 | 28 | |
29 | - public function __construct() { |
|
30 | - } |
|
29 | + public function __construct() { |
|
30 | + } |
|
31 | 31 | |
32 | - public function setPolicy($policy) { |
|
33 | - $this->policy = $policy; |
|
34 | - } |
|
32 | + public function setPolicy($policy) { |
|
33 | + $this->policy = $policy; |
|
34 | + } |
|
35 | 35 | |
36 | - public function getPolicy() { |
|
37 | - return $this->policy; |
|
38 | - } |
|
36 | + public function getPolicy() { |
|
37 | + return $this->policy; |
|
38 | + } |
|
39 | 39 | |
40 | - public function checkUpdate($path, $cachedEntry = null) { |
|
41 | - return false; |
|
42 | - } |
|
40 | + public function checkUpdate($path, $cachedEntry = null) { |
|
41 | + return false; |
|
42 | + } |
|
43 | 43 | |
44 | - public function update($path, $cachedData) { |
|
45 | - } |
|
44 | + public function update($path, $cachedData) { |
|
45 | + } |
|
46 | 46 | |
47 | - public function needsUpdate($path, $cachedData) { |
|
48 | - return false; |
|
49 | - } |
|
47 | + public function needsUpdate($path, $cachedData) { |
|
48 | + return false; |
|
49 | + } |
|
50 | 50 | |
51 | - public function cleanFolder($path) { |
|
52 | - } |
|
51 | + public function cleanFolder($path) { |
|
52 | + } |
|
53 | 53 | } |
@@ -106,7 +106,7 @@ |
||
106 | 106 | $jsTrans = []; |
107 | 107 | foreach ($translations as $id => $val) { |
108 | 108 | if (is_array($val)) { |
109 | - $val = '[ ' . implode(',', $val) . ']'; |
|
109 | + $val = '[ '.implode(',', $val).']'; |
|
110 | 110 | } |
111 | 111 | $jsTrans[] = "\"$id\" : \"$val\""; |
112 | 112 | } |
@@ -22,141 +22,141 @@ |
||
22 | 22 | use UnexpectedValueException; |
23 | 23 | |
24 | 24 | class CreateJs extends Command implements CompletionAwareInterface { |
25 | - public function __construct( |
|
26 | - protected IAppManager $appManager, |
|
27 | - ) { |
|
28 | - parent::__construct(); |
|
29 | - } |
|
30 | - |
|
31 | - protected function configure() { |
|
32 | - $this |
|
33 | - ->setName('l10n:createjs') |
|
34 | - ->setDescription('Create javascript translation files for a given app') |
|
35 | - ->addArgument( |
|
36 | - 'app', |
|
37 | - InputOption::VALUE_REQUIRED, |
|
38 | - 'name of the app' |
|
39 | - ) |
|
40 | - ->addArgument( |
|
41 | - 'lang', |
|
42 | - InputOption::VALUE_OPTIONAL, |
|
43 | - 'name of the language' |
|
44 | - ); |
|
45 | - } |
|
46 | - |
|
47 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
48 | - $app = $input->getArgument('app'); |
|
49 | - $lang = $input->getArgument('lang'); |
|
50 | - |
|
51 | - $path = $this->appManager->getAppPath($app); |
|
52 | - $languages = $lang; |
|
53 | - if (empty($lang)) { |
|
54 | - $languages = $this->getAllLanguages($path); |
|
55 | - } |
|
56 | - |
|
57 | - foreach ($languages as $lang) { |
|
58 | - $this->writeFiles($app, $path, $lang, $output); |
|
59 | - } |
|
60 | - return 0; |
|
61 | - } |
|
62 | - |
|
63 | - private function getAllLanguages($path) { |
|
64 | - $result = []; |
|
65 | - foreach (new DirectoryIterator("$path/l10n") as $fileInfo) { |
|
66 | - if ($fileInfo->isDot()) { |
|
67 | - continue; |
|
68 | - } |
|
69 | - if ($fileInfo->isDir()) { |
|
70 | - continue; |
|
71 | - } |
|
72 | - if ($fileInfo->getExtension() !== 'php') { |
|
73 | - continue; |
|
74 | - } |
|
75 | - $result[] = substr($fileInfo->getBasename(), 0, -4); |
|
76 | - } |
|
77 | - |
|
78 | - return $result; |
|
79 | - } |
|
80 | - |
|
81 | - private function writeFiles($app, $path, $lang, OutputInterface $output) { |
|
82 | - [$translations, $plurals] = $this->loadTranslations($path, $lang); |
|
83 | - $this->writeJsFile($app, $path, $lang, $output, $translations, $plurals); |
|
84 | - $this->writeJsonFile($path, $lang, $output, $translations, $plurals); |
|
85 | - } |
|
86 | - |
|
87 | - private function writeJsFile($app, $path, $lang, OutputInterface $output, $translations, $plurals) { |
|
88 | - $jsFile = "$path/l10n/$lang.js"; |
|
89 | - if (file_exists($jsFile)) { |
|
90 | - $output->writeln("File already exists: $jsFile"); |
|
91 | - return; |
|
92 | - } |
|
93 | - $content = "OC.L10N.register(\n \"$app\",\n {\n "; |
|
94 | - $jsTrans = []; |
|
95 | - foreach ($translations as $id => $val) { |
|
96 | - if (is_array($val)) { |
|
97 | - $val = '[ ' . implode(',', $val) . ']'; |
|
98 | - } |
|
99 | - $jsTrans[] = "\"$id\" : \"$val\""; |
|
100 | - } |
|
101 | - $content .= implode(",\n ", $jsTrans); |
|
102 | - $content .= "\n},\n\"$plurals\");\n"; |
|
103 | - |
|
104 | - file_put_contents($jsFile, $content); |
|
105 | - $output->writeln("Javascript translation file generated: $jsFile"); |
|
106 | - } |
|
107 | - |
|
108 | - private function writeJsonFile($path, $lang, OutputInterface $output, $translations, $plurals) { |
|
109 | - $jsFile = "$path/l10n/$lang.json"; |
|
110 | - if (file_exists($jsFile)) { |
|
111 | - $output->writeln("File already exists: $jsFile"); |
|
112 | - return; |
|
113 | - } |
|
114 | - $content = ['translations' => $translations, 'pluralForm' => $plurals]; |
|
115 | - file_put_contents($jsFile, json_encode($content)); |
|
116 | - $output->writeln("Json translation file generated: $jsFile"); |
|
117 | - } |
|
118 | - |
|
119 | - private function loadTranslations($path, $lang) { |
|
120 | - $phpFile = "$path/l10n/$lang.php"; |
|
121 | - $TRANSLATIONS = []; |
|
122 | - $PLURAL_FORMS = ''; |
|
123 | - if (!file_exists($phpFile)) { |
|
124 | - throw new UnexpectedValueException("PHP translation file <$phpFile> does not exist."); |
|
125 | - } |
|
126 | - require $phpFile; |
|
127 | - |
|
128 | - return [$TRANSLATIONS, $PLURAL_FORMS]; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Return possible values for the named option |
|
133 | - * |
|
134 | - * @param string $optionName |
|
135 | - * @param CompletionContext $context |
|
136 | - * @return string[] |
|
137 | - */ |
|
138 | - public function completeOptionValues($optionName, CompletionContext $context) { |
|
139 | - return []; |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Return possible values for the named argument |
|
144 | - * |
|
145 | - * @param string $argumentName |
|
146 | - * @param CompletionContext $context |
|
147 | - * @return string[] |
|
148 | - */ |
|
149 | - public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
150 | - if ($argumentName === 'app') { |
|
151 | - return $this->appManager->getAllAppsInAppsFolders(); |
|
152 | - } elseif ($argumentName === 'lang') { |
|
153 | - $appName = $context->getWordAtIndex($context->getWordIndex() - 1); |
|
154 | - try { |
|
155 | - return $this->getAllLanguages($this->appManager->getAppPath($appName)); |
|
156 | - } catch (AppPathNotFoundException) { |
|
157 | - return []; |
|
158 | - } |
|
159 | - } |
|
160 | - return []; |
|
161 | - } |
|
25 | + public function __construct( |
|
26 | + protected IAppManager $appManager, |
|
27 | + ) { |
|
28 | + parent::__construct(); |
|
29 | + } |
|
30 | + |
|
31 | + protected function configure() { |
|
32 | + $this |
|
33 | + ->setName('l10n:createjs') |
|
34 | + ->setDescription('Create javascript translation files for a given app') |
|
35 | + ->addArgument( |
|
36 | + 'app', |
|
37 | + InputOption::VALUE_REQUIRED, |
|
38 | + 'name of the app' |
|
39 | + ) |
|
40 | + ->addArgument( |
|
41 | + 'lang', |
|
42 | + InputOption::VALUE_OPTIONAL, |
|
43 | + 'name of the language' |
|
44 | + ); |
|
45 | + } |
|
46 | + |
|
47 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
48 | + $app = $input->getArgument('app'); |
|
49 | + $lang = $input->getArgument('lang'); |
|
50 | + |
|
51 | + $path = $this->appManager->getAppPath($app); |
|
52 | + $languages = $lang; |
|
53 | + if (empty($lang)) { |
|
54 | + $languages = $this->getAllLanguages($path); |
|
55 | + } |
|
56 | + |
|
57 | + foreach ($languages as $lang) { |
|
58 | + $this->writeFiles($app, $path, $lang, $output); |
|
59 | + } |
|
60 | + return 0; |
|
61 | + } |
|
62 | + |
|
63 | + private function getAllLanguages($path) { |
|
64 | + $result = []; |
|
65 | + foreach (new DirectoryIterator("$path/l10n") as $fileInfo) { |
|
66 | + if ($fileInfo->isDot()) { |
|
67 | + continue; |
|
68 | + } |
|
69 | + if ($fileInfo->isDir()) { |
|
70 | + continue; |
|
71 | + } |
|
72 | + if ($fileInfo->getExtension() !== 'php') { |
|
73 | + continue; |
|
74 | + } |
|
75 | + $result[] = substr($fileInfo->getBasename(), 0, -4); |
|
76 | + } |
|
77 | + |
|
78 | + return $result; |
|
79 | + } |
|
80 | + |
|
81 | + private function writeFiles($app, $path, $lang, OutputInterface $output) { |
|
82 | + [$translations, $plurals] = $this->loadTranslations($path, $lang); |
|
83 | + $this->writeJsFile($app, $path, $lang, $output, $translations, $plurals); |
|
84 | + $this->writeJsonFile($path, $lang, $output, $translations, $plurals); |
|
85 | + } |
|
86 | + |
|
87 | + private function writeJsFile($app, $path, $lang, OutputInterface $output, $translations, $plurals) { |
|
88 | + $jsFile = "$path/l10n/$lang.js"; |
|
89 | + if (file_exists($jsFile)) { |
|
90 | + $output->writeln("File already exists: $jsFile"); |
|
91 | + return; |
|
92 | + } |
|
93 | + $content = "OC.L10N.register(\n \"$app\",\n {\n "; |
|
94 | + $jsTrans = []; |
|
95 | + foreach ($translations as $id => $val) { |
|
96 | + if (is_array($val)) { |
|
97 | + $val = '[ ' . implode(',', $val) . ']'; |
|
98 | + } |
|
99 | + $jsTrans[] = "\"$id\" : \"$val\""; |
|
100 | + } |
|
101 | + $content .= implode(",\n ", $jsTrans); |
|
102 | + $content .= "\n},\n\"$plurals\");\n"; |
|
103 | + |
|
104 | + file_put_contents($jsFile, $content); |
|
105 | + $output->writeln("Javascript translation file generated: $jsFile"); |
|
106 | + } |
|
107 | + |
|
108 | + private function writeJsonFile($path, $lang, OutputInterface $output, $translations, $plurals) { |
|
109 | + $jsFile = "$path/l10n/$lang.json"; |
|
110 | + if (file_exists($jsFile)) { |
|
111 | + $output->writeln("File already exists: $jsFile"); |
|
112 | + return; |
|
113 | + } |
|
114 | + $content = ['translations' => $translations, 'pluralForm' => $plurals]; |
|
115 | + file_put_contents($jsFile, json_encode($content)); |
|
116 | + $output->writeln("Json translation file generated: $jsFile"); |
|
117 | + } |
|
118 | + |
|
119 | + private function loadTranslations($path, $lang) { |
|
120 | + $phpFile = "$path/l10n/$lang.php"; |
|
121 | + $TRANSLATIONS = []; |
|
122 | + $PLURAL_FORMS = ''; |
|
123 | + if (!file_exists($phpFile)) { |
|
124 | + throw new UnexpectedValueException("PHP translation file <$phpFile> does not exist."); |
|
125 | + } |
|
126 | + require $phpFile; |
|
127 | + |
|
128 | + return [$TRANSLATIONS, $PLURAL_FORMS]; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Return possible values for the named option |
|
133 | + * |
|
134 | + * @param string $optionName |
|
135 | + * @param CompletionContext $context |
|
136 | + * @return string[] |
|
137 | + */ |
|
138 | + public function completeOptionValues($optionName, CompletionContext $context) { |
|
139 | + return []; |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Return possible values for the named argument |
|
144 | + * |
|
145 | + * @param string $argumentName |
|
146 | + * @param CompletionContext $context |
|
147 | + * @return string[] |
|
148 | + */ |
|
149 | + public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
150 | + if ($argumentName === 'app') { |
|
151 | + return $this->appManager->getAllAppsInAppsFolders(); |
|
152 | + } elseif ($argumentName === 'lang') { |
|
153 | + $appName = $context->getWordAtIndex($context->getWordIndex() - 1); |
|
154 | + try { |
|
155 | + return $this->getAllLanguages($this->appManager->getAppPath($appName)); |
|
156 | + } catch (AppPathNotFoundException) { |
|
157 | + return []; |
|
158 | + } |
|
159 | + } |
|
160 | + return []; |
|
161 | + } |
|
162 | 162 | } |
@@ -73,7 +73,7 @@ |
||
73 | 73 | } |
74 | 74 | |
75 | 75 | $providers = $this->registry->getProviderStates($user); |
76 | - $state2fa = array_reduce($providers, function (bool $carry, bool $state) { |
|
76 | + $state2fa = array_reduce($providers, function(bool $carry, bool $state) { |
|
77 | 77 | return $carry || $state; |
78 | 78 | }, false); |
79 | 79 |
@@ -17,61 +17,61 @@ |
||
17 | 17 | |
18 | 18 | class RememberBackupCodesJob extends TimedJob { |
19 | 19 | |
20 | - public function __construct( |
|
21 | - private IRegistry $registry, |
|
22 | - private IUserManager $userManager, |
|
23 | - ITimeFactory $timeFactory, |
|
24 | - private IManager $notificationManager, |
|
25 | - private IJobList $jobList, |
|
26 | - ) { |
|
27 | - parent::__construct($timeFactory); |
|
28 | - $this->time = $timeFactory; |
|
20 | + public function __construct( |
|
21 | + private IRegistry $registry, |
|
22 | + private IUserManager $userManager, |
|
23 | + ITimeFactory $timeFactory, |
|
24 | + private IManager $notificationManager, |
|
25 | + private IJobList $jobList, |
|
26 | + ) { |
|
27 | + parent::__construct($timeFactory); |
|
28 | + $this->time = $timeFactory; |
|
29 | 29 | |
30 | - $this->setInterval(60 * 60 * 24 * 14); |
|
31 | - $this->setTimeSensitivity(self::TIME_INSENSITIVE); |
|
32 | - } |
|
30 | + $this->setInterval(60 * 60 * 24 * 14); |
|
31 | + $this->setTimeSensitivity(self::TIME_INSENSITIVE); |
|
32 | + } |
|
33 | 33 | |
34 | - protected function run($argument) { |
|
35 | - $uid = $argument['uid']; |
|
36 | - $user = $this->userManager->get($uid); |
|
34 | + protected function run($argument) { |
|
35 | + $uid = $argument['uid']; |
|
36 | + $user = $this->userManager->get($uid); |
|
37 | 37 | |
38 | - if ($user === null) { |
|
39 | - // We can't run with an invalid user |
|
40 | - $this->jobList->remove(self::class, $argument); |
|
41 | - return; |
|
42 | - } |
|
38 | + if ($user === null) { |
|
39 | + // We can't run with an invalid user |
|
40 | + $this->jobList->remove(self::class, $argument); |
|
41 | + return; |
|
42 | + } |
|
43 | 43 | |
44 | - $providers = $this->registry->getProviderStates($user); |
|
45 | - $state2fa = array_reduce($providers, function (bool $carry, bool $state) { |
|
46 | - return $carry || $state; |
|
47 | - }, false); |
|
44 | + $providers = $this->registry->getProviderStates($user); |
|
45 | + $state2fa = array_reduce($providers, function (bool $carry, bool $state) { |
|
46 | + return $carry || $state; |
|
47 | + }, false); |
|
48 | 48 | |
49 | - /* |
|
49 | + /* |
|
50 | 50 | * If no provider is active or if the backup codes are already generate |
51 | 51 | * we can remove the job |
52 | 52 | */ |
53 | - if ($state2fa === false || (isset($providers['backup_codes']) && $providers['backup_codes'] === true)) { |
|
54 | - // Backup codes already generated lets remove this job |
|
55 | - $this->jobList->remove(self::class, $argument); |
|
56 | - return; |
|
57 | - } |
|
53 | + if ($state2fa === false || (isset($providers['backup_codes']) && $providers['backup_codes'] === true)) { |
|
54 | + // Backup codes already generated lets remove this job |
|
55 | + $this->jobList->remove(self::class, $argument); |
|
56 | + return; |
|
57 | + } |
|
58 | 58 | |
59 | - $date = new \DateTime(); |
|
60 | - $date->setTimestamp($this->time->getTime()); |
|
59 | + $date = new \DateTime(); |
|
60 | + $date->setTimestamp($this->time->getTime()); |
|
61 | 61 | |
62 | - $notification = $this->notificationManager->createNotification(); |
|
63 | - $notification->setApp('twofactor_backupcodes') |
|
64 | - ->setUser($user->getUID()) |
|
65 | - ->setObject('create', 'codes') |
|
66 | - ->setSubject('create_backupcodes'); |
|
67 | - $this->notificationManager->markProcessed($notification); |
|
62 | + $notification = $this->notificationManager->createNotification(); |
|
63 | + $notification->setApp('twofactor_backupcodes') |
|
64 | + ->setUser($user->getUID()) |
|
65 | + ->setObject('create', 'codes') |
|
66 | + ->setSubject('create_backupcodes'); |
|
67 | + $this->notificationManager->markProcessed($notification); |
|
68 | 68 | |
69 | - if (!$user->isEnabled()) { |
|
70 | - // Don't recreate a notification for a user that can not read it |
|
71 | - $this->jobList->remove(self::class, $argument); |
|
72 | - return; |
|
73 | - } |
|
74 | - $notification->setDateTime($date); |
|
75 | - $this->notificationManager->notify($notification); |
|
76 | - } |
|
69 | + if (!$user->isEnabled()) { |
|
70 | + // Don't recreate a notification for a user that can not read it |
|
71 | + $this->jobList->remove(self::class, $argument); |
|
72 | + return; |
|
73 | + } |
|
74 | + $notification->setDateTime($date); |
|
75 | + $this->notificationManager->notify($notification); |
|
76 | + } |
|
77 | 77 | } |