@@ -47,262 +47,262 @@ |
||
47 | 47 | use Symfony\Component\Console\Output\OutputInterface; |
48 | 48 | |
49 | 49 | class Notify extends Base { |
50 | - /** @var GlobalStoragesService */ |
|
51 | - private $globalService; |
|
52 | - /** @var IDBConnection */ |
|
53 | - private $connection; |
|
54 | - /** @var ILogger */ |
|
55 | - private $logger; |
|
50 | + /** @var GlobalStoragesService */ |
|
51 | + private $globalService; |
|
52 | + /** @var IDBConnection */ |
|
53 | + private $connection; |
|
54 | + /** @var ILogger */ |
|
55 | + private $logger; |
|
56 | 56 | |
57 | - public function __construct(GlobalStoragesService $globalService, IDBConnection $connection, ILogger $logger) { |
|
58 | - parent::__construct(); |
|
59 | - $this->globalService = $globalService; |
|
60 | - $this->connection = $connection; |
|
61 | - $this->logger = $logger; |
|
62 | - } |
|
57 | + public function __construct(GlobalStoragesService $globalService, IDBConnection $connection, ILogger $logger) { |
|
58 | + parent::__construct(); |
|
59 | + $this->globalService = $globalService; |
|
60 | + $this->connection = $connection; |
|
61 | + $this->logger = $logger; |
|
62 | + } |
|
63 | 63 | |
64 | - protected function configure() { |
|
65 | - $this |
|
66 | - ->setName('files_external:notify') |
|
67 | - ->setDescription('Listen for active update notifications for a configured external mount') |
|
68 | - ->addArgument( |
|
69 | - 'mount_id', |
|
70 | - InputArgument::REQUIRED, |
|
71 | - 'the mount id of the mount to listen to' |
|
72 | - )->addOption( |
|
73 | - 'user', |
|
74 | - 'u', |
|
75 | - InputOption::VALUE_REQUIRED, |
|
76 | - 'The username for the remote mount (required only for some mount configuration that don\'t store credentials)' |
|
77 | - )->addOption( |
|
78 | - 'password', |
|
79 | - 'p', |
|
80 | - InputOption::VALUE_REQUIRED, |
|
81 | - 'The password for the remote mount (required only for some mount configuration that don\'t store credentials)' |
|
82 | - )->addOption( |
|
83 | - 'path', |
|
84 | - '', |
|
85 | - InputOption::VALUE_REQUIRED, |
|
86 | - 'The directory in the storage to listen for updates in', |
|
87 | - '/' |
|
88 | - )->addOption( |
|
89 | - 'no-self-check', |
|
90 | - '', |
|
91 | - InputOption::VALUE_NONE, |
|
92 | - 'Disable self check on startup' |
|
93 | - ); |
|
94 | - parent::configure(); |
|
95 | - } |
|
64 | + protected function configure() { |
|
65 | + $this |
|
66 | + ->setName('files_external:notify') |
|
67 | + ->setDescription('Listen for active update notifications for a configured external mount') |
|
68 | + ->addArgument( |
|
69 | + 'mount_id', |
|
70 | + InputArgument::REQUIRED, |
|
71 | + 'the mount id of the mount to listen to' |
|
72 | + )->addOption( |
|
73 | + 'user', |
|
74 | + 'u', |
|
75 | + InputOption::VALUE_REQUIRED, |
|
76 | + 'The username for the remote mount (required only for some mount configuration that don\'t store credentials)' |
|
77 | + )->addOption( |
|
78 | + 'password', |
|
79 | + 'p', |
|
80 | + InputOption::VALUE_REQUIRED, |
|
81 | + 'The password for the remote mount (required only for some mount configuration that don\'t store credentials)' |
|
82 | + )->addOption( |
|
83 | + 'path', |
|
84 | + '', |
|
85 | + InputOption::VALUE_REQUIRED, |
|
86 | + 'The directory in the storage to listen for updates in', |
|
87 | + '/' |
|
88 | + )->addOption( |
|
89 | + 'no-self-check', |
|
90 | + '', |
|
91 | + InputOption::VALUE_NONE, |
|
92 | + 'Disable self check on startup' |
|
93 | + ); |
|
94 | + parent::configure(); |
|
95 | + } |
|
96 | 96 | |
97 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
98 | - $mount = $this->globalService->getStorage($input->getArgument('mount_id')); |
|
99 | - if (is_null($mount)) { |
|
100 | - $output->writeln('<error>Mount not found</error>'); |
|
101 | - return 1; |
|
102 | - } |
|
103 | - $noAuth = false; |
|
104 | - try { |
|
105 | - $authBackend = $mount->getAuthMechanism(); |
|
106 | - $authBackend->manipulateStorageConfig($mount); |
|
107 | - } catch (InsufficientDataForMeaningfulAnswerException $e) { |
|
108 | - $noAuth = true; |
|
109 | - } catch (StorageNotAvailableException $e) { |
|
110 | - $noAuth = true; |
|
111 | - } |
|
97 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
98 | + $mount = $this->globalService->getStorage($input->getArgument('mount_id')); |
|
99 | + if (is_null($mount)) { |
|
100 | + $output->writeln('<error>Mount not found</error>'); |
|
101 | + return 1; |
|
102 | + } |
|
103 | + $noAuth = false; |
|
104 | + try { |
|
105 | + $authBackend = $mount->getAuthMechanism(); |
|
106 | + $authBackend->manipulateStorageConfig($mount); |
|
107 | + } catch (InsufficientDataForMeaningfulAnswerException $e) { |
|
108 | + $noAuth = true; |
|
109 | + } catch (StorageNotAvailableException $e) { |
|
110 | + $noAuth = true; |
|
111 | + } |
|
112 | 112 | |
113 | - if ($input->getOption('user')) { |
|
114 | - $mount->setBackendOption('user', $input->getOption('user')); |
|
115 | - } elseif (isset($_ENV['NOTIFY_USER'])) { |
|
116 | - $mount->setBackendOption('user', $_ENV['NOTIFY_USER']); |
|
117 | - } elseif (isset($_SERVER['NOTIFY_USER'])) { |
|
118 | - $mount->setBackendOption('user', $_SERVER['NOTIFY_USER']); |
|
119 | - } |
|
120 | - if ($input->getOption('password')) { |
|
121 | - $mount->setBackendOption('password', $input->getOption('password')); |
|
122 | - } elseif (isset($_ENV['NOTIFY_PASSWORD'])) { |
|
123 | - $mount->setBackendOption('password', $_ENV['NOTIFY_PASSWORD']); |
|
124 | - } elseif (isset($_SERVER['NOTIFY_PASSWORD'])) { |
|
125 | - $mount->setBackendOption('password', $_SERVER['NOTIFY_PASSWORD']); |
|
126 | - } |
|
113 | + if ($input->getOption('user')) { |
|
114 | + $mount->setBackendOption('user', $input->getOption('user')); |
|
115 | + } elseif (isset($_ENV['NOTIFY_USER'])) { |
|
116 | + $mount->setBackendOption('user', $_ENV['NOTIFY_USER']); |
|
117 | + } elseif (isset($_SERVER['NOTIFY_USER'])) { |
|
118 | + $mount->setBackendOption('user', $_SERVER['NOTIFY_USER']); |
|
119 | + } |
|
120 | + if ($input->getOption('password')) { |
|
121 | + $mount->setBackendOption('password', $input->getOption('password')); |
|
122 | + } elseif (isset($_ENV['NOTIFY_PASSWORD'])) { |
|
123 | + $mount->setBackendOption('password', $_ENV['NOTIFY_PASSWORD']); |
|
124 | + } elseif (isset($_SERVER['NOTIFY_PASSWORD'])) { |
|
125 | + $mount->setBackendOption('password', $_SERVER['NOTIFY_PASSWORD']); |
|
126 | + } |
|
127 | 127 | |
128 | - try { |
|
129 | - $storage = $this->createStorage($mount); |
|
130 | - } catch (\Exception $e) { |
|
131 | - $output->writeln('<error>Error while trying to create storage</error>'); |
|
132 | - if ($noAuth) { |
|
133 | - $output->writeln('<error>Username and/or password required</error>'); |
|
134 | - } |
|
135 | - return 1; |
|
136 | - } |
|
137 | - if (!$storage instanceof INotifyStorage) { |
|
138 | - $output->writeln('<error>Mount of type "' . $mount->getBackend()->getText() . '" does not support active update notifications</error>'); |
|
139 | - return 1; |
|
140 | - } |
|
128 | + try { |
|
129 | + $storage = $this->createStorage($mount); |
|
130 | + } catch (\Exception $e) { |
|
131 | + $output->writeln('<error>Error while trying to create storage</error>'); |
|
132 | + if ($noAuth) { |
|
133 | + $output->writeln('<error>Username and/or password required</error>'); |
|
134 | + } |
|
135 | + return 1; |
|
136 | + } |
|
137 | + if (!$storage instanceof INotifyStorage) { |
|
138 | + $output->writeln('<error>Mount of type "' . $mount->getBackend()->getText() . '" does not support active update notifications</error>'); |
|
139 | + return 1; |
|
140 | + } |
|
141 | 141 | |
142 | - $verbose = $input->getOption('verbose'); |
|
142 | + $verbose = $input->getOption('verbose'); |
|
143 | 143 | |
144 | - $path = trim($input->getOption('path'), '/'); |
|
145 | - $notifyHandler = $storage->notify($path); |
|
144 | + $path = trim($input->getOption('path'), '/'); |
|
145 | + $notifyHandler = $storage->notify($path); |
|
146 | 146 | |
147 | - if (!$input->getOption('no-self-check')) { |
|
148 | - $this->selfTest($storage, $notifyHandler, $verbose, $output); |
|
149 | - } |
|
147 | + if (!$input->getOption('no-self-check')) { |
|
148 | + $this->selfTest($storage, $notifyHandler, $verbose, $output); |
|
149 | + } |
|
150 | 150 | |
151 | - $notifyHandler->listen(function (IChange $change) use ($mount, $verbose, $output) { |
|
152 | - if ($verbose) { |
|
153 | - $this->logUpdate($change, $output); |
|
154 | - } |
|
155 | - if ($change instanceof IRenameChange) { |
|
156 | - $this->markParentAsOutdated($mount->getId(), $change->getTargetPath(), $output); |
|
157 | - } |
|
158 | - $this->markParentAsOutdated($mount->getId(), $change->getPath(), $output); |
|
159 | - }); |
|
160 | - return 0; |
|
161 | - } |
|
151 | + $notifyHandler->listen(function (IChange $change) use ($mount, $verbose, $output) { |
|
152 | + if ($verbose) { |
|
153 | + $this->logUpdate($change, $output); |
|
154 | + } |
|
155 | + if ($change instanceof IRenameChange) { |
|
156 | + $this->markParentAsOutdated($mount->getId(), $change->getTargetPath(), $output); |
|
157 | + } |
|
158 | + $this->markParentAsOutdated($mount->getId(), $change->getPath(), $output); |
|
159 | + }); |
|
160 | + return 0; |
|
161 | + } |
|
162 | 162 | |
163 | - private function createStorage(StorageConfig $mount) { |
|
164 | - $class = $mount->getBackend()->getStorageClass(); |
|
165 | - return new $class($mount->getBackendOptions()); |
|
166 | - } |
|
163 | + private function createStorage(StorageConfig $mount) { |
|
164 | + $class = $mount->getBackend()->getStorageClass(); |
|
165 | + return new $class($mount->getBackendOptions()); |
|
166 | + } |
|
167 | 167 | |
168 | - private function markParentAsOutdated($mountId, $path, OutputInterface $output) { |
|
169 | - $parent = ltrim(dirname($path), '/'); |
|
170 | - if ($parent === '.') { |
|
171 | - $parent = ''; |
|
172 | - } |
|
168 | + private function markParentAsOutdated($mountId, $path, OutputInterface $output) { |
|
169 | + $parent = ltrim(dirname($path), '/'); |
|
170 | + if ($parent === '.') { |
|
171 | + $parent = ''; |
|
172 | + } |
|
173 | 173 | |
174 | - try { |
|
175 | - $storageIds = $this->getStorageIds($mountId); |
|
176 | - } catch (DriverException $ex) { |
|
177 | - $this->logger->logException($ex, ['message' => 'Error while trying to find correct storage ids.', 'level' => ILogger::WARN]); |
|
178 | - $this->connection = $this->reconnectToDatabase($this->connection, $output); |
|
179 | - $output->writeln('<info>Needed to reconnect to the database</info>'); |
|
180 | - $storageIds = $this->getStorageIds($mountId); |
|
181 | - } |
|
182 | - if (count($storageIds) === 0) { |
|
183 | - throw new StorageNotAvailableException('No storages found by mount ID ' . $mountId); |
|
184 | - } |
|
185 | - $storageIds = array_map('intval', $storageIds); |
|
174 | + try { |
|
175 | + $storageIds = $this->getStorageIds($mountId); |
|
176 | + } catch (DriverException $ex) { |
|
177 | + $this->logger->logException($ex, ['message' => 'Error while trying to find correct storage ids.', 'level' => ILogger::WARN]); |
|
178 | + $this->connection = $this->reconnectToDatabase($this->connection, $output); |
|
179 | + $output->writeln('<info>Needed to reconnect to the database</info>'); |
|
180 | + $storageIds = $this->getStorageIds($mountId); |
|
181 | + } |
|
182 | + if (count($storageIds) === 0) { |
|
183 | + throw new StorageNotAvailableException('No storages found by mount ID ' . $mountId); |
|
184 | + } |
|
185 | + $storageIds = array_map('intval', $storageIds); |
|
186 | 186 | |
187 | - $result = $this->updateParent($storageIds, $parent); |
|
188 | - if ($result === 0) { |
|
189 | - //TODO: Find existing parent further up the tree in the database and register that folder instead. |
|
190 | - $this->logger->info('Failed updating parent for "' . $path . '" while trying to register change. It may not exist in the filecache.'); |
|
191 | - } |
|
192 | - } |
|
187 | + $result = $this->updateParent($storageIds, $parent); |
|
188 | + if ($result === 0) { |
|
189 | + //TODO: Find existing parent further up the tree in the database and register that folder instead. |
|
190 | + $this->logger->info('Failed updating parent for "' . $path . '" while trying to register change. It may not exist in the filecache.'); |
|
191 | + } |
|
192 | + } |
|
193 | 193 | |
194 | - private function logUpdate(IChange $change, OutputInterface $output) { |
|
195 | - switch ($change->getType()) { |
|
196 | - case INotifyStorage::NOTIFY_ADDED: |
|
197 | - $text = 'added'; |
|
198 | - break; |
|
199 | - case INotifyStorage::NOTIFY_MODIFIED: |
|
200 | - $text = 'modified'; |
|
201 | - break; |
|
202 | - case INotifyStorage::NOTIFY_REMOVED: |
|
203 | - $text = 'removed'; |
|
204 | - break; |
|
205 | - case INotifyStorage::NOTIFY_RENAMED: |
|
206 | - $text = 'renamed'; |
|
207 | - break; |
|
208 | - default: |
|
209 | - return; |
|
210 | - } |
|
194 | + private function logUpdate(IChange $change, OutputInterface $output) { |
|
195 | + switch ($change->getType()) { |
|
196 | + case INotifyStorage::NOTIFY_ADDED: |
|
197 | + $text = 'added'; |
|
198 | + break; |
|
199 | + case INotifyStorage::NOTIFY_MODIFIED: |
|
200 | + $text = 'modified'; |
|
201 | + break; |
|
202 | + case INotifyStorage::NOTIFY_REMOVED: |
|
203 | + $text = 'removed'; |
|
204 | + break; |
|
205 | + case INotifyStorage::NOTIFY_RENAMED: |
|
206 | + $text = 'renamed'; |
|
207 | + break; |
|
208 | + default: |
|
209 | + return; |
|
210 | + } |
|
211 | 211 | |
212 | - $text .= ' ' . $change->getPath(); |
|
213 | - if ($change instanceof IRenameChange) { |
|
214 | - $text .= ' to ' . $change->getTargetPath(); |
|
215 | - } |
|
212 | + $text .= ' ' . $change->getPath(); |
|
213 | + if ($change instanceof IRenameChange) { |
|
214 | + $text .= ' to ' . $change->getTargetPath(); |
|
215 | + } |
|
216 | 216 | |
217 | - $output->writeln($text); |
|
218 | - } |
|
217 | + $output->writeln($text); |
|
218 | + } |
|
219 | 219 | |
220 | - /** |
|
221 | - * @param int $mountId |
|
222 | - * @return array |
|
223 | - */ |
|
224 | - private function getStorageIds($mountId) { |
|
225 | - $qb = $this->connection->getQueryBuilder(); |
|
226 | - return $qb |
|
227 | - ->select('storage_id') |
|
228 | - ->from('mounts') |
|
229 | - ->where($qb->expr()->eq('mount_id', $qb->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))) |
|
230 | - ->execute() |
|
231 | - ->fetchAll(\PDO::FETCH_COLUMN); |
|
232 | - } |
|
220 | + /** |
|
221 | + * @param int $mountId |
|
222 | + * @return array |
|
223 | + */ |
|
224 | + private function getStorageIds($mountId) { |
|
225 | + $qb = $this->connection->getQueryBuilder(); |
|
226 | + return $qb |
|
227 | + ->select('storage_id') |
|
228 | + ->from('mounts') |
|
229 | + ->where($qb->expr()->eq('mount_id', $qb->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))) |
|
230 | + ->execute() |
|
231 | + ->fetchAll(\PDO::FETCH_COLUMN); |
|
232 | + } |
|
233 | 233 | |
234 | - /** |
|
235 | - * @param array $storageIds |
|
236 | - * @param string $parent |
|
237 | - * @return int |
|
238 | - */ |
|
239 | - private function updateParent($storageIds, $parent) { |
|
240 | - $pathHash = md5(trim(\OC_Util::normalizeUnicode($parent), '/')); |
|
241 | - $qb = $this->connection->getQueryBuilder(); |
|
242 | - return $qb |
|
243 | - ->update('filecache') |
|
244 | - ->set('size', $qb->createNamedParameter(-1, IQueryBuilder::PARAM_INT)) |
|
245 | - ->where($qb->expr()->in('storage', $qb->createNamedParameter($storageIds, IQueryBuilder::PARAM_INT_ARRAY, ':storage_ids'))) |
|
246 | - ->andWhere($qb->expr()->eq('path_hash', $qb->createNamedParameter($pathHash, IQueryBuilder::PARAM_STR))) |
|
247 | - ->execute(); |
|
248 | - } |
|
234 | + /** |
|
235 | + * @param array $storageIds |
|
236 | + * @param string $parent |
|
237 | + * @return int |
|
238 | + */ |
|
239 | + private function updateParent($storageIds, $parent) { |
|
240 | + $pathHash = md5(trim(\OC_Util::normalizeUnicode($parent), '/')); |
|
241 | + $qb = $this->connection->getQueryBuilder(); |
|
242 | + return $qb |
|
243 | + ->update('filecache') |
|
244 | + ->set('size', $qb->createNamedParameter(-1, IQueryBuilder::PARAM_INT)) |
|
245 | + ->where($qb->expr()->in('storage', $qb->createNamedParameter($storageIds, IQueryBuilder::PARAM_INT_ARRAY, ':storage_ids'))) |
|
246 | + ->andWhere($qb->expr()->eq('path_hash', $qb->createNamedParameter($pathHash, IQueryBuilder::PARAM_STR))) |
|
247 | + ->execute(); |
|
248 | + } |
|
249 | 249 | |
250 | - /** |
|
251 | - * @return \OCP\IDBConnection |
|
252 | - */ |
|
253 | - private function reconnectToDatabase(IDBConnection $connection, OutputInterface $output) { |
|
254 | - try { |
|
255 | - $connection->close(); |
|
256 | - } catch (\Exception $ex) { |
|
257 | - $this->logger->logException($ex, ['app' => 'files_external', 'message' => 'Error while disconnecting from DB', 'level' => ILogger::WARN]); |
|
258 | - $output->writeln("<info>Error while disconnecting from database: {$ex->getMessage()}</info>"); |
|
259 | - } |
|
260 | - while (!$connection->isConnected()) { |
|
261 | - try { |
|
262 | - $connection->connect(); |
|
263 | - } catch (\Exception $ex) { |
|
264 | - $this->logger->logException($ex, ['app' => 'files_external', 'message' => 'Error while re-connecting to database', 'level' => ILogger::WARN]); |
|
265 | - $output->writeln("<info>Error while re-connecting to database: {$ex->getMessage()}</info>"); |
|
266 | - sleep(60); |
|
267 | - } |
|
268 | - } |
|
269 | - return $connection; |
|
270 | - } |
|
250 | + /** |
|
251 | + * @return \OCP\IDBConnection |
|
252 | + */ |
|
253 | + private function reconnectToDatabase(IDBConnection $connection, OutputInterface $output) { |
|
254 | + try { |
|
255 | + $connection->close(); |
|
256 | + } catch (\Exception $ex) { |
|
257 | + $this->logger->logException($ex, ['app' => 'files_external', 'message' => 'Error while disconnecting from DB', 'level' => ILogger::WARN]); |
|
258 | + $output->writeln("<info>Error while disconnecting from database: {$ex->getMessage()}</info>"); |
|
259 | + } |
|
260 | + while (!$connection->isConnected()) { |
|
261 | + try { |
|
262 | + $connection->connect(); |
|
263 | + } catch (\Exception $ex) { |
|
264 | + $this->logger->logException($ex, ['app' => 'files_external', 'message' => 'Error while re-connecting to database', 'level' => ILogger::WARN]); |
|
265 | + $output->writeln("<info>Error while re-connecting to database: {$ex->getMessage()}</info>"); |
|
266 | + sleep(60); |
|
267 | + } |
|
268 | + } |
|
269 | + return $connection; |
|
270 | + } |
|
271 | 271 | |
272 | 272 | |
273 | - private function selfTest(IStorage $storage, INotifyHandler $notifyHandler, $verbose, OutputInterface $output) { |
|
274 | - usleep(100 * 1000); //give time for the notify to start |
|
275 | - $storage->file_put_contents('/.nc_test_file.txt', 'test content'); |
|
276 | - $storage->mkdir('/.nc_test_folder'); |
|
277 | - $storage->file_put_contents('/.nc_test_folder/subfile.txt', 'test content'); |
|
273 | + private function selfTest(IStorage $storage, INotifyHandler $notifyHandler, $verbose, OutputInterface $output) { |
|
274 | + usleep(100 * 1000); //give time for the notify to start |
|
275 | + $storage->file_put_contents('/.nc_test_file.txt', 'test content'); |
|
276 | + $storage->mkdir('/.nc_test_folder'); |
|
277 | + $storage->file_put_contents('/.nc_test_folder/subfile.txt', 'test content'); |
|
278 | 278 | |
279 | - usleep(100 * 1000); //time for all changes to be processed |
|
280 | - $changes = $notifyHandler->getChanges(); |
|
279 | + usleep(100 * 1000); //time for all changes to be processed |
|
280 | + $changes = $notifyHandler->getChanges(); |
|
281 | 281 | |
282 | - $storage->unlink('/.nc_test_file.txt'); |
|
283 | - $storage->unlink('/.nc_test_folder/subfile.txt'); |
|
284 | - $storage->rmdir('/.nc_test_folder'); |
|
282 | + $storage->unlink('/.nc_test_file.txt'); |
|
283 | + $storage->unlink('/.nc_test_folder/subfile.txt'); |
|
284 | + $storage->rmdir('/.nc_test_folder'); |
|
285 | 285 | |
286 | - usleep(100 * 1000); //time for all changes to be processed |
|
287 | - $notifyHandler->getChanges(); // flush |
|
286 | + usleep(100 * 1000); //time for all changes to be processed |
|
287 | + $notifyHandler->getChanges(); // flush |
|
288 | 288 | |
289 | - $foundRootChange = false; |
|
290 | - $foundSubfolderChange = false; |
|
289 | + $foundRootChange = false; |
|
290 | + $foundSubfolderChange = false; |
|
291 | 291 | |
292 | - foreach ($changes as $change) { |
|
293 | - if ($change->getPath() === '/.nc_test_file.txt' || $change->getPath() === '.nc_test_file.txt') { |
|
294 | - $foundRootChange = true; |
|
295 | - } elseif ($change->getPath() === '/.nc_test_folder/subfile.txt' || $change->getPath() === '.nc_test_folder/subfile.txt') { |
|
296 | - $foundSubfolderChange = true; |
|
297 | - } |
|
298 | - } |
|
292 | + foreach ($changes as $change) { |
|
293 | + if ($change->getPath() === '/.nc_test_file.txt' || $change->getPath() === '.nc_test_file.txt') { |
|
294 | + $foundRootChange = true; |
|
295 | + } elseif ($change->getPath() === '/.nc_test_folder/subfile.txt' || $change->getPath() === '.nc_test_folder/subfile.txt') { |
|
296 | + $foundSubfolderChange = true; |
|
297 | + } |
|
298 | + } |
|
299 | 299 | |
300 | - if ($foundRootChange && $foundSubfolderChange && $verbose) { |
|
301 | - $output->writeln('<info>Self-test successful</info>'); |
|
302 | - } elseif ($foundRootChange && !$foundSubfolderChange) { |
|
303 | - $output->writeln('<error>Error while running self-test, change is subfolder not detected</error>'); |
|
304 | - } elseif (!$foundRootChange) { |
|
305 | - $output->writeln('<error>Error while running self-test, no changes detected</error>'); |
|
306 | - } |
|
307 | - } |
|
300 | + if ($foundRootChange && $foundSubfolderChange && $verbose) { |
|
301 | + $output->writeln('<info>Self-test successful</info>'); |
|
302 | + } elseif ($foundRootChange && !$foundSubfolderChange) { |
|
303 | + $output->writeln('<error>Error while running self-test, change is subfolder not detected</error>'); |
|
304 | + } elseif (!$foundRootChange) { |
|
305 | + $output->writeln('<error>Error while running self-test, no changes detected</error>'); |
|
306 | + } |
|
307 | + } |
|
308 | 308 | } |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | return 1; |
136 | 136 | } |
137 | 137 | if (!$storage instanceof INotifyStorage) { |
138 | - $output->writeln('<error>Mount of type "' . $mount->getBackend()->getText() . '" does not support active update notifications</error>'); |
|
138 | + $output->writeln('<error>Mount of type "'.$mount->getBackend()->getText().'" does not support active update notifications</error>'); |
|
139 | 139 | return 1; |
140 | 140 | } |
141 | 141 | |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | $this->selfTest($storage, $notifyHandler, $verbose, $output); |
149 | 149 | } |
150 | 150 | |
151 | - $notifyHandler->listen(function (IChange $change) use ($mount, $verbose, $output) { |
|
151 | + $notifyHandler->listen(function(IChange $change) use ($mount, $verbose, $output) { |
|
152 | 152 | if ($verbose) { |
153 | 153 | $this->logUpdate($change, $output); |
154 | 154 | } |
@@ -180,14 +180,14 @@ discard block |
||
180 | 180 | $storageIds = $this->getStorageIds($mountId); |
181 | 181 | } |
182 | 182 | if (count($storageIds) === 0) { |
183 | - throw new StorageNotAvailableException('No storages found by mount ID ' . $mountId); |
|
183 | + throw new StorageNotAvailableException('No storages found by mount ID '.$mountId); |
|
184 | 184 | } |
185 | 185 | $storageIds = array_map('intval', $storageIds); |
186 | 186 | |
187 | 187 | $result = $this->updateParent($storageIds, $parent); |
188 | 188 | if ($result === 0) { |
189 | 189 | //TODO: Find existing parent further up the tree in the database and register that folder instead. |
190 | - $this->logger->info('Failed updating parent for "' . $path . '" while trying to register change. It may not exist in the filecache.'); |
|
190 | + $this->logger->info('Failed updating parent for "'.$path.'" while trying to register change. It may not exist in the filecache.'); |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
@@ -209,9 +209,9 @@ discard block |
||
209 | 209 | return; |
210 | 210 | } |
211 | 211 | |
212 | - $text .= ' ' . $change->getPath(); |
|
212 | + $text .= ' '.$change->getPath(); |
|
213 | 213 | if ($change instanceof IRenameChange) { |
214 | - $text .= ' to ' . $change->getTargetPath(); |
|
214 | + $text .= ' to '.$change->getTargetPath(); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | $output->writeln($text); |