@@ -41,48 +41,48 @@ |
||
41 | 41 | $is_optional = $parameter->isFlagSet(DefinitionParameter::FLAG_OPTIONAL); |
42 | 42 | |
43 | 43 | switch ($parameter->getType()) { |
44 | - case DefinitionParameter::VALUE_PASSWORD: ?> |
|
45 | - <?php if ($is_optional) { |
|
46 | - $classes[] = 'optional'; |
|
47 | - } ?> |
|
48 | - <input type="password" |
|
44 | + case DefinitionParameter::VALUE_PASSWORD: ?> |
|
45 | + <?php if ($is_optional) { |
|
46 | + $classes[] = 'optional'; |
|
47 | + } ?> |
|
48 | + <input type="password" |
|
49 | 49 | <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
50 | - data-parameter="<?php p($parameter->getName()); ?>" |
|
50 | + data-parameter="<?php p($parameter->getName()); ?>" |
|
51 | 51 | value="<?php p($value); ?>" |
52 | 52 | placeholder="<?php p($placeholder); ?>" |
53 | 53 | /> |
54 | 54 | <?php |
55 | - break; |
|
56 | - case DefinitionParameter::VALUE_BOOLEAN: ?> |
|
57 | - <?php $checkboxId = uniqid("checkbox_"); ?> |
|
55 | + break; |
|
56 | + case DefinitionParameter::VALUE_BOOLEAN: ?> |
|
57 | + <?php $checkboxId = uniqid("checkbox_"); ?> |
|
58 | 58 | <div> |
59 | 59 | <label> |
60 | 60 | <input type="checkbox" |
61 | 61 | id="<?php p($checkboxId); ?>" |
62 | 62 | <?php if (!empty($classes)): ?> class="checkbox <?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
63 | - data-parameter="<?php p($parameter->getName()); ?>" |
|
63 | + data-parameter="<?php p($parameter->getName()); ?>" |
|
64 | 64 | <?php if ($value === true): ?> checked="checked"<?php endif; ?> |
65 | - /> |
|
65 | + /> |
|
66 | 66 | <?php p($placeholder); ?> |
67 | 67 | </label> |
68 | 68 | </div> |
69 | 69 | <?php |
70 | - break; |
|
71 | - case DefinitionParameter::VALUE_HIDDEN: ?> |
|
72 | - <input type="hidden" |
|
70 | + break; |
|
71 | + case DefinitionParameter::VALUE_HIDDEN: ?> |
|
72 | + <input type="hidden" |
|
73 | 73 | <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
74 | - data-parameter="<?php p($parameter->getName()); ?>" |
|
74 | + data-parameter="<?php p($parameter->getName()); ?>" |
|
75 | 75 | value="<?php p($value); ?>" |
76 | 76 | /> |
77 | 77 | <?php |
78 | - break; |
|
79 | - default: ?> |
|
80 | - <?php if ($is_optional) { |
|
81 | - $classes[] = 'optional'; |
|
82 | - } ?> |
|
83 | - <input type="text" |
|
78 | + break; |
|
79 | + default: ?> |
|
80 | + <?php if ($is_optional) { |
|
81 | + $classes[] = 'optional'; |
|
82 | + } ?> |
|
83 | + <input type="text" |
|
84 | 84 | <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
85 | - data-parameter="<?php p($parameter->getName()); ?>" |
|
85 | + data-parameter="<?php p($parameter->getName()); ?>" |
|
86 | 86 | value="<?php p($value); ?>" |
87 | 87 | placeholder="<?php p($placeholder); ?>" |
88 | 88 | /> |
@@ -194,8 +194,11 @@ |
||
194 | 194 | <?php $i = 0; foreach ($userBackends as $backend): ?> |
195 | 195 | <?php if ($deprecateTo = $backend->getDeprecateTo()): ?> |
196 | 196 | <input type="hidden" id="allowUserMountingBackends<?php p($i); ?>" name="allowUserMountingBackends[]" value="<?php p($backend->getIdentifier()); ?>" data-deprecate-to="<?php p($deprecateTo->getIdentifier()); ?>" /> |
197 | - <?php else: ?> |
|
198 | - <input type="checkbox" id="allowUserMountingBackends<?php p($i); ?>" class="checkbox" name="allowUserMountingBackends[]" value="<?php p($backend->getIdentifier()); ?>" <?php if ($backend->isVisibleFor(BackendService::VISIBILITY_PERSONAL)) { |
|
197 | + <?php else { |
|
198 | + : ?> |
|
199 | + <input type="checkbox" id="allowUserMountingBackends<?php p($i); |
|
200 | +} |
|
201 | +?>" class="checkbox" name="allowUserMountingBackends[]" value="<?php p($backend->getIdentifier()); ?>" <?php if ($backend->isVisibleFor(BackendService::VISIBILITY_PERSONAL)) { |
|
199 | 202 | print_unescaped(' checked="checked"'); |
200 | 203 | } ?> /> |
201 | 204 | <label for="allowUserMountingBackends<?php p($i); ?>"><?php p($backend->getText()); ?></label> <br /> |
@@ -103,9 +103,9 @@ discard block |
||
103 | 103 | <?php |
104 | 104 | $canCreateNewLocalStorage = \OC::$server->getConfig()->getSystemValue('files_external_allow_create_new_local', true); |
105 | 105 | ?> |
106 | -<form data-can-create="<?php echo $canCreateMounts?'true':'false' ?>" data-can-create-local="<?php echo $canCreateNewLocalStorage?'true':'false' ?>" id="files_external" class="section" data-encryption-enabled="<?php echo $_['encryptionEnabled']?'true': 'false'; ?>"> |
|
106 | +<form data-can-create="<?php echo $canCreateMounts ? 'true' : 'false' ?>" data-can-create-local="<?php echo $canCreateNewLocalStorage ? 'true' : 'false' ?>" id="files_external" class="section" data-encryption-enabled="<?php echo $_['encryptionEnabled'] ? 'true' : 'false'; ?>"> |
|
107 | 107 | <h2 class="inlineblock" data-anchor-name="external-storage"><?php p($l->t('External storage')); ?></h2> |
108 | - <a target="_blank" rel="noreferrer" class="icon-info" title="<?php p($l->t('Open documentation'));?>" href="<?php p(link_to_docs('admin-external-storage')); ?>"></a> |
|
108 | + <a target="_blank" rel="noreferrer" class="icon-info" title="<?php p($l->t('Open documentation')); ?>" href="<?php p(link_to_docs('admin-external-storage')); ?>"></a> |
|
109 | 109 | <p class="settings-hint"><?php p($l->t('External storage enables you to mount external storage services and devices as secondary Nextcloud storage devices. You may also allow users to mount their own external storage services.')); ?></p> |
110 | 110 | <?php if (isset($_['dependencies']) and ($_['dependencies'] !== '') and $canCreateMounts) { |
111 | 111 | print_unescaped(''.$_['dependencies'].''); |
@@ -150,10 +150,10 @@ discard block |
||
150 | 150 | <?php p($l->t('Add storage')); ?> |
151 | 151 | </option> |
152 | 152 | <?php |
153 | - $sortedBackends = array_filter($_['backends'], function ($backend) use ($_) { |
|
153 | + $sortedBackends = array_filter($_['backends'], function($backend) use ($_) { |
|
154 | 154 | return $backend->isVisibleFor($_['visibilityType']); |
155 | 155 | }); |
156 | - uasort($sortedBackends, function ($a, $b) { |
|
156 | + uasort($sortedBackends, function($a, $b) { |
|
157 | 157 | return strcasecmp($a->getText(), $b->getText()); |
158 | 158 | }); |
159 | 159 | ?> |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | |
193 | 193 | <p id="userMountingBackends"<?php if (!$_['allowUserMounting']): ?> class="hidden"<?php endif; ?>> |
194 | 194 | <?php |
195 | - $userBackends = array_filter($_['backends'], function ($backend) { |
|
195 | + $userBackends = array_filter($_['backends'], function($backend) { |
|
196 | 196 | return $backend->isAllowedVisibleFor(BackendService::VISIBILITY_PERSONAL); |
197 | 197 | }); |
198 | 198 | ?> |
@@ -8,49 +8,49 @@ discard block |
||
8 | 8 | |
9 | 9 | $canCreateMounts = $_['visibilityType'] === BackendService::VISIBILITY_ADMIN || $_['allowUserMounting']; |
10 | 10 | |
11 | - $l->t("Enable encryption"); |
|
12 | - $l->t("Enable previews"); |
|
13 | - $l->t("Enable sharing"); |
|
14 | - $l->t("Check for changes"); |
|
15 | - $l->t("Never"); |
|
16 | - $l->t("Once every direct access"); |
|
17 | - $l->t('Read only'); |
|
11 | + $l->t("Enable encryption"); |
|
12 | + $l->t("Enable previews"); |
|
13 | + $l->t("Enable sharing"); |
|
14 | + $l->t("Check for changes"); |
|
15 | + $l->t("Never"); |
|
16 | + $l->t("Once every direct access"); |
|
17 | + $l->t('Read only'); |
|
18 | 18 | |
19 | - script('files_external', [ |
|
20 | - 'settings', |
|
21 | - 'templates' |
|
22 | - ]); |
|
23 | - style('files_external', 'settings'); |
|
19 | + script('files_external', [ |
|
20 | + 'settings', |
|
21 | + 'templates' |
|
22 | + ]); |
|
23 | + style('files_external', 'settings'); |
|
24 | 24 | |
25 | - // load custom JS |
|
26 | - foreach ($_['backends'] as $backend) { |
|
27 | - /** @var Backend $backend */ |
|
28 | - $scripts = $backend->getCustomJs(); |
|
29 | - foreach ($scripts as $script) { |
|
30 | - script('files_external', $script); |
|
31 | - } |
|
32 | - } |
|
33 | - foreach ($_['authMechanisms'] as $authMechanism) { |
|
34 | - /** @var AuthMechanism $authMechanism */ |
|
35 | - $scripts = $authMechanism->getCustomJs(); |
|
36 | - foreach ($scripts as $script) { |
|
37 | - script('files_external', $script); |
|
38 | - } |
|
39 | - } |
|
25 | + // load custom JS |
|
26 | + foreach ($_['backends'] as $backend) { |
|
27 | + /** @var Backend $backend */ |
|
28 | + $scripts = $backend->getCustomJs(); |
|
29 | + foreach ($scripts as $script) { |
|
30 | + script('files_external', $script); |
|
31 | + } |
|
32 | + } |
|
33 | + foreach ($_['authMechanisms'] as $authMechanism) { |
|
34 | + /** @var AuthMechanism $authMechanism */ |
|
35 | + $scripts = $authMechanism->getCustomJs(); |
|
36 | + foreach ($scripts as $script) { |
|
37 | + script('files_external', $script); |
|
38 | + } |
|
39 | + } |
|
40 | 40 | |
41 | - function writeParameterInput($parameter, $options, $classes = []) { |
|
42 | - $value = ''; |
|
43 | - if (isset($options[$parameter->getName()])) { |
|
44 | - $value = $options[$parameter->getName()]; |
|
45 | - } |
|
46 | - $placeholder = $parameter->getText(); |
|
47 | - $is_optional = $parameter->isFlagSet(DefinitionParameter::FLAG_OPTIONAL); |
|
41 | + function writeParameterInput($parameter, $options, $classes = []) { |
|
42 | + $value = ''; |
|
43 | + if (isset($options[$parameter->getName()])) { |
|
44 | + $value = $options[$parameter->getName()]; |
|
45 | + } |
|
46 | + $placeholder = $parameter->getText(); |
|
47 | + $is_optional = $parameter->isFlagSet(DefinitionParameter::FLAG_OPTIONAL); |
|
48 | 48 | |
49 | - switch ($parameter->getType()) { |
|
50 | - case DefinitionParameter::VALUE_PASSWORD: ?> |
|
49 | + switch ($parameter->getType()) { |
|
50 | + case DefinitionParameter::VALUE_PASSWORD: ?> |
|
51 | 51 | <?php if ($is_optional) { |
52 | - $classes[] = 'optional'; |
|
53 | - } ?> |
|
52 | + $classes[] = 'optional'; |
|
53 | + } ?> |
|
54 | 54 | <input type="password" |
55 | 55 | <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
56 | 56 | data-parameter="<?php p($parameter->getName()); ?>" |
@@ -58,8 +58,8 @@ discard block |
||
58 | 58 | placeholder="<?php p($placeholder); ?>" |
59 | 59 | /> |
60 | 60 | <?php |
61 | - break; |
|
62 | - case DefinitionParameter::VALUE_BOOLEAN: ?> |
|
61 | + break; |
|
62 | + case DefinitionParameter::VALUE_BOOLEAN: ?> |
|
63 | 63 | <?php $checkboxId = uniqid("checkbox_"); ?> |
64 | 64 | <div> |
65 | 65 | <label> |
@@ -73,19 +73,19 @@ discard block |
||
73 | 73 | </label> |
74 | 74 | </div> |
75 | 75 | <?php |
76 | - break; |
|
77 | - case DefinitionParameter::VALUE_HIDDEN: ?> |
|
76 | + break; |
|
77 | + case DefinitionParameter::VALUE_HIDDEN: ?> |
|
78 | 78 | <input type="hidden" |
79 | 79 | <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
80 | 80 | data-parameter="<?php p($parameter->getName()); ?>" |
81 | 81 | value="<?php p($value); ?>" |
82 | 82 | /> |
83 | 83 | <?php |
84 | - break; |
|
85 | - default: ?> |
|
84 | + break; |
|
85 | + default: ?> |
|
86 | 86 | <?php if ($is_optional) { |
87 | - $classes[] = 'optional'; |
|
88 | - } ?> |
|
87 | + $classes[] = 'optional'; |
|
88 | + } ?> |
|
89 | 89 | <input type="text" |
90 | 90 | <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
91 | 91 | data-parameter="<?php p($parameter->getName()); ?>" |
@@ -93,8 +93,8 @@ discard block |
||
93 | 93 | placeholder="<?php p($placeholder); ?>" |
94 | 94 | /> |
95 | 95 | <?php |
96 | - } |
|
97 | - } |
|
96 | + } |
|
97 | + } |
|
98 | 98 | ?> |
99 | 99 | |
100 | 100 | <div class="emptyfilelist emptycontent hidden"> |
@@ -103,14 +103,14 @@ discard block |
||
103 | 103 | </div> |
104 | 104 | |
105 | 105 | <?php |
106 | - $canCreateNewLocalStorage = \OC::$server->getConfig()->getSystemValue('files_external_allow_create_new_local', true); |
|
106 | + $canCreateNewLocalStorage = \OC::$server->getConfig()->getSystemValue('files_external_allow_create_new_local', true); |
|
107 | 107 | ?> |
108 | 108 | <form data-can-create="<?php echo $canCreateMounts?'true':'false' ?>" data-can-create-local="<?php echo $canCreateNewLocalStorage?'true':'false' ?>" id="files_external" class="section" data-encryption-enabled="<?php echo $_['encryptionEnabled']?'true': 'false'; ?>"> |
109 | 109 | <h2 class="inlineblock" data-anchor-name="external-storage"><?php p($l->t('External storage')); ?></h2> |
110 | 110 | <a target="_blank" rel="noreferrer" class="icon-info" title="<?php p($l->t('Open documentation'));?>" href="<?php p(link_to_docs('admin-external-storage')); ?>"></a> |
111 | 111 | <p class="settings-hint"><?php p($l->t('External storage enables you to mount external storage services and devices as secondary Nextcloud storage devices. You may also allow users to mount their own external storage services.')); ?></p> |
112 | 112 | <?php if (isset($_['dependencies']) and ($_['dependencies'] !== '') and $canCreateMounts) { |
113 | - print_unescaped(''.$_['dependencies'].''); |
|
113 | + print_unescaped(''.$_['dependencies'].''); |
|
114 | 114 | } ?> |
115 | 115 | <table id="externalStorage" class="grid" data-admin='<?php print_unescaped(json_encode($_['visibilityType'] === BackendService::VISIBILITY_ADMIN)); ?>'> |
116 | 116 | <thead> |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | <th><?php p($l->t('Authentication')); ?></th> |
122 | 122 | <th><?php p($l->t('Configuration')); ?></th> |
123 | 123 | <?php if ($_['visibilityType'] === BackendService::VISIBILITY_ADMIN) { |
124 | - print_unescaped('<th>'.$l->t('Available for').'</th>'); |
|
124 | + print_unescaped('<th>'.$l->t('Available for').'</th>'); |
|
125 | 125 | } ?> |
126 | 126 | <th> </th> |
127 | 127 | <th> </th> |
@@ -152,17 +152,17 @@ discard block |
||
152 | 152 | <?php p($l->t('Add storage')); ?> |
153 | 153 | </option> |
154 | 154 | <?php |
155 | - $sortedBackends = array_filter($_['backends'], function ($backend) use ($_) { |
|
156 | - return $backend->isVisibleFor($_['visibilityType']); |
|
157 | - }); |
|
158 | - uasort($sortedBackends, function ($a, $b) { |
|
159 | - return strcasecmp($a->getText(), $b->getText()); |
|
160 | - }); |
|
161 | - ?> |
|
155 | + $sortedBackends = array_filter($_['backends'], function ($backend) use ($_) { |
|
156 | + return $backend->isVisibleFor($_['visibilityType']); |
|
157 | + }); |
|
158 | + uasort($sortedBackends, function ($a, $b) { |
|
159 | + return strcasecmp($a->getText(), $b->getText()); |
|
160 | + }); |
|
161 | + ?> |
|
162 | 162 | <?php foreach ($sortedBackends as $backend): ?> |
163 | 163 | <?php if ($backend->getDeprecateTo() || (!$canCreateNewLocalStorage && $backend->getIdentifier() == "local")) { |
164 | - continue; |
|
165 | - } // ignore deprecated backends?> |
|
164 | + continue; |
|
165 | + } // ignore deprecated backends?> |
|
166 | 166 | <option value="<?php p($backend->getIdentifier()); ?>"><?php p($backend->getText()); ?></option> |
167 | 167 | <?php endforeach; ?> |
168 | 168 | </select> |
@@ -188,23 +188,23 @@ discard block |
||
188 | 188 | <?php if ($_['visibilityType'] === BackendService::VISIBILITY_ADMIN): ?> |
189 | 189 | <input type="checkbox" name="allowUserMounting" id="allowUserMounting" class="checkbox" |
190 | 190 | value="1" <?php if ($_['allowUserMounting']) { |
191 | - print_unescaped(' checked="checked"'); |
|
192 | - } ?> /> |
|
191 | + print_unescaped(' checked="checked"'); |
|
192 | + } ?> /> |
|
193 | 193 | <label for="allowUserMounting"><?php p($l->t('Allow users to mount external storage')); ?></label> <span id="userMountingMsg" class="msg"></span> |
194 | 194 | |
195 | 195 | <p id="userMountingBackends"<?php if (!$_['allowUserMounting']): ?> class="hidden"<?php endif; ?>> |
196 | 196 | <?php |
197 | - $userBackends = array_filter($_['backends'], function ($backend) { |
|
198 | - return $backend->isAllowedVisibleFor(BackendService::VISIBILITY_PERSONAL); |
|
199 | - }); |
|
200 | - ?> |
|
197 | + $userBackends = array_filter($_['backends'], function ($backend) { |
|
198 | + return $backend->isAllowedVisibleFor(BackendService::VISIBILITY_PERSONAL); |
|
199 | + }); |
|
200 | + ?> |
|
201 | 201 | <?php $i = 0; foreach ($userBackends as $backend): ?> |
202 | 202 | <?php if ($deprecateTo = $backend->getDeprecateTo()): ?> |
203 | 203 | <input type="hidden" id="allowUserMountingBackends<?php p($i); ?>" name="allowUserMountingBackends[]" value="<?php p($backend->getIdentifier()); ?>" data-deprecate-to="<?php p($deprecateTo->getIdentifier()); ?>" /> |
204 | 204 | <?php else: ?> |
205 | 205 | <input type="checkbox" id="allowUserMountingBackends<?php p($i); ?>" class="checkbox" name="allowUserMountingBackends[]" value="<?php p($backend->getIdentifier()); ?>" <?php if ($backend->isVisibleFor(BackendService::VISIBILITY_PERSONAL)) { |
206 | - print_unescaped(' checked="checked"'); |
|
207 | - } ?> /> |
|
206 | + print_unescaped(' checked="checked"'); |
|
207 | + } ?> /> |
|
208 | 208 | <label for="allowUserMountingBackends<?php p($i); ?>"><?php p($backend->getText()); ?></label> <br /> |
209 | 209 | <?php endif; ?> |
210 | 210 | <?php $i++; ?> |
@@ -29,40 +29,40 @@ |
||
29 | 29 | |
30 | 30 | class FedAuth extends AbstractBasic { |
31 | 31 | |
32 | - /** @var DbHandler */ |
|
33 | - private $db; |
|
32 | + /** @var DbHandler */ |
|
33 | + private $db; |
|
34 | 34 | |
35 | - /** |
|
36 | - * FedAuth constructor. |
|
37 | - * |
|
38 | - * @param DbHandler $db |
|
39 | - */ |
|
40 | - public function __construct(DbHandler $db) { |
|
41 | - $this->db = $db; |
|
42 | - $this->principalPrefix = 'principals/system/'; |
|
35 | + /** |
|
36 | + * FedAuth constructor. |
|
37 | + * |
|
38 | + * @param DbHandler $db |
|
39 | + */ |
|
40 | + public function __construct(DbHandler $db) { |
|
41 | + $this->db = $db; |
|
42 | + $this->principalPrefix = 'principals/system/'; |
|
43 | 43 | |
44 | - // setup realm |
|
45 | - $defaults = new \OCP\Defaults(); |
|
46 | - $this->realm = $defaults->getName(); |
|
47 | - } |
|
44 | + // setup realm |
|
45 | + $defaults = new \OCP\Defaults(); |
|
46 | + $this->realm = $defaults->getName(); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Validates a username and password |
|
51 | - * |
|
52 | - * This method should return true or false depending on if login |
|
53 | - * succeeded. |
|
54 | - * |
|
55 | - * @param string $username |
|
56 | - * @param string $password |
|
57 | - * @return bool |
|
58 | - */ |
|
59 | - protected function validateUserPass($username, $password) { |
|
60 | - return $this->db->auth($username, $password); |
|
61 | - } |
|
49 | + /** |
|
50 | + * Validates a username and password |
|
51 | + * |
|
52 | + * This method should return true or false depending on if login |
|
53 | + * succeeded. |
|
54 | + * |
|
55 | + * @param string $username |
|
56 | + * @param string $password |
|
57 | + * @return bool |
|
58 | + */ |
|
59 | + protected function validateUserPass($username, $password) { |
|
60 | + return $this->db->auth($username, $password); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @inheritdoc |
|
65 | - */ |
|
66 | - public function challenge(RequestInterface $request, ResponseInterface $response) { |
|
67 | - } |
|
63 | + /** |
|
64 | + * @inheritdoc |
|
65 | + */ |
|
66 | + public function challenge(RequestInterface $request, ResponseInterface $response) { |
|
67 | + } |
|
68 | 68 | } |
@@ -29,32 +29,32 @@ |
||
29 | 29 | |
30 | 30 | class LastUsedController extends Controller { |
31 | 31 | |
32 | - /** @var IConfig */ |
|
33 | - protected $config; |
|
32 | + /** @var IConfig */ |
|
33 | + protected $config; |
|
34 | 34 | |
35 | - /** @var IUserSession */ |
|
36 | - protected $userSession; |
|
35 | + /** @var IUserSession */ |
|
36 | + protected $userSession; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @param string $appName |
|
40 | - * @param IRequest $request |
|
41 | - * @param IConfig $config |
|
42 | - * @param IUserSession $userSession |
|
43 | - */ |
|
44 | - public function __construct($appName, IRequest $request, IConfig $config, IUserSession $userSession) { |
|
45 | - parent::__construct($appName, $request); |
|
46 | - $this->config = $config; |
|
47 | - $this->userSession = $userSession; |
|
48 | - } |
|
38 | + /** |
|
39 | + * @param string $appName |
|
40 | + * @param IRequest $request |
|
41 | + * @param IConfig $config |
|
42 | + * @param IUserSession $userSession |
|
43 | + */ |
|
44 | + public function __construct($appName, IRequest $request, IConfig $config, IUserSession $userSession) { |
|
45 | + parent::__construct($appName, $request); |
|
46 | + $this->config = $config; |
|
47 | + $this->userSession = $userSession; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @NoAdminRequired |
|
52 | - */ |
|
53 | - public function getLastUsedTagIds() { |
|
54 | - $lastUsed = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'systemtags', 'last_used', '[]'); |
|
55 | - $tagIds = json_decode($lastUsed, true); |
|
56 | - return new DataResponse(array_map(function ($id) { |
|
57 | - return (string) $id; |
|
58 | - }, $tagIds)); |
|
59 | - } |
|
50 | + /** |
|
51 | + * @NoAdminRequired |
|
52 | + */ |
|
53 | + public function getLastUsedTagIds() { |
|
54 | + $lastUsed = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'systemtags', 'last_used', '[]'); |
|
55 | + $tagIds = json_decode($lastUsed, true); |
|
56 | + return new DataResponse(array_map(function ($id) { |
|
57 | + return (string) $id; |
|
58 | + }, $tagIds)); |
|
59 | + } |
|
60 | 60 | } |
@@ -53,7 +53,7 @@ |
||
53 | 53 | public function getLastUsedTagIds() { |
54 | 54 | $lastUsed = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'systemtags', 'last_used', '[]'); |
55 | 55 | $tagIds = json_decode($lastUsed, true); |
56 | - return new DataResponse(array_map(function ($id) { |
|
56 | + return new DataResponse(array_map(function($id) { |
|
57 | 57 | return (string) $id; |
58 | 58 | }, $tagIds)); |
59 | 59 | } |
@@ -31,30 +31,30 @@ |
||
31 | 31 | use OCP\Command\ICommand; |
32 | 32 | |
33 | 33 | class Expire implements ICommand { |
34 | - use FileAccess; |
|
34 | + use FileAccess; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - private $user; |
|
36 | + /** |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + private $user; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param string $user |
|
43 | - */ |
|
44 | - public function __construct($user) { |
|
45 | - $this->user = $user; |
|
46 | - } |
|
41 | + /** |
|
42 | + * @param string $user |
|
43 | + */ |
|
44 | + public function __construct($user) { |
|
45 | + $this->user = $user; |
|
46 | + } |
|
47 | 47 | |
48 | - public function handle() { |
|
49 | - $userManager = \OC::$server->getUserManager(); |
|
50 | - if (!$userManager->userExists($this->user)) { |
|
51 | - // User has been deleted already |
|
52 | - return; |
|
53 | - } |
|
48 | + public function handle() { |
|
49 | + $userManager = \OC::$server->getUserManager(); |
|
50 | + if (!$userManager->userExists($this->user)) { |
|
51 | + // User has been deleted already |
|
52 | + return; |
|
53 | + } |
|
54 | 54 | |
55 | - \OC_Util::tearDownFS(); |
|
56 | - \OC_Util::setupFS($this->user); |
|
57 | - Trashbin::expire($this->user); |
|
58 | - \OC_Util::tearDownFS(); |
|
59 | - } |
|
55 | + \OC_Util::tearDownFS(); |
|
56 | + \OC_Util::setupFS($this->user); |
|
57 | + Trashbin::expire($this->user); |
|
58 | + \OC_Util::tearDownFS(); |
|
59 | + } |
|
60 | 60 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | } else { |
91 | 91 | $p = new ProgressBar($output); |
92 | 92 | $p->start(); |
93 | - $this->userManager->callForSeenUsers(function (IUser $user) use ($p) { |
|
93 | + $this->userManager->callForSeenUsers(function(IUser $user) use ($p) { |
|
94 | 94 | $p->advance(); |
95 | 95 | $this->expireTrashForUser($user); |
96 | 96 | }); |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | \OC_Util::setupFS($user); |
119 | 119 | |
120 | 120 | // Check if this user has a trashbin directory |
121 | - $view = new \OC\Files\View('/' . $user); |
|
121 | + $view = new \OC\Files\View('/'.$user); |
|
122 | 122 | if (!$view->is_dir('/files_trashbin/files')) { |
123 | 123 | return false; |
124 | 124 | } |
@@ -38,95 +38,95 @@ |
||
38 | 38 | |
39 | 39 | class ExpireTrash extends Command { |
40 | 40 | |
41 | - /** |
|
42 | - * @var Expiration |
|
43 | - */ |
|
44 | - private $expiration; |
|
41 | + /** |
|
42 | + * @var Expiration |
|
43 | + */ |
|
44 | + private $expiration; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @var IUserManager |
|
48 | - */ |
|
49 | - private $userManager; |
|
46 | + /** |
|
47 | + * @var IUserManager |
|
48 | + */ |
|
49 | + private $userManager; |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param IUserManager|null $userManager |
|
53 | - * @param Expiration|null $expiration |
|
54 | - */ |
|
55 | - public function __construct(IUserManager $userManager = null, |
|
56 | - Expiration $expiration = null) { |
|
57 | - parent::__construct(); |
|
51 | + /** |
|
52 | + * @param IUserManager|null $userManager |
|
53 | + * @param Expiration|null $expiration |
|
54 | + */ |
|
55 | + public function __construct(IUserManager $userManager = null, |
|
56 | + Expiration $expiration = null) { |
|
57 | + parent::__construct(); |
|
58 | 58 | |
59 | - $this->userManager = $userManager; |
|
60 | - $this->expiration = $expiration; |
|
61 | - } |
|
59 | + $this->userManager = $userManager; |
|
60 | + $this->expiration = $expiration; |
|
61 | + } |
|
62 | 62 | |
63 | - protected function configure() { |
|
64 | - $this |
|
65 | - ->setName('trashbin:expire') |
|
66 | - ->setDescription('Expires the users trashbin') |
|
67 | - ->addArgument( |
|
68 | - 'user_id', |
|
69 | - InputArgument::OPTIONAL | InputArgument::IS_ARRAY, |
|
70 | - 'expires the trashbin of the given user(s), if no user is given the trash for all users will be expired' |
|
71 | - ); |
|
72 | - } |
|
63 | + protected function configure() { |
|
64 | + $this |
|
65 | + ->setName('trashbin:expire') |
|
66 | + ->setDescription('Expires the users trashbin') |
|
67 | + ->addArgument( |
|
68 | + 'user_id', |
|
69 | + InputArgument::OPTIONAL | InputArgument::IS_ARRAY, |
|
70 | + 'expires the trashbin of the given user(s), if no user is given the trash for all users will be expired' |
|
71 | + ); |
|
72 | + } |
|
73 | 73 | |
74 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
75 | - $maxAge = $this->expiration->getMaxAgeAsTimestamp(); |
|
76 | - if (!$maxAge) { |
|
77 | - $output->writeln("Auto expiration is configured - keeps files and folders in the trash bin for 30 days and automatically deletes anytime after that if space is needed (note: files may not be deleted if space is not needed)"); |
|
78 | - return 1; |
|
79 | - } |
|
74 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
75 | + $maxAge = $this->expiration->getMaxAgeAsTimestamp(); |
|
76 | + if (!$maxAge) { |
|
77 | + $output->writeln("Auto expiration is configured - keeps files and folders in the trash bin for 30 days and automatically deletes anytime after that if space is needed (note: files may not be deleted if space is not needed)"); |
|
78 | + return 1; |
|
79 | + } |
|
80 | 80 | |
81 | - $users = $input->getArgument('user_id'); |
|
82 | - if (!empty($users)) { |
|
83 | - foreach ($users as $user) { |
|
84 | - if ($this->userManager->userExists($user)) { |
|
85 | - $output->writeln("Remove deleted files of <info>$user</info>"); |
|
86 | - $userObject = $this->userManager->get($user); |
|
87 | - $this->expireTrashForUser($userObject); |
|
88 | - } else { |
|
89 | - $output->writeln("<error>Unknown user $user</error>"); |
|
90 | - return 1; |
|
91 | - } |
|
92 | - } |
|
93 | - } else { |
|
94 | - $p = new ProgressBar($output); |
|
95 | - $p->start(); |
|
96 | - $this->userManager->callForSeenUsers(function (IUser $user) use ($p) { |
|
97 | - $p->advance(); |
|
98 | - $this->expireTrashForUser($user); |
|
99 | - }); |
|
100 | - $p->finish(); |
|
101 | - $output->writeln(''); |
|
102 | - } |
|
103 | - return 0; |
|
104 | - } |
|
81 | + $users = $input->getArgument('user_id'); |
|
82 | + if (!empty($users)) { |
|
83 | + foreach ($users as $user) { |
|
84 | + if ($this->userManager->userExists($user)) { |
|
85 | + $output->writeln("Remove deleted files of <info>$user</info>"); |
|
86 | + $userObject = $this->userManager->get($user); |
|
87 | + $this->expireTrashForUser($userObject); |
|
88 | + } else { |
|
89 | + $output->writeln("<error>Unknown user $user</error>"); |
|
90 | + return 1; |
|
91 | + } |
|
92 | + } |
|
93 | + } else { |
|
94 | + $p = new ProgressBar($output); |
|
95 | + $p->start(); |
|
96 | + $this->userManager->callForSeenUsers(function (IUser $user) use ($p) { |
|
97 | + $p->advance(); |
|
98 | + $this->expireTrashForUser($user); |
|
99 | + }); |
|
100 | + $p->finish(); |
|
101 | + $output->writeln(''); |
|
102 | + } |
|
103 | + return 0; |
|
104 | + } |
|
105 | 105 | |
106 | - public function expireTrashForUser(IUser $user) { |
|
107 | - $uid = $user->getUID(); |
|
108 | - if (!$this->setupFS($uid)) { |
|
109 | - return; |
|
110 | - } |
|
111 | - $dirContent = Helper::getTrashFiles('/', $uid, 'mtime'); |
|
112 | - Trashbin::deleteExpiredFiles($dirContent, $uid); |
|
113 | - } |
|
106 | + public function expireTrashForUser(IUser $user) { |
|
107 | + $uid = $user->getUID(); |
|
108 | + if (!$this->setupFS($uid)) { |
|
109 | + return; |
|
110 | + } |
|
111 | + $dirContent = Helper::getTrashFiles('/', $uid, 'mtime'); |
|
112 | + Trashbin::deleteExpiredFiles($dirContent, $uid); |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * Act on behalf on trash item owner |
|
117 | - * @param string $user |
|
118 | - * @return boolean |
|
119 | - */ |
|
120 | - protected function setupFS($user) { |
|
121 | - \OC_Util::tearDownFS(); |
|
122 | - \OC_Util::setupFS($user); |
|
115 | + /** |
|
116 | + * Act on behalf on trash item owner |
|
117 | + * @param string $user |
|
118 | + * @return boolean |
|
119 | + */ |
|
120 | + protected function setupFS($user) { |
|
121 | + \OC_Util::tearDownFS(); |
|
122 | + \OC_Util::setupFS($user); |
|
123 | 123 | |
124 | - // Check if this user has a trashbin directory |
|
125 | - $view = new \OC\Files\View('/' . $user); |
|
126 | - if (!$view->is_dir('/files_trashbin/files')) { |
|
127 | - return false; |
|
128 | - } |
|
124 | + // Check if this user has a trashbin directory |
|
125 | + $view = new \OC\Files\View('/' . $user); |
|
126 | + if (!$view->is_dir('/files_trashbin/files')) { |
|
127 | + return false; |
|
128 | + } |
|
129 | 129 | |
130 | - return true; |
|
131 | - } |
|
130 | + return true; |
|
131 | + } |
|
132 | 132 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | return; |
79 | 79 | } |
80 | 80 | |
81 | - $this->userManager->callForSeenUsers(function (IUser $user) { |
|
81 | + $this->userManager->callForSeenUsers(function(IUser $user) { |
|
82 | 82 | $uid = $user->getUID(); |
83 | 83 | if (!$this->setupFS($uid)) { |
84 | 84 | return; |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | \OC_Util::setupFS($user); |
101 | 101 | |
102 | 102 | // Check if this user has a trashbin directory |
103 | - $view = new \OC\Files\View('/' . $user); |
|
103 | + $view = new \OC\Files\View('/'.$user); |
|
104 | 104 | if (!$view->is_dir('/files_trashbin/files')) { |
105 | 105 | return false; |
106 | 106 | } |
@@ -37,65 +37,65 @@ |
||
37 | 37 | use OCP\IUserManager; |
38 | 38 | |
39 | 39 | class ExpireTrash extends TimedJob { |
40 | - private IConfig $config; |
|
41 | - private Expiration $expiration; |
|
42 | - private IUserManager $userManager; |
|
40 | + private IConfig $config; |
|
41 | + private Expiration $expiration; |
|
42 | + private IUserManager $userManager; |
|
43 | 43 | |
44 | - public function __construct( |
|
45 | - IConfig $config, |
|
46 | - IUserManager $userManager, |
|
47 | - Expiration $expiration, |
|
48 | - ITimeFactory $time |
|
49 | - ) { |
|
50 | - parent::__construct($time); |
|
51 | - // Run once per 30 minutes |
|
52 | - $this->setInterval(60 * 30); |
|
44 | + public function __construct( |
|
45 | + IConfig $config, |
|
46 | + IUserManager $userManager, |
|
47 | + Expiration $expiration, |
|
48 | + ITimeFactory $time |
|
49 | + ) { |
|
50 | + parent::__construct($time); |
|
51 | + // Run once per 30 minutes |
|
52 | + $this->setInterval(60 * 30); |
|
53 | 53 | |
54 | - $this->config = $config; |
|
55 | - $this->userManager = $userManager; |
|
56 | - $this->expiration = $expiration; |
|
57 | - } |
|
54 | + $this->config = $config; |
|
55 | + $this->userManager = $userManager; |
|
56 | + $this->expiration = $expiration; |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @param $argument |
|
61 | - * @throws \Exception |
|
62 | - */ |
|
63 | - protected function run($argument) { |
|
64 | - $backgroundJob = $this->config->getAppValue('files_trashbin', 'background_job_expire_trash', 'yes'); |
|
65 | - if ($backgroundJob === 'no') { |
|
66 | - return; |
|
67 | - } |
|
59 | + /** |
|
60 | + * @param $argument |
|
61 | + * @throws \Exception |
|
62 | + */ |
|
63 | + protected function run($argument) { |
|
64 | + $backgroundJob = $this->config->getAppValue('files_trashbin', 'background_job_expire_trash', 'yes'); |
|
65 | + if ($backgroundJob === 'no') { |
|
66 | + return; |
|
67 | + } |
|
68 | 68 | |
69 | - $maxAge = $this->expiration->getMaxAgeAsTimestamp(); |
|
70 | - if (!$maxAge) { |
|
71 | - return; |
|
72 | - } |
|
69 | + $maxAge = $this->expiration->getMaxAgeAsTimestamp(); |
|
70 | + if (!$maxAge) { |
|
71 | + return; |
|
72 | + } |
|
73 | 73 | |
74 | - $this->userManager->callForSeenUsers(function (IUser $user) { |
|
75 | - $uid = $user->getUID(); |
|
76 | - if (!$this->setupFS($uid)) { |
|
77 | - return; |
|
78 | - } |
|
79 | - $dirContent = Helper::getTrashFiles('/', $uid, 'mtime'); |
|
80 | - Trashbin::deleteExpiredFiles($dirContent, $uid); |
|
81 | - }); |
|
74 | + $this->userManager->callForSeenUsers(function (IUser $user) { |
|
75 | + $uid = $user->getUID(); |
|
76 | + if (!$this->setupFS($uid)) { |
|
77 | + return; |
|
78 | + } |
|
79 | + $dirContent = Helper::getTrashFiles('/', $uid, 'mtime'); |
|
80 | + Trashbin::deleteExpiredFiles($dirContent, $uid); |
|
81 | + }); |
|
82 | 82 | |
83 | - \OC_Util::tearDownFS(); |
|
84 | - } |
|
83 | + \OC_Util::tearDownFS(); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Act on behalf on trash item owner |
|
88 | - */ |
|
89 | - protected function setupFS(string $user): bool { |
|
90 | - \OC_Util::tearDownFS(); |
|
91 | - \OC_Util::setupFS($user); |
|
86 | + /** |
|
87 | + * Act on behalf on trash item owner |
|
88 | + */ |
|
89 | + protected function setupFS(string $user): bool { |
|
90 | + \OC_Util::tearDownFS(); |
|
91 | + \OC_Util::setupFS($user); |
|
92 | 92 | |
93 | - // Check if this user has a trashbin directory |
|
94 | - $view = new \OC\Files\View('/' . $user); |
|
95 | - if (!$view->is_dir('/files_trashbin/files')) { |
|
96 | - return false; |
|
97 | - } |
|
93 | + // Check if this user has a trashbin directory |
|
94 | + $view = new \OC\Files\View('/' . $user); |
|
95 | + if (!$view->is_dir('/files_trashbin/files')) { |
|
96 | + return false; |
|
97 | + } |
|
98 | 98 | |
99 | - return true; |
|
100 | - } |
|
99 | + return true; |
|
100 | + } |
|
101 | 101 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | $result = []; |
45 | 45 | $timestamp = null; |
46 | 46 | |
47 | - $view = new \OC\Files\View('/' . $user . '/files_trashbin/files'); |
|
47 | + $view = new \OC\Files\View('/'.$user.'/files_trashbin/files'); |
|
48 | 48 | |
49 | 49 | if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) { |
50 | 50 | throw new \Exception('Directory does not exists'); |
@@ -91,12 +91,12 @@ discard block |
||
91 | 91 | ]; |
92 | 92 | if ($originalPath) { |
93 | 93 | if ($originalPath !== '.') { |
94 | - $i['extraData'] = $originalPath . '/' . $originalName; |
|
94 | + $i['extraData'] = $originalPath.'/'.$originalName; |
|
95 | 95 | } else { |
96 | 96 | $i['extraData'] = $originalName; |
97 | 97 | } |
98 | 98 | } |
99 | - $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount); |
|
99 | + $result[] = new FileInfo($absoluteDir.'/'.$i['name'], $storage, $internalPath.'/'.$i['name'], $i, $mount); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | if ($sortAttribute !== '') { |
@@ -36,95 +36,95 @@ |
||
36 | 36 | use OCP\Files\Cache\ICacheEntry; |
37 | 37 | |
38 | 38 | class Helper { |
39 | - /** |
|
40 | - * Retrieves the contents of a trash bin directory. |
|
41 | - * |
|
42 | - * @param string $dir path to the directory inside the trashbin |
|
43 | - * or empty to retrieve the root of the trashbin |
|
44 | - * @param string $user |
|
45 | - * @param string $sortAttribute attribute to sort on or empty to disable sorting |
|
46 | - * @param bool $sortDescending true for descending sort, false otherwise |
|
47 | - * @return \OCP\Files\FileInfo[] |
|
48 | - */ |
|
49 | - public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDescending = false) { |
|
50 | - $result = []; |
|
51 | - $timestamp = null; |
|
39 | + /** |
|
40 | + * Retrieves the contents of a trash bin directory. |
|
41 | + * |
|
42 | + * @param string $dir path to the directory inside the trashbin |
|
43 | + * or empty to retrieve the root of the trashbin |
|
44 | + * @param string $user |
|
45 | + * @param string $sortAttribute attribute to sort on or empty to disable sorting |
|
46 | + * @param bool $sortDescending true for descending sort, false otherwise |
|
47 | + * @return \OCP\Files\FileInfo[] |
|
48 | + */ |
|
49 | + public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDescending = false) { |
|
50 | + $result = []; |
|
51 | + $timestamp = null; |
|
52 | 52 | |
53 | - $view = new \OC\Files\View('/' . $user . '/files_trashbin/files'); |
|
53 | + $view = new \OC\Files\View('/' . $user . '/files_trashbin/files'); |
|
54 | 54 | |
55 | - if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) { |
|
56 | - throw new \Exception('Directory does not exists'); |
|
57 | - } |
|
55 | + if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) { |
|
56 | + throw new \Exception('Directory does not exists'); |
|
57 | + } |
|
58 | 58 | |
59 | - $mount = $view->getMount($dir); |
|
60 | - $storage = $mount->getStorage(); |
|
61 | - $absoluteDir = $view->getAbsolutePath($dir); |
|
62 | - $internalPath = $mount->getInternalPath($absoluteDir); |
|
59 | + $mount = $view->getMount($dir); |
|
60 | + $storage = $mount->getStorage(); |
|
61 | + $absoluteDir = $view->getAbsolutePath($dir); |
|
62 | + $internalPath = $mount->getInternalPath($absoluteDir); |
|
63 | 63 | |
64 | - $originalLocations = \OCA\Files_Trashbin\Trashbin::getLocations($user); |
|
65 | - $dirContent = $storage->getCache()->getFolderContents($mount->getInternalPath($view->getAbsolutePath($dir))); |
|
66 | - foreach ($dirContent as $entry) { |
|
67 | - $entryName = $entry->getName(); |
|
68 | - $name = $entryName; |
|
69 | - if ($dir === '' || $dir === '/') { |
|
70 | - $pathparts = pathinfo($entryName); |
|
71 | - $timestamp = substr($pathparts['extension'], 1); |
|
72 | - $name = $pathparts['filename']; |
|
73 | - } elseif ($timestamp === null) { |
|
74 | - // for subfolders we need to calculate the timestamp only once |
|
75 | - $parts = explode('/', ltrim($dir, '/')); |
|
76 | - $timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1); |
|
77 | - } |
|
78 | - $originalPath = ''; |
|
79 | - $originalName = substr($entryName, 0, -strlen($timestamp) - 2); |
|
80 | - if (isset($originalLocations[$originalName][$timestamp])) { |
|
81 | - $originalPath = $originalLocations[$originalName][$timestamp]; |
|
82 | - if (substr($originalPath, -1) === '/') { |
|
83 | - $originalPath = substr($originalPath, 0, -1); |
|
84 | - } |
|
85 | - } |
|
86 | - $type = $entry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE ? 'dir' : 'file'; |
|
87 | - $i = [ |
|
88 | - 'name' => $name, |
|
89 | - 'mtime' => $timestamp, |
|
90 | - 'mimetype' => $type === 'dir' ? 'httpd/unix-directory' : \OC::$server->getMimeTypeDetector()->detectPath($name), |
|
91 | - 'type' => $type, |
|
92 | - 'directory' => ($dir === '/') ? '' : $dir, |
|
93 | - 'size' => $entry->getSize(), |
|
94 | - 'etag' => '', |
|
95 | - 'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE, |
|
96 | - 'fileid' => $entry->getId(), |
|
97 | - ]; |
|
98 | - if ($originalPath) { |
|
99 | - if ($originalPath !== '.') { |
|
100 | - $i['extraData'] = $originalPath . '/' . $originalName; |
|
101 | - } else { |
|
102 | - $i['extraData'] = $originalName; |
|
103 | - } |
|
104 | - } |
|
105 | - $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount); |
|
106 | - } |
|
64 | + $originalLocations = \OCA\Files_Trashbin\Trashbin::getLocations($user); |
|
65 | + $dirContent = $storage->getCache()->getFolderContents($mount->getInternalPath($view->getAbsolutePath($dir))); |
|
66 | + foreach ($dirContent as $entry) { |
|
67 | + $entryName = $entry->getName(); |
|
68 | + $name = $entryName; |
|
69 | + if ($dir === '' || $dir === '/') { |
|
70 | + $pathparts = pathinfo($entryName); |
|
71 | + $timestamp = substr($pathparts['extension'], 1); |
|
72 | + $name = $pathparts['filename']; |
|
73 | + } elseif ($timestamp === null) { |
|
74 | + // for subfolders we need to calculate the timestamp only once |
|
75 | + $parts = explode('/', ltrim($dir, '/')); |
|
76 | + $timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1); |
|
77 | + } |
|
78 | + $originalPath = ''; |
|
79 | + $originalName = substr($entryName, 0, -strlen($timestamp) - 2); |
|
80 | + if (isset($originalLocations[$originalName][$timestamp])) { |
|
81 | + $originalPath = $originalLocations[$originalName][$timestamp]; |
|
82 | + if (substr($originalPath, -1) === '/') { |
|
83 | + $originalPath = substr($originalPath, 0, -1); |
|
84 | + } |
|
85 | + } |
|
86 | + $type = $entry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE ? 'dir' : 'file'; |
|
87 | + $i = [ |
|
88 | + 'name' => $name, |
|
89 | + 'mtime' => $timestamp, |
|
90 | + 'mimetype' => $type === 'dir' ? 'httpd/unix-directory' : \OC::$server->getMimeTypeDetector()->detectPath($name), |
|
91 | + 'type' => $type, |
|
92 | + 'directory' => ($dir === '/') ? '' : $dir, |
|
93 | + 'size' => $entry->getSize(), |
|
94 | + 'etag' => '', |
|
95 | + 'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE, |
|
96 | + 'fileid' => $entry->getId(), |
|
97 | + ]; |
|
98 | + if ($originalPath) { |
|
99 | + if ($originalPath !== '.') { |
|
100 | + $i['extraData'] = $originalPath . '/' . $originalName; |
|
101 | + } else { |
|
102 | + $i['extraData'] = $originalName; |
|
103 | + } |
|
104 | + } |
|
105 | + $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount); |
|
106 | + } |
|
107 | 107 | |
108 | - if ($sortAttribute !== '') { |
|
109 | - return \OCA\Files\Helper::sortFiles($result, $sortAttribute, $sortDescending); |
|
110 | - } |
|
111 | - return $result; |
|
112 | - } |
|
108 | + if ($sortAttribute !== '') { |
|
109 | + return \OCA\Files\Helper::sortFiles($result, $sortAttribute, $sortDescending); |
|
110 | + } |
|
111 | + return $result; |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * Format file infos for JSON |
|
116 | - * |
|
117 | - * @param \OCP\Files\FileInfo[] $fileInfos file infos |
|
118 | - */ |
|
119 | - public static function formatFileInfos($fileInfos) { |
|
120 | - $files = []; |
|
121 | - foreach ($fileInfos as $i) { |
|
122 | - $entry = \OCA\Files\Helper::formatFileInfo($i); |
|
123 | - $entry['id'] = $i->getId(); |
|
124 | - $entry['etag'] = $entry['mtime']; // add fake etag, it is only needed to identify the preview image |
|
125 | - $entry['permissions'] = \OCP\Constants::PERMISSION_READ; |
|
126 | - $files[] = $entry; |
|
127 | - } |
|
128 | - return $files; |
|
129 | - } |
|
114 | + /** |
|
115 | + * Format file infos for JSON |
|
116 | + * |
|
117 | + * @param \OCP\Files\FileInfo[] $fileInfos file infos |
|
118 | + */ |
|
119 | + public static function formatFileInfos($fileInfos) { |
|
120 | + $files = []; |
|
121 | + foreach ($fileInfos as $i) { |
|
122 | + $entry = \OCA\Files\Helper::formatFileInfo($i); |
|
123 | + $entry['id'] = $i->getId(); |
|
124 | + $entry['etag'] = $entry['mtime']; // add fake etag, it is only needed to identify the preview image |
|
125 | + $entry['permissions'] = \OCP\Constants::PERMISSION_READ; |
|
126 | + $files[] = $entry; |
|
127 | + } |
|
128 | + return $files; |
|
129 | + } |
|
130 | 130 | } |
@@ -90,7 +90,7 @@ |
||
90 | 90 | $notification |
91 | 91 | ->setApp('comments') |
92 | 92 | ->setObject('comment', $comment->getId()) |
93 | - ->setSubject('mention', [ $comment->getObjectType(), $comment->getObjectId() ]) |
|
93 | + ->setSubject('mention', [$comment->getObjectType(), $comment->getObjectId()]) |
|
94 | 94 | ->setDateTime($comment->getCreationDateTime()); |
95 | 95 | |
96 | 96 | return $notification; |
@@ -30,85 +30,85 @@ |
||
30 | 30 | |
31 | 31 | class Listener { |
32 | 32 | |
33 | - protected IManager $notificationManager; |
|
34 | - protected IUserManager $userManager; |
|
33 | + protected IManager $notificationManager; |
|
34 | + protected IUserManager $userManager; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Listener constructor. |
|
38 | - */ |
|
39 | - public function __construct( |
|
40 | - IManager $notificationManager, |
|
41 | - IUserManager $userManager |
|
42 | - ) { |
|
43 | - $this->notificationManager = $notificationManager; |
|
44 | - $this->userManager = $userManager; |
|
45 | - } |
|
36 | + /** |
|
37 | + * Listener constructor. |
|
38 | + */ |
|
39 | + public function __construct( |
|
40 | + IManager $notificationManager, |
|
41 | + IUserManager $userManager |
|
42 | + ) { |
|
43 | + $this->notificationManager = $notificationManager; |
|
44 | + $this->userManager = $userManager; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * @param CommentsEvent $event |
|
49 | - */ |
|
50 | - public function evaluate(CommentsEvent $event) { |
|
51 | - $comment = $event->getComment(); |
|
47 | + /** |
|
48 | + * @param CommentsEvent $event |
|
49 | + */ |
|
50 | + public function evaluate(CommentsEvent $event) { |
|
51 | + $comment = $event->getComment(); |
|
52 | 52 | |
53 | - $mentions = $this->extractMentions($comment->getMentions()); |
|
54 | - if (empty($mentions)) { |
|
55 | - // no one to notify |
|
56 | - return; |
|
57 | - } |
|
53 | + $mentions = $this->extractMentions($comment->getMentions()); |
|
54 | + if (empty($mentions)) { |
|
55 | + // no one to notify |
|
56 | + return; |
|
57 | + } |
|
58 | 58 | |
59 | - $notification = $this->instantiateNotification($comment); |
|
59 | + $notification = $this->instantiateNotification($comment); |
|
60 | 60 | |
61 | - foreach ($mentions as $uid) { |
|
62 | - if (($comment->getActorType() === 'users' && $uid === $comment->getActorId()) |
|
63 | - || !$this->userManager->userExists($uid) |
|
64 | - ) { |
|
65 | - // do not notify unknown users or yourself |
|
66 | - continue; |
|
67 | - } |
|
61 | + foreach ($mentions as $uid) { |
|
62 | + if (($comment->getActorType() === 'users' && $uid === $comment->getActorId()) |
|
63 | + || !$this->userManager->userExists($uid) |
|
64 | + ) { |
|
65 | + // do not notify unknown users or yourself |
|
66 | + continue; |
|
67 | + } |
|
68 | 68 | |
69 | - $notification->setUser($uid); |
|
70 | - if ($event->getEvent() === CommentsEvent::EVENT_DELETE |
|
71 | - || $event->getEvent() === CommentsEvent::EVENT_PRE_UPDATE) { |
|
72 | - $this->notificationManager->markProcessed($notification); |
|
73 | - } else { |
|
74 | - $this->notificationManager->notify($notification); |
|
75 | - } |
|
76 | - } |
|
77 | - } |
|
69 | + $notification->setUser($uid); |
|
70 | + if ($event->getEvent() === CommentsEvent::EVENT_DELETE |
|
71 | + || $event->getEvent() === CommentsEvent::EVENT_PRE_UPDATE) { |
|
72 | + $this->notificationManager->markProcessed($notification); |
|
73 | + } else { |
|
74 | + $this->notificationManager->notify($notification); |
|
75 | + } |
|
76 | + } |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * creates a notification instance and fills it with comment data |
|
81 | - * |
|
82 | - * @param IComment $comment |
|
83 | - * @return \OCP\Notification\INotification |
|
84 | - */ |
|
85 | - public function instantiateNotification(IComment $comment) { |
|
86 | - $notification = $this->notificationManager->createNotification(); |
|
87 | - $notification |
|
88 | - ->setApp('comments') |
|
89 | - ->setObject('comment', $comment->getId()) |
|
90 | - ->setSubject('mention', [ $comment->getObjectType(), $comment->getObjectId() ]) |
|
91 | - ->setDateTime($comment->getCreationDateTime()); |
|
79 | + /** |
|
80 | + * creates a notification instance and fills it with comment data |
|
81 | + * |
|
82 | + * @param IComment $comment |
|
83 | + * @return \OCP\Notification\INotification |
|
84 | + */ |
|
85 | + public function instantiateNotification(IComment $comment) { |
|
86 | + $notification = $this->notificationManager->createNotification(); |
|
87 | + $notification |
|
88 | + ->setApp('comments') |
|
89 | + ->setObject('comment', $comment->getId()) |
|
90 | + ->setSubject('mention', [ $comment->getObjectType(), $comment->getObjectId() ]) |
|
91 | + ->setDateTime($comment->getCreationDateTime()); |
|
92 | 92 | |
93 | - return $notification; |
|
94 | - } |
|
93 | + return $notification; |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * flattens the mention array returned from comments to a list of user ids. |
|
98 | - * |
|
99 | - * @param array $mentions |
|
100 | - * @return string[] containing the mentions, e.g. ['alice', 'bob'] |
|
101 | - */ |
|
102 | - public function extractMentions(array $mentions) { |
|
103 | - if (empty($mentions)) { |
|
104 | - return []; |
|
105 | - } |
|
106 | - $uids = []; |
|
107 | - foreach ($mentions as $mention) { |
|
108 | - if ($mention['type'] === 'user') { |
|
109 | - $uids[] = $mention['id']; |
|
110 | - } |
|
111 | - } |
|
112 | - return $uids; |
|
113 | - } |
|
96 | + /** |
|
97 | + * flattens the mention array returned from comments to a list of user ids. |
|
98 | + * |
|
99 | + * @param array $mentions |
|
100 | + * @return string[] containing the mentions, e.g. ['alice', 'bob'] |
|
101 | + */ |
|
102 | + public function extractMentions(array $mentions) { |
|
103 | + if (empty($mentions)) { |
|
104 | + return []; |
|
105 | + } |
|
106 | + $uids = []; |
|
107 | + foreach ($mentions as $mention) { |
|
108 | + if ($mention['type'] === 'user') { |
|
109 | + $uids[] = $mention['id']; |
|
110 | + } |
|
111 | + } |
|
112 | + return $uids; |
|
113 | + } |
|
114 | 114 | } |
@@ -36,56 +36,56 @@ |
||
36 | 36 | * @package OCA\Comments |
37 | 37 | */ |
38 | 38 | class EventHandler implements ICommentsEventHandler { |
39 | - /** @var ActivityListener */ |
|
40 | - private $activityListener; |
|
39 | + /** @var ActivityListener */ |
|
40 | + private $activityListener; |
|
41 | 41 | |
42 | - /** @var NotificationListener */ |
|
43 | - private $notificationListener; |
|
42 | + /** @var NotificationListener */ |
|
43 | + private $notificationListener; |
|
44 | 44 | |
45 | - public function __construct(ActivityListener $activityListener, NotificationListener $notificationListener) { |
|
46 | - $this->activityListener = $activityListener; |
|
47 | - $this->notificationListener = $notificationListener; |
|
48 | - } |
|
45 | + public function __construct(ActivityListener $activityListener, NotificationListener $notificationListener) { |
|
46 | + $this->activityListener = $activityListener; |
|
47 | + $this->notificationListener = $notificationListener; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @param CommentsEvent $event |
|
52 | - */ |
|
53 | - public function handle(CommentsEvent $event) { |
|
54 | - if ($event->getComment()->getObjectType() !== 'files') { |
|
55 | - // this is a 'files'-specific Handler |
|
56 | - return; |
|
57 | - } |
|
50 | + /** |
|
51 | + * @param CommentsEvent $event |
|
52 | + */ |
|
53 | + public function handle(CommentsEvent $event) { |
|
54 | + if ($event->getComment()->getObjectType() !== 'files') { |
|
55 | + // this is a 'files'-specific Handler |
|
56 | + return; |
|
57 | + } |
|
58 | 58 | |
59 | - $eventType = $event->getEvent(); |
|
60 | - if ($eventType === CommentsEvent::EVENT_ADD |
|
61 | - ) { |
|
62 | - $this->notificationHandler($event); |
|
63 | - $this->activityHandler($event); |
|
64 | - return; |
|
65 | - } |
|
59 | + $eventType = $event->getEvent(); |
|
60 | + if ($eventType === CommentsEvent::EVENT_ADD |
|
61 | + ) { |
|
62 | + $this->notificationHandler($event); |
|
63 | + $this->activityHandler($event); |
|
64 | + return; |
|
65 | + } |
|
66 | 66 | |
67 | - $applicableEvents = [ |
|
68 | - CommentsEvent::EVENT_PRE_UPDATE, |
|
69 | - CommentsEvent::EVENT_UPDATE, |
|
70 | - CommentsEvent::EVENT_DELETE, |
|
71 | - ]; |
|
72 | - if (in_array($eventType, $applicableEvents)) { |
|
73 | - $this->notificationHandler($event); |
|
74 | - return; |
|
75 | - } |
|
76 | - } |
|
67 | + $applicableEvents = [ |
|
68 | + CommentsEvent::EVENT_PRE_UPDATE, |
|
69 | + CommentsEvent::EVENT_UPDATE, |
|
70 | + CommentsEvent::EVENT_DELETE, |
|
71 | + ]; |
|
72 | + if (in_array($eventType, $applicableEvents)) { |
|
73 | + $this->notificationHandler($event); |
|
74 | + return; |
|
75 | + } |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @param CommentsEvent $event |
|
80 | - */ |
|
81 | - private function activityHandler(CommentsEvent $event) { |
|
82 | - $this->activityListener->commentEvent($event); |
|
83 | - } |
|
78 | + /** |
|
79 | + * @param CommentsEvent $event |
|
80 | + */ |
|
81 | + private function activityHandler(CommentsEvent $event) { |
|
82 | + $this->activityListener->commentEvent($event); |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * @param CommentsEvent $event |
|
87 | - */ |
|
88 | - private function notificationHandler(CommentsEvent $event) { |
|
89 | - $this->notificationListener->evaluate($event); |
|
90 | - } |
|
85 | + /** |
|
86 | + * @param CommentsEvent $event |
|
87 | + */ |
|
88 | + private function notificationHandler(CommentsEvent $event) { |
|
89 | + $this->notificationListener->evaluate($event); |
|
90 | + } |
|
91 | 91 | } |