@@ -27,7 +27,7 @@ |
||
27 | 27 | * {@inheritDoc} |
28 | 28 | */ |
29 | 29 | public function getName() { |
30 | - return (string)$this->l10n->t('Groupware bundle'); |
|
30 | + return (string) $this->l10n->t('Groupware bundle'); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -25,23 +25,23 @@ |
||
25 | 25 | |
26 | 26 | class GroupwareBundle extends Bundle { |
27 | 27 | |
28 | - /** |
|
29 | - * {@inheritDoc} |
|
30 | - */ |
|
31 | - public function getName() { |
|
32 | - return (string)$this->l10n->t('Groupware bundle'); |
|
33 | - } |
|
28 | + /** |
|
29 | + * {@inheritDoc} |
|
30 | + */ |
|
31 | + public function getName() { |
|
32 | + return (string)$this->l10n->t('Groupware bundle'); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * {@inheritDoc} |
|
37 | - */ |
|
38 | - public function getAppIdentifiers() { |
|
39 | - return [ |
|
40 | - 'calendar', |
|
41 | - 'contacts', |
|
42 | - 'deck', |
|
43 | - 'mail' |
|
44 | - ]; |
|
45 | - } |
|
35 | + /** |
|
36 | + * {@inheritDoc} |
|
37 | + */ |
|
38 | + public function getAppIdentifiers() { |
|
39 | + return [ |
|
40 | + 'calendar', |
|
41 | + 'contacts', |
|
42 | + 'deck', |
|
43 | + 'mail' |
|
44 | + ]; |
|
45 | + } |
|
46 | 46 | |
47 | 47 | } |
@@ -24,36 +24,36 @@ |
||
24 | 24 | use OCP\IL10N; |
25 | 25 | |
26 | 26 | abstract class Bundle { |
27 | - /** @var IL10N */ |
|
28 | - protected $l10n; |
|
27 | + /** @var IL10N */ |
|
28 | + protected $l10n; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @param IL10N $l10n |
|
32 | - */ |
|
33 | - public function __construct(IL10N $l10n) { |
|
34 | - $this->l10n = $l10n; |
|
35 | - } |
|
30 | + /** |
|
31 | + * @param IL10N $l10n |
|
32 | + */ |
|
33 | + public function __construct(IL10N $l10n) { |
|
34 | + $this->l10n = $l10n; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Get the identifier of the bundle |
|
39 | - * |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public final function getIdentifier() { |
|
43 | - return substr(strrchr(get_class($this), '\\'), 1); |
|
44 | - } |
|
37 | + /** |
|
38 | + * Get the identifier of the bundle |
|
39 | + * |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public final function getIdentifier() { |
|
43 | + return substr(strrchr(get_class($this), '\\'), 1); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Get the name of the bundle |
|
48 | - * |
|
49 | - * @return string |
|
50 | - */ |
|
51 | - public abstract function getName(); |
|
46 | + /** |
|
47 | + * Get the name of the bundle |
|
48 | + * |
|
49 | + * @return string |
|
50 | + */ |
|
51 | + public abstract function getName(); |
|
52 | 52 | |
53 | - /** |
|
54 | - * Get the list of app identifiers in the bundle |
|
55 | - * |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - public abstract function getAppIdentifiers(); |
|
53 | + /** |
|
54 | + * Get the list of app identifiers in the bundle |
|
55 | + * |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + public abstract function getAppIdentifiers(); |
|
59 | 59 | } |
@@ -34,59 +34,59 @@ |
||
34 | 34 | use Symfony\Component\Console\Output\OutputInterface; |
35 | 35 | |
36 | 36 | class ConvertMysqlToMB4 extends Command { |
37 | - /** @var IConfig */ |
|
38 | - private $config; |
|
37 | + /** @var IConfig */ |
|
38 | + private $config; |
|
39 | 39 | |
40 | - /** @var IDBConnection */ |
|
41 | - private $connection; |
|
40 | + /** @var IDBConnection */ |
|
41 | + private $connection; |
|
42 | 42 | |
43 | - /** @var IURLGenerator */ |
|
44 | - private $urlGenerator; |
|
43 | + /** @var IURLGenerator */ |
|
44 | + private $urlGenerator; |
|
45 | 45 | |
46 | - /** @var ILogger */ |
|
47 | - private $logger; |
|
46 | + /** @var ILogger */ |
|
47 | + private $logger; |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param IConfig $config |
|
51 | - * @param IDBConnection $connection |
|
52 | - * @param IURLGenerator $urlGenerator |
|
53 | - * @param ILogger $logger |
|
54 | - */ |
|
55 | - public function __construct(IConfig $config, IDBConnection $connection, IURLGenerator $urlGenerator, ILogger $logger) { |
|
56 | - $this->config = $config; |
|
57 | - $this->connection = $connection; |
|
58 | - $this->urlGenerator = $urlGenerator; |
|
59 | - $this->logger = $logger; |
|
60 | - parent::__construct(); |
|
61 | - } |
|
49 | + /** |
|
50 | + * @param IConfig $config |
|
51 | + * @param IDBConnection $connection |
|
52 | + * @param IURLGenerator $urlGenerator |
|
53 | + * @param ILogger $logger |
|
54 | + */ |
|
55 | + public function __construct(IConfig $config, IDBConnection $connection, IURLGenerator $urlGenerator, ILogger $logger) { |
|
56 | + $this->config = $config; |
|
57 | + $this->connection = $connection; |
|
58 | + $this->urlGenerator = $urlGenerator; |
|
59 | + $this->logger = $logger; |
|
60 | + parent::__construct(); |
|
61 | + } |
|
62 | 62 | |
63 | - protected function configure() { |
|
64 | - $this |
|
65 | - ->setName('db:convert-mysql-charset') |
|
66 | - ->setDescription('Convert charset of MySQL/MariaDB to use utf8mb4'); |
|
67 | - } |
|
63 | + protected function configure() { |
|
64 | + $this |
|
65 | + ->setName('db:convert-mysql-charset') |
|
66 | + ->setDescription('Convert charset of MySQL/MariaDB to use utf8mb4'); |
|
67 | + } |
|
68 | 68 | |
69 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
70 | - if (!$this->connection->getDatabasePlatform() instanceof MySqlPlatform) { |
|
71 | - $output->writeln("This command is only valid for MySQL/MariaDB databases."); |
|
72 | - return 1; |
|
73 | - } |
|
69 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
70 | + if (!$this->connection->getDatabasePlatform() instanceof MySqlPlatform) { |
|
71 | + $output->writeln("This command is only valid for MySQL/MariaDB databases."); |
|
72 | + return 1; |
|
73 | + } |
|
74 | 74 | |
75 | - $tools = new MySqlTools(); |
|
76 | - if (!$tools->supports4ByteCharset($this->connection)) { |
|
77 | - $url = $this->urlGenerator->linkToDocs('admin-mysql-utf8mb4'); |
|
78 | - $output->writeln("The database is not properly setup to use the charset utf8mb4."); |
|
79 | - $output->writeln("For more information please read the documentation at $url"); |
|
80 | - return 1; |
|
81 | - } |
|
75 | + $tools = new MySqlTools(); |
|
76 | + if (!$tools->supports4ByteCharset($this->connection)) { |
|
77 | + $url = $this->urlGenerator->linkToDocs('admin-mysql-utf8mb4'); |
|
78 | + $output->writeln("The database is not properly setup to use the charset utf8mb4."); |
|
79 | + $output->writeln("For more information please read the documentation at $url"); |
|
80 | + return 1; |
|
81 | + } |
|
82 | 82 | |
83 | - // enable charset |
|
84 | - $this->config->setSystemValue('mysql.utf8mb4', true); |
|
83 | + // enable charset |
|
84 | + $this->config->setSystemValue('mysql.utf8mb4', true); |
|
85 | 85 | |
86 | - // run conversion |
|
87 | - $coll = new Collation($this->config, $this->logger, $this->connection, false); |
|
88 | - $coll->run(new ConsoleOutput($output)); |
|
86 | + // run conversion |
|
87 | + $coll = new Collation($this->config, $this->logger, $this->connection, false); |
|
88 | + $coll->run(new ConsoleOutput($output)); |
|
89 | 89 | |
90 | - return 0; |
|
91 | - } |
|
90 | + return 0; |
|
91 | + } |
|
92 | 92 | } |
@@ -195,38 +195,38 @@ |
||
195 | 195 | $emailVerified = isset($oldData[self::PROPERTY_EMAIL]['verified']) && $oldData[self::PROPERTY_EMAIL]['verified'] === self::VERIFIED; |
196 | 196 | |
197 | 197 | // keep old verification status if we don't have a new one |
198 | - if(!isset($newData[self::PROPERTY_TWITTER]['verified'])) { |
|
198 | + if (!isset($newData[self::PROPERTY_TWITTER]['verified'])) { |
|
199 | 199 | // keep old verification status if value didn't changed and an old value exists |
200 | 200 | $keepOldStatus = $newData[self::PROPERTY_TWITTER]['value'] === $oldData[self::PROPERTY_TWITTER]['value'] && isset($oldData[self::PROPERTY_TWITTER]['verified']); |
201 | 201 | $newData[self::PROPERTY_TWITTER]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_TWITTER]['verified'] : self::NOT_VERIFIED; |
202 | 202 | } |
203 | 203 | |
204 | - if(!isset($newData[self::PROPERTY_WEBSITE]['verified'])) { |
|
204 | + if (!isset($newData[self::PROPERTY_WEBSITE]['verified'])) { |
|
205 | 205 | // keep old verification status if value didn't changed and an old value exists |
206 | 206 | $keepOldStatus = $newData[self::PROPERTY_WEBSITE]['value'] === $oldData[self::PROPERTY_WEBSITE]['value'] && isset($oldData[self::PROPERTY_WEBSITE]['verified']); |
207 | 207 | $newData[self::PROPERTY_WEBSITE]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_WEBSITE]['verified'] : self::NOT_VERIFIED; |
208 | 208 | } |
209 | 209 | |
210 | - if(!isset($newData[self::PROPERTY_EMAIL]['verified'])) { |
|
210 | + if (!isset($newData[self::PROPERTY_EMAIL]['verified'])) { |
|
211 | 211 | // keep old verification status if value didn't changed and an old value exists |
212 | 212 | $keepOldStatus = $newData[self::PROPERTY_EMAIL]['value'] === $oldData[self::PROPERTY_EMAIL]['value'] && isset($oldData[self::PROPERTY_EMAIL]['verified']); |
213 | 213 | $newData[self::PROPERTY_EMAIL]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_EMAIL]['verified'] : self::VERIFICATION_IN_PROGRESS; |
214 | 214 | } |
215 | 215 | |
216 | 216 | // reset verification status if a value from a previously verified data was changed |
217 | - if($twitterVerified && |
|
217 | + if ($twitterVerified && |
|
218 | 218 | $oldData[self::PROPERTY_TWITTER]['value'] !== $newData[self::PROPERTY_TWITTER]['value'] |
219 | 219 | ) { |
220 | 220 | $newData[self::PROPERTY_TWITTER]['verified'] = self::NOT_VERIFIED; |
221 | 221 | } |
222 | 222 | |
223 | - if($websiteVerified && |
|
223 | + if ($websiteVerified && |
|
224 | 224 | $oldData[self::PROPERTY_WEBSITE]['value'] !== $newData[self::PROPERTY_WEBSITE]['value'] |
225 | 225 | ) { |
226 | 226 | $newData[self::PROPERTY_WEBSITE]['verified'] = self::NOT_VERIFIED; |
227 | 227 | } |
228 | 228 | |
229 | - if($emailVerified && |
|
229 | + if ($emailVerified && |
|
230 | 230 | $oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value'] |
231 | 231 | ) { |
232 | 232 | $newData[self::PROPERTY_EMAIL]['verified'] = self::NOT_VERIFIED; |
@@ -43,305 +43,305 @@ |
||
43 | 43 | */ |
44 | 44 | class AccountManager { |
45 | 45 | |
46 | - /** nobody can see my account details */ |
|
47 | - const VISIBILITY_PRIVATE = 'private'; |
|
48 | - /** only contacts, especially trusted servers can see my contact details */ |
|
49 | - const VISIBILITY_CONTACTS_ONLY = 'contacts'; |
|
50 | - /** every body ca see my contact detail, will be published to the lookup server */ |
|
51 | - const VISIBILITY_PUBLIC = 'public'; |
|
52 | - |
|
53 | - const PROPERTY_AVATAR = 'avatar'; |
|
54 | - const PROPERTY_DISPLAYNAME = 'displayname'; |
|
55 | - const PROPERTY_PHONE = 'phone'; |
|
56 | - const PROPERTY_EMAIL = 'email'; |
|
57 | - const PROPERTY_WEBSITE = 'website'; |
|
58 | - const PROPERTY_ADDRESS = 'address'; |
|
59 | - const PROPERTY_TWITTER = 'twitter'; |
|
60 | - |
|
61 | - const NOT_VERIFIED = '0'; |
|
62 | - const VERIFICATION_IN_PROGRESS = '1'; |
|
63 | - const VERIFIED = '2'; |
|
64 | - |
|
65 | - /** @var IDBConnection database connection */ |
|
66 | - private $connection; |
|
67 | - |
|
68 | - /** @var string table name */ |
|
69 | - private $table = 'accounts'; |
|
70 | - |
|
71 | - /** @var EventDispatcherInterface */ |
|
72 | - private $eventDispatcher; |
|
73 | - |
|
74 | - /** @var IJobList */ |
|
75 | - private $jobList; |
|
76 | - |
|
77 | - /** |
|
78 | - * AccountManager constructor. |
|
79 | - * |
|
80 | - * @param IDBConnection $connection |
|
81 | - * @param EventDispatcherInterface $eventDispatcher |
|
82 | - * @param IJobList $jobList |
|
83 | - */ |
|
84 | - public function __construct(IDBConnection $connection, |
|
85 | - EventDispatcherInterface $eventDispatcher, |
|
86 | - IJobList $jobList) { |
|
87 | - $this->connection = $connection; |
|
88 | - $this->eventDispatcher = $eventDispatcher; |
|
89 | - $this->jobList = $jobList; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * update user record |
|
94 | - * |
|
95 | - * @param IUser $user |
|
96 | - * @param $data |
|
97 | - */ |
|
98 | - public function updateUser(IUser $user, $data) { |
|
99 | - $userData = $this->getUser($user); |
|
100 | - $updated = true; |
|
101 | - if (empty($userData)) { |
|
102 | - $this->insertNewUser($user, $data); |
|
103 | - } elseif ($userData !== $data) { |
|
104 | - $data = $this->checkEmailVerification($userData, $data, $user); |
|
105 | - $data = $this->updateVerifyStatus($userData, $data); |
|
106 | - $this->updateExistingUser($user, $data); |
|
107 | - } else { |
|
108 | - // nothing needs to be done if new and old data set are the same |
|
109 | - $updated = false; |
|
110 | - } |
|
111 | - |
|
112 | - if ($updated) { |
|
113 | - $this->eventDispatcher->dispatch( |
|
114 | - 'OC\AccountManager::userUpdated', |
|
115 | - new GenericEvent($user, $data) |
|
116 | - ); |
|
117 | - } |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * delete user from accounts table |
|
122 | - * |
|
123 | - * @param IUser $user |
|
124 | - */ |
|
125 | - public function deleteUser(IUser $user) { |
|
126 | - $uid = $user->getUID(); |
|
127 | - $query = $this->connection->getQueryBuilder(); |
|
128 | - $query->delete($this->table) |
|
129 | - ->where($query->expr()->eq('uid', $query->createNamedParameter($uid))) |
|
130 | - ->execute(); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * get stored data from a given user |
|
135 | - * |
|
136 | - * @param IUser $user |
|
137 | - * @return array |
|
138 | - */ |
|
139 | - public function getUser(IUser $user) { |
|
140 | - $uid = $user->getUID(); |
|
141 | - $query = $this->connection->getQueryBuilder(); |
|
142 | - $query->select('data')->from($this->table) |
|
143 | - ->where($query->expr()->eq('uid', $query->createParameter('uid'))) |
|
144 | - ->setParameter('uid', $uid); |
|
145 | - $query->execute(); |
|
146 | - $result = $query->execute()->fetchAll(); |
|
147 | - |
|
148 | - if (empty($result)) { |
|
149 | - $userData = $this->buildDefaultUserRecord($user); |
|
150 | - $this->insertNewUser($user, $userData); |
|
151 | - return $userData; |
|
152 | - } |
|
153 | - |
|
154 | - $userDataArray = json_decode($result[0]['data'], true); |
|
155 | - |
|
156 | - $userDataArray = $this->addMissingDefaultValues($userDataArray); |
|
157 | - |
|
158 | - return $userDataArray; |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * check if we need to ask the server for email verification, if yes we create a cronjob |
|
163 | - * |
|
164 | - * @param $oldData |
|
165 | - * @param $newData |
|
166 | - * @param IUser $user |
|
167 | - * @return array |
|
168 | - */ |
|
169 | - protected function checkEmailVerification($oldData, $newData, IUser $user) { |
|
170 | - if ($oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value']) { |
|
171 | - $this->jobList->add(VerifyUserData::class, |
|
172 | - [ |
|
173 | - 'verificationCode' => '', |
|
174 | - 'data' => $newData[self::PROPERTY_EMAIL]['value'], |
|
175 | - 'type' => self::PROPERTY_EMAIL, |
|
176 | - 'uid' => $user->getUID(), |
|
177 | - 'try' => 0, |
|
178 | - 'lastRun' => time() |
|
179 | - ] |
|
180 | - ); |
|
181 | - $newData[AccountManager::PROPERTY_EMAIL]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS; |
|
182 | - } |
|
183 | - |
|
184 | - return $newData; |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * make sure that all expected data are set |
|
189 | - * |
|
190 | - * @param array $userData |
|
191 | - * @return array |
|
192 | - */ |
|
193 | - protected function addMissingDefaultValues(array $userData) { |
|
194 | - |
|
195 | - foreach ($userData as $key => $value) { |
|
196 | - if (!isset($userData[$key]['verified'])) { |
|
197 | - $userData[$key]['verified'] = self::NOT_VERIFIED; |
|
198 | - } |
|
199 | - } |
|
200 | - |
|
201 | - return $userData; |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * reset verification status if personal data changed |
|
206 | - * |
|
207 | - * @param array $oldData |
|
208 | - * @param array $newData |
|
209 | - * @return array |
|
210 | - */ |
|
211 | - protected function updateVerifyStatus($oldData, $newData) { |
|
212 | - |
|
213 | - // which account was already verified successfully? |
|
214 | - $twitterVerified = isset($oldData[self::PROPERTY_TWITTER]['verified']) && $oldData[self::PROPERTY_TWITTER]['verified'] === self::VERIFIED; |
|
215 | - $websiteVerified = isset($oldData[self::PROPERTY_WEBSITE]['verified']) && $oldData[self::PROPERTY_WEBSITE]['verified'] === self::VERIFIED; |
|
216 | - $emailVerified = isset($oldData[self::PROPERTY_EMAIL]['verified']) && $oldData[self::PROPERTY_EMAIL]['verified'] === self::VERIFIED; |
|
217 | - |
|
218 | - // keep old verification status if we don't have a new one |
|
219 | - if(!isset($newData[self::PROPERTY_TWITTER]['verified'])) { |
|
220 | - // keep old verification status if value didn't changed and an old value exists |
|
221 | - $keepOldStatus = $newData[self::PROPERTY_TWITTER]['value'] === $oldData[self::PROPERTY_TWITTER]['value'] && isset($oldData[self::PROPERTY_TWITTER]['verified']); |
|
222 | - $newData[self::PROPERTY_TWITTER]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_TWITTER]['verified'] : self::NOT_VERIFIED; |
|
223 | - } |
|
224 | - |
|
225 | - if(!isset($newData[self::PROPERTY_WEBSITE]['verified'])) { |
|
226 | - // keep old verification status if value didn't changed and an old value exists |
|
227 | - $keepOldStatus = $newData[self::PROPERTY_WEBSITE]['value'] === $oldData[self::PROPERTY_WEBSITE]['value'] && isset($oldData[self::PROPERTY_WEBSITE]['verified']); |
|
228 | - $newData[self::PROPERTY_WEBSITE]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_WEBSITE]['verified'] : self::NOT_VERIFIED; |
|
229 | - } |
|
230 | - |
|
231 | - if(!isset($newData[self::PROPERTY_EMAIL]['verified'])) { |
|
232 | - // keep old verification status if value didn't changed and an old value exists |
|
233 | - $keepOldStatus = $newData[self::PROPERTY_EMAIL]['value'] === $oldData[self::PROPERTY_EMAIL]['value'] && isset($oldData[self::PROPERTY_EMAIL]['verified']); |
|
234 | - $newData[self::PROPERTY_EMAIL]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_EMAIL]['verified'] : self::VERIFICATION_IN_PROGRESS; |
|
235 | - } |
|
236 | - |
|
237 | - // reset verification status if a value from a previously verified data was changed |
|
238 | - if($twitterVerified && |
|
239 | - $oldData[self::PROPERTY_TWITTER]['value'] !== $newData[self::PROPERTY_TWITTER]['value'] |
|
240 | - ) { |
|
241 | - $newData[self::PROPERTY_TWITTER]['verified'] = self::NOT_VERIFIED; |
|
242 | - } |
|
243 | - |
|
244 | - if($websiteVerified && |
|
245 | - $oldData[self::PROPERTY_WEBSITE]['value'] !== $newData[self::PROPERTY_WEBSITE]['value'] |
|
246 | - ) { |
|
247 | - $newData[self::PROPERTY_WEBSITE]['verified'] = self::NOT_VERIFIED; |
|
248 | - } |
|
249 | - |
|
250 | - if($emailVerified && |
|
251 | - $oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value'] |
|
252 | - ) { |
|
253 | - $newData[self::PROPERTY_EMAIL]['verified'] = self::NOT_VERIFIED; |
|
254 | - } |
|
255 | - |
|
256 | - return $newData; |
|
257 | - |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * add new user to accounts table |
|
262 | - * |
|
263 | - * @param IUser $user |
|
264 | - * @param array $data |
|
265 | - */ |
|
266 | - protected function insertNewUser(IUser $user, $data) { |
|
267 | - $uid = $user->getUID(); |
|
268 | - $jsonEncodedData = json_encode($data); |
|
269 | - $query = $this->connection->getQueryBuilder(); |
|
270 | - $query->insert($this->table) |
|
271 | - ->values( |
|
272 | - [ |
|
273 | - 'uid' => $query->createNamedParameter($uid), |
|
274 | - 'data' => $query->createNamedParameter($jsonEncodedData), |
|
275 | - ] |
|
276 | - ) |
|
277 | - ->execute(); |
|
278 | - } |
|
279 | - |
|
280 | - /** |
|
281 | - * update existing user in accounts table |
|
282 | - * |
|
283 | - * @param IUser $user |
|
284 | - * @param array $data |
|
285 | - */ |
|
286 | - protected function updateExistingUser(IUser $user, $data) { |
|
287 | - $uid = $user->getUID(); |
|
288 | - $jsonEncodedData = json_encode($data); |
|
289 | - $query = $this->connection->getQueryBuilder(); |
|
290 | - $query->update($this->table) |
|
291 | - ->set('data', $query->createNamedParameter($jsonEncodedData)) |
|
292 | - ->where($query->expr()->eq('uid', $query->createNamedParameter($uid))) |
|
293 | - ->execute(); |
|
294 | - } |
|
295 | - |
|
296 | - /** |
|
297 | - * build default user record in case not data set exists yet |
|
298 | - * |
|
299 | - * @param IUser $user |
|
300 | - * @return array |
|
301 | - */ |
|
302 | - protected function buildDefaultUserRecord(IUser $user) { |
|
303 | - return [ |
|
304 | - self::PROPERTY_DISPLAYNAME => |
|
305 | - [ |
|
306 | - 'value' => $user->getDisplayName(), |
|
307 | - 'scope' => self::VISIBILITY_CONTACTS_ONLY, |
|
308 | - 'verified' => self::NOT_VERIFIED, |
|
309 | - ], |
|
310 | - self::PROPERTY_ADDRESS => |
|
311 | - [ |
|
312 | - 'value' => '', |
|
313 | - 'scope' => self::VISIBILITY_PRIVATE, |
|
314 | - 'verified' => self::NOT_VERIFIED, |
|
315 | - ], |
|
316 | - self::PROPERTY_WEBSITE => |
|
317 | - [ |
|
318 | - 'value' => '', |
|
319 | - 'scope' => self::VISIBILITY_PRIVATE, |
|
320 | - 'verified' => self::NOT_VERIFIED, |
|
321 | - ], |
|
322 | - self::PROPERTY_EMAIL => |
|
323 | - [ |
|
324 | - 'value' => $user->getEMailAddress(), |
|
325 | - 'scope' => self::VISIBILITY_CONTACTS_ONLY, |
|
326 | - 'verified' => self::NOT_VERIFIED, |
|
327 | - ], |
|
328 | - self::PROPERTY_AVATAR => |
|
329 | - [ |
|
330 | - 'scope' => self::VISIBILITY_CONTACTS_ONLY |
|
331 | - ], |
|
332 | - self::PROPERTY_PHONE => |
|
333 | - [ |
|
334 | - 'value' => '', |
|
335 | - 'scope' => self::VISIBILITY_PRIVATE, |
|
336 | - 'verified' => self::NOT_VERIFIED, |
|
337 | - ], |
|
338 | - self::PROPERTY_TWITTER => |
|
339 | - [ |
|
340 | - 'value' => '', |
|
341 | - 'scope' => self::VISIBILITY_PRIVATE, |
|
342 | - 'verified' => self::NOT_VERIFIED, |
|
343 | - ], |
|
344 | - ]; |
|
345 | - } |
|
46 | + /** nobody can see my account details */ |
|
47 | + const VISIBILITY_PRIVATE = 'private'; |
|
48 | + /** only contacts, especially trusted servers can see my contact details */ |
|
49 | + const VISIBILITY_CONTACTS_ONLY = 'contacts'; |
|
50 | + /** every body ca see my contact detail, will be published to the lookup server */ |
|
51 | + const VISIBILITY_PUBLIC = 'public'; |
|
52 | + |
|
53 | + const PROPERTY_AVATAR = 'avatar'; |
|
54 | + const PROPERTY_DISPLAYNAME = 'displayname'; |
|
55 | + const PROPERTY_PHONE = 'phone'; |
|
56 | + const PROPERTY_EMAIL = 'email'; |
|
57 | + const PROPERTY_WEBSITE = 'website'; |
|
58 | + const PROPERTY_ADDRESS = 'address'; |
|
59 | + const PROPERTY_TWITTER = 'twitter'; |
|
60 | + |
|
61 | + const NOT_VERIFIED = '0'; |
|
62 | + const VERIFICATION_IN_PROGRESS = '1'; |
|
63 | + const VERIFIED = '2'; |
|
64 | + |
|
65 | + /** @var IDBConnection database connection */ |
|
66 | + private $connection; |
|
67 | + |
|
68 | + /** @var string table name */ |
|
69 | + private $table = 'accounts'; |
|
70 | + |
|
71 | + /** @var EventDispatcherInterface */ |
|
72 | + private $eventDispatcher; |
|
73 | + |
|
74 | + /** @var IJobList */ |
|
75 | + private $jobList; |
|
76 | + |
|
77 | + /** |
|
78 | + * AccountManager constructor. |
|
79 | + * |
|
80 | + * @param IDBConnection $connection |
|
81 | + * @param EventDispatcherInterface $eventDispatcher |
|
82 | + * @param IJobList $jobList |
|
83 | + */ |
|
84 | + public function __construct(IDBConnection $connection, |
|
85 | + EventDispatcherInterface $eventDispatcher, |
|
86 | + IJobList $jobList) { |
|
87 | + $this->connection = $connection; |
|
88 | + $this->eventDispatcher = $eventDispatcher; |
|
89 | + $this->jobList = $jobList; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * update user record |
|
94 | + * |
|
95 | + * @param IUser $user |
|
96 | + * @param $data |
|
97 | + */ |
|
98 | + public function updateUser(IUser $user, $data) { |
|
99 | + $userData = $this->getUser($user); |
|
100 | + $updated = true; |
|
101 | + if (empty($userData)) { |
|
102 | + $this->insertNewUser($user, $data); |
|
103 | + } elseif ($userData !== $data) { |
|
104 | + $data = $this->checkEmailVerification($userData, $data, $user); |
|
105 | + $data = $this->updateVerifyStatus($userData, $data); |
|
106 | + $this->updateExistingUser($user, $data); |
|
107 | + } else { |
|
108 | + // nothing needs to be done if new and old data set are the same |
|
109 | + $updated = false; |
|
110 | + } |
|
111 | + |
|
112 | + if ($updated) { |
|
113 | + $this->eventDispatcher->dispatch( |
|
114 | + 'OC\AccountManager::userUpdated', |
|
115 | + new GenericEvent($user, $data) |
|
116 | + ); |
|
117 | + } |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * delete user from accounts table |
|
122 | + * |
|
123 | + * @param IUser $user |
|
124 | + */ |
|
125 | + public function deleteUser(IUser $user) { |
|
126 | + $uid = $user->getUID(); |
|
127 | + $query = $this->connection->getQueryBuilder(); |
|
128 | + $query->delete($this->table) |
|
129 | + ->where($query->expr()->eq('uid', $query->createNamedParameter($uid))) |
|
130 | + ->execute(); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * get stored data from a given user |
|
135 | + * |
|
136 | + * @param IUser $user |
|
137 | + * @return array |
|
138 | + */ |
|
139 | + public function getUser(IUser $user) { |
|
140 | + $uid = $user->getUID(); |
|
141 | + $query = $this->connection->getQueryBuilder(); |
|
142 | + $query->select('data')->from($this->table) |
|
143 | + ->where($query->expr()->eq('uid', $query->createParameter('uid'))) |
|
144 | + ->setParameter('uid', $uid); |
|
145 | + $query->execute(); |
|
146 | + $result = $query->execute()->fetchAll(); |
|
147 | + |
|
148 | + if (empty($result)) { |
|
149 | + $userData = $this->buildDefaultUserRecord($user); |
|
150 | + $this->insertNewUser($user, $userData); |
|
151 | + return $userData; |
|
152 | + } |
|
153 | + |
|
154 | + $userDataArray = json_decode($result[0]['data'], true); |
|
155 | + |
|
156 | + $userDataArray = $this->addMissingDefaultValues($userDataArray); |
|
157 | + |
|
158 | + return $userDataArray; |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * check if we need to ask the server for email verification, if yes we create a cronjob |
|
163 | + * |
|
164 | + * @param $oldData |
|
165 | + * @param $newData |
|
166 | + * @param IUser $user |
|
167 | + * @return array |
|
168 | + */ |
|
169 | + protected function checkEmailVerification($oldData, $newData, IUser $user) { |
|
170 | + if ($oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value']) { |
|
171 | + $this->jobList->add(VerifyUserData::class, |
|
172 | + [ |
|
173 | + 'verificationCode' => '', |
|
174 | + 'data' => $newData[self::PROPERTY_EMAIL]['value'], |
|
175 | + 'type' => self::PROPERTY_EMAIL, |
|
176 | + 'uid' => $user->getUID(), |
|
177 | + 'try' => 0, |
|
178 | + 'lastRun' => time() |
|
179 | + ] |
|
180 | + ); |
|
181 | + $newData[AccountManager::PROPERTY_EMAIL]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS; |
|
182 | + } |
|
183 | + |
|
184 | + return $newData; |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * make sure that all expected data are set |
|
189 | + * |
|
190 | + * @param array $userData |
|
191 | + * @return array |
|
192 | + */ |
|
193 | + protected function addMissingDefaultValues(array $userData) { |
|
194 | + |
|
195 | + foreach ($userData as $key => $value) { |
|
196 | + if (!isset($userData[$key]['verified'])) { |
|
197 | + $userData[$key]['verified'] = self::NOT_VERIFIED; |
|
198 | + } |
|
199 | + } |
|
200 | + |
|
201 | + return $userData; |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * reset verification status if personal data changed |
|
206 | + * |
|
207 | + * @param array $oldData |
|
208 | + * @param array $newData |
|
209 | + * @return array |
|
210 | + */ |
|
211 | + protected function updateVerifyStatus($oldData, $newData) { |
|
212 | + |
|
213 | + // which account was already verified successfully? |
|
214 | + $twitterVerified = isset($oldData[self::PROPERTY_TWITTER]['verified']) && $oldData[self::PROPERTY_TWITTER]['verified'] === self::VERIFIED; |
|
215 | + $websiteVerified = isset($oldData[self::PROPERTY_WEBSITE]['verified']) && $oldData[self::PROPERTY_WEBSITE]['verified'] === self::VERIFIED; |
|
216 | + $emailVerified = isset($oldData[self::PROPERTY_EMAIL]['verified']) && $oldData[self::PROPERTY_EMAIL]['verified'] === self::VERIFIED; |
|
217 | + |
|
218 | + // keep old verification status if we don't have a new one |
|
219 | + if(!isset($newData[self::PROPERTY_TWITTER]['verified'])) { |
|
220 | + // keep old verification status if value didn't changed and an old value exists |
|
221 | + $keepOldStatus = $newData[self::PROPERTY_TWITTER]['value'] === $oldData[self::PROPERTY_TWITTER]['value'] && isset($oldData[self::PROPERTY_TWITTER]['verified']); |
|
222 | + $newData[self::PROPERTY_TWITTER]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_TWITTER]['verified'] : self::NOT_VERIFIED; |
|
223 | + } |
|
224 | + |
|
225 | + if(!isset($newData[self::PROPERTY_WEBSITE]['verified'])) { |
|
226 | + // keep old verification status if value didn't changed and an old value exists |
|
227 | + $keepOldStatus = $newData[self::PROPERTY_WEBSITE]['value'] === $oldData[self::PROPERTY_WEBSITE]['value'] && isset($oldData[self::PROPERTY_WEBSITE]['verified']); |
|
228 | + $newData[self::PROPERTY_WEBSITE]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_WEBSITE]['verified'] : self::NOT_VERIFIED; |
|
229 | + } |
|
230 | + |
|
231 | + if(!isset($newData[self::PROPERTY_EMAIL]['verified'])) { |
|
232 | + // keep old verification status if value didn't changed and an old value exists |
|
233 | + $keepOldStatus = $newData[self::PROPERTY_EMAIL]['value'] === $oldData[self::PROPERTY_EMAIL]['value'] && isset($oldData[self::PROPERTY_EMAIL]['verified']); |
|
234 | + $newData[self::PROPERTY_EMAIL]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_EMAIL]['verified'] : self::VERIFICATION_IN_PROGRESS; |
|
235 | + } |
|
236 | + |
|
237 | + // reset verification status if a value from a previously verified data was changed |
|
238 | + if($twitterVerified && |
|
239 | + $oldData[self::PROPERTY_TWITTER]['value'] !== $newData[self::PROPERTY_TWITTER]['value'] |
|
240 | + ) { |
|
241 | + $newData[self::PROPERTY_TWITTER]['verified'] = self::NOT_VERIFIED; |
|
242 | + } |
|
243 | + |
|
244 | + if($websiteVerified && |
|
245 | + $oldData[self::PROPERTY_WEBSITE]['value'] !== $newData[self::PROPERTY_WEBSITE]['value'] |
|
246 | + ) { |
|
247 | + $newData[self::PROPERTY_WEBSITE]['verified'] = self::NOT_VERIFIED; |
|
248 | + } |
|
249 | + |
|
250 | + if($emailVerified && |
|
251 | + $oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value'] |
|
252 | + ) { |
|
253 | + $newData[self::PROPERTY_EMAIL]['verified'] = self::NOT_VERIFIED; |
|
254 | + } |
|
255 | + |
|
256 | + return $newData; |
|
257 | + |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * add new user to accounts table |
|
262 | + * |
|
263 | + * @param IUser $user |
|
264 | + * @param array $data |
|
265 | + */ |
|
266 | + protected function insertNewUser(IUser $user, $data) { |
|
267 | + $uid = $user->getUID(); |
|
268 | + $jsonEncodedData = json_encode($data); |
|
269 | + $query = $this->connection->getQueryBuilder(); |
|
270 | + $query->insert($this->table) |
|
271 | + ->values( |
|
272 | + [ |
|
273 | + 'uid' => $query->createNamedParameter($uid), |
|
274 | + 'data' => $query->createNamedParameter($jsonEncodedData), |
|
275 | + ] |
|
276 | + ) |
|
277 | + ->execute(); |
|
278 | + } |
|
279 | + |
|
280 | + /** |
|
281 | + * update existing user in accounts table |
|
282 | + * |
|
283 | + * @param IUser $user |
|
284 | + * @param array $data |
|
285 | + */ |
|
286 | + protected function updateExistingUser(IUser $user, $data) { |
|
287 | + $uid = $user->getUID(); |
|
288 | + $jsonEncodedData = json_encode($data); |
|
289 | + $query = $this->connection->getQueryBuilder(); |
|
290 | + $query->update($this->table) |
|
291 | + ->set('data', $query->createNamedParameter($jsonEncodedData)) |
|
292 | + ->where($query->expr()->eq('uid', $query->createNamedParameter($uid))) |
|
293 | + ->execute(); |
|
294 | + } |
|
295 | + |
|
296 | + /** |
|
297 | + * build default user record in case not data set exists yet |
|
298 | + * |
|
299 | + * @param IUser $user |
|
300 | + * @return array |
|
301 | + */ |
|
302 | + protected function buildDefaultUserRecord(IUser $user) { |
|
303 | + return [ |
|
304 | + self::PROPERTY_DISPLAYNAME => |
|
305 | + [ |
|
306 | + 'value' => $user->getDisplayName(), |
|
307 | + 'scope' => self::VISIBILITY_CONTACTS_ONLY, |
|
308 | + 'verified' => self::NOT_VERIFIED, |
|
309 | + ], |
|
310 | + self::PROPERTY_ADDRESS => |
|
311 | + [ |
|
312 | + 'value' => '', |
|
313 | + 'scope' => self::VISIBILITY_PRIVATE, |
|
314 | + 'verified' => self::NOT_VERIFIED, |
|
315 | + ], |
|
316 | + self::PROPERTY_WEBSITE => |
|
317 | + [ |
|
318 | + 'value' => '', |
|
319 | + 'scope' => self::VISIBILITY_PRIVATE, |
|
320 | + 'verified' => self::NOT_VERIFIED, |
|
321 | + ], |
|
322 | + self::PROPERTY_EMAIL => |
|
323 | + [ |
|
324 | + 'value' => $user->getEMailAddress(), |
|
325 | + 'scope' => self::VISIBILITY_CONTACTS_ONLY, |
|
326 | + 'verified' => self::NOT_VERIFIED, |
|
327 | + ], |
|
328 | + self::PROPERTY_AVATAR => |
|
329 | + [ |
|
330 | + 'scope' => self::VISIBILITY_CONTACTS_ONLY |
|
331 | + ], |
|
332 | + self::PROPERTY_PHONE => |
|
333 | + [ |
|
334 | + 'value' => '', |
|
335 | + 'scope' => self::VISIBILITY_PRIVATE, |
|
336 | + 'verified' => self::NOT_VERIFIED, |
|
337 | + ], |
|
338 | + self::PROPERTY_TWITTER => |
|
339 | + [ |
|
340 | + 'value' => '', |
|
341 | + 'scope' => self::VISIBILITY_PRIVATE, |
|
342 | + 'verified' => self::NOT_VERIFIED, |
|
343 | + ], |
|
344 | + ]; |
|
345 | + } |
|
346 | 346 | |
347 | 347 | } |
@@ -48,6 +48,9 @@ discard block |
||
48 | 48 | $this->stack = $stack; |
49 | 49 | } |
50 | 50 | |
51 | + /** |
|
52 | + * @param double $time |
|
53 | + */ |
|
51 | 54 | public function end($time) { |
52 | 55 | $this->end = $time; |
53 | 56 | } |
@@ -67,7 +70,7 @@ discard block |
||
67 | 70 | } |
68 | 71 | |
69 | 72 | /** |
70 | - * @return float |
|
73 | + * @return integer |
|
71 | 74 | */ |
72 | 75 | public function getStart() { |
73 | 76 | return $this->start; |
@@ -26,65 +26,65 @@ |
||
26 | 26 | use OCP\Diagnostics\IQuery; |
27 | 27 | |
28 | 28 | class Query implements IQuery { |
29 | - private $sql; |
|
29 | + private $sql; |
|
30 | 30 | |
31 | - private $params; |
|
31 | + private $params; |
|
32 | 32 | |
33 | - private $start; |
|
33 | + private $start; |
|
34 | 34 | |
35 | - private $end; |
|
35 | + private $end; |
|
36 | 36 | |
37 | - private $stack; |
|
37 | + private $stack; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param string $sql |
|
41 | - * @param array $params |
|
42 | - * @param int $start |
|
43 | - */ |
|
44 | - public function __construct($sql, $params, $start, array $stack) { |
|
45 | - $this->sql = $sql; |
|
46 | - $this->params = $params; |
|
47 | - $this->start = $start; |
|
48 | - $this->stack = $stack; |
|
49 | - } |
|
39 | + /** |
|
40 | + * @param string $sql |
|
41 | + * @param array $params |
|
42 | + * @param int $start |
|
43 | + */ |
|
44 | + public function __construct($sql, $params, $start, array $stack) { |
|
45 | + $this->sql = $sql; |
|
46 | + $this->params = $params; |
|
47 | + $this->start = $start; |
|
48 | + $this->stack = $stack; |
|
49 | + } |
|
50 | 50 | |
51 | - public function end($time) { |
|
52 | - $this->end = $time; |
|
53 | - } |
|
51 | + public function end($time) { |
|
52 | + $this->end = $time; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - public function getParams() { |
|
59 | - return $this->params; |
|
60 | - } |
|
55 | + /** |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + public function getParams() { |
|
59 | + return $this->params; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - public function getSql() { |
|
66 | - return $this->sql; |
|
67 | - } |
|
62 | + /** |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + public function getSql() { |
|
66 | + return $this->sql; |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @return float |
|
71 | - */ |
|
72 | - public function getStart() { |
|
73 | - return $this->start; |
|
74 | - } |
|
69 | + /** |
|
70 | + * @return float |
|
71 | + */ |
|
72 | + public function getStart() { |
|
73 | + return $this->start; |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * @return float |
|
78 | - */ |
|
79 | - public function getDuration() { |
|
80 | - return $this->end - $this->start; |
|
81 | - } |
|
76 | + /** |
|
77 | + * @return float |
|
78 | + */ |
|
79 | + public function getDuration() { |
|
80 | + return $this->end - $this->start; |
|
81 | + } |
|
82 | 82 | |
83 | - public function getStartTime() { |
|
84 | - return $this->start; |
|
85 | - } |
|
83 | + public function getStartTime() { |
|
84 | + return $this->start; |
|
85 | + } |
|
86 | 86 | |
87 | - public function getStacktrace() { |
|
88 | - return $this->stack; |
|
89 | - } |
|
87 | + public function getStacktrace() { |
|
88 | + return $this->stack; |
|
89 | + } |
|
90 | 90 | } |
@@ -35,55 +35,55 @@ |
||
35 | 35 | * @since 8.0.0 |
36 | 36 | */ |
37 | 37 | interface IEventLogger { |
38 | - /** |
|
39 | - * Mark the start of an event setting its ID $id and providing event description $description. |
|
40 | - * |
|
41 | - * @param string $id |
|
42 | - * @param string $description |
|
43 | - * @since 8.0.0 |
|
44 | - */ |
|
45 | - public function start($id, $description); |
|
38 | + /** |
|
39 | + * Mark the start of an event setting its ID $id and providing event description $description. |
|
40 | + * |
|
41 | + * @param string $id |
|
42 | + * @param string $description |
|
43 | + * @since 8.0.0 |
|
44 | + */ |
|
45 | + public function start($id, $description); |
|
46 | 46 | |
47 | - /** |
|
48 | - * Mark the end of an event with specific ID $id, marked by start() method. |
|
49 | - * Ending event should store \OCP\Diagnostics\IEvent to |
|
50 | - * be returned with getEvents() method. |
|
51 | - * |
|
52 | - * @param string $id |
|
53 | - * @since 8.0.0 |
|
54 | - */ |
|
55 | - public function end($id); |
|
47 | + /** |
|
48 | + * Mark the end of an event with specific ID $id, marked by start() method. |
|
49 | + * Ending event should store \OCP\Diagnostics\IEvent to |
|
50 | + * be returned with getEvents() method. |
|
51 | + * |
|
52 | + * @param string $id |
|
53 | + * @since 8.0.0 |
|
54 | + */ |
|
55 | + public function end($id); |
|
56 | 56 | |
57 | - /** |
|
58 | - * Mark the start and the end of an event with specific ID $id and description $description, |
|
59 | - * explicitly marking start and end of the event, represented by $start and $end timestamps. |
|
60 | - * Logging event should store \OCP\Diagnostics\IEvent to |
|
61 | - * be returned with getEvents() method. |
|
62 | - * |
|
63 | - * @param string $id |
|
64 | - * @param string $description |
|
65 | - * @param float $start |
|
66 | - * @param float $end |
|
67 | - * @since 8.0.0 |
|
68 | - */ |
|
69 | - public function log($id, $description, $start, $end); |
|
57 | + /** |
|
58 | + * Mark the start and the end of an event with specific ID $id and description $description, |
|
59 | + * explicitly marking start and end of the event, represented by $start and $end timestamps. |
|
60 | + * Logging event should store \OCP\Diagnostics\IEvent to |
|
61 | + * be returned with getEvents() method. |
|
62 | + * |
|
63 | + * @param string $id |
|
64 | + * @param string $description |
|
65 | + * @param float $start |
|
66 | + * @param float $end |
|
67 | + * @since 8.0.0 |
|
68 | + */ |
|
69 | + public function log($id, $description, $start, $end); |
|
70 | 70 | |
71 | - /** |
|
72 | - * This method should return all \OCP\Diagnostics\IEvent objects stored using |
|
73 | - * start()/end() or log() methods |
|
74 | - * |
|
75 | - * @return \OCP\Diagnostics\IEvent[] |
|
76 | - * @since 8.0.0 |
|
77 | - */ |
|
78 | - public function getEvents(); |
|
71 | + /** |
|
72 | + * This method should return all \OCP\Diagnostics\IEvent objects stored using |
|
73 | + * start()/end() or log() methods |
|
74 | + * |
|
75 | + * @return \OCP\Diagnostics\IEvent[] |
|
76 | + * @since 8.0.0 |
|
77 | + */ |
|
78 | + public function getEvents(); |
|
79 | 79 | |
80 | - /** |
|
81 | - * Activate the module for the duration of the request. Deactivated module |
|
82 | - * does not create and store \OCP\Diagnostics\IEvent objects. |
|
83 | - * Only activated module should create and store objects to be |
|
84 | - * returned with getEvents() call. |
|
85 | - * |
|
86 | - * @since 12.0.0 |
|
87 | - */ |
|
88 | - public function activate(); |
|
80 | + /** |
|
81 | + * Activate the module for the duration of the request. Deactivated module |
|
82 | + * does not create and store \OCP\Diagnostics\IEvent objects. |
|
83 | + * Only activated module should create and store objects to be |
|
84 | + * returned with getEvents() call. |
|
85 | + * |
|
86 | + * @since 12.0.0 |
|
87 | + */ |
|
88 | + public function activate(); |
|
89 | 89 | } |
@@ -30,38 +30,38 @@ |
||
30 | 30 | * @since 8.0.0 |
31 | 31 | */ |
32 | 32 | interface IQuery { |
33 | - /** |
|
34 | - * @return string |
|
35 | - * @since 8.0.0 |
|
36 | - */ |
|
37 | - public function getSql(); |
|
33 | + /** |
|
34 | + * @return string |
|
35 | + * @since 8.0.0 |
|
36 | + */ |
|
37 | + public function getSql(); |
|
38 | 38 | |
39 | - /** |
|
40 | - * @return array |
|
41 | - * @since 8.0.0 |
|
42 | - */ |
|
43 | - public function getParams(); |
|
39 | + /** |
|
40 | + * @return array |
|
41 | + * @since 8.0.0 |
|
42 | + */ |
|
43 | + public function getParams(); |
|
44 | 44 | |
45 | - /** |
|
46 | - * @return float |
|
47 | - * @since 8.0.0 |
|
48 | - */ |
|
49 | - public function getDuration(); |
|
45 | + /** |
|
46 | + * @return float |
|
47 | + * @since 8.0.0 |
|
48 | + */ |
|
49 | + public function getDuration(); |
|
50 | 50 | |
51 | - /** |
|
52 | - * @return float |
|
53 | - * @since 11.0.0 |
|
54 | - */ |
|
55 | - public function getStartTime(); |
|
51 | + /** |
|
52 | + * @return float |
|
53 | + * @since 11.0.0 |
|
54 | + */ |
|
55 | + public function getStartTime(); |
|
56 | 56 | |
57 | - /** |
|
58 | - * @return array |
|
59 | - * @since 11.0.0 |
|
60 | - */ |
|
61 | - public function getStacktrace(); |
|
62 | - /** |
|
63 | - * @return array |
|
64 | - * @since 12.0.0 |
|
65 | - */ |
|
66 | - public function getStart(); |
|
57 | + /** |
|
58 | + * @return array |
|
59 | + * @since 11.0.0 |
|
60 | + */ |
|
61 | + public function getStacktrace(); |
|
62 | + /** |
|
63 | + * @return array |
|
64 | + * @since 12.0.0 |
|
65 | + */ |
|
66 | + public function getStart(); |
|
67 | 67 | } |
@@ -28,56 +28,56 @@ |
||
28 | 28 | use OCP\Diagnostics\IEventLogger; |
29 | 29 | |
30 | 30 | class EventLogger implements IEventLogger { |
31 | - /** |
|
32 | - * @var \OC\Diagnostics\Event[] |
|
33 | - */ |
|
34 | - private $events = []; |
|
31 | + /** |
|
32 | + * @var \OC\Diagnostics\Event[] |
|
33 | + */ |
|
34 | + private $events = []; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @var bool - Module needs to be activated by some app |
|
38 | - */ |
|
39 | - private $activated = false; |
|
36 | + /** |
|
37 | + * @var bool - Module needs to be activated by some app |
|
38 | + */ |
|
39 | + private $activated = false; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @inheritdoc |
|
43 | - */ |
|
44 | - public function start($id, $description) { |
|
45 | - if ($this->activated){ |
|
46 | - $this->events[$id] = new Event($id, $description, microtime(true)); |
|
47 | - } |
|
48 | - } |
|
41 | + /** |
|
42 | + * @inheritdoc |
|
43 | + */ |
|
44 | + public function start($id, $description) { |
|
45 | + if ($this->activated){ |
|
46 | + $this->events[$id] = new Event($id, $description, microtime(true)); |
|
47 | + } |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @inheritdoc |
|
52 | - */ |
|
53 | - public function end($id) { |
|
54 | - if ($this->activated && isset($this->events[$id])) { |
|
55 | - $timing = $this->events[$id]; |
|
56 | - $timing->end(microtime(true)); |
|
57 | - } |
|
58 | - } |
|
50 | + /** |
|
51 | + * @inheritdoc |
|
52 | + */ |
|
53 | + public function end($id) { |
|
54 | + if ($this->activated && isset($this->events[$id])) { |
|
55 | + $timing = $this->events[$id]; |
|
56 | + $timing->end(microtime(true)); |
|
57 | + } |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @inheritdoc |
|
62 | - */ |
|
63 | - public function log($id, $description, $start, $end) { |
|
64 | - if ($this->activated) { |
|
65 | - $this->events[$id] = new Event($id, $description, $start); |
|
66 | - $this->events[$id]->end($end); |
|
67 | - } |
|
68 | - } |
|
60 | + /** |
|
61 | + * @inheritdoc |
|
62 | + */ |
|
63 | + public function log($id, $description, $start, $end) { |
|
64 | + if ($this->activated) { |
|
65 | + $this->events[$id] = new Event($id, $description, $start); |
|
66 | + $this->events[$id]->end($end); |
|
67 | + } |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * @inheritdoc |
|
72 | - */ |
|
73 | - public function getEvents() { |
|
74 | - return $this->events; |
|
75 | - } |
|
70 | + /** |
|
71 | + * @inheritdoc |
|
72 | + */ |
|
73 | + public function getEvents() { |
|
74 | + return $this->events; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * @inheritdoc |
|
79 | - */ |
|
80 | - public function activate() { |
|
81 | - $this->activated = true; |
|
82 | - } |
|
77 | + /** |
|
78 | + * @inheritdoc |
|
79 | + */ |
|
80 | + public function activate() { |
|
81 | + $this->activated = true; |
|
82 | + } |
|
83 | 83 | } |
@@ -42,7 +42,7 @@ |
||
42 | 42 | * @inheritdoc |
43 | 43 | */ |
44 | 44 | public function start($id, $description) { |
45 | - if ($this->activated){ |
|
45 | + if ($this->activated) { |
|
46 | 46 | $this->events[$id] = new Event($id, $description, microtime(true)); |
47 | 47 | } |
48 | 48 | } |
@@ -118,17 +118,17 @@ discard block |
||
118 | 118 | protected function attachListener($mount) { |
119 | 119 | $scanner = $mount->getStorage()->getScanner(); |
120 | 120 | $emitter = $this; |
121 | - $scanner->listen('\OC\Files\Cache\Scanner', 'scanFile', function ($path) use ($mount, $emitter) { |
|
122 | - $emitter->emit('\OC\Files\Utils\Scanner', 'scanFile', array($mount->getMountPoint() . $path)); |
|
121 | + $scanner->listen('\OC\Files\Cache\Scanner', 'scanFile', function($path) use ($mount, $emitter) { |
|
122 | + $emitter->emit('\OC\Files\Utils\Scanner', 'scanFile', array($mount->getMountPoint().$path)); |
|
123 | 123 | }); |
124 | - $scanner->listen('\OC\Files\Cache\Scanner', 'scanFolder', function ($path) use ($mount, $emitter) { |
|
125 | - $emitter->emit('\OC\Files\Utils\Scanner', 'scanFolder', array($mount->getMountPoint() . $path)); |
|
124 | + $scanner->listen('\OC\Files\Cache\Scanner', 'scanFolder', function($path) use ($mount, $emitter) { |
|
125 | + $emitter->emit('\OC\Files\Utils\Scanner', 'scanFolder', array($mount->getMountPoint().$path)); |
|
126 | 126 | }); |
127 | - $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFile', function ($path) use ($mount, $emitter) { |
|
128 | - $emitter->emit('\OC\Files\Utils\Scanner', 'postScanFile', array($mount->getMountPoint() . $path)); |
|
127 | + $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFile', function($path) use ($mount, $emitter) { |
|
128 | + $emitter->emit('\OC\Files\Utils\Scanner', 'postScanFile', array($mount->getMountPoint().$path)); |
|
129 | 129 | }); |
130 | - $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFolder', function ($path) use ($mount, $emitter) { |
|
131 | - $emitter->emit('\OC\Files\Utils\Scanner', 'postScanFolder', array($mount->getMountPoint() . $path)); |
|
130 | + $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFolder', function($path) use ($mount, $emitter) { |
|
131 | + $emitter->emit('\OC\Files\Utils\Scanner', 'postScanFolder', array($mount->getMountPoint().$path)); |
|
132 | 132 | }); |
133 | 133 | } |
134 | 134 | |
@@ -160,13 +160,13 @@ discard block |
||
160 | 160 | $scanner = $storage->getScanner(); |
161 | 161 | $this->attachListener($mount); |
162 | 162 | |
163 | - $scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function ($path) use ($storage) { |
|
163 | + $scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function($path) use ($storage) { |
|
164 | 164 | $this->triggerPropagator($storage, $path); |
165 | 165 | }); |
166 | - $scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function ($path) use ($storage) { |
|
166 | + $scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function($path) use ($storage) { |
|
167 | 167 | $this->triggerPropagator($storage, $path); |
168 | 168 | }); |
169 | - $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path) use ($storage) { |
|
169 | + $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function($path) use ($storage) { |
|
170 | 170 | $this->triggerPropagator($storage, $path); |
171 | 171 | }); |
172 | 172 | |
@@ -219,13 +219,13 @@ discard block |
||
219 | 219 | $scanner->setUseTransactions(false); |
220 | 220 | $this->attachListener($mount); |
221 | 221 | |
222 | - $scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function ($path) use ($storage) { |
|
222 | + $scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function($path) use ($storage) { |
|
223 | 223 | $this->postProcessEntry($storage, $path); |
224 | 224 | }); |
225 | - $scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function ($path) use ($storage) { |
|
225 | + $scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function($path) use ($storage) { |
|
226 | 226 | $this->postProcessEntry($storage, $path); |
227 | 227 | }); |
228 | - $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path) use ($storage) { |
|
228 | + $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function($path) use ($storage) { |
|
229 | 229 | $this->postProcessEntry($storage, $path); |
230 | 230 | }); |
231 | 231 | |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | } |
248 | 248 | $propagator->commitBatch(); |
249 | 249 | } catch (StorageNotAvailableException $e) { |
250 | - $this->logger->error('Storage ' . $storage->getId() . ' not available'); |
|
250 | + $this->logger->error('Storage '.$storage->getId().' not available'); |
|
251 | 251 | $this->logger->logException($e); |
252 | 252 | $this->emit('\OC\Files\Utils\Scanner', 'StorageNotAvailable', [$e]); |
253 | 253 | } |
@@ -182,7 +182,7 @@ |
||
182 | 182 | |
183 | 183 | /** |
184 | 184 | * @param string $dir |
185 | - * @param $recursive |
|
185 | + * @param boolean $recursive |
|
186 | 186 | * @param callable|null $mountFilter |
187 | 187 | * @throws ForbiddenException |
188 | 188 | * @throws NotFoundException |
@@ -50,233 +50,233 @@ |
||
50 | 50 | * @package OC\Files\Utils |
51 | 51 | */ |
52 | 52 | class Scanner extends PublicEmitter { |
53 | - const MAX_ENTRIES_TO_COMMIT = 10000; |
|
53 | + const MAX_ENTRIES_TO_COMMIT = 10000; |
|
54 | 54 | |
55 | - /** |
|
56 | - * @var string $user |
|
57 | - */ |
|
58 | - private $user; |
|
55 | + /** |
|
56 | + * @var string $user |
|
57 | + */ |
|
58 | + private $user; |
|
59 | 59 | |
60 | - /** |
|
61 | - * @var \OCP\IDBConnection |
|
62 | - */ |
|
63 | - protected $db; |
|
60 | + /** |
|
61 | + * @var \OCP\IDBConnection |
|
62 | + */ |
|
63 | + protected $db; |
|
64 | 64 | |
65 | - /** |
|
66 | - * @var ILogger |
|
67 | - */ |
|
68 | - protected $logger; |
|
65 | + /** |
|
66 | + * @var ILogger |
|
67 | + */ |
|
68 | + protected $logger; |
|
69 | 69 | |
70 | - /** |
|
71 | - * Whether to use a DB transaction |
|
72 | - * |
|
73 | - * @var bool |
|
74 | - */ |
|
75 | - protected $useTransaction; |
|
70 | + /** |
|
71 | + * Whether to use a DB transaction |
|
72 | + * |
|
73 | + * @var bool |
|
74 | + */ |
|
75 | + protected $useTransaction; |
|
76 | 76 | |
77 | - /** |
|
78 | - * Number of entries scanned to commit |
|
79 | - * |
|
80 | - * @var int |
|
81 | - */ |
|
82 | - protected $entriesToCommit; |
|
77 | + /** |
|
78 | + * Number of entries scanned to commit |
|
79 | + * |
|
80 | + * @var int |
|
81 | + */ |
|
82 | + protected $entriesToCommit; |
|
83 | 83 | |
84 | - /** |
|
85 | - * @param string $user |
|
86 | - * @param \OCP\IDBConnection $db |
|
87 | - * @param ILogger $logger |
|
88 | - */ |
|
89 | - public function __construct($user, $db, ILogger $logger) { |
|
90 | - $this->logger = $logger; |
|
91 | - $this->user = $user; |
|
92 | - $this->db = $db; |
|
93 | - // when DB locking is used, no DB transactions will be used |
|
94 | - $this->useTransaction = !(\OC::$server->getLockingProvider() instanceof DBLockingProvider); |
|
95 | - } |
|
84 | + /** |
|
85 | + * @param string $user |
|
86 | + * @param \OCP\IDBConnection $db |
|
87 | + * @param ILogger $logger |
|
88 | + */ |
|
89 | + public function __construct($user, $db, ILogger $logger) { |
|
90 | + $this->logger = $logger; |
|
91 | + $this->user = $user; |
|
92 | + $this->db = $db; |
|
93 | + // when DB locking is used, no DB transactions will be used |
|
94 | + $this->useTransaction = !(\OC::$server->getLockingProvider() instanceof DBLockingProvider); |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * get all storages for $dir |
|
99 | - * |
|
100 | - * @param string $dir |
|
101 | - * @return \OC\Files\Mount\MountPoint[] |
|
102 | - */ |
|
103 | - protected function getMounts($dir) { |
|
104 | - //TODO: move to the node based fileapi once that's done |
|
105 | - \OC_Util::tearDownFS(); |
|
106 | - \OC_Util::setupFS($this->user); |
|
97 | + /** |
|
98 | + * get all storages for $dir |
|
99 | + * |
|
100 | + * @param string $dir |
|
101 | + * @return \OC\Files\Mount\MountPoint[] |
|
102 | + */ |
|
103 | + protected function getMounts($dir) { |
|
104 | + //TODO: move to the node based fileapi once that's done |
|
105 | + \OC_Util::tearDownFS(); |
|
106 | + \OC_Util::setupFS($this->user); |
|
107 | 107 | |
108 | - $mountManager = Filesystem::getMountManager(); |
|
109 | - $mounts = $mountManager->findIn($dir); |
|
110 | - $mounts[] = $mountManager->find($dir); |
|
111 | - $mounts = array_reverse($mounts); //start with the mount of $dir |
|
108 | + $mountManager = Filesystem::getMountManager(); |
|
109 | + $mounts = $mountManager->findIn($dir); |
|
110 | + $mounts[] = $mountManager->find($dir); |
|
111 | + $mounts = array_reverse($mounts); //start with the mount of $dir |
|
112 | 112 | |
113 | - return $mounts; |
|
114 | - } |
|
113 | + return $mounts; |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * attach listeners to the scanner |
|
118 | - * |
|
119 | - * @param \OC\Files\Mount\MountPoint $mount |
|
120 | - */ |
|
121 | - protected function attachListener($mount) { |
|
122 | - $scanner = $mount->getStorage()->getScanner(); |
|
123 | - $emitter = $this; |
|
124 | - $scanner->listen('\OC\Files\Cache\Scanner', 'scanFile', function ($path) use ($mount, $emitter) { |
|
125 | - $emitter->emit('\OC\Files\Utils\Scanner', 'scanFile', array($mount->getMountPoint() . $path)); |
|
126 | - }); |
|
127 | - $scanner->listen('\OC\Files\Cache\Scanner', 'scanFolder', function ($path) use ($mount, $emitter) { |
|
128 | - $emitter->emit('\OC\Files\Utils\Scanner', 'scanFolder', array($mount->getMountPoint() . $path)); |
|
129 | - }); |
|
130 | - $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFile', function ($path) use ($mount, $emitter) { |
|
131 | - $emitter->emit('\OC\Files\Utils\Scanner', 'postScanFile', array($mount->getMountPoint() . $path)); |
|
132 | - }); |
|
133 | - $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFolder', function ($path) use ($mount, $emitter) { |
|
134 | - $emitter->emit('\OC\Files\Utils\Scanner', 'postScanFolder', array($mount->getMountPoint() . $path)); |
|
135 | - }); |
|
136 | - } |
|
116 | + /** |
|
117 | + * attach listeners to the scanner |
|
118 | + * |
|
119 | + * @param \OC\Files\Mount\MountPoint $mount |
|
120 | + */ |
|
121 | + protected function attachListener($mount) { |
|
122 | + $scanner = $mount->getStorage()->getScanner(); |
|
123 | + $emitter = $this; |
|
124 | + $scanner->listen('\OC\Files\Cache\Scanner', 'scanFile', function ($path) use ($mount, $emitter) { |
|
125 | + $emitter->emit('\OC\Files\Utils\Scanner', 'scanFile', array($mount->getMountPoint() . $path)); |
|
126 | + }); |
|
127 | + $scanner->listen('\OC\Files\Cache\Scanner', 'scanFolder', function ($path) use ($mount, $emitter) { |
|
128 | + $emitter->emit('\OC\Files\Utils\Scanner', 'scanFolder', array($mount->getMountPoint() . $path)); |
|
129 | + }); |
|
130 | + $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFile', function ($path) use ($mount, $emitter) { |
|
131 | + $emitter->emit('\OC\Files\Utils\Scanner', 'postScanFile', array($mount->getMountPoint() . $path)); |
|
132 | + }); |
|
133 | + $scanner->listen('\OC\Files\Cache\Scanner', 'postScanFolder', function ($path) use ($mount, $emitter) { |
|
134 | + $emitter->emit('\OC\Files\Utils\Scanner', 'postScanFolder', array($mount->getMountPoint() . $path)); |
|
135 | + }); |
|
136 | + } |
|
137 | 137 | |
138 | - /** |
|
139 | - * @param string $dir |
|
140 | - */ |
|
141 | - public function backgroundScan($dir) { |
|
142 | - $mounts = $this->getMounts($dir); |
|
143 | - foreach ($mounts as $mount) { |
|
144 | - $storage = $mount->getStorage(); |
|
145 | - if (is_null($storage)) { |
|
146 | - continue; |
|
147 | - } |
|
138 | + /** |
|
139 | + * @param string $dir |
|
140 | + */ |
|
141 | + public function backgroundScan($dir) { |
|
142 | + $mounts = $this->getMounts($dir); |
|
143 | + foreach ($mounts as $mount) { |
|
144 | + $storage = $mount->getStorage(); |
|
145 | + if (is_null($storage)) { |
|
146 | + continue; |
|
147 | + } |
|
148 | 148 | |
149 | - // don't bother scanning failed storages (shortcut for same result) |
|
150 | - if ($storage->instanceOfStorage(FailedStorage::class)) { |
|
151 | - continue; |
|
152 | - } |
|
149 | + // don't bother scanning failed storages (shortcut for same result) |
|
150 | + if ($storage->instanceOfStorage(FailedStorage::class)) { |
|
151 | + continue; |
|
152 | + } |
|
153 | 153 | |
154 | - // don't scan received local shares, these can be scanned when scanning the owner's storage |
|
155 | - if ($storage->instanceOfStorage(SharedStorage::class)) { |
|
156 | - continue; |
|
157 | - } |
|
158 | - $scanner = $storage->getScanner(); |
|
159 | - $this->attachListener($mount); |
|
154 | + // don't scan received local shares, these can be scanned when scanning the owner's storage |
|
155 | + if ($storage->instanceOfStorage(SharedStorage::class)) { |
|
156 | + continue; |
|
157 | + } |
|
158 | + $scanner = $storage->getScanner(); |
|
159 | + $this->attachListener($mount); |
|
160 | 160 | |
161 | - $scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function ($path) use ($storage) { |
|
162 | - $this->triggerPropagator($storage, $path); |
|
163 | - }); |
|
164 | - $scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function ($path) use ($storage) { |
|
165 | - $this->triggerPropagator($storage, $path); |
|
166 | - }); |
|
167 | - $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path) use ($storage) { |
|
168 | - $this->triggerPropagator($storage, $path); |
|
169 | - }); |
|
161 | + $scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function ($path) use ($storage) { |
|
162 | + $this->triggerPropagator($storage, $path); |
|
163 | + }); |
|
164 | + $scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function ($path) use ($storage) { |
|
165 | + $this->triggerPropagator($storage, $path); |
|
166 | + }); |
|
167 | + $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path) use ($storage) { |
|
168 | + $this->triggerPropagator($storage, $path); |
|
169 | + }); |
|
170 | 170 | |
171 | - $propagator = $storage->getPropagator(); |
|
172 | - $propagator->beginBatch(); |
|
173 | - $scanner->backgroundScan(); |
|
174 | - $propagator->commitBatch(); |
|
175 | - } |
|
176 | - } |
|
171 | + $propagator = $storage->getPropagator(); |
|
172 | + $propagator->beginBatch(); |
|
173 | + $scanner->backgroundScan(); |
|
174 | + $propagator->commitBatch(); |
|
175 | + } |
|
176 | + } |
|
177 | 177 | |
178 | - /** |
|
179 | - * @param string $dir |
|
180 | - * @param $recursive |
|
181 | - * @param callable|null $mountFilter |
|
182 | - * @throws ForbiddenException |
|
183 | - * @throws NotFoundException |
|
184 | - */ |
|
185 | - public function scan($dir = '', $recursive = \OC\Files\Cache\Scanner::SCAN_RECURSIVE, callable $mountFilter = null) { |
|
186 | - if (!Filesystem::isValidPath($dir)) { |
|
187 | - throw new \InvalidArgumentException('Invalid path to scan'); |
|
188 | - } |
|
189 | - $mounts = $this->getMounts($dir); |
|
190 | - foreach ($mounts as $mount) { |
|
191 | - if ($mountFilter && !$mountFilter($mount)) { |
|
192 | - continue; |
|
193 | - } |
|
194 | - $storage = $mount->getStorage(); |
|
195 | - if (is_null($storage)) { |
|
196 | - continue; |
|
197 | - } |
|
178 | + /** |
|
179 | + * @param string $dir |
|
180 | + * @param $recursive |
|
181 | + * @param callable|null $mountFilter |
|
182 | + * @throws ForbiddenException |
|
183 | + * @throws NotFoundException |
|
184 | + */ |
|
185 | + public function scan($dir = '', $recursive = \OC\Files\Cache\Scanner::SCAN_RECURSIVE, callable $mountFilter = null) { |
|
186 | + if (!Filesystem::isValidPath($dir)) { |
|
187 | + throw new \InvalidArgumentException('Invalid path to scan'); |
|
188 | + } |
|
189 | + $mounts = $this->getMounts($dir); |
|
190 | + foreach ($mounts as $mount) { |
|
191 | + if ($mountFilter && !$mountFilter($mount)) { |
|
192 | + continue; |
|
193 | + } |
|
194 | + $storage = $mount->getStorage(); |
|
195 | + if (is_null($storage)) { |
|
196 | + continue; |
|
197 | + } |
|
198 | 198 | |
199 | - // don't bother scanning failed storages (shortcut for same result) |
|
200 | - if ($storage->instanceOfStorage(FailedStorage::class)) { |
|
201 | - continue; |
|
202 | - } |
|
199 | + // don't bother scanning failed storages (shortcut for same result) |
|
200 | + if ($storage->instanceOfStorage(FailedStorage::class)) { |
|
201 | + continue; |
|
202 | + } |
|
203 | 203 | |
204 | - // if the home storage isn't writable then the scanner is run as the wrong user |
|
205 | - if ($storage->instanceOfStorage('\OC\Files\Storage\Home') and |
|
206 | - (!$storage->isCreatable('') or !$storage->isCreatable('files')) |
|
207 | - ) { |
|
208 | - if ($storage->file_exists('') or $storage->getCache()->inCache('')) { |
|
209 | - throw new ForbiddenException(); |
|
210 | - } else {// if the root exists in neither the cache nor the storage the user isn't setup yet |
|
211 | - break; |
|
212 | - } |
|
204 | + // if the home storage isn't writable then the scanner is run as the wrong user |
|
205 | + if ($storage->instanceOfStorage('\OC\Files\Storage\Home') and |
|
206 | + (!$storage->isCreatable('') or !$storage->isCreatable('files')) |
|
207 | + ) { |
|
208 | + if ($storage->file_exists('') or $storage->getCache()->inCache('')) { |
|
209 | + throw new ForbiddenException(); |
|
210 | + } else {// if the root exists in neither the cache nor the storage the user isn't setup yet |
|
211 | + break; |
|
212 | + } |
|
213 | 213 | |
214 | - } |
|
214 | + } |
|
215 | 215 | |
216 | - // don't scan received local shares, these can be scanned when scanning the owner's storage |
|
217 | - if ($storage->instanceOfStorage(SharedStorage::class)) { |
|
218 | - continue; |
|
219 | - } |
|
220 | - $relativePath = $mount->getInternalPath($dir); |
|
221 | - $scanner = $storage->getScanner(); |
|
222 | - $scanner->setUseTransactions(false); |
|
223 | - $this->attachListener($mount); |
|
216 | + // don't scan received local shares, these can be scanned when scanning the owner's storage |
|
217 | + if ($storage->instanceOfStorage(SharedStorage::class)) { |
|
218 | + continue; |
|
219 | + } |
|
220 | + $relativePath = $mount->getInternalPath($dir); |
|
221 | + $scanner = $storage->getScanner(); |
|
222 | + $scanner->setUseTransactions(false); |
|
223 | + $this->attachListener($mount); |
|
224 | 224 | |
225 | - $scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function ($path) use ($storage) { |
|
226 | - $this->postProcessEntry($storage, $path); |
|
227 | - }); |
|
228 | - $scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function ($path) use ($storage) { |
|
229 | - $this->postProcessEntry($storage, $path); |
|
230 | - }); |
|
231 | - $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path) use ($storage) { |
|
232 | - $this->postProcessEntry($storage, $path); |
|
233 | - }); |
|
225 | + $scanner->listen('\OC\Files\Cache\Scanner', 'removeFromCache', function ($path) use ($storage) { |
|
226 | + $this->postProcessEntry($storage, $path); |
|
227 | + }); |
|
228 | + $scanner->listen('\OC\Files\Cache\Scanner', 'updateCache', function ($path) use ($storage) { |
|
229 | + $this->postProcessEntry($storage, $path); |
|
230 | + }); |
|
231 | + $scanner->listen('\OC\Files\Cache\Scanner', 'addToCache', function ($path) use ($storage) { |
|
232 | + $this->postProcessEntry($storage, $path); |
|
233 | + }); |
|
234 | 234 | |
235 | - if (!$storage->file_exists($relativePath)) { |
|
236 | - throw new NotFoundException($dir); |
|
237 | - } |
|
235 | + if (!$storage->file_exists($relativePath)) { |
|
236 | + throw new NotFoundException($dir); |
|
237 | + } |
|
238 | 238 | |
239 | - if ($this->useTransaction) { |
|
240 | - $this->db->beginTransaction(); |
|
241 | - } |
|
242 | - try { |
|
243 | - $propagator = $storage->getPropagator(); |
|
244 | - $propagator->beginBatch(); |
|
245 | - $scanner->scan($relativePath, $recursive, \OC\Files\Cache\Scanner::REUSE_ETAG | \OC\Files\Cache\Scanner::REUSE_SIZE); |
|
246 | - $cache = $storage->getCache(); |
|
247 | - if ($cache instanceof Cache) { |
|
248 | - // only re-calculate for the root folder we scanned, anything below that is taken care of by the scanner |
|
249 | - $cache->correctFolderSize($relativePath); |
|
250 | - } |
|
251 | - $propagator->commitBatch(); |
|
252 | - } catch (StorageNotAvailableException $e) { |
|
253 | - $this->logger->error('Storage ' . $storage->getId() . ' not available'); |
|
254 | - $this->logger->logException($e); |
|
255 | - $this->emit('\OC\Files\Utils\Scanner', 'StorageNotAvailable', [$e]); |
|
256 | - } |
|
257 | - if ($this->useTransaction) { |
|
258 | - $this->db->commit(); |
|
259 | - } |
|
260 | - } |
|
261 | - } |
|
239 | + if ($this->useTransaction) { |
|
240 | + $this->db->beginTransaction(); |
|
241 | + } |
|
242 | + try { |
|
243 | + $propagator = $storage->getPropagator(); |
|
244 | + $propagator->beginBatch(); |
|
245 | + $scanner->scan($relativePath, $recursive, \OC\Files\Cache\Scanner::REUSE_ETAG | \OC\Files\Cache\Scanner::REUSE_SIZE); |
|
246 | + $cache = $storage->getCache(); |
|
247 | + if ($cache instanceof Cache) { |
|
248 | + // only re-calculate for the root folder we scanned, anything below that is taken care of by the scanner |
|
249 | + $cache->correctFolderSize($relativePath); |
|
250 | + } |
|
251 | + $propagator->commitBatch(); |
|
252 | + } catch (StorageNotAvailableException $e) { |
|
253 | + $this->logger->error('Storage ' . $storage->getId() . ' not available'); |
|
254 | + $this->logger->logException($e); |
|
255 | + $this->emit('\OC\Files\Utils\Scanner', 'StorageNotAvailable', [$e]); |
|
256 | + } |
|
257 | + if ($this->useTransaction) { |
|
258 | + $this->db->commit(); |
|
259 | + } |
|
260 | + } |
|
261 | + } |
|
262 | 262 | |
263 | - private function triggerPropagator(IStorage $storage, $internalPath) { |
|
264 | - $storage->getPropagator()->propagateChange($internalPath, time()); |
|
265 | - } |
|
263 | + private function triggerPropagator(IStorage $storage, $internalPath) { |
|
264 | + $storage->getPropagator()->propagateChange($internalPath, time()); |
|
265 | + } |
|
266 | 266 | |
267 | - private function postProcessEntry(IStorage $storage, $internalPath) { |
|
268 | - $this->triggerPropagator($storage, $internalPath); |
|
269 | - if ($this->useTransaction) { |
|
270 | - $this->entriesToCommit++; |
|
271 | - if ($this->entriesToCommit >= self::MAX_ENTRIES_TO_COMMIT) { |
|
272 | - $propagator = $storage->getPropagator(); |
|
273 | - $this->entriesToCommit = 0; |
|
274 | - $this->db->commit(); |
|
275 | - $propagator->commitBatch(); |
|
276 | - $this->db->beginTransaction(); |
|
277 | - $propagator->beginBatch(); |
|
278 | - } |
|
279 | - } |
|
280 | - } |
|
267 | + private function postProcessEntry(IStorage $storage, $internalPath) { |
|
268 | + $this->triggerPropagator($storage, $internalPath); |
|
269 | + if ($this->useTransaction) { |
|
270 | + $this->entriesToCommit++; |
|
271 | + if ($this->entriesToCommit >= self::MAX_ENTRIES_TO_COMMIT) { |
|
272 | + $propagator = $storage->getPropagator(); |
|
273 | + $this->entriesToCommit = 0; |
|
274 | + $this->db->commit(); |
|
275 | + $propagator->commitBatch(); |
|
276 | + $this->db->beginTransaction(); |
|
277 | + $propagator->beginBatch(); |
|
278 | + } |
|
279 | + } |
|
280 | + } |
|
281 | 281 | } |
282 | 282 |