@@ -30,28 +30,28 @@ |
||
30 | 30 | * @package OC\IntegrityCheck\Helpers |
31 | 31 | */ |
32 | 32 | class AppLocator { |
33 | - /** |
|
34 | - * Provides \OC_App::getAppPath($appId) |
|
35 | - * |
|
36 | - * @param string $appId |
|
37 | - * @return string |
|
38 | - * @throws \Exception If the app cannot be found |
|
39 | - */ |
|
40 | - public function getAppPath($appId) { |
|
41 | - $path = \OC_App::getAppPath($appId); |
|
42 | - if($path === false) { |
|
33 | + /** |
|
34 | + * Provides \OC_App::getAppPath($appId) |
|
35 | + * |
|
36 | + * @param string $appId |
|
37 | + * @return string |
|
38 | + * @throws \Exception If the app cannot be found |
|
39 | + */ |
|
40 | + public function getAppPath($appId) { |
|
41 | + $path = \OC_App::getAppPath($appId); |
|
42 | + if($path === false) { |
|
43 | 43 | |
44 | - throw new \Exception('App not found'); |
|
45 | - } |
|
46 | - return $path; |
|
47 | - } |
|
44 | + throw new \Exception('App not found'); |
|
45 | + } |
|
46 | + return $path; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Providers \OC_App::getAllApps() |
|
51 | - * |
|
52 | - * @return array |
|
53 | - */ |
|
54 | - public function getAllApps() { |
|
55 | - return \OC_App::getAllApps(); |
|
56 | - } |
|
49 | + /** |
|
50 | + * Providers \OC_App::getAllApps() |
|
51 | + * |
|
52 | + * @return array |
|
53 | + */ |
|
54 | + public function getAllApps() { |
|
55 | + return \OC_App::getAllApps(); |
|
56 | + } |
|
57 | 57 | } |
@@ -39,7 +39,7 @@ |
||
39 | 39 | */ |
40 | 40 | public function getAppPath($appId) { |
41 | 41 | $path = \OC_App::getAppPath($appId); |
42 | - if($path === false) { |
|
42 | + if ($path === false) { |
|
43 | 43 | |
44 | 44 | throw new \Exception('App not found'); |
45 | 45 | } |
@@ -35,46 +35,46 @@ |
||
35 | 35 | */ |
36 | 36 | class HintException extends \Exception { |
37 | 37 | |
38 | - private $hint; |
|
38 | + private $hint; |
|
39 | 39 | |
40 | - /** |
|
41 | - * HintException constructor. |
|
42 | - * |
|
43 | - * @param string $message The error message. It will be not revealed to the |
|
44 | - * the user (unless the hint is empty) and thus |
|
45 | - * should be not translated. |
|
46 | - * @param string $hint A useful message that is presented to the end |
|
47 | - * user. It should be translated, but must not |
|
48 | - * contain sensitive data. |
|
49 | - * @param int $code |
|
50 | - * @param \Exception|null $previous |
|
51 | - */ |
|
52 | - public function __construct($message, $hint = '', $code = 0, \Exception $previous = null) { |
|
53 | - $this->hint = $hint; |
|
54 | - parent::__construct($message, $code, $previous); |
|
55 | - } |
|
40 | + /** |
|
41 | + * HintException constructor. |
|
42 | + * |
|
43 | + * @param string $message The error message. It will be not revealed to the |
|
44 | + * the user (unless the hint is empty) and thus |
|
45 | + * should be not translated. |
|
46 | + * @param string $hint A useful message that is presented to the end |
|
47 | + * user. It should be translated, but must not |
|
48 | + * contain sensitive data. |
|
49 | + * @param int $code |
|
50 | + * @param \Exception|null $previous |
|
51 | + */ |
|
52 | + public function __construct($message, $hint = '', $code = 0, \Exception $previous = null) { |
|
53 | + $this->hint = $hint; |
|
54 | + parent::__construct($message, $code, $previous); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Returns a string representation of this Exception that includes the error |
|
59 | - * code, the message and the hint. |
|
60 | - * |
|
61 | - * @return string |
|
62 | - */ |
|
63 | - public function __toString() { |
|
64 | - return __CLASS__ . ": [{$this->code}]: {$this->message} ({$this->hint})\n"; |
|
65 | - } |
|
57 | + /** |
|
58 | + * Returns a string representation of this Exception that includes the error |
|
59 | + * code, the message and the hint. |
|
60 | + * |
|
61 | + * @return string |
|
62 | + */ |
|
63 | + public function __toString() { |
|
64 | + return __CLASS__ . ": [{$this->code}]: {$this->message} ({$this->hint})\n"; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * Returns the hint with the intention to be presented to the end user. If |
|
69 | - * an empty hint was specified upon instatiation, the message is returned |
|
70 | - * instead. |
|
71 | - * |
|
72 | - * @return string |
|
73 | - */ |
|
74 | - public function getHint() { |
|
75 | - if (empty($this->hint)) { |
|
76 | - return $this->message; |
|
77 | - } |
|
78 | - return $this->hint; |
|
79 | - } |
|
67 | + /** |
|
68 | + * Returns the hint with the intention to be presented to the end user. If |
|
69 | + * an empty hint was specified upon instatiation, the message is returned |
|
70 | + * instead. |
|
71 | + * |
|
72 | + * @return string |
|
73 | + */ |
|
74 | + public function getHint() { |
|
75 | + if (empty($this->hint)) { |
|
76 | + return $this->message; |
|
77 | + } |
|
78 | + return $this->hint; |
|
79 | + } |
|
80 | 80 | } |
@@ -61,7 +61,7 @@ |
||
61 | 61 | * @return string |
62 | 62 | */ |
63 | 63 | public function __toString() { |
64 | - return __CLASS__ . ": [{$this->code}]: {$this->message} ({$this->hint})\n"; |
|
64 | + return __CLASS__.": [{$this->code}]: {$this->message} ({$this->hint})\n"; |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | /** |
81 | 81 | * @inheritdoc |
82 | 82 | */ |
83 | - public function get ($size = 64) { |
|
83 | + public function get($size = 64) { |
|
84 | 84 | try { |
85 | 85 | $file = $this->getFile($size); |
86 | 86 | } catch (NotFoundException $e) { |
@@ -110,9 +110,9 @@ discard block |
||
110 | 110 | * @throws NotSquareException if the image is not square |
111 | 111 | * @return void |
112 | 112 | */ |
113 | - public function set ($data) { |
|
113 | + public function set($data) { |
|
114 | 114 | |
115 | - if($data instanceOf IImage) { |
|
115 | + if ($data instanceOf IImage) { |
|
116 | 116 | $img = $data; |
117 | 117 | $data = $img->data(); |
118 | 118 | } else { |
@@ -143,12 +143,12 @@ discard block |
||
143 | 143 | * remove the users avatar |
144 | 144 | * @return void |
145 | 145 | */ |
146 | - public function remove () { |
|
146 | + public function remove() { |
|
147 | 147 | $regex = '/^avatar\.([0-9]+\.)?(jpg|png)$/'; |
148 | 148 | $avatars = $this->folder->getDirectoryListing(); |
149 | 149 | |
150 | 150 | $this->config->setUserValue($this->user->getUID(), 'avatar', 'version', |
151 | - (int)$this->config->getUserValue($this->user->getUID(), 'avatar', 'version', 0) + 1); |
|
151 | + (int) $this->config->getUserValue($this->user->getUID(), 'avatar', 'version', 0) + 1); |
|
152 | 152 | |
153 | 153 | foreach ($avatars as $avatar) { |
154 | 154 | if (preg_match($regex, $avatar->getName())) { |
@@ -165,9 +165,9 @@ discard block |
||
165 | 165 | $ext = $this->getExtension(); |
166 | 166 | |
167 | 167 | if ($size === -1) { |
168 | - $path = 'avatar.' . $ext; |
|
168 | + $path = 'avatar.'.$ext; |
|
169 | 169 | } else { |
170 | - $path = 'avatar.' . $size . '.' . $ext; |
|
170 | + $path = 'avatar.'.$size.'.'.$ext; |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | try { |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | |
180 | 180 | $avatar = new OC_Image(); |
181 | 181 | /** @var ISimpleFile $file */ |
182 | - $file = $this->folder->getFile('avatar.' . $ext); |
|
182 | + $file = $this->folder->getFile('avatar.'.$ext); |
|
183 | 183 | $avatar->loadFromData($file->getContent()); |
184 | 184 | if ($size !== -1) { |
185 | 185 | $avatar->resize($size); |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | $file = $this->folder->newFile($path); |
189 | 189 | $file->putContent($avatar->data()); |
190 | 190 | } catch (NotPermittedException $e) { |
191 | - $this->logger->error('Failed to save avatar for ' . $this->user->getUID()); |
|
191 | + $this->logger->error('Failed to save avatar for '.$this->user->getUID()); |
|
192 | 192 | } |
193 | 193 | } |
194 | 194 |
@@ -45,169 +45,169 @@ |
||
45 | 45 | */ |
46 | 46 | |
47 | 47 | class Avatar implements IAvatar { |
48 | - /** @var ISimpleFolder */ |
|
49 | - private $folder; |
|
50 | - /** @var IL10N */ |
|
51 | - private $l; |
|
52 | - /** @var User */ |
|
53 | - private $user; |
|
54 | - /** @var ILogger */ |
|
55 | - private $logger; |
|
56 | - /** @var IConfig */ |
|
57 | - private $config; |
|
58 | - |
|
59 | - /** |
|
60 | - * constructor |
|
61 | - * |
|
62 | - * @param ISimpleFolder $folder The folder where the avatars are |
|
63 | - * @param IL10N $l |
|
64 | - * @param User $user |
|
65 | - * @param ILogger $logger |
|
66 | - * @param IConfig $config |
|
67 | - */ |
|
68 | - public function __construct(ISimpleFolder $folder, |
|
69 | - IL10N $l, |
|
70 | - $user, |
|
71 | - ILogger $logger, |
|
72 | - IConfig $config) { |
|
73 | - $this->folder = $folder; |
|
74 | - $this->l = $l; |
|
75 | - $this->user = $user; |
|
76 | - $this->logger = $logger; |
|
77 | - $this->config = $config; |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * @inheritdoc |
|
82 | - */ |
|
83 | - public function get ($size = 64) { |
|
84 | - try { |
|
85 | - $file = $this->getFile($size); |
|
86 | - } catch (NotFoundException $e) { |
|
87 | - return false; |
|
88 | - } |
|
89 | - |
|
90 | - $avatar = new OC_Image(); |
|
91 | - $avatar->loadFromData($file->getContent()); |
|
92 | - return $avatar; |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Check if an avatar exists for the user |
|
97 | - * |
|
98 | - * @return bool |
|
99 | - */ |
|
100 | - public function exists() { |
|
101 | - |
|
102 | - return $this->folder->fileExists('avatar.jpg') || $this->folder->fileExists('avatar.png'); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * sets the users avatar |
|
107 | - * @param IImage|resource|string $data An image object, imagedata or path to set a new avatar |
|
108 | - * @throws \Exception if the provided file is not a jpg or png image |
|
109 | - * @throws \Exception if the provided image is not valid |
|
110 | - * @throws NotSquareException if the image is not square |
|
111 | - * @return void |
|
112 | - */ |
|
113 | - public function set ($data) { |
|
114 | - |
|
115 | - if($data instanceOf IImage) { |
|
116 | - $img = $data; |
|
117 | - $data = $img->data(); |
|
118 | - } else { |
|
119 | - $img = new OC_Image($data); |
|
120 | - } |
|
121 | - $type = substr($img->mimeType(), -3); |
|
122 | - if ($type === 'peg') { |
|
123 | - $type = 'jpg'; |
|
124 | - } |
|
125 | - if ($type !== 'jpg' && $type !== 'png') { |
|
126 | - throw new \Exception($this->l->t("Unknown filetype")); |
|
127 | - } |
|
128 | - |
|
129 | - if (!$img->valid()) { |
|
130 | - throw new \Exception($this->l->t("Invalid image")); |
|
131 | - } |
|
132 | - |
|
133 | - if (!($img->height() === $img->width())) { |
|
134 | - throw new NotSquareException($this->l->t("Avatar image is not square")); |
|
135 | - } |
|
136 | - |
|
137 | - $this->remove(); |
|
138 | - $file = $this->folder->newFile('avatar.'.$type); |
|
139 | - $file->putContent($data); |
|
140 | - $this->user->triggerChange('avatar', $file); |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * remove the users avatar |
|
145 | - * @return void |
|
146 | - */ |
|
147 | - public function remove () { |
|
148 | - $regex = '/^avatar\.([0-9]+\.)?(jpg|png)$/'; |
|
149 | - $avatars = $this->folder->getDirectoryListing(); |
|
150 | - |
|
151 | - $this->config->setUserValue($this->user->getUID(), 'avatar', 'version', |
|
152 | - (int)$this->config->getUserValue($this->user->getUID(), 'avatar', 'version', 0) + 1); |
|
153 | - |
|
154 | - foreach ($avatars as $avatar) { |
|
155 | - if (preg_match($regex, $avatar->getName())) { |
|
156 | - $avatar->delete(); |
|
157 | - } |
|
158 | - } |
|
159 | - $this->user->triggerChange('avatar', ''); |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * @inheritdoc |
|
164 | - */ |
|
165 | - public function getFile($size) { |
|
166 | - $ext = $this->getExtension(); |
|
167 | - |
|
168 | - if ($size === -1) { |
|
169 | - $path = 'avatar.' . $ext; |
|
170 | - } else { |
|
171 | - $path = 'avatar.' . $size . '.' . $ext; |
|
172 | - } |
|
173 | - |
|
174 | - try { |
|
175 | - $file = $this->folder->getFile($path); |
|
176 | - } catch (NotFoundException $e) { |
|
177 | - if ($size <= 0) { |
|
178 | - throw new NotFoundException; |
|
179 | - } |
|
180 | - |
|
181 | - $avatar = new OC_Image(); |
|
182 | - /** @var ISimpleFile $file */ |
|
183 | - $file = $this->folder->getFile('avatar.' . $ext); |
|
184 | - $avatar->loadFromData($file->getContent()); |
|
185 | - if ($size !== -1) { |
|
186 | - $avatar->resize($size); |
|
187 | - } |
|
188 | - try { |
|
189 | - $file = $this->folder->newFile($path); |
|
190 | - $file->putContent($avatar->data()); |
|
191 | - } catch (NotPermittedException $e) { |
|
192 | - $this->logger->error('Failed to save avatar for ' . $this->user->getUID()); |
|
193 | - } |
|
194 | - } |
|
195 | - |
|
196 | - return $file; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Get the extension of the avatar. If there is no avatar throw Exception |
|
201 | - * |
|
202 | - * @return string |
|
203 | - * @throws NotFoundException |
|
204 | - */ |
|
205 | - private function getExtension() { |
|
206 | - if ($this->folder->fileExists('avatar.jpg')) { |
|
207 | - return 'jpg'; |
|
208 | - } elseif ($this->folder->fileExists('avatar.png')) { |
|
209 | - return 'png'; |
|
210 | - } |
|
211 | - throw new NotFoundException; |
|
212 | - } |
|
48 | + /** @var ISimpleFolder */ |
|
49 | + private $folder; |
|
50 | + /** @var IL10N */ |
|
51 | + private $l; |
|
52 | + /** @var User */ |
|
53 | + private $user; |
|
54 | + /** @var ILogger */ |
|
55 | + private $logger; |
|
56 | + /** @var IConfig */ |
|
57 | + private $config; |
|
58 | + |
|
59 | + /** |
|
60 | + * constructor |
|
61 | + * |
|
62 | + * @param ISimpleFolder $folder The folder where the avatars are |
|
63 | + * @param IL10N $l |
|
64 | + * @param User $user |
|
65 | + * @param ILogger $logger |
|
66 | + * @param IConfig $config |
|
67 | + */ |
|
68 | + public function __construct(ISimpleFolder $folder, |
|
69 | + IL10N $l, |
|
70 | + $user, |
|
71 | + ILogger $logger, |
|
72 | + IConfig $config) { |
|
73 | + $this->folder = $folder; |
|
74 | + $this->l = $l; |
|
75 | + $this->user = $user; |
|
76 | + $this->logger = $logger; |
|
77 | + $this->config = $config; |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * @inheritdoc |
|
82 | + */ |
|
83 | + public function get ($size = 64) { |
|
84 | + try { |
|
85 | + $file = $this->getFile($size); |
|
86 | + } catch (NotFoundException $e) { |
|
87 | + return false; |
|
88 | + } |
|
89 | + |
|
90 | + $avatar = new OC_Image(); |
|
91 | + $avatar->loadFromData($file->getContent()); |
|
92 | + return $avatar; |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Check if an avatar exists for the user |
|
97 | + * |
|
98 | + * @return bool |
|
99 | + */ |
|
100 | + public function exists() { |
|
101 | + |
|
102 | + return $this->folder->fileExists('avatar.jpg') || $this->folder->fileExists('avatar.png'); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * sets the users avatar |
|
107 | + * @param IImage|resource|string $data An image object, imagedata or path to set a new avatar |
|
108 | + * @throws \Exception if the provided file is not a jpg or png image |
|
109 | + * @throws \Exception if the provided image is not valid |
|
110 | + * @throws NotSquareException if the image is not square |
|
111 | + * @return void |
|
112 | + */ |
|
113 | + public function set ($data) { |
|
114 | + |
|
115 | + if($data instanceOf IImage) { |
|
116 | + $img = $data; |
|
117 | + $data = $img->data(); |
|
118 | + } else { |
|
119 | + $img = new OC_Image($data); |
|
120 | + } |
|
121 | + $type = substr($img->mimeType(), -3); |
|
122 | + if ($type === 'peg') { |
|
123 | + $type = 'jpg'; |
|
124 | + } |
|
125 | + if ($type !== 'jpg' && $type !== 'png') { |
|
126 | + throw new \Exception($this->l->t("Unknown filetype")); |
|
127 | + } |
|
128 | + |
|
129 | + if (!$img->valid()) { |
|
130 | + throw new \Exception($this->l->t("Invalid image")); |
|
131 | + } |
|
132 | + |
|
133 | + if (!($img->height() === $img->width())) { |
|
134 | + throw new NotSquareException($this->l->t("Avatar image is not square")); |
|
135 | + } |
|
136 | + |
|
137 | + $this->remove(); |
|
138 | + $file = $this->folder->newFile('avatar.'.$type); |
|
139 | + $file->putContent($data); |
|
140 | + $this->user->triggerChange('avatar', $file); |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * remove the users avatar |
|
145 | + * @return void |
|
146 | + */ |
|
147 | + public function remove () { |
|
148 | + $regex = '/^avatar\.([0-9]+\.)?(jpg|png)$/'; |
|
149 | + $avatars = $this->folder->getDirectoryListing(); |
|
150 | + |
|
151 | + $this->config->setUserValue($this->user->getUID(), 'avatar', 'version', |
|
152 | + (int)$this->config->getUserValue($this->user->getUID(), 'avatar', 'version', 0) + 1); |
|
153 | + |
|
154 | + foreach ($avatars as $avatar) { |
|
155 | + if (preg_match($regex, $avatar->getName())) { |
|
156 | + $avatar->delete(); |
|
157 | + } |
|
158 | + } |
|
159 | + $this->user->triggerChange('avatar', ''); |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * @inheritdoc |
|
164 | + */ |
|
165 | + public function getFile($size) { |
|
166 | + $ext = $this->getExtension(); |
|
167 | + |
|
168 | + if ($size === -1) { |
|
169 | + $path = 'avatar.' . $ext; |
|
170 | + } else { |
|
171 | + $path = 'avatar.' . $size . '.' . $ext; |
|
172 | + } |
|
173 | + |
|
174 | + try { |
|
175 | + $file = $this->folder->getFile($path); |
|
176 | + } catch (NotFoundException $e) { |
|
177 | + if ($size <= 0) { |
|
178 | + throw new NotFoundException; |
|
179 | + } |
|
180 | + |
|
181 | + $avatar = new OC_Image(); |
|
182 | + /** @var ISimpleFile $file */ |
|
183 | + $file = $this->folder->getFile('avatar.' . $ext); |
|
184 | + $avatar->loadFromData($file->getContent()); |
|
185 | + if ($size !== -1) { |
|
186 | + $avatar->resize($size); |
|
187 | + } |
|
188 | + try { |
|
189 | + $file = $this->folder->newFile($path); |
|
190 | + $file->putContent($avatar->data()); |
|
191 | + } catch (NotPermittedException $e) { |
|
192 | + $this->logger->error('Failed to save avatar for ' . $this->user->getUID()); |
|
193 | + } |
|
194 | + } |
|
195 | + |
|
196 | + return $file; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Get the extension of the avatar. If there is no avatar throw Exception |
|
201 | + * |
|
202 | + * @return string |
|
203 | + * @throws NotFoundException |
|
204 | + */ |
|
205 | + private function getExtension() { |
|
206 | + if ($this->folder->fileExists('avatar.jpg')) { |
|
207 | + return 'jpg'; |
|
208 | + } elseif ($this->folder->fileExists('avatar.png')) { |
|
209 | + return 'png'; |
|
210 | + } |
|
211 | + throw new NotFoundException; |
|
212 | + } |
|
213 | 213 | } |
@@ -29,136 +29,136 @@ |
||
29 | 29 | * capabilities. |
30 | 30 | */ |
31 | 31 | abstract class Backend implements UserInterface { |
32 | - /** |
|
33 | - * error code for functions not provided by the user backend |
|
34 | - */ |
|
35 | - const NOT_IMPLEMENTED = -501; |
|
32 | + /** |
|
33 | + * error code for functions not provided by the user backend |
|
34 | + */ |
|
35 | + const NOT_IMPLEMENTED = -501; |
|
36 | 36 | |
37 | - /** |
|
38 | - * actions that user backends can define |
|
39 | - */ |
|
40 | - const CREATE_USER = 1; // 1 << 0 |
|
41 | - const SET_PASSWORD = 16; // 1 << 4 |
|
42 | - const CHECK_PASSWORD = 256; // 1 << 8 |
|
43 | - const GET_HOME = 4096; // 1 << 12 |
|
44 | - const GET_DISPLAYNAME = 65536; // 1 << 16 |
|
45 | - const SET_DISPLAYNAME = 1048576; // 1 << 20 |
|
46 | - const PROVIDE_AVATAR = 16777216; // 1 << 24 |
|
47 | - const COUNT_USERS = 268435456; // 1 << 28 |
|
37 | + /** |
|
38 | + * actions that user backends can define |
|
39 | + */ |
|
40 | + const CREATE_USER = 1; // 1 << 0 |
|
41 | + const SET_PASSWORD = 16; // 1 << 4 |
|
42 | + const CHECK_PASSWORD = 256; // 1 << 8 |
|
43 | + const GET_HOME = 4096; // 1 << 12 |
|
44 | + const GET_DISPLAYNAME = 65536; // 1 << 16 |
|
45 | + const SET_DISPLAYNAME = 1048576; // 1 << 20 |
|
46 | + const PROVIDE_AVATAR = 16777216; // 1 << 24 |
|
47 | + const COUNT_USERS = 268435456; // 1 << 28 |
|
48 | 48 | |
49 | - protected $possibleActions = array( |
|
50 | - self::CREATE_USER => 'createUser', |
|
51 | - self::SET_PASSWORD => 'setPassword', |
|
52 | - self::CHECK_PASSWORD => 'checkPassword', |
|
53 | - self::GET_HOME => 'getHome', |
|
54 | - self::GET_DISPLAYNAME => 'getDisplayName', |
|
55 | - self::SET_DISPLAYNAME => 'setDisplayName', |
|
56 | - self::PROVIDE_AVATAR => 'canChangeAvatar', |
|
57 | - self::COUNT_USERS => 'countUsers', |
|
58 | - ); |
|
49 | + protected $possibleActions = array( |
|
50 | + self::CREATE_USER => 'createUser', |
|
51 | + self::SET_PASSWORD => 'setPassword', |
|
52 | + self::CHECK_PASSWORD => 'checkPassword', |
|
53 | + self::GET_HOME => 'getHome', |
|
54 | + self::GET_DISPLAYNAME => 'getDisplayName', |
|
55 | + self::SET_DISPLAYNAME => 'setDisplayName', |
|
56 | + self::PROVIDE_AVATAR => 'canChangeAvatar', |
|
57 | + self::COUNT_USERS => 'countUsers', |
|
58 | + ); |
|
59 | 59 | |
60 | - /** |
|
61 | - * Get all supported actions |
|
62 | - * @return int bitwise-or'ed actions |
|
63 | - * |
|
64 | - * Returns the supported actions as int to be |
|
65 | - * compared with self::CREATE_USER etc. |
|
66 | - */ |
|
67 | - public function getSupportedActions() { |
|
68 | - $actions = 0; |
|
69 | - foreach($this->possibleActions AS $action => $methodName) { |
|
70 | - if(method_exists($this, $methodName)) { |
|
71 | - $actions |= $action; |
|
72 | - } |
|
73 | - } |
|
60 | + /** |
|
61 | + * Get all supported actions |
|
62 | + * @return int bitwise-or'ed actions |
|
63 | + * |
|
64 | + * Returns the supported actions as int to be |
|
65 | + * compared with self::CREATE_USER etc. |
|
66 | + */ |
|
67 | + public function getSupportedActions() { |
|
68 | + $actions = 0; |
|
69 | + foreach($this->possibleActions AS $action => $methodName) { |
|
70 | + if(method_exists($this, $methodName)) { |
|
71 | + $actions |= $action; |
|
72 | + } |
|
73 | + } |
|
74 | 74 | |
75 | - return $actions; |
|
76 | - } |
|
75 | + return $actions; |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Check if backend implements actions |
|
80 | - * @param int $actions bitwise-or'ed actions |
|
81 | - * @return boolean |
|
82 | - * |
|
83 | - * Returns the supported actions as int to be |
|
84 | - * compared with self::CREATE_USER etc. |
|
85 | - */ |
|
86 | - public function implementsActions($actions) { |
|
87 | - return (bool)($this->getSupportedActions() & $actions); |
|
88 | - } |
|
78 | + /** |
|
79 | + * Check if backend implements actions |
|
80 | + * @param int $actions bitwise-or'ed actions |
|
81 | + * @return boolean |
|
82 | + * |
|
83 | + * Returns the supported actions as int to be |
|
84 | + * compared with self::CREATE_USER etc. |
|
85 | + */ |
|
86 | + public function implementsActions($actions) { |
|
87 | + return (bool)($this->getSupportedActions() & $actions); |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * delete a user |
|
92 | - * @param string $uid The username of the user to delete |
|
93 | - * @return bool |
|
94 | - * |
|
95 | - * Deletes a user |
|
96 | - */ |
|
97 | - public function deleteUser( $uid ) { |
|
98 | - return false; |
|
99 | - } |
|
90 | + /** |
|
91 | + * delete a user |
|
92 | + * @param string $uid The username of the user to delete |
|
93 | + * @return bool |
|
94 | + * |
|
95 | + * Deletes a user |
|
96 | + */ |
|
97 | + public function deleteUser( $uid ) { |
|
98 | + return false; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Get a list of all users |
|
103 | - * |
|
104 | - * @param string $search |
|
105 | - * @param null|int $limit |
|
106 | - * @param null|int $offset |
|
107 | - * @return string[] an array of all uids |
|
108 | - */ |
|
109 | - public function getUsers($search = '', $limit = null, $offset = null) { |
|
110 | - return array(); |
|
111 | - } |
|
101 | + /** |
|
102 | + * Get a list of all users |
|
103 | + * |
|
104 | + * @param string $search |
|
105 | + * @param null|int $limit |
|
106 | + * @param null|int $offset |
|
107 | + * @return string[] an array of all uids |
|
108 | + */ |
|
109 | + public function getUsers($search = '', $limit = null, $offset = null) { |
|
110 | + return array(); |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * check if a user exists |
|
115 | - * @param string $uid the username |
|
116 | - * @return boolean |
|
117 | - */ |
|
118 | - public function userExists($uid) { |
|
119 | - return false; |
|
120 | - } |
|
113 | + /** |
|
114 | + * check if a user exists |
|
115 | + * @param string $uid the username |
|
116 | + * @return boolean |
|
117 | + */ |
|
118 | + public function userExists($uid) { |
|
119 | + return false; |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * get the user's home directory |
|
124 | - * @param string $uid the username |
|
125 | - * @return boolean |
|
126 | - */ |
|
127 | - public function getHome($uid) { |
|
128 | - return false; |
|
129 | - } |
|
122 | + /** |
|
123 | + * get the user's home directory |
|
124 | + * @param string $uid the username |
|
125 | + * @return boolean |
|
126 | + */ |
|
127 | + public function getHome($uid) { |
|
128 | + return false; |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * get display name of the user |
|
133 | - * @param string $uid user ID of the user |
|
134 | - * @return string display name |
|
135 | - */ |
|
136 | - public function getDisplayName($uid) { |
|
137 | - return $uid; |
|
138 | - } |
|
131 | + /** |
|
132 | + * get display name of the user |
|
133 | + * @param string $uid user ID of the user |
|
134 | + * @return string display name |
|
135 | + */ |
|
136 | + public function getDisplayName($uid) { |
|
137 | + return $uid; |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * Get a list of all display names and user ids. |
|
142 | - * |
|
143 | - * @param string $search |
|
144 | - * @param string|null $limit |
|
145 | - * @param string|null $offset |
|
146 | - * @return array an array of all displayNames (value) and the corresponding uids (key) |
|
147 | - */ |
|
148 | - public function getDisplayNames($search = '', $limit = null, $offset = null) { |
|
149 | - $displayNames = array(); |
|
150 | - $users = $this->getUsers($search, $limit, $offset); |
|
151 | - foreach ( $users as $user) { |
|
152 | - $displayNames[$user] = $user; |
|
153 | - } |
|
154 | - return $displayNames; |
|
155 | - } |
|
140 | + /** |
|
141 | + * Get a list of all display names and user ids. |
|
142 | + * |
|
143 | + * @param string $search |
|
144 | + * @param string|null $limit |
|
145 | + * @param string|null $offset |
|
146 | + * @return array an array of all displayNames (value) and the corresponding uids (key) |
|
147 | + */ |
|
148 | + public function getDisplayNames($search = '', $limit = null, $offset = null) { |
|
149 | + $displayNames = array(); |
|
150 | + $users = $this->getUsers($search, $limit, $offset); |
|
151 | + foreach ( $users as $user) { |
|
152 | + $displayNames[$user] = $user; |
|
153 | + } |
|
154 | + return $displayNames; |
|
155 | + } |
|
156 | 156 | |
157 | - /** |
|
158 | - * Check if a user list is available or not |
|
159 | - * @return boolean if users can be listed or not |
|
160 | - */ |
|
161 | - public function hasUserListings() { |
|
162 | - return false; |
|
163 | - } |
|
157 | + /** |
|
158 | + * Check if a user list is available or not |
|
159 | + * @return boolean if users can be listed or not |
|
160 | + */ |
|
161 | + public function hasUserListings() { |
|
162 | + return false; |
|
163 | + } |
|
164 | 164 | } |
@@ -37,14 +37,14 @@ discard block |
||
37 | 37 | /** |
38 | 38 | * actions that user backends can define |
39 | 39 | */ |
40 | - const CREATE_USER = 1; // 1 << 0 |
|
41 | - const SET_PASSWORD = 16; // 1 << 4 |
|
42 | - const CHECK_PASSWORD = 256; // 1 << 8 |
|
43 | - const GET_HOME = 4096; // 1 << 12 |
|
44 | - const GET_DISPLAYNAME = 65536; // 1 << 16 |
|
45 | - const SET_DISPLAYNAME = 1048576; // 1 << 20 |
|
46 | - const PROVIDE_AVATAR = 16777216; // 1 << 24 |
|
47 | - const COUNT_USERS = 268435456; // 1 << 28 |
|
40 | + const CREATE_USER = 1; // 1 << 0 |
|
41 | + const SET_PASSWORD = 16; // 1 << 4 |
|
42 | + const CHECK_PASSWORD = 256; // 1 << 8 |
|
43 | + const GET_HOME = 4096; // 1 << 12 |
|
44 | + const GET_DISPLAYNAME = 65536; // 1 << 16 |
|
45 | + const SET_DISPLAYNAME = 1048576; // 1 << 20 |
|
46 | + const PROVIDE_AVATAR = 16777216; // 1 << 24 |
|
47 | + const COUNT_USERS = 268435456; // 1 << 28 |
|
48 | 48 | |
49 | 49 | protected $possibleActions = array( |
50 | 50 | self::CREATE_USER => 'createUser', |
@@ -66,8 +66,8 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function getSupportedActions() { |
68 | 68 | $actions = 0; |
69 | - foreach($this->possibleActions AS $action => $methodName) { |
|
70 | - if(method_exists($this, $methodName)) { |
|
69 | + foreach ($this->possibleActions AS $action => $methodName) { |
|
70 | + if (method_exists($this, $methodName)) { |
|
71 | 71 | $actions |= $action; |
72 | 72 | } |
73 | 73 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * compared with self::CREATE_USER etc. |
85 | 85 | */ |
86 | 86 | public function implementsActions($actions) { |
87 | - return (bool)($this->getSupportedActions() & $actions); |
|
87 | + return (bool) ($this->getSupportedActions() & $actions); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * |
95 | 95 | * Deletes a user |
96 | 96 | */ |
97 | - public function deleteUser( $uid ) { |
|
97 | + public function deleteUser($uid) { |
|
98 | 98 | return false; |
99 | 99 | } |
100 | 100 | |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | public function getDisplayNames($search = '', $limit = null, $offset = null) { |
149 | 149 | $displayNames = array(); |
150 | 150 | $users = $this->getUsers($search, $limit, $offset); |
151 | - foreach ( $users as $user) { |
|
151 | + foreach ($users as $user) { |
|
152 | 152 | $displayNames[$user] = $user; |
153 | 153 | } |
154 | 154 | return $displayNames; |
@@ -26,79 +26,79 @@ |
||
26 | 26 | use OCP\Diagnostics\IEvent; |
27 | 27 | |
28 | 28 | class Event implements IEvent { |
29 | - /** |
|
30 | - * @var string |
|
31 | - */ |
|
32 | - protected $id; |
|
29 | + /** |
|
30 | + * @var string |
|
31 | + */ |
|
32 | + protected $id; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @var float |
|
36 | - */ |
|
37 | - protected $start; |
|
34 | + /** |
|
35 | + * @var float |
|
36 | + */ |
|
37 | + protected $start; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @var float |
|
41 | - */ |
|
42 | - protected $end; |
|
39 | + /** |
|
40 | + * @var float |
|
41 | + */ |
|
42 | + protected $end; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @var string |
|
46 | - */ |
|
47 | - protected $description; |
|
44 | + /** |
|
45 | + * @var string |
|
46 | + */ |
|
47 | + protected $description; |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param string $id |
|
51 | - * @param string $description |
|
52 | - * @param float $start |
|
53 | - */ |
|
54 | - public function __construct($id, $description, $start) { |
|
55 | - $this->id = $id; |
|
56 | - $this->description = $description; |
|
57 | - $this->start = $start; |
|
58 | - } |
|
49 | + /** |
|
50 | + * @param string $id |
|
51 | + * @param string $description |
|
52 | + * @param float $start |
|
53 | + */ |
|
54 | + public function __construct($id, $description, $start) { |
|
55 | + $this->id = $id; |
|
56 | + $this->description = $description; |
|
57 | + $this->start = $start; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @param float $time |
|
62 | - */ |
|
63 | - public function end($time) { |
|
64 | - $this->end = $time; |
|
65 | - } |
|
60 | + /** |
|
61 | + * @param float $time |
|
62 | + */ |
|
63 | + public function end($time) { |
|
64 | + $this->end = $time; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @return float |
|
69 | - */ |
|
70 | - public function getStart() { |
|
71 | - return $this->start; |
|
72 | - } |
|
67 | + /** |
|
68 | + * @return float |
|
69 | + */ |
|
70 | + public function getStart() { |
|
71 | + return $this->start; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @return string |
|
76 | - */ |
|
77 | - public function getId() { |
|
78 | - return $this->id; |
|
79 | - } |
|
74 | + /** |
|
75 | + * @return string |
|
76 | + */ |
|
77 | + public function getId() { |
|
78 | + return $this->id; |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @return string |
|
83 | - */ |
|
84 | - public function getDescription() { |
|
85 | - return $this->description; |
|
86 | - } |
|
81 | + /** |
|
82 | + * @return string |
|
83 | + */ |
|
84 | + public function getDescription() { |
|
85 | + return $this->description; |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * @return float |
|
90 | - */ |
|
91 | - public function getEnd() { |
|
92 | - return $this->end; |
|
93 | - } |
|
88 | + /** |
|
89 | + * @return float |
|
90 | + */ |
|
91 | + public function getEnd() { |
|
92 | + return $this->end; |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * @return float |
|
97 | - */ |
|
98 | - public function getDuration() { |
|
99 | - if (!$this->end) { |
|
100 | - $this->end = microtime(true); |
|
101 | - } |
|
102 | - return $this->end - $this->start; |
|
103 | - } |
|
95 | + /** |
|
96 | + * @return float |
|
97 | + */ |
|
98 | + public function getDuration() { |
|
99 | + if (!$this->end) { |
|
100 | + $this->end = microtime(true); |
|
101 | + } |
|
102 | + return $this->end - $this->start; |
|
103 | + } |
|
104 | 104 | } |
@@ -29,100 +29,100 @@ |
||
29 | 29 | use OCP\ISession; |
30 | 30 | |
31 | 31 | class DateTimeZone implements IDateTimeZone { |
32 | - /** @var IConfig */ |
|
33 | - protected $config; |
|
32 | + /** @var IConfig */ |
|
33 | + protected $config; |
|
34 | 34 | |
35 | - /** @var ISession */ |
|
36 | - protected $session; |
|
35 | + /** @var ISession */ |
|
36 | + protected $session; |
|
37 | 37 | |
38 | - /** |
|
39 | - * Constructor |
|
40 | - * |
|
41 | - * @param IConfig $config |
|
42 | - * @param ISession $session |
|
43 | - */ |
|
44 | - public function __construct(IConfig $config, ISession $session) { |
|
45 | - $this->config = $config; |
|
46 | - $this->session = $session; |
|
47 | - } |
|
38 | + /** |
|
39 | + * Constructor |
|
40 | + * |
|
41 | + * @param IConfig $config |
|
42 | + * @param ISession $session |
|
43 | + */ |
|
44 | + public function __construct(IConfig $config, ISession $session) { |
|
45 | + $this->config = $config; |
|
46 | + $this->session = $session; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Get the timezone of the current user, based on his session information and config data |
|
51 | - * |
|
52 | - * @param bool|int $timestamp |
|
53 | - * @return \DateTimeZone |
|
54 | - */ |
|
55 | - public function getTimeZone($timestamp = false) { |
|
56 | - $timeZone = $this->config->getUserValue($this->session->get('user_id'), 'core', 'timezone', null); |
|
57 | - if ($timeZone === null) { |
|
58 | - if ($this->session->exists('timezone')) { |
|
59 | - return $this->guessTimeZoneFromOffset($this->session->get('timezone'), $timestamp); |
|
60 | - } |
|
61 | - $timeZone = $this->getDefaultTimeZone(); |
|
62 | - } |
|
49 | + /** |
|
50 | + * Get the timezone of the current user, based on his session information and config data |
|
51 | + * |
|
52 | + * @param bool|int $timestamp |
|
53 | + * @return \DateTimeZone |
|
54 | + */ |
|
55 | + public function getTimeZone($timestamp = false) { |
|
56 | + $timeZone = $this->config->getUserValue($this->session->get('user_id'), 'core', 'timezone', null); |
|
57 | + if ($timeZone === null) { |
|
58 | + if ($this->session->exists('timezone')) { |
|
59 | + return $this->guessTimeZoneFromOffset($this->session->get('timezone'), $timestamp); |
|
60 | + } |
|
61 | + $timeZone = $this->getDefaultTimeZone(); |
|
62 | + } |
|
63 | 63 | |
64 | - try { |
|
65 | - return new \DateTimeZone($timeZone); |
|
66 | - } catch (\Exception $e) { |
|
67 | - \OCP\Util::writeLog('datetimezone', 'Failed to created DateTimeZone "' . $timeZone . "'", \OCP\Util::DEBUG); |
|
68 | - return new \DateTimeZone($this->getDefaultTimeZone()); |
|
69 | - } |
|
70 | - } |
|
64 | + try { |
|
65 | + return new \DateTimeZone($timeZone); |
|
66 | + } catch (\Exception $e) { |
|
67 | + \OCP\Util::writeLog('datetimezone', 'Failed to created DateTimeZone "' . $timeZone . "'", \OCP\Util::DEBUG); |
|
68 | + return new \DateTimeZone($this->getDefaultTimeZone()); |
|
69 | + } |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * Guess the DateTimeZone for a given offset |
|
74 | - * |
|
75 | - * We first try to find a Etc/GMT* timezone, if that does not exist, |
|
76 | - * we try to find it manually, before falling back to UTC. |
|
77 | - * |
|
78 | - * @param mixed $offset |
|
79 | - * @param bool|int $timestamp |
|
80 | - * @return \DateTimeZone |
|
81 | - */ |
|
82 | - protected function guessTimeZoneFromOffset($offset, $timestamp) { |
|
83 | - try { |
|
84 | - // Note: the timeZone name is the inverse to the offset, |
|
85 | - // so a positive offset means negative timeZone |
|
86 | - // and the other way around. |
|
87 | - if ($offset > 0) { |
|
88 | - $timeZone = 'Etc/GMT-' . $offset; |
|
89 | - } else { |
|
90 | - $timeZone = 'Etc/GMT+' . abs($offset); |
|
91 | - } |
|
72 | + /** |
|
73 | + * Guess the DateTimeZone for a given offset |
|
74 | + * |
|
75 | + * We first try to find a Etc/GMT* timezone, if that does not exist, |
|
76 | + * we try to find it manually, before falling back to UTC. |
|
77 | + * |
|
78 | + * @param mixed $offset |
|
79 | + * @param bool|int $timestamp |
|
80 | + * @return \DateTimeZone |
|
81 | + */ |
|
82 | + protected function guessTimeZoneFromOffset($offset, $timestamp) { |
|
83 | + try { |
|
84 | + // Note: the timeZone name is the inverse to the offset, |
|
85 | + // so a positive offset means negative timeZone |
|
86 | + // and the other way around. |
|
87 | + if ($offset > 0) { |
|
88 | + $timeZone = 'Etc/GMT-' . $offset; |
|
89 | + } else { |
|
90 | + $timeZone = 'Etc/GMT+' . abs($offset); |
|
91 | + } |
|
92 | 92 | |
93 | - return new \DateTimeZone($timeZone); |
|
94 | - } catch (\Exception $e) { |
|
95 | - // If the offset has no Etc/GMT* timezone, |
|
96 | - // we try to guess one timezone that has the same offset |
|
97 | - foreach (\DateTimeZone::listIdentifiers() as $timeZone) { |
|
98 | - $dtz = new \DateTimeZone($timeZone); |
|
99 | - $dateTime = new \DateTime(); |
|
93 | + return new \DateTimeZone($timeZone); |
|
94 | + } catch (\Exception $e) { |
|
95 | + // If the offset has no Etc/GMT* timezone, |
|
96 | + // we try to guess one timezone that has the same offset |
|
97 | + foreach (\DateTimeZone::listIdentifiers() as $timeZone) { |
|
98 | + $dtz = new \DateTimeZone($timeZone); |
|
99 | + $dateTime = new \DateTime(); |
|
100 | 100 | |
101 | - if ($timestamp !== false) { |
|
102 | - $dateTime->setTimestamp($timestamp); |
|
103 | - } |
|
101 | + if ($timestamp !== false) { |
|
102 | + $dateTime->setTimestamp($timestamp); |
|
103 | + } |
|
104 | 104 | |
105 | - $dtOffset = $dtz->getOffset($dateTime); |
|
106 | - if ($dtOffset == 3600 * $offset) { |
|
107 | - return $dtz; |
|
108 | - } |
|
109 | - } |
|
105 | + $dtOffset = $dtz->getOffset($dateTime); |
|
106 | + if ($dtOffset == 3600 * $offset) { |
|
107 | + return $dtz; |
|
108 | + } |
|
109 | + } |
|
110 | 110 | |
111 | - // No timezone found, fallback to UTC |
|
112 | - \OCP\Util::writeLog('datetimezone', 'Failed to find DateTimeZone for offset "' . $offset . "'", \OCP\Util::DEBUG); |
|
113 | - return new \DateTimeZone($this->getDefaultTimeZone()); |
|
114 | - } |
|
115 | - } |
|
111 | + // No timezone found, fallback to UTC |
|
112 | + \OCP\Util::writeLog('datetimezone', 'Failed to find DateTimeZone for offset "' . $offset . "'", \OCP\Util::DEBUG); |
|
113 | + return new \DateTimeZone($this->getDefaultTimeZone()); |
|
114 | + } |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * Get the default timezone of the server |
|
119 | - * |
|
120 | - * Falls back to UTC if it is not yet set. |
|
121 | - * |
|
122 | - * @return string |
|
123 | - */ |
|
124 | - protected function getDefaultTimeZone() { |
|
125 | - $serverTimeZone = date_default_timezone_get(); |
|
126 | - return $serverTimeZone ?: 'UTC'; |
|
127 | - } |
|
117 | + /** |
|
118 | + * Get the default timezone of the server |
|
119 | + * |
|
120 | + * Falls back to UTC if it is not yet set. |
|
121 | + * |
|
122 | + * @return string |
|
123 | + */ |
|
124 | + protected function getDefaultTimeZone() { |
|
125 | + $serverTimeZone = date_default_timezone_get(); |
|
126 | + return $serverTimeZone ?: 'UTC'; |
|
127 | + } |
|
128 | 128 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | try { |
65 | 65 | return new \DateTimeZone($timeZone); |
66 | 66 | } catch (\Exception $e) { |
67 | - \OCP\Util::writeLog('datetimezone', 'Failed to created DateTimeZone "' . $timeZone . "'", \OCP\Util::DEBUG); |
|
67 | + \OCP\Util::writeLog('datetimezone', 'Failed to created DateTimeZone "'.$timeZone."'", \OCP\Util::DEBUG); |
|
68 | 68 | return new \DateTimeZone($this->getDefaultTimeZone()); |
69 | 69 | } |
70 | 70 | } |
@@ -85,9 +85,9 @@ discard block |
||
85 | 85 | // so a positive offset means negative timeZone |
86 | 86 | // and the other way around. |
87 | 87 | if ($offset > 0) { |
88 | - $timeZone = 'Etc/GMT-' . $offset; |
|
88 | + $timeZone = 'Etc/GMT-'.$offset; |
|
89 | 89 | } else { |
90 | - $timeZone = 'Etc/GMT+' . abs($offset); |
|
90 | + $timeZone = 'Etc/GMT+'.abs($offset); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | return new \DateTimeZone($timeZone); |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | } |
110 | 110 | |
111 | 111 | // No timezone found, fallback to UTC |
112 | - \OCP\Util::writeLog('datetimezone', 'Failed to find DateTimeZone for offset "' . $offset . "'", \OCP\Util::DEBUG); |
|
112 | + \OCP\Util::writeLog('datetimezone', 'Failed to find DateTimeZone for offset "'.$offset."'", \OCP\Util::DEBUG); |
|
113 | 113 | return new \DateTimeZone($this->getDefaultTimeZone()); |
114 | 114 | } |
115 | 115 | } |
@@ -33,47 +33,47 @@ |
||
33 | 33 | */ |
34 | 34 | class TagMapper extends Mapper { |
35 | 35 | |
36 | - /** |
|
37 | - * Constructor. |
|
38 | - * |
|
39 | - * @param IDBConnection $db Instance of the Db abstraction layer. |
|
40 | - */ |
|
41 | - public function __construct(IDBConnection $db) { |
|
42 | - parent::__construct($db, 'vcategory', 'OC\Tagging\Tag'); |
|
43 | - } |
|
36 | + /** |
|
37 | + * Constructor. |
|
38 | + * |
|
39 | + * @param IDBConnection $db Instance of the Db abstraction layer. |
|
40 | + */ |
|
41 | + public function __construct(IDBConnection $db) { |
|
42 | + parent::__construct($db, 'vcategory', 'OC\Tagging\Tag'); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Load tags from the database. |
|
47 | - * |
|
48 | - * @param array|string $owners The user(s) whose tags we are going to load. |
|
49 | - * @param string $type The type of item for which we are loading tags. |
|
50 | - * @return array An array of Tag objects. |
|
51 | - */ |
|
52 | - public function loadTags($owners, $type) { |
|
53 | - if(!is_array($owners)) { |
|
54 | - $owners = array($owners); |
|
55 | - } |
|
45 | + /** |
|
46 | + * Load tags from the database. |
|
47 | + * |
|
48 | + * @param array|string $owners The user(s) whose tags we are going to load. |
|
49 | + * @param string $type The type of item for which we are loading tags. |
|
50 | + * @return array An array of Tag objects. |
|
51 | + */ |
|
52 | + public function loadTags($owners, $type) { |
|
53 | + if(!is_array($owners)) { |
|
54 | + $owners = array($owners); |
|
55 | + } |
|
56 | 56 | |
57 | - $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
58 | - . 'WHERE `uid` IN (' . str_repeat('?,', count($owners)-1) . '?) AND `type` = ? ORDER BY `category`'; |
|
59 | - return $this->findEntities($sql, array_merge($owners, array($type))); |
|
60 | - } |
|
57 | + $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
58 | + . 'WHERE `uid` IN (' . str_repeat('?,', count($owners)-1) . '?) AND `type` = ? ORDER BY `category`'; |
|
59 | + return $this->findEntities($sql, array_merge($owners, array($type))); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Check if a given Tag object already exists in the database. |
|
64 | - * |
|
65 | - * @param Tag $tag The tag to look for in the database. |
|
66 | - * @return bool |
|
67 | - */ |
|
68 | - public function tagExists($tag) { |
|
69 | - $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
70 | - . 'WHERE `uid` = ? AND `type` = ? AND `category` = ?'; |
|
71 | - try { |
|
72 | - $this->findEntity($sql, array($tag->getOwner(), $tag->getType(), $tag->getName())); |
|
73 | - } catch (DoesNotExistException $e) { |
|
74 | - return false; |
|
75 | - } |
|
76 | - return true; |
|
77 | - } |
|
62 | + /** |
|
63 | + * Check if a given Tag object already exists in the database. |
|
64 | + * |
|
65 | + * @param Tag $tag The tag to look for in the database. |
|
66 | + * @return bool |
|
67 | + */ |
|
68 | + public function tagExists($tag) { |
|
69 | + $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
70 | + . 'WHERE `uid` = ? AND `type` = ? AND `category` = ?'; |
|
71 | + try { |
|
72 | + $this->findEntity($sql, array($tag->getOwner(), $tag->getType(), $tag->getName())); |
|
73 | + } catch (DoesNotExistException $e) { |
|
74 | + return false; |
|
75 | + } |
|
76 | + return true; |
|
77 | + } |
|
78 | 78 | } |
79 | 79 |
@@ -50,12 +50,12 @@ discard block |
||
50 | 50 | * @return array An array of Tag objects. |
51 | 51 | */ |
52 | 52 | public function loadTags($owners, $type) { |
53 | - if(!is_array($owners)) { |
|
53 | + if (!is_array($owners)) { |
|
54 | 54 | $owners = array($owners); |
55 | 55 | } |
56 | 56 | |
57 | - $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
58 | - . 'WHERE `uid` IN (' . str_repeat('?,', count($owners)-1) . '?) AND `type` = ? ORDER BY `category`'; |
|
57 | + $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `'.$this->getTableName().'` ' |
|
58 | + . 'WHERE `uid` IN ('.str_repeat('?,', count($owners) - 1).'?) AND `type` = ? ORDER BY `category`'; |
|
59 | 59 | return $this->findEntities($sql, array_merge($owners, array($type))); |
60 | 60 | } |
61 | 61 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @return bool |
67 | 67 | */ |
68 | 68 | public function tagExists($tag) { |
69 | - $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
69 | + $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `'.$this->getTableName().'` ' |
|
70 | 70 | . 'WHERE `uid` = ? AND `type` = ? AND `category` = ?'; |
71 | 71 | try { |
72 | 72 | $this->findEntity($sql, array($tag->getOwner(), $tag->getType(), $tag->getName())); |
@@ -37,54 +37,54 @@ |
||
37 | 37 | */ |
38 | 38 | class Tag extends Entity { |
39 | 39 | |
40 | - protected $owner; |
|
41 | - protected $type; |
|
42 | - protected $name; |
|
40 | + protected $owner; |
|
41 | + protected $type; |
|
42 | + protected $name; |
|
43 | 43 | |
44 | - /** |
|
45 | - * Constructor. |
|
46 | - * |
|
47 | - * @param string $owner The tag's owner |
|
48 | - * @param string $type The type of item this tag is used for |
|
49 | - * @param string $name The tag's name |
|
50 | - */ |
|
51 | - public function __construct($owner = null, $type = null, $name = null) { |
|
52 | - $this->setOwner($owner); |
|
53 | - $this->setType($type); |
|
54 | - $this->setName($name); |
|
55 | - } |
|
44 | + /** |
|
45 | + * Constructor. |
|
46 | + * |
|
47 | + * @param string $owner The tag's owner |
|
48 | + * @param string $type The type of item this tag is used for |
|
49 | + * @param string $name The tag's name |
|
50 | + */ |
|
51 | + public function __construct($owner = null, $type = null, $name = null) { |
|
52 | + $this->setOwner($owner); |
|
53 | + $this->setType($type); |
|
54 | + $this->setName($name); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Transform a database columnname to a property |
|
59 | - * |
|
60 | - * @param string $columnName the name of the column |
|
61 | - * @return string the property name |
|
62 | - * @todo migrate existing database columns to the correct names |
|
63 | - * to be able to drop this direct mapping |
|
64 | - */ |
|
65 | - public function columnToProperty($columnName){ |
|
66 | - if ($columnName === 'category') { |
|
67 | - return 'name'; |
|
68 | - } elseif ($columnName === 'uid') { |
|
69 | - return 'owner'; |
|
70 | - } else { |
|
71 | - return parent::columnToProperty($columnName); |
|
72 | - } |
|
73 | - } |
|
57 | + /** |
|
58 | + * Transform a database columnname to a property |
|
59 | + * |
|
60 | + * @param string $columnName the name of the column |
|
61 | + * @return string the property name |
|
62 | + * @todo migrate existing database columns to the correct names |
|
63 | + * to be able to drop this direct mapping |
|
64 | + */ |
|
65 | + public function columnToProperty($columnName){ |
|
66 | + if ($columnName === 'category') { |
|
67 | + return 'name'; |
|
68 | + } elseif ($columnName === 'uid') { |
|
69 | + return 'owner'; |
|
70 | + } else { |
|
71 | + return parent::columnToProperty($columnName); |
|
72 | + } |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Transform a property to a database column name |
|
77 | - * |
|
78 | - * @param string $property the name of the property |
|
79 | - * @return string the column name |
|
80 | - */ |
|
81 | - public function propertyToColumn($property){ |
|
82 | - if ($property === 'name') { |
|
83 | - return 'category'; |
|
84 | - } elseif ($property === 'owner') { |
|
85 | - return 'uid'; |
|
86 | - } else { |
|
87 | - return parent::propertyToColumn($property); |
|
88 | - } |
|
89 | - } |
|
75 | + /** |
|
76 | + * Transform a property to a database column name |
|
77 | + * |
|
78 | + * @param string $property the name of the property |
|
79 | + * @return string the column name |
|
80 | + */ |
|
81 | + public function propertyToColumn($property){ |
|
82 | + if ($property === 'name') { |
|
83 | + return 'category'; |
|
84 | + } elseif ($property === 'owner') { |
|
85 | + return 'uid'; |
|
86 | + } else { |
|
87 | + return parent::propertyToColumn($property); |
|
88 | + } |
|
89 | + } |
|
90 | 90 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * @todo migrate existing database columns to the correct names |
63 | 63 | * to be able to drop this direct mapping |
64 | 64 | */ |
65 | - public function columnToProperty($columnName){ |
|
65 | + public function columnToProperty($columnName) { |
|
66 | 66 | if ($columnName === 'category') { |
67 | 67 | return 'name'; |
68 | 68 | } elseif ($columnName === 'uid') { |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * @param string $property the name of the property |
79 | 79 | * @return string the column name |
80 | 80 | */ |
81 | - public function propertyToColumn($property){ |
|
81 | + public function propertyToColumn($property) { |
|
82 | 82 | if ($property === 'name') { |
83 | 83 | return 'category'; |
84 | 84 | } elseif ($property === 'owner') { |
@@ -28,38 +28,38 @@ |
||
28 | 28 | use OCP\ILogger; |
29 | 29 | |
30 | 30 | class CachingRouter extends Router { |
31 | - /** |
|
32 | - * @var \OCP\ICache |
|
33 | - */ |
|
34 | - protected $cache; |
|
31 | + /** |
|
32 | + * @var \OCP\ICache |
|
33 | + */ |
|
34 | + protected $cache; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param \OCP\ICache $cache |
|
38 | - * @param ILogger $logger |
|
39 | - */ |
|
40 | - public function __construct($cache, ILogger $logger) { |
|
41 | - $this->cache = $cache; |
|
42 | - parent::__construct($logger); |
|
43 | - } |
|
36 | + /** |
|
37 | + * @param \OCP\ICache $cache |
|
38 | + * @param ILogger $logger |
|
39 | + */ |
|
40 | + public function __construct($cache, ILogger $logger) { |
|
41 | + $this->cache = $cache; |
|
42 | + parent::__construct($logger); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Generate url based on $name and $parameters |
|
47 | - * |
|
48 | - * @param string $name Name of the route to use. |
|
49 | - * @param array $parameters Parameters for the route |
|
50 | - * @param bool $absolute |
|
51 | - * @return string |
|
52 | - */ |
|
53 | - public function generate($name, $parameters = array(), $absolute = false) { |
|
54 | - asort($parameters); |
|
55 | - $key = $this->context->getHost() . '#' . $this->context->getBaseUrl() . $name . sha1(json_encode($parameters)) . intval($absolute); |
|
56 | - $cachedKey = $this->cache->get($key); |
|
57 | - if ($cachedKey) { |
|
58 | - return $cachedKey; |
|
59 | - } else { |
|
60 | - $url = parent::generate($name, $parameters, $absolute); |
|
61 | - $this->cache->set($key, $url, 3600); |
|
62 | - return $url; |
|
63 | - } |
|
64 | - } |
|
45 | + /** |
|
46 | + * Generate url based on $name and $parameters |
|
47 | + * |
|
48 | + * @param string $name Name of the route to use. |
|
49 | + * @param array $parameters Parameters for the route |
|
50 | + * @param bool $absolute |
|
51 | + * @return string |
|
52 | + */ |
|
53 | + public function generate($name, $parameters = array(), $absolute = false) { |
|
54 | + asort($parameters); |
|
55 | + $key = $this->context->getHost() . '#' . $this->context->getBaseUrl() . $name . sha1(json_encode($parameters)) . intval($absolute); |
|
56 | + $cachedKey = $this->cache->get($key); |
|
57 | + if ($cachedKey) { |
|
58 | + return $cachedKey; |
|
59 | + } else { |
|
60 | + $url = parent::generate($name, $parameters, $absolute); |
|
61 | + $this->cache->set($key, $url, 3600); |
|
62 | + return $url; |
|
63 | + } |
|
64 | + } |
|
65 | 65 | } |
@@ -52,7 +52,7 @@ |
||
52 | 52 | */ |
53 | 53 | public function generate($name, $parameters = array(), $absolute = false) { |
54 | 54 | asort($parameters); |
55 | - $key = $this->context->getHost() . '#' . $this->context->getBaseUrl() . $name . sha1(json_encode($parameters)) . intval($absolute); |
|
55 | + $key = $this->context->getHost().'#'.$this->context->getBaseUrl().$name.sha1(json_encode($parameters)).intval($absolute); |
|
56 | 56 | $cachedKey = $this->cache->get($key); |
57 | 57 | if ($cachedKey) { |
58 | 58 | return $cachedKey; |