@@ -36,178 +36,178 @@ |
||
36 | 36 | */ |
37 | 37 | interface IUser { |
38 | 38 | |
39 | - /** |
|
40 | - * get the user id |
|
41 | - * |
|
42 | - * @return string |
|
43 | - * @since 8.0.0 |
|
44 | - */ |
|
45 | - public function getUID(); |
|
46 | - |
|
47 | - /** |
|
48 | - * get the display name for the user, if no specific display name is set it will fallback to the user id |
|
49 | - * |
|
50 | - * @return string |
|
51 | - * @since 8.0.0 |
|
52 | - */ |
|
53 | - public function getDisplayName(); |
|
54 | - |
|
55 | - /** |
|
56 | - * set the display name for the user |
|
57 | - * |
|
58 | - * @param string $displayName |
|
59 | - * @return bool |
|
60 | - * @since 8.0.0 |
|
61 | - */ |
|
62 | - public function setDisplayName($displayName); |
|
63 | - |
|
64 | - /** |
|
65 | - * returns the timestamp of the user's last login or 0 if the user did never |
|
66 | - * login |
|
67 | - * |
|
68 | - * @return int |
|
69 | - * @since 8.0.0 |
|
70 | - */ |
|
71 | - public function getLastLogin(); |
|
72 | - |
|
73 | - /** |
|
74 | - * updates the timestamp of the most recent login of this user |
|
75 | - * @since 8.0.0 |
|
76 | - */ |
|
77 | - public function updateLastLoginTimestamp(); |
|
78 | - |
|
79 | - /** |
|
80 | - * Delete the user |
|
81 | - * |
|
82 | - * @return bool |
|
83 | - * @since 8.0.0 |
|
84 | - */ |
|
85 | - public function delete(); |
|
86 | - |
|
87 | - /** |
|
88 | - * Set the password of the user |
|
89 | - * |
|
90 | - * @param string $password |
|
91 | - * @param string $recoveryPassword for the encryption app to reset encryption keys |
|
92 | - * @return bool |
|
93 | - * @since 8.0.0 |
|
94 | - */ |
|
95 | - public function setPassword($password, $recoveryPassword = null); |
|
96 | - |
|
97 | - /** |
|
98 | - * get the users home folder to mount |
|
99 | - * |
|
100 | - * @return string |
|
101 | - * @since 8.0.0 |
|
102 | - */ |
|
103 | - public function getHome(); |
|
104 | - |
|
105 | - /** |
|
106 | - * Get the name of the backend class the user is connected with |
|
107 | - * |
|
108 | - * @return string |
|
109 | - * @since 8.0.0 |
|
110 | - */ |
|
111 | - public function getBackendClassName(); |
|
112 | - |
|
113 | - /** |
|
114 | - * Get the backend for the current user object |
|
115 | - * |
|
116 | - * @return UserInterface |
|
117 | - * @since 15.0.0 |
|
118 | - */ |
|
119 | - public function getBackend(); |
|
120 | - |
|
121 | - /** |
|
122 | - * check if the backend allows the user to change his avatar on Personal page |
|
123 | - * |
|
124 | - * @return bool |
|
125 | - * @since 8.0.0 |
|
126 | - */ |
|
127 | - public function canChangeAvatar(); |
|
128 | - |
|
129 | - /** |
|
130 | - * check if the backend supports changing passwords |
|
131 | - * |
|
132 | - * @return bool |
|
133 | - * @since 8.0.0 |
|
134 | - */ |
|
135 | - public function canChangePassword(); |
|
136 | - |
|
137 | - /** |
|
138 | - * check if the backend supports changing display names |
|
139 | - * |
|
140 | - * @return bool |
|
141 | - * @since 8.0.0 |
|
142 | - */ |
|
143 | - public function canChangeDisplayName(); |
|
144 | - |
|
145 | - /** |
|
146 | - * check if the user is enabled |
|
147 | - * |
|
148 | - * @return bool |
|
149 | - * @since 8.0.0 |
|
150 | - */ |
|
151 | - public function isEnabled(); |
|
152 | - |
|
153 | - /** |
|
154 | - * set the enabled status for the user |
|
155 | - * |
|
156 | - * @param bool $enabled |
|
157 | - * @since 8.0.0 |
|
158 | - */ |
|
159 | - public function setEnabled(bool $enabled = true); |
|
160 | - |
|
161 | - /** |
|
162 | - * get the users email address |
|
163 | - * |
|
164 | - * @return string|null |
|
165 | - * @since 9.0.0 |
|
166 | - */ |
|
167 | - public function getEMailAddress(); |
|
168 | - |
|
169 | - /** |
|
170 | - * get the avatar image if it exists |
|
171 | - * |
|
172 | - * @param int $size |
|
173 | - * @return IImage|null |
|
174 | - * @since 9.0.0 |
|
175 | - */ |
|
176 | - public function getAvatarImage($size); |
|
177 | - |
|
178 | - /** |
|
179 | - * get the federation cloud id |
|
180 | - * |
|
181 | - * @return string |
|
182 | - * @since 9.0.0 |
|
183 | - */ |
|
184 | - public function getCloudId(); |
|
185 | - |
|
186 | - /** |
|
187 | - * set the email address of the user |
|
188 | - * |
|
189 | - * @param string|null $mailAddress |
|
190 | - * @return void |
|
191 | - * @since 9.0.0 |
|
192 | - */ |
|
193 | - public function setEMailAddress($mailAddress); |
|
194 | - |
|
195 | - /** |
|
196 | - * get the users' quota in human readable form. If a specific quota is not |
|
197 | - * set for the user, the default value is returned. If a default setting |
|
198 | - * was not set otherwise, it is return as 'none', i.e. quota is not limited. |
|
199 | - * |
|
200 | - * @return string |
|
201 | - * @since 9.0.0 |
|
202 | - */ |
|
203 | - public function getQuota(); |
|
204 | - |
|
205 | - /** |
|
206 | - * set the users' quota |
|
207 | - * |
|
208 | - * @param string $quota |
|
209 | - * @return void |
|
210 | - * @since 9.0.0 |
|
211 | - */ |
|
212 | - public function setQuota($quota); |
|
39 | + /** |
|
40 | + * get the user id |
|
41 | + * |
|
42 | + * @return string |
|
43 | + * @since 8.0.0 |
|
44 | + */ |
|
45 | + public function getUID(); |
|
46 | + |
|
47 | + /** |
|
48 | + * get the display name for the user, if no specific display name is set it will fallback to the user id |
|
49 | + * |
|
50 | + * @return string |
|
51 | + * @since 8.0.0 |
|
52 | + */ |
|
53 | + public function getDisplayName(); |
|
54 | + |
|
55 | + /** |
|
56 | + * set the display name for the user |
|
57 | + * |
|
58 | + * @param string $displayName |
|
59 | + * @return bool |
|
60 | + * @since 8.0.0 |
|
61 | + */ |
|
62 | + public function setDisplayName($displayName); |
|
63 | + |
|
64 | + /** |
|
65 | + * returns the timestamp of the user's last login or 0 if the user did never |
|
66 | + * login |
|
67 | + * |
|
68 | + * @return int |
|
69 | + * @since 8.0.0 |
|
70 | + */ |
|
71 | + public function getLastLogin(); |
|
72 | + |
|
73 | + /** |
|
74 | + * updates the timestamp of the most recent login of this user |
|
75 | + * @since 8.0.0 |
|
76 | + */ |
|
77 | + public function updateLastLoginTimestamp(); |
|
78 | + |
|
79 | + /** |
|
80 | + * Delete the user |
|
81 | + * |
|
82 | + * @return bool |
|
83 | + * @since 8.0.0 |
|
84 | + */ |
|
85 | + public function delete(); |
|
86 | + |
|
87 | + /** |
|
88 | + * Set the password of the user |
|
89 | + * |
|
90 | + * @param string $password |
|
91 | + * @param string $recoveryPassword for the encryption app to reset encryption keys |
|
92 | + * @return bool |
|
93 | + * @since 8.0.0 |
|
94 | + */ |
|
95 | + public function setPassword($password, $recoveryPassword = null); |
|
96 | + |
|
97 | + /** |
|
98 | + * get the users home folder to mount |
|
99 | + * |
|
100 | + * @return string |
|
101 | + * @since 8.0.0 |
|
102 | + */ |
|
103 | + public function getHome(); |
|
104 | + |
|
105 | + /** |
|
106 | + * Get the name of the backend class the user is connected with |
|
107 | + * |
|
108 | + * @return string |
|
109 | + * @since 8.0.0 |
|
110 | + */ |
|
111 | + public function getBackendClassName(); |
|
112 | + |
|
113 | + /** |
|
114 | + * Get the backend for the current user object |
|
115 | + * |
|
116 | + * @return UserInterface |
|
117 | + * @since 15.0.0 |
|
118 | + */ |
|
119 | + public function getBackend(); |
|
120 | + |
|
121 | + /** |
|
122 | + * check if the backend allows the user to change his avatar on Personal page |
|
123 | + * |
|
124 | + * @return bool |
|
125 | + * @since 8.0.0 |
|
126 | + */ |
|
127 | + public function canChangeAvatar(); |
|
128 | + |
|
129 | + /** |
|
130 | + * check if the backend supports changing passwords |
|
131 | + * |
|
132 | + * @return bool |
|
133 | + * @since 8.0.0 |
|
134 | + */ |
|
135 | + public function canChangePassword(); |
|
136 | + |
|
137 | + /** |
|
138 | + * check if the backend supports changing display names |
|
139 | + * |
|
140 | + * @return bool |
|
141 | + * @since 8.0.0 |
|
142 | + */ |
|
143 | + public function canChangeDisplayName(); |
|
144 | + |
|
145 | + /** |
|
146 | + * check if the user is enabled |
|
147 | + * |
|
148 | + * @return bool |
|
149 | + * @since 8.0.0 |
|
150 | + */ |
|
151 | + public function isEnabled(); |
|
152 | + |
|
153 | + /** |
|
154 | + * set the enabled status for the user |
|
155 | + * |
|
156 | + * @param bool $enabled |
|
157 | + * @since 8.0.0 |
|
158 | + */ |
|
159 | + public function setEnabled(bool $enabled = true); |
|
160 | + |
|
161 | + /** |
|
162 | + * get the users email address |
|
163 | + * |
|
164 | + * @return string|null |
|
165 | + * @since 9.0.0 |
|
166 | + */ |
|
167 | + public function getEMailAddress(); |
|
168 | + |
|
169 | + /** |
|
170 | + * get the avatar image if it exists |
|
171 | + * |
|
172 | + * @param int $size |
|
173 | + * @return IImage|null |
|
174 | + * @since 9.0.0 |
|
175 | + */ |
|
176 | + public function getAvatarImage($size); |
|
177 | + |
|
178 | + /** |
|
179 | + * get the federation cloud id |
|
180 | + * |
|
181 | + * @return string |
|
182 | + * @since 9.0.0 |
|
183 | + */ |
|
184 | + public function getCloudId(); |
|
185 | + |
|
186 | + /** |
|
187 | + * set the email address of the user |
|
188 | + * |
|
189 | + * @param string|null $mailAddress |
|
190 | + * @return void |
|
191 | + * @since 9.0.0 |
|
192 | + */ |
|
193 | + public function setEMailAddress($mailAddress); |
|
194 | + |
|
195 | + /** |
|
196 | + * get the users' quota in human readable form. If a specific quota is not |
|
197 | + * set for the user, the default value is returned. If a default setting |
|
198 | + * was not set otherwise, it is return as 'none', i.e. quota is not limited. |
|
199 | + * |
|
200 | + * @return string |
|
201 | + * @since 9.0.0 |
|
202 | + */ |
|
203 | + public function getQuota(); |
|
204 | + |
|
205 | + /** |
|
206 | + * set the users' quota |
|
207 | + * |
|
208 | + * @param string $quota |
|
209 | + * @return void |
|
210 | + * @since 9.0.0 |
|
211 | + */ |
|
212 | + public function setQuota($quota); |
|
213 | 213 | } |
@@ -29,60 +29,60 @@ |
||
29 | 29 | use OC\Updater\VersionCheck; |
30 | 30 | |
31 | 31 | class UpdateChecker { |
32 | - /** @var VersionCheck */ |
|
33 | - private $updater; |
|
34 | - /** @var ChangesCheck */ |
|
35 | - private $changesCheck; |
|
32 | + /** @var VersionCheck */ |
|
33 | + private $updater; |
|
34 | + /** @var ChangesCheck */ |
|
35 | + private $changesCheck; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param VersionCheck $updater |
|
39 | - */ |
|
40 | - public function __construct(VersionCheck $updater, ChangesCheck $changesCheck) { |
|
41 | - $this->updater = $updater; |
|
42 | - $this->changesCheck = $changesCheck; |
|
43 | - } |
|
37 | + /** |
|
38 | + * @param VersionCheck $updater |
|
39 | + */ |
|
40 | + public function __construct(VersionCheck $updater, ChangesCheck $changesCheck) { |
|
41 | + $this->updater = $updater; |
|
42 | + $this->changesCheck = $changesCheck; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * @return array |
|
47 | - */ |
|
48 | - public function getUpdateState(): array { |
|
49 | - $data = $this->updater->check(); |
|
50 | - $result = []; |
|
45 | + /** |
|
46 | + * @return array |
|
47 | + */ |
|
48 | + public function getUpdateState(): array { |
|
49 | + $data = $this->updater->check(); |
|
50 | + $result = []; |
|
51 | 51 | |
52 | - if (isset($data['version']) && $data['version'] !== '' && $data['version'] !== []) { |
|
53 | - $result['updateAvailable'] = true; |
|
54 | - $result['updateVersion'] = $data['version']; |
|
55 | - $result['updateVersionString'] = $data['versionstring']; |
|
56 | - $result['updaterEnabled'] = $data['autoupdater'] === '1'; |
|
57 | - $result['versionIsEol'] = $data['eol'] === '1'; |
|
58 | - if (strpos($data['web'], 'https://') === 0) { |
|
59 | - $result['updateLink'] = $data['web']; |
|
60 | - } |
|
61 | - if (strpos($data['url'], 'https://') === 0) { |
|
62 | - $result['downloadLink'] = $data['url']; |
|
63 | - } |
|
64 | - if (strpos($data['changes'], 'https://') === 0) { |
|
65 | - try { |
|
66 | - $result['changes'] = $this->changesCheck->check($data['changes'], $data['version']); |
|
67 | - } catch (\Exception $e) { |
|
68 | - // no info, not a problem |
|
69 | - } |
|
70 | - } |
|
52 | + if (isset($data['version']) && $data['version'] !== '' && $data['version'] !== []) { |
|
53 | + $result['updateAvailable'] = true; |
|
54 | + $result['updateVersion'] = $data['version']; |
|
55 | + $result['updateVersionString'] = $data['versionstring']; |
|
56 | + $result['updaterEnabled'] = $data['autoupdater'] === '1'; |
|
57 | + $result['versionIsEol'] = $data['eol'] === '1'; |
|
58 | + if (strpos($data['web'], 'https://') === 0) { |
|
59 | + $result['updateLink'] = $data['web']; |
|
60 | + } |
|
61 | + if (strpos($data['url'], 'https://') === 0) { |
|
62 | + $result['downloadLink'] = $data['url']; |
|
63 | + } |
|
64 | + if (strpos($data['changes'], 'https://') === 0) { |
|
65 | + try { |
|
66 | + $result['changes'] = $this->changesCheck->check($data['changes'], $data['version']); |
|
67 | + } catch (\Exception $e) { |
|
68 | + // no info, not a problem |
|
69 | + } |
|
70 | + } |
|
71 | 71 | |
72 | - return $result; |
|
73 | - } |
|
72 | + return $result; |
|
73 | + } |
|
74 | 74 | |
75 | - return []; |
|
76 | - } |
|
75 | + return []; |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @param array $data |
|
80 | - */ |
|
81 | - public function populateJavaScriptVariables(array $data) { |
|
82 | - $data['array']['oc_updateState'] = json_encode([ |
|
83 | - 'updateAvailable' => true, |
|
84 | - 'updateVersion' => $this->getUpdateState()['updateVersionString'], |
|
85 | - 'updateLink' => $this->getUpdateState()['updateLink'] ?? '', |
|
86 | - ]); |
|
87 | - } |
|
78 | + /** |
|
79 | + * @param array $data |
|
80 | + */ |
|
81 | + public function populateJavaScriptVariables(array $data) { |
|
82 | + $data['array']['oc_updateState'] = json_encode([ |
|
83 | + 'updateAvailable' => true, |
|
84 | + 'updateVersion' => $this->getUpdateState()['updateVersionString'], |
|
85 | + 'updateLink' => $this->getUpdateState()['updateLink'] ?? '', |
|
86 | + ]); |
|
87 | + } |
|
88 | 88 | } |
@@ -79,7 +79,7 @@ |
||
79 | 79 | * @param array $data |
80 | 80 | */ |
81 | 81 | public function populateJavaScriptVariables(array $data) { |
82 | - $data['array']['oc_updateState'] = json_encode([ |
|
82 | + $data['array']['oc_updateState'] = json_encode([ |
|
83 | 83 | 'updateAvailable' => true, |
84 | 84 | 'updateVersion' => $this->getUpdateState()['updateVersionString'], |
85 | 85 | 'updateLink' => $this->getUpdateState()['updateLink'] ?? '', |
@@ -36,143 +36,143 @@ |
||
36 | 36 | */ |
37 | 37 | class Loader implements IMimeTypeLoader { |
38 | 38 | |
39 | - /** @var IDBConnection */ |
|
40 | - private $dbConnection; |
|
41 | - |
|
42 | - /** @var array [id => mimetype] */ |
|
43 | - protected $mimetypes; |
|
44 | - |
|
45 | - /** @var array [mimetype => id] */ |
|
46 | - protected $mimetypeIds; |
|
47 | - |
|
48 | - /** |
|
49 | - * @param IDBConnection $dbConnection |
|
50 | - */ |
|
51 | - public function __construct(IDBConnection $dbConnection) { |
|
52 | - $this->dbConnection = $dbConnection; |
|
53 | - $this->mimetypes = []; |
|
54 | - $this->mimetypeIds = []; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Get a mimetype from its ID |
|
59 | - * |
|
60 | - * @param int $id |
|
61 | - * @return string|null |
|
62 | - */ |
|
63 | - public function getMimetypeById($id) { |
|
64 | - if (!$this->mimetypes) { |
|
65 | - $this->loadMimetypes(); |
|
66 | - } |
|
67 | - if (isset($this->mimetypes[$id])) { |
|
68 | - return $this->mimetypes[$id]; |
|
69 | - } |
|
70 | - return null; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Get a mimetype ID, adding the mimetype to the DB if it does not exist |
|
75 | - * |
|
76 | - * @param string $mimetype |
|
77 | - * @return int |
|
78 | - */ |
|
79 | - public function getId($mimetype) { |
|
80 | - if (!$this->mimetypeIds) { |
|
81 | - $this->loadMimetypes(); |
|
82 | - } |
|
83 | - if (isset($this->mimetypeIds[$mimetype])) { |
|
84 | - return $this->mimetypeIds[$mimetype]; |
|
85 | - } |
|
86 | - return $this->store($mimetype); |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Test if a mimetype exists in the database |
|
91 | - * |
|
92 | - * @param string $mimetype |
|
93 | - * @return bool |
|
94 | - */ |
|
95 | - public function exists($mimetype) { |
|
96 | - if (!$this->mimetypeIds) { |
|
97 | - $this->loadMimetypes(); |
|
98 | - } |
|
99 | - return isset($this->mimetypeIds[$mimetype]); |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Clear all loaded mimetypes, allow for re-loading |
|
104 | - */ |
|
105 | - public function reset() { |
|
106 | - $this->mimetypes = []; |
|
107 | - $this->mimetypeIds = []; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Store a mimetype in the DB |
|
112 | - * |
|
113 | - * @param string $mimetype |
|
114 | - * @param int inserted ID |
|
115 | - */ |
|
116 | - protected function store($mimetype) { |
|
117 | - $this->dbConnection->insertIfNotExist('*PREFIX*mimetypes', [ |
|
118 | - 'mimetype' => $mimetype |
|
119 | - ]); |
|
120 | - |
|
121 | - $fetch = $this->dbConnection->getQueryBuilder(); |
|
122 | - $fetch->select('id') |
|
123 | - ->from('mimetypes') |
|
124 | - ->where( |
|
125 | - $fetch->expr()->eq('mimetype', $fetch->createNamedParameter($mimetype) |
|
126 | - )); |
|
127 | - $row = $fetch->execute()->fetch(); |
|
128 | - |
|
129 | - if (!$row) { |
|
130 | - throw new \Exception("Failed to get mimetype id for $mimetype after trying to store it"); |
|
131 | - } |
|
132 | - |
|
133 | - $this->mimetypes[$row['id']] = $mimetype; |
|
134 | - $this->mimetypeIds[$mimetype] = $row['id']; |
|
135 | - return $row['id']; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Load all mimetypes from DB |
|
140 | - */ |
|
141 | - private function loadMimetypes() { |
|
142 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
143 | - $qb->select('id', 'mimetype') |
|
144 | - ->from('mimetypes'); |
|
145 | - $results = $qb->execute()->fetchAll(); |
|
146 | - |
|
147 | - foreach ($results as $row) { |
|
148 | - $this->mimetypes[$row['id']] = $row['mimetype']; |
|
149 | - $this->mimetypeIds[$row['mimetype']] = $row['id']; |
|
150 | - } |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * Update filecache mimetype based on file extension |
|
155 | - * |
|
156 | - * @param string $ext file extension |
|
157 | - * @param int $mimeTypeId |
|
158 | - * @return int number of changed rows |
|
159 | - */ |
|
160 | - public function updateFilecache($ext, $mimeTypeId) { |
|
161 | - $folderMimeTypeId = $this->getId('httpd/unix-directory'); |
|
162 | - $update = $this->dbConnection->getQueryBuilder(); |
|
163 | - $update->update('filecache') |
|
164 | - ->set('mimetype', $update->createNamedParameter($mimeTypeId)) |
|
165 | - ->where($update->expr()->neq( |
|
166 | - 'mimetype', $update->createNamedParameter($mimeTypeId) |
|
167 | - )) |
|
168 | - ->andWhere($update->expr()->neq( |
|
169 | - 'mimetype', $update->createNamedParameter($folderMimeTypeId) |
|
170 | - )) |
|
171 | - ->andWhere($update->expr()->like( |
|
172 | - $update->func()->lower('name'), |
|
173 | - $update->createNamedParameter('%' . $this->dbConnection->escapeLikeParameter('.' . $ext)) |
|
174 | - )); |
|
175 | - return $update->execute(); |
|
176 | - } |
|
39 | + /** @var IDBConnection */ |
|
40 | + private $dbConnection; |
|
41 | + |
|
42 | + /** @var array [id => mimetype] */ |
|
43 | + protected $mimetypes; |
|
44 | + |
|
45 | + /** @var array [mimetype => id] */ |
|
46 | + protected $mimetypeIds; |
|
47 | + |
|
48 | + /** |
|
49 | + * @param IDBConnection $dbConnection |
|
50 | + */ |
|
51 | + public function __construct(IDBConnection $dbConnection) { |
|
52 | + $this->dbConnection = $dbConnection; |
|
53 | + $this->mimetypes = []; |
|
54 | + $this->mimetypeIds = []; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Get a mimetype from its ID |
|
59 | + * |
|
60 | + * @param int $id |
|
61 | + * @return string|null |
|
62 | + */ |
|
63 | + public function getMimetypeById($id) { |
|
64 | + if (!$this->mimetypes) { |
|
65 | + $this->loadMimetypes(); |
|
66 | + } |
|
67 | + if (isset($this->mimetypes[$id])) { |
|
68 | + return $this->mimetypes[$id]; |
|
69 | + } |
|
70 | + return null; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Get a mimetype ID, adding the mimetype to the DB if it does not exist |
|
75 | + * |
|
76 | + * @param string $mimetype |
|
77 | + * @return int |
|
78 | + */ |
|
79 | + public function getId($mimetype) { |
|
80 | + if (!$this->mimetypeIds) { |
|
81 | + $this->loadMimetypes(); |
|
82 | + } |
|
83 | + if (isset($this->mimetypeIds[$mimetype])) { |
|
84 | + return $this->mimetypeIds[$mimetype]; |
|
85 | + } |
|
86 | + return $this->store($mimetype); |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Test if a mimetype exists in the database |
|
91 | + * |
|
92 | + * @param string $mimetype |
|
93 | + * @return bool |
|
94 | + */ |
|
95 | + public function exists($mimetype) { |
|
96 | + if (!$this->mimetypeIds) { |
|
97 | + $this->loadMimetypes(); |
|
98 | + } |
|
99 | + return isset($this->mimetypeIds[$mimetype]); |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Clear all loaded mimetypes, allow for re-loading |
|
104 | + */ |
|
105 | + public function reset() { |
|
106 | + $this->mimetypes = []; |
|
107 | + $this->mimetypeIds = []; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Store a mimetype in the DB |
|
112 | + * |
|
113 | + * @param string $mimetype |
|
114 | + * @param int inserted ID |
|
115 | + */ |
|
116 | + protected function store($mimetype) { |
|
117 | + $this->dbConnection->insertIfNotExist('*PREFIX*mimetypes', [ |
|
118 | + 'mimetype' => $mimetype |
|
119 | + ]); |
|
120 | + |
|
121 | + $fetch = $this->dbConnection->getQueryBuilder(); |
|
122 | + $fetch->select('id') |
|
123 | + ->from('mimetypes') |
|
124 | + ->where( |
|
125 | + $fetch->expr()->eq('mimetype', $fetch->createNamedParameter($mimetype) |
|
126 | + )); |
|
127 | + $row = $fetch->execute()->fetch(); |
|
128 | + |
|
129 | + if (!$row) { |
|
130 | + throw new \Exception("Failed to get mimetype id for $mimetype after trying to store it"); |
|
131 | + } |
|
132 | + |
|
133 | + $this->mimetypes[$row['id']] = $mimetype; |
|
134 | + $this->mimetypeIds[$mimetype] = $row['id']; |
|
135 | + return $row['id']; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Load all mimetypes from DB |
|
140 | + */ |
|
141 | + private function loadMimetypes() { |
|
142 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
143 | + $qb->select('id', 'mimetype') |
|
144 | + ->from('mimetypes'); |
|
145 | + $results = $qb->execute()->fetchAll(); |
|
146 | + |
|
147 | + foreach ($results as $row) { |
|
148 | + $this->mimetypes[$row['id']] = $row['mimetype']; |
|
149 | + $this->mimetypeIds[$row['mimetype']] = $row['id']; |
|
150 | + } |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * Update filecache mimetype based on file extension |
|
155 | + * |
|
156 | + * @param string $ext file extension |
|
157 | + * @param int $mimeTypeId |
|
158 | + * @return int number of changed rows |
|
159 | + */ |
|
160 | + public function updateFilecache($ext, $mimeTypeId) { |
|
161 | + $folderMimeTypeId = $this->getId('httpd/unix-directory'); |
|
162 | + $update = $this->dbConnection->getQueryBuilder(); |
|
163 | + $update->update('filecache') |
|
164 | + ->set('mimetype', $update->createNamedParameter($mimeTypeId)) |
|
165 | + ->where($update->expr()->neq( |
|
166 | + 'mimetype', $update->createNamedParameter($mimeTypeId) |
|
167 | + )) |
|
168 | + ->andWhere($update->expr()->neq( |
|
169 | + 'mimetype', $update->createNamedParameter($folderMimeTypeId) |
|
170 | + )) |
|
171 | + ->andWhere($update->expr()->like( |
|
172 | + $update->func()->lower('name'), |
|
173 | + $update->createNamedParameter('%' . $this->dbConnection->escapeLikeParameter('.' . $ext)) |
|
174 | + )); |
|
175 | + return $update->execute(); |
|
176 | + } |
|
177 | 177 | |
178 | 178 | } |
@@ -170,7 +170,7 @@ |
||
170 | 170 | )) |
171 | 171 | ->andWhere($update->expr()->like( |
172 | 172 | $update->func()->lower('name'), |
173 | - $update->createNamedParameter('%' . $this->dbConnection->escapeLikeParameter('.' . $ext)) |
|
173 | + $update->createNamedParameter('%'.$this->dbConnection->escapeLikeParameter('.'.$ext)) |
|
174 | 174 | )); |
175 | 175 | return $update->execute(); |
176 | 176 | } |
@@ -34,46 +34,46 @@ |
||
34 | 34 | |
35 | 35 | class Version1008Date20181105110300 extends SimpleMigrationStep { |
36 | 36 | |
37 | - /** @var IDBConnection */ |
|
38 | - private $connection; |
|
37 | + /** @var IDBConnection */ |
|
38 | + private $connection; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Version1008Date20181105110300 constructor. |
|
42 | - * |
|
43 | - * @param IDBConnection $connection |
|
44 | - */ |
|
45 | - public function __construct(IDBConnection $connection) { |
|
46 | - $this->connection = $connection; |
|
47 | - } |
|
40 | + /** |
|
41 | + * Version1008Date20181105110300 constructor. |
|
42 | + * |
|
43 | + * @param IDBConnection $connection |
|
44 | + */ |
|
45 | + public function __construct(IDBConnection $connection) { |
|
46 | + $this->connection = $connection; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param IOutput $output |
|
51 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
52 | - * @param array $options |
|
53 | - * @return null|ISchemaWrapper |
|
54 | - */ |
|
55 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
56 | - /** @var ISchemaWrapper $schema */ |
|
57 | - $schema = $schemaClosure(); |
|
58 | - $table = $schema->getTable('calendarsubscriptions'); |
|
59 | - $table->addColumn('source', Type::TEXT, [ |
|
60 | - 'notnull' => false, |
|
61 | - 'length' => null, |
|
62 | - ]); |
|
49 | + /** |
|
50 | + * @param IOutput $output |
|
51 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
52 | + * @param array $options |
|
53 | + * @return null|ISchemaWrapper |
|
54 | + */ |
|
55 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
56 | + /** @var ISchemaWrapper $schema */ |
|
57 | + $schema = $schemaClosure(); |
|
58 | + $table = $schema->getTable('calendarsubscriptions'); |
|
59 | + $table->addColumn('source', Type::TEXT, [ |
|
60 | + 'notnull' => false, |
|
61 | + 'length' => null, |
|
62 | + ]); |
|
63 | 63 | |
64 | - return $schema; |
|
65 | - } |
|
64 | + return $schema; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @param IOutput $output |
|
69 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
70 | - * @param array $options |
|
71 | - */ |
|
72 | - public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) { |
|
73 | - $qb = $this->connection->getQueryBuilder(); |
|
74 | - $qb->update('calendarsubscriptions') |
|
75 | - ->set('source', 'source_copy') |
|
76 | - ->execute(); |
|
77 | - } |
|
67 | + /** |
|
68 | + * @param IOutput $output |
|
69 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
70 | + * @param array $options |
|
71 | + */ |
|
72 | + public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) { |
|
73 | + $qb = $this->connection->getQueryBuilder(); |
|
74 | + $qb->update('calendarsubscriptions') |
|
75 | + ->set('source', 'source_copy') |
|
76 | + ->execute(); |
|
77 | + } |
|
78 | 78 | |
79 | 79 | } |
@@ -32,18 +32,18 @@ |
||
32 | 32 | |
33 | 33 | class Version1008Date20181105112049 extends SimpleMigrationStep { |
34 | 34 | |
35 | - /** |
|
36 | - * @param IOutput $output |
|
37 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
38 | - * @param array $options |
|
39 | - * @return null|ISchemaWrapper |
|
40 | - */ |
|
41 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
42 | - /** @var ISchemaWrapper $schema */ |
|
43 | - $schema = $schemaClosure(); |
|
44 | - $table = $schema->getTable('calendarsubscriptions'); |
|
45 | - $table->dropColumn('source_copy'); |
|
35 | + /** |
|
36 | + * @param IOutput $output |
|
37 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
38 | + * @param array $options |
|
39 | + * @return null|ISchemaWrapper |
|
40 | + */ |
|
41 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
42 | + /** @var ISchemaWrapper $schema */ |
|
43 | + $schema = $schemaClosure(); |
|
44 | + $table = $schema->getTable('calendarsubscriptions'); |
|
45 | + $table->dropColumn('source_copy'); |
|
46 | 46 | |
47 | - return $schema; |
|
48 | - } |
|
47 | + return $schema; |
|
48 | + } |
|
49 | 49 | } |
@@ -35,46 +35,46 @@ |
||
35 | 35 | |
36 | 36 | class Version1008Date20181105104826 extends SimpleMigrationStep { |
37 | 37 | |
38 | - /** @var IDBConnection */ |
|
39 | - private $connection; |
|
38 | + /** @var IDBConnection */ |
|
39 | + private $connection; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Version1008Date20181105104826 constructor. |
|
43 | - * |
|
44 | - * @param IDBConnection $connection |
|
45 | - */ |
|
46 | - public function __construct(IDBConnection $connection) { |
|
47 | - $this->connection = $connection; |
|
48 | - } |
|
41 | + /** |
|
42 | + * Version1008Date20181105104826 constructor. |
|
43 | + * |
|
44 | + * @param IDBConnection $connection |
|
45 | + */ |
|
46 | + public function __construct(IDBConnection $connection) { |
|
47 | + $this->connection = $connection; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @param IOutput $output |
|
52 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
53 | - * @param array $options |
|
54 | - * @return null|ISchemaWrapper |
|
55 | - */ |
|
56 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
57 | - /** @var ISchemaWrapper $schema */ |
|
58 | - $schema = $schemaClosure(); |
|
59 | - $table = $schema->getTable('calendarsubscriptions'); |
|
50 | + /** |
|
51 | + * @param IOutput $output |
|
52 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
53 | + * @param array $options |
|
54 | + * @return null|ISchemaWrapper |
|
55 | + */ |
|
56 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
57 | + /** @var ISchemaWrapper $schema */ |
|
58 | + $schema = $schemaClosure(); |
|
59 | + $table = $schema->getTable('calendarsubscriptions'); |
|
60 | 60 | |
61 | - $table->addColumn('source_copy', Type::TEXT, [ |
|
62 | - 'notnull' => false, |
|
63 | - 'length' => null, |
|
64 | - ]); |
|
61 | + $table->addColumn('source_copy', Type::TEXT, [ |
|
62 | + 'notnull' => false, |
|
63 | + 'length' => null, |
|
64 | + ]); |
|
65 | 65 | |
66 | - return $schema; |
|
67 | - } |
|
66 | + return $schema; |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @param IOutput $output |
|
71 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
72 | - * @param array $options |
|
73 | - */ |
|
74 | - public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) { |
|
75 | - $qb = $this->connection->getQueryBuilder(); |
|
76 | - $qb->update('calendarsubscriptions') |
|
77 | - ->set('source_copy', 'source') |
|
78 | - ->execute(); |
|
79 | - } |
|
69 | + /** |
|
70 | + * @param IOutput $output |
|
71 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
72 | + * @param array $options |
|
73 | + */ |
|
74 | + public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) { |
|
75 | + $qb = $this->connection->getQueryBuilder(); |
|
76 | + $qb->update('calendarsubscriptions') |
|
77 | + ->set('source_copy', 'source') |
|
78 | + ->execute(); |
|
79 | + } |
|
80 | 80 | } |
@@ -32,18 +32,18 @@ |
||
32 | 32 | |
33 | 33 | class Version1008Date20181105104833 extends SimpleMigrationStep { |
34 | 34 | |
35 | - /** |
|
36 | - * @param IOutput $output |
|
37 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
38 | - * @param array $options |
|
39 | - * @return null|ISchemaWrapper |
|
40 | - */ |
|
41 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
42 | - /** @var ISchemaWrapper $schema */ |
|
43 | - $schema = $schemaClosure(); |
|
44 | - $table = $schema->getTable('calendarsubscriptions'); |
|
45 | - $table->dropColumn('source'); |
|
35 | + /** |
|
36 | + * @param IOutput $output |
|
37 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
38 | + * @param array $options |
|
39 | + * @return null|ISchemaWrapper |
|
40 | + */ |
|
41 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
42 | + /** @var ISchemaWrapper $schema */ |
|
43 | + $schema = $schemaClosure(); |
|
44 | + $table = $schema->getTable('calendarsubscriptions'); |
|
45 | + $table->dropColumn('source'); |
|
46 | 46 | |
47 | - return $schema; |
|
48 | - } |
|
47 | + return $schema; |
|
48 | + } |
|
49 | 49 | } |
@@ -37,31 +37,31 @@ |
||
37 | 37 | */ |
38 | 38 | interface ICrypto { |
39 | 39 | |
40 | - /** |
|
41 | - * @param string $message The message to authenticate |
|
42 | - * @param string $password Password to use (defaults to `secret` in config.php) |
|
43 | - * @return string Calculated HMAC |
|
44 | - * @since 8.0.0 |
|
45 | - */ |
|
46 | - public function calculateHMAC(string $message, string $password = ''): string; |
|
40 | + /** |
|
41 | + * @param string $message The message to authenticate |
|
42 | + * @param string $password Password to use (defaults to `secret` in config.php) |
|
43 | + * @return string Calculated HMAC |
|
44 | + * @since 8.0.0 |
|
45 | + */ |
|
46 | + public function calculateHMAC(string $message, string $password = ''): string; |
|
47 | 47 | |
48 | - /** |
|
49 | - * Encrypts a value and adds an HMAC (Encrypt-Then-MAC) |
|
50 | - * @param string $plaintext |
|
51 | - * @param string $password Password to encrypt, if not specified the secret from config.php will be taken |
|
52 | - * @return string Authenticated ciphertext |
|
53 | - * @since 8.0.0 |
|
54 | - */ |
|
55 | - public function encrypt(string $plaintext, string $password = ''): string; |
|
48 | + /** |
|
49 | + * Encrypts a value and adds an HMAC (Encrypt-Then-MAC) |
|
50 | + * @param string $plaintext |
|
51 | + * @param string $password Password to encrypt, if not specified the secret from config.php will be taken |
|
52 | + * @return string Authenticated ciphertext |
|
53 | + * @since 8.0.0 |
|
54 | + */ |
|
55 | + public function encrypt(string $plaintext, string $password = ''): string; |
|
56 | 56 | |
57 | - /** |
|
58 | - * Decrypts a value and verifies the HMAC (Encrypt-Then-Mac) |
|
59 | - * @param string $authenticatedCiphertext |
|
60 | - * @param string $password Password to encrypt, if not specified the secret from config.php will be taken |
|
61 | - * @return string plaintext |
|
62 | - * @throws \Exception If the HMAC does not match |
|
63 | - * @throws \Exception If the decryption failed |
|
64 | - * @since 8.0.0 |
|
65 | - */ |
|
66 | - public function decrypt(string $authenticatedCiphertext, string $password = ''): string; |
|
57 | + /** |
|
58 | + * Decrypts a value and verifies the HMAC (Encrypt-Then-Mac) |
|
59 | + * @param string $authenticatedCiphertext |
|
60 | + * @param string $password Password to encrypt, if not specified the secret from config.php will be taken |
|
61 | + * @return string plaintext |
|
62 | + * @throws \Exception If the HMAC does not match |
|
63 | + * @throws \Exception If the decryption failed |
|
64 | + * @since 8.0.0 |
|
65 | + */ |
|
66 | + public function decrypt(string $authenticatedCiphertext, string $password = ''): string; |
|
67 | 67 | } |
@@ -33,27 +33,27 @@ |
||
33 | 33 | class Version1008Date20181114084440 extends SimpleMigrationStep { |
34 | 34 | |
35 | 35 | |
36 | - /** |
|
37 | - * @param IOutput $output |
|
38 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
39 | - * @param array $options |
|
40 | - * @return null|ISchemaWrapper |
|
41 | - */ |
|
42 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
43 | - /** @var ISchemaWrapper $schema */ |
|
44 | - $schema = $schemaClosure(); |
|
45 | - |
|
46 | - if ($schema->hasTable('calendarchanges')) { |
|
47 | - $calendarChangesTable = $schema->getTable('calendarchanges'); |
|
48 | - if ($calendarChangesTable->hasIndex('calendarid_calendartype_synctoken')) { |
|
49 | - $calendarChangesTable->dropIndex('calendarid_calendartype_synctoken'); |
|
50 | - } |
|
51 | - |
|
52 | - if (!$calendarChangesTable->hasIndex('calid_type_synctoken')) { |
|
53 | - $calendarChangesTable->addIndex(['calendarid', 'calendartype', 'synctoken'], 'calid_type_synctoken'); |
|
54 | - } |
|
55 | - } |
|
56 | - |
|
57 | - return $schema; |
|
58 | - } |
|
36 | + /** |
|
37 | + * @param IOutput $output |
|
38 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
39 | + * @param array $options |
|
40 | + * @return null|ISchemaWrapper |
|
41 | + */ |
|
42 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
43 | + /** @var ISchemaWrapper $schema */ |
|
44 | + $schema = $schemaClosure(); |
|
45 | + |
|
46 | + if ($schema->hasTable('calendarchanges')) { |
|
47 | + $calendarChangesTable = $schema->getTable('calendarchanges'); |
|
48 | + if ($calendarChangesTable->hasIndex('calendarid_calendartype_synctoken')) { |
|
49 | + $calendarChangesTable->dropIndex('calendarid_calendartype_synctoken'); |
|
50 | + } |
|
51 | + |
|
52 | + if (!$calendarChangesTable->hasIndex('calid_type_synctoken')) { |
|
53 | + $calendarChangesTable->addIndex(['calendarid', 'calendartype', 'synctoken'], 'calid_type_synctoken'); |
|
54 | + } |
|
55 | + } |
|
56 | + |
|
57 | + return $schema; |
|
58 | + } |
|
59 | 59 | } |