@@ -370,18 +370,18 @@ discard block |
||
| 370 | 370 | private function findFileWithExtension($class, $ext) |
| 371 | 371 | { |
| 372 | 372 | // PSR-4 lookup |
| 373 | - $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; |
|
| 373 | + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR).$ext; |
|
| 374 | 374 | |
| 375 | 375 | $first = $class[0]; |
| 376 | 376 | if (isset($this->prefixLengthsPsr4[$first])) { |
| 377 | 377 | $subPath = $class; |
| 378 | 378 | while (false !== $lastPos = strrpos($subPath, '\\')) { |
| 379 | 379 | $subPath = substr($subPath, 0, $lastPos); |
| 380 | - $search = $subPath . '\\'; |
|
| 380 | + $search = $subPath.'\\'; |
|
| 381 | 381 | if (isset($this->prefixDirsPsr4[$search])) { |
| 382 | - $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); |
|
| 382 | + $pathEnd = DIRECTORY_SEPARATOR.substr($logicalPathPsr4, $lastPos + 1); |
|
| 383 | 383 | foreach ($this->prefixDirsPsr4[$search] as $dir) { |
| 384 | - if (file_exists($file = $dir . $pathEnd)) { |
|
| 384 | + if (file_exists($file = $dir.$pathEnd)) { |
|
| 385 | 385 | return $file; |
| 386 | 386 | } |
| 387 | 387 | } |
@@ -391,7 +391,7 @@ discard block |
||
| 391 | 391 | |
| 392 | 392 | // PSR-4 fallback dirs |
| 393 | 393 | foreach ($this->fallbackDirsPsr4 as $dir) { |
| 394 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { |
|
| 394 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr4)) { |
|
| 395 | 395 | return $file; |
| 396 | 396 | } |
| 397 | 397 | } |
@@ -403,14 +403,14 @@ discard block |
||
| 403 | 403 | . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); |
| 404 | 404 | } else { |
| 405 | 405 | // PEAR-like class name |
| 406 | - $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; |
|
| 406 | + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR).$ext; |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | if (isset($this->prefixesPsr0[$first])) { |
| 410 | 410 | foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { |
| 411 | 411 | if (0 === strpos($class, $prefix)) { |
| 412 | 412 | foreach ($dirs as $dir) { |
| 413 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
| 413 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
| 414 | 414 | return $file; |
| 415 | 415 | } |
| 416 | 416 | } |
@@ -420,7 +420,7 @@ discard block |
||
| 420 | 420 | |
| 421 | 421 | // PSR-0 fallback dirs |
| 422 | 422 | foreach ($this->fallbackDirsPsr0 as $dir) { |
| 423 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
| 423 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
| 424 | 424 | return $file; |
| 425 | 425 | } |
| 426 | 426 | } |
@@ -370,18 +370,18 @@ discard block |
||
| 370 | 370 | private function findFileWithExtension($class, $ext) |
| 371 | 371 | { |
| 372 | 372 | // PSR-4 lookup |
| 373 | - $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; |
|
| 373 | + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR).$ext; |
|
| 374 | 374 | |
| 375 | 375 | $first = $class[0]; |
| 376 | 376 | if (isset($this->prefixLengthsPsr4[$first])) { |
| 377 | 377 | $subPath = $class; |
| 378 | 378 | while (false !== $lastPos = strrpos($subPath, '\\')) { |
| 379 | 379 | $subPath = substr($subPath, 0, $lastPos); |
| 380 | - $search = $subPath . '\\'; |
|
| 380 | + $search = $subPath.'\\'; |
|
| 381 | 381 | if (isset($this->prefixDirsPsr4[$search])) { |
| 382 | - $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); |
|
| 382 | + $pathEnd = DIRECTORY_SEPARATOR.substr($logicalPathPsr4, $lastPos + 1); |
|
| 383 | 383 | foreach ($this->prefixDirsPsr4[$search] as $dir) { |
| 384 | - if (file_exists($file = $dir . $pathEnd)) { |
|
| 384 | + if (file_exists($file = $dir.$pathEnd)) { |
|
| 385 | 385 | return $file; |
| 386 | 386 | } |
| 387 | 387 | } |
@@ -391,7 +391,7 @@ discard block |
||
| 391 | 391 | |
| 392 | 392 | // PSR-4 fallback dirs |
| 393 | 393 | foreach ($this->fallbackDirsPsr4 as $dir) { |
| 394 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { |
|
| 394 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr4)) { |
|
| 395 | 395 | return $file; |
| 396 | 396 | } |
| 397 | 397 | } |
@@ -403,14 +403,14 @@ discard block |
||
| 403 | 403 | . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); |
| 404 | 404 | } else { |
| 405 | 405 | // PEAR-like class name |
| 406 | - $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; |
|
| 406 | + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR).$ext; |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | if (isset($this->prefixesPsr0[$first])) { |
| 410 | 410 | foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { |
| 411 | 411 | if (0 === strpos($class, $prefix)) { |
| 412 | 412 | foreach ($dirs as $dir) { |
| 413 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
| 413 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
| 414 | 414 | return $file; |
| 415 | 415 | } |
| 416 | 416 | } |
@@ -420,7 +420,7 @@ discard block |
||
| 420 | 420 | |
| 421 | 421 | // PSR-0 fallback dirs |
| 422 | 422 | foreach ($this->fallbackDirsPsr0 as $dir) { |
| 423 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
| 423 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
| 424 | 424 | return $file; |
| 425 | 425 | } |
| 426 | 426 | } |
@@ -25,26 +25,26 @@ |
||
| 25 | 25 | |
| 26 | 26 | class EnterpriseBundle extends Bundle { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * {@inheritDoc} |
|
| 30 | - */ |
|
| 31 | - public function getName(): string { |
|
| 32 | - return $this->l10n->t('Enterprise bundle'); |
|
| 33 | - } |
|
| 28 | + /** |
|
| 29 | + * {@inheritDoc} |
|
| 30 | + */ |
|
| 31 | + public function getName(): string { |
|
| 32 | + return $this->l10n->t('Enterprise bundle'); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * {@inheritDoc} |
|
| 37 | - */ |
|
| 38 | - public function getAppIdentifiers(): array { |
|
| 39 | - return [ |
|
| 40 | - 'admin_audit', |
|
| 41 | - 'user_ldap', |
|
| 42 | - 'files_retention', |
|
| 43 | - 'files_automatedtagging', |
|
| 44 | - 'user_saml', |
|
| 45 | - 'files_accesscontrol', |
|
| 46 | - 'terms_of_service', |
|
| 47 | - ]; |
|
| 48 | - } |
|
| 35 | + /** |
|
| 36 | + * {@inheritDoc} |
|
| 37 | + */ |
|
| 38 | + public function getAppIdentifiers(): array { |
|
| 39 | + return [ |
|
| 40 | + 'admin_audit', |
|
| 41 | + 'user_ldap', |
|
| 42 | + 'files_retention', |
|
| 43 | + 'files_automatedtagging', |
|
| 44 | + 'user_saml', |
|
| 45 | + 'files_accesscontrol', |
|
| 46 | + 'terms_of_service', |
|
| 47 | + ]; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | 50 | } |
@@ -31,21 +31,21 @@ |
||
| 31 | 31 | |
| 32 | 32 | class Version1002Date20180821043638 extends SimpleMigrationStep { |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @param IOutput $output |
|
| 36 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
| 37 | - * @param array $options |
|
| 38 | - * |
|
| 39 | - * @return ISchemaWrapper |
|
| 40 | - */ |
|
| 41 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
| 42 | - /** @var ISchemaWrapper $schema */ |
|
| 43 | - $schema = $schemaClosure(); |
|
| 44 | - $table = $schema->getTable('twofactor_backupcodes'); |
|
| 45 | - |
|
| 46 | - $table->getColumn('code')->setLength(128); |
|
| 47 | - |
|
| 48 | - return $schema; |
|
| 49 | - } |
|
| 34 | + /** |
|
| 35 | + * @param IOutput $output |
|
| 36 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
| 37 | + * @param array $options |
|
| 38 | + * |
|
| 39 | + * @return ISchemaWrapper |
|
| 40 | + */ |
|
| 41 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
|
| 42 | + /** @var ISchemaWrapper $schema */ |
|
| 43 | + $schema = $schemaClosure(); |
|
| 44 | + $table = $schema->getTable('twofactor_backupcodes'); |
|
| 45 | + |
|
| 46 | + $table->getColumn('code')->setLength(128); |
|
| 47 | + |
|
| 48 | + return $schema; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | 51 | } |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | $this->groupedShares = $arguments['groupedShares']; |
| 76 | 76 | |
| 77 | 77 | $newMountPoint = $this->verifyMountPoint($this->superShare, $mountpoints, $folderExistCache); |
| 78 | - $absMountPoint = '/' . $this->user . '/files' . $newMountPoint; |
|
| 78 | + $absMountPoint = '/'.$this->user.'/files'.$newMountPoint; |
|
| 79 | 79 | parent::__construct($storage, $absMountPoint, $arguments, $loader); |
| 80 | 80 | } |
| 81 | 81 | |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | $newMountPoint = $this->generateUniqueTarget( |
| 105 | - \OC\Files\Filesystem::normalizePath($parent . '/' . $mountPoint), |
|
| 105 | + \OC\Files\Filesystem::normalizePath($parent.'/'.$mountPoint), |
|
| 106 | 106 | $this->recipientView, |
| 107 | 107 | $mountpoints |
| 108 | 108 | ); |
@@ -139,15 +139,15 @@ discard block |
||
| 139 | 139 | */ |
| 140 | 140 | private function generateUniqueTarget($path, $view, array $mountpoints) { |
| 141 | 141 | $pathinfo = pathinfo($path); |
| 142 | - $ext = isset($pathinfo['extension']) ? '.' . $pathinfo['extension'] : ''; |
|
| 142 | + $ext = isset($pathinfo['extension']) ? '.'.$pathinfo['extension'] : ''; |
|
| 143 | 143 | $name = $pathinfo['filename']; |
| 144 | 144 | $dir = $pathinfo['dirname']; |
| 145 | 145 | |
| 146 | 146 | $i = 2; |
| 147 | - $absolutePath = $this->recipientView->getAbsolutePath($path) . '/'; |
|
| 147 | + $absolutePath = $this->recipientView->getAbsolutePath($path).'/'; |
|
| 148 | 148 | while ($view->file_exists($path) || isset($mountpoints[$absolutePath])) { |
| 149 | - $path = Filesystem::normalizePath($dir . '/' . $name . ' (' . $i . ')' . $ext); |
|
| 150 | - $absolutePath = $this->recipientView->getAbsolutePath($path) . '/'; |
|
| 149 | + $path = Filesystem::normalizePath($dir.'/'.$name.' ('.$i.')'.$ext); |
|
| 150 | + $absolutePath = $this->recipientView->getAbsolutePath($path).'/'; |
|
| 151 | 151 | $i++; |
| 152 | 152 | } |
| 153 | 153 | |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | |
| 168 | 168 | // it is not a file relative to data/user/files |
| 169 | 169 | if (count($split) < 3 || $split[1] !== 'files') { |
| 170 | - \OC::$server->getLogger()->error('Can not strip userid and "files/" from path: ' . $path, ['app' => 'files_sharing']); |
|
| 170 | + \OC::$server->getLogger()->error('Can not strip userid and "files/" from path: '.$path, ['app' => 'files_sharing']); |
|
| 171 | 171 | throw new \OCA\Files_Sharing\Exceptions\BrokenPath('Path does not start with /user/files', 10); |
| 172 | 172 | } |
| 173 | 173 | |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | $sliced = array_slice($split, 2); |
| 176 | 176 | $relPath = implode('/', $sliced); |
| 177 | 177 | |
| 178 | - return '/' . $relPath; |
|
| 178 | + return '/'.$relPath; |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | $this->setMountPoint($target); |
| 197 | 197 | $this->storage->setMountPoint($relTargetPath); |
| 198 | 198 | } catch (\Exception $e) { |
| 199 | - \OC::$server->getLogger()->logException($e, ['app' => 'files_sharing', 'message' => 'Could not rename mount point for shared folder "' . $this->getMountPoint() . '" to "' . $target . '"']); |
|
| 199 | + \OC::$server->getLogger()->logException($e, ['app' => 'files_sharing', 'message' => 'Could not rename mount point for shared folder "'.$this->getMountPoint().'" to "'.$target.'"']); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | return $result; |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | $row = $result->fetch(); |
| 251 | 251 | $result->closeCursor(); |
| 252 | 252 | if ($row) { |
| 253 | - return (int)$row['storage']; |
|
| 253 | + return (int) $row['storage']; |
|
| 254 | 254 | } |
| 255 | 255 | return -1; |
| 256 | 256 | } |
@@ -41,228 +41,228 @@ |
||
| 41 | 41 | * Shared mount points can be moved by the user |
| 42 | 42 | */ |
| 43 | 43 | class SharedMount extends MountPoint implements MoveableMount { |
| 44 | - /** |
|
| 45 | - * @var \OCA\Files_Sharing\SharedStorage $storage |
|
| 46 | - */ |
|
| 47 | - protected $storage = null; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @var \OC\Files\View |
|
| 51 | - */ |
|
| 52 | - private $recipientView; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @var string |
|
| 56 | - */ |
|
| 57 | - private $user; |
|
| 58 | - |
|
| 59 | - /** @var \OCP\Share\IShare */ |
|
| 60 | - private $superShare; |
|
| 61 | - |
|
| 62 | - /** @var \OCP\Share\IShare[] */ |
|
| 63 | - private $groupedShares; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @param string $storage |
|
| 67 | - * @param SharedMount[] $mountpoints |
|
| 68 | - * @param array $arguments |
|
| 69 | - * @param IStorageFactory $loader |
|
| 70 | - * @param View $recipientView |
|
| 71 | - */ |
|
| 72 | - public function __construct($storage, array $mountpoints, $arguments, IStorageFactory $loader, View $recipientView, CappedMemoryCache $folderExistCache) { |
|
| 73 | - $this->user = $arguments['user']; |
|
| 74 | - $this->recipientView = $recipientView; |
|
| 75 | - |
|
| 76 | - $this->superShare = $arguments['superShare']; |
|
| 77 | - $this->groupedShares = $arguments['groupedShares']; |
|
| 78 | - |
|
| 79 | - $newMountPoint = $this->verifyMountPoint($this->superShare, $mountpoints, $folderExistCache); |
|
| 80 | - $absMountPoint = '/' . $this->user . '/files' . $newMountPoint; |
|
| 81 | - parent::__construct($storage, $absMountPoint, $arguments, $loader); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * check if the parent folder exists otherwise move the mount point up |
|
| 86 | - * |
|
| 87 | - * @param \OCP\Share\IShare $share |
|
| 88 | - * @param SharedMount[] $mountpoints |
|
| 89 | - * @return string |
|
| 90 | - */ |
|
| 91 | - private function verifyMountPoint(\OCP\Share\IShare $share, array $mountpoints, CappedMemoryCache $folderExistCache) { |
|
| 92 | - $mountPoint = basename($share->getTarget()); |
|
| 93 | - $parent = dirname($share->getTarget()); |
|
| 94 | - |
|
| 95 | - $event = new VerifyMountPointEvent($share, $this->recipientView, $parent); |
|
| 96 | - /** @var IEventDispatcher $dispatcher */ |
|
| 97 | - $dispatcher = \OC::$server->query(IEventDispatcher::class); |
|
| 98 | - $dispatcher->dispatchTyped($event); |
|
| 99 | - $parent = $event->getParent(); |
|
| 100 | - |
|
| 101 | - if ($folderExistCache->hasKey($parent)) { |
|
| 102 | - $parentExists = $folderExistCache->get($parent); |
|
| 103 | - } else { |
|
| 104 | - $parentExists = $this->recipientView->is_dir($parent); |
|
| 105 | - $folderExistCache->set($parent, $parentExists); |
|
| 106 | - } |
|
| 107 | - if (!$parentExists) { |
|
| 108 | - $parent = Helper::getShareFolder($this->recipientView); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - $newMountPoint = $this->generateUniqueTarget( |
|
| 112 | - \OC\Files\Filesystem::normalizePath($parent . '/' . $mountPoint), |
|
| 113 | - $this->recipientView, |
|
| 114 | - $mountpoints |
|
| 115 | - ); |
|
| 116 | - |
|
| 117 | - if ($newMountPoint !== $share->getTarget()) { |
|
| 118 | - $this->updateFileTarget($newMountPoint, $share); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - return $newMountPoint; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * update fileTarget in the database if the mount point changed |
|
| 126 | - * |
|
| 127 | - * @param string $newPath |
|
| 128 | - * @param \OCP\Share\IShare $share |
|
| 129 | - * @return bool |
|
| 130 | - */ |
|
| 131 | - private function updateFileTarget($newPath, &$share) { |
|
| 132 | - $share->setTarget($newPath); |
|
| 133 | - |
|
| 134 | - foreach ($this->groupedShares as $tmpShare) { |
|
| 135 | - $tmpShare->setTarget($newPath); |
|
| 136 | - \OC::$server->getShareManager()->moveShare($tmpShare, $this->user); |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @param string $path |
|
| 143 | - * @param View $view |
|
| 144 | - * @param SharedMount[] $mountpoints |
|
| 145 | - * @return mixed |
|
| 146 | - */ |
|
| 147 | - private function generateUniqueTarget($path, $view, array $mountpoints) { |
|
| 148 | - $pathinfo = pathinfo($path); |
|
| 149 | - $ext = isset($pathinfo['extension']) ? '.' . $pathinfo['extension'] : ''; |
|
| 150 | - $name = $pathinfo['filename']; |
|
| 151 | - $dir = $pathinfo['dirname']; |
|
| 152 | - |
|
| 153 | - $i = 2; |
|
| 154 | - $absolutePath = $this->recipientView->getAbsolutePath($path) . '/'; |
|
| 155 | - while ($view->file_exists($path) || isset($mountpoints[$absolutePath])) { |
|
| 156 | - $path = Filesystem::normalizePath($dir . '/' . $name . ' (' . $i . ')' . $ext); |
|
| 157 | - $absolutePath = $this->recipientView->getAbsolutePath($path) . '/'; |
|
| 158 | - $i++; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - return $path; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Format a path to be relative to the /user/files/ directory |
|
| 166 | - * |
|
| 167 | - * @param string $path the absolute path |
|
| 168 | - * @return string e.g. turns '/admin/files/test.txt' into '/test.txt' |
|
| 169 | - * @throws \OCA\Files_Sharing\Exceptions\BrokenPath |
|
| 170 | - */ |
|
| 171 | - protected function stripUserFilesPath($path) { |
|
| 172 | - $trimmed = ltrim($path, '/'); |
|
| 173 | - $split = explode('/', $trimmed); |
|
| 174 | - |
|
| 175 | - // it is not a file relative to data/user/files |
|
| 176 | - if (count($split) < 3 || $split[1] !== 'files') { |
|
| 177 | - \OC::$server->getLogger()->error('Can not strip userid and "files/" from path: ' . $path, ['app' => 'files_sharing']); |
|
| 178 | - throw new \OCA\Files_Sharing\Exceptions\BrokenPath('Path does not start with /user/files', 10); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // skip 'user' and 'files' |
|
| 182 | - $sliced = array_slice($split, 2); |
|
| 183 | - $relPath = implode('/', $sliced); |
|
| 184 | - |
|
| 185 | - return '/' . $relPath; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * Move the mount point to $target |
|
| 190 | - * |
|
| 191 | - * @param string $target the target mount point |
|
| 192 | - * @return bool |
|
| 193 | - */ |
|
| 194 | - public function moveMount($target) { |
|
| 195 | - $relTargetPath = $this->stripUserFilesPath($target); |
|
| 196 | - $share = $this->storage->getShare(); |
|
| 197 | - |
|
| 198 | - $result = true; |
|
| 199 | - |
|
| 200 | - try { |
|
| 201 | - $this->updateFileTarget($relTargetPath, $share); |
|
| 202 | - $this->setMountPoint($target); |
|
| 203 | - $this->storage->setMountPoint($relTargetPath); |
|
| 204 | - } catch (\Exception $e) { |
|
| 205 | - \OC::$server->getLogger()->logException($e, ['app' => 'files_sharing', 'message' => 'Could not rename mount point for shared folder "' . $this->getMountPoint() . '" to "' . $target . '"']); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - return $result; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * Remove the mount points |
|
| 213 | - * |
|
| 214 | - * @return bool |
|
| 215 | - */ |
|
| 216 | - public function removeMount() { |
|
| 217 | - $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
| 218 | - /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
| 219 | - $storage = $this->getStorage(); |
|
| 220 | - $result = $storage->unshareStorage(); |
|
| 221 | - $mountManager->removeMount($this->mountPoint); |
|
| 222 | - |
|
| 223 | - return $result; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * @return \OCP\Share\IShare |
|
| 228 | - */ |
|
| 229 | - public function getShare() { |
|
| 230 | - return $this->superShare; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * Get the file id of the root of the storage |
|
| 235 | - * |
|
| 236 | - * @return int |
|
| 237 | - */ |
|
| 238 | - public function getStorageRootId() { |
|
| 239 | - return $this->getShare()->getNodeId(); |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * @return int |
|
| 244 | - */ |
|
| 245 | - public function getNumericStorageId() { |
|
| 246 | - if (!is_null($this->getShare()->getNodeCacheEntry())) { |
|
| 247 | - return $this->getShare()->getNodeCacheEntry()->getStorageId(); |
|
| 248 | - } else { |
|
| 249 | - $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 250 | - |
|
| 251 | - $query = $builder->select('storage') |
|
| 252 | - ->from('filecache') |
|
| 253 | - ->where($builder->expr()->eq('fileid', $builder->createNamedParameter($this->getStorageRootId()))); |
|
| 254 | - |
|
| 255 | - $result = $query->execute(); |
|
| 256 | - $row = $result->fetch(); |
|
| 257 | - $result->closeCursor(); |
|
| 258 | - if ($row) { |
|
| 259 | - return (int)$row['storage']; |
|
| 260 | - } |
|
| 261 | - return -1; |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - public function getMountType() { |
|
| 266 | - return 'shared'; |
|
| 267 | - } |
|
| 44 | + /** |
|
| 45 | + * @var \OCA\Files_Sharing\SharedStorage $storage |
|
| 46 | + */ |
|
| 47 | + protected $storage = null; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @var \OC\Files\View |
|
| 51 | + */ |
|
| 52 | + private $recipientView; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @var string |
|
| 56 | + */ |
|
| 57 | + private $user; |
|
| 58 | + |
|
| 59 | + /** @var \OCP\Share\IShare */ |
|
| 60 | + private $superShare; |
|
| 61 | + |
|
| 62 | + /** @var \OCP\Share\IShare[] */ |
|
| 63 | + private $groupedShares; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @param string $storage |
|
| 67 | + * @param SharedMount[] $mountpoints |
|
| 68 | + * @param array $arguments |
|
| 69 | + * @param IStorageFactory $loader |
|
| 70 | + * @param View $recipientView |
|
| 71 | + */ |
|
| 72 | + public function __construct($storage, array $mountpoints, $arguments, IStorageFactory $loader, View $recipientView, CappedMemoryCache $folderExistCache) { |
|
| 73 | + $this->user = $arguments['user']; |
|
| 74 | + $this->recipientView = $recipientView; |
|
| 75 | + |
|
| 76 | + $this->superShare = $arguments['superShare']; |
|
| 77 | + $this->groupedShares = $arguments['groupedShares']; |
|
| 78 | + |
|
| 79 | + $newMountPoint = $this->verifyMountPoint($this->superShare, $mountpoints, $folderExistCache); |
|
| 80 | + $absMountPoint = '/' . $this->user . '/files' . $newMountPoint; |
|
| 81 | + parent::__construct($storage, $absMountPoint, $arguments, $loader); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * check if the parent folder exists otherwise move the mount point up |
|
| 86 | + * |
|
| 87 | + * @param \OCP\Share\IShare $share |
|
| 88 | + * @param SharedMount[] $mountpoints |
|
| 89 | + * @return string |
|
| 90 | + */ |
|
| 91 | + private function verifyMountPoint(\OCP\Share\IShare $share, array $mountpoints, CappedMemoryCache $folderExistCache) { |
|
| 92 | + $mountPoint = basename($share->getTarget()); |
|
| 93 | + $parent = dirname($share->getTarget()); |
|
| 94 | + |
|
| 95 | + $event = new VerifyMountPointEvent($share, $this->recipientView, $parent); |
|
| 96 | + /** @var IEventDispatcher $dispatcher */ |
|
| 97 | + $dispatcher = \OC::$server->query(IEventDispatcher::class); |
|
| 98 | + $dispatcher->dispatchTyped($event); |
|
| 99 | + $parent = $event->getParent(); |
|
| 100 | + |
|
| 101 | + if ($folderExistCache->hasKey($parent)) { |
|
| 102 | + $parentExists = $folderExistCache->get($parent); |
|
| 103 | + } else { |
|
| 104 | + $parentExists = $this->recipientView->is_dir($parent); |
|
| 105 | + $folderExistCache->set($parent, $parentExists); |
|
| 106 | + } |
|
| 107 | + if (!$parentExists) { |
|
| 108 | + $parent = Helper::getShareFolder($this->recipientView); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + $newMountPoint = $this->generateUniqueTarget( |
|
| 112 | + \OC\Files\Filesystem::normalizePath($parent . '/' . $mountPoint), |
|
| 113 | + $this->recipientView, |
|
| 114 | + $mountpoints |
|
| 115 | + ); |
|
| 116 | + |
|
| 117 | + if ($newMountPoint !== $share->getTarget()) { |
|
| 118 | + $this->updateFileTarget($newMountPoint, $share); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + return $newMountPoint; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * update fileTarget in the database if the mount point changed |
|
| 126 | + * |
|
| 127 | + * @param string $newPath |
|
| 128 | + * @param \OCP\Share\IShare $share |
|
| 129 | + * @return bool |
|
| 130 | + */ |
|
| 131 | + private function updateFileTarget($newPath, &$share) { |
|
| 132 | + $share->setTarget($newPath); |
|
| 133 | + |
|
| 134 | + foreach ($this->groupedShares as $tmpShare) { |
|
| 135 | + $tmpShare->setTarget($newPath); |
|
| 136 | + \OC::$server->getShareManager()->moveShare($tmpShare, $this->user); |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * @param string $path |
|
| 143 | + * @param View $view |
|
| 144 | + * @param SharedMount[] $mountpoints |
|
| 145 | + * @return mixed |
|
| 146 | + */ |
|
| 147 | + private function generateUniqueTarget($path, $view, array $mountpoints) { |
|
| 148 | + $pathinfo = pathinfo($path); |
|
| 149 | + $ext = isset($pathinfo['extension']) ? '.' . $pathinfo['extension'] : ''; |
|
| 150 | + $name = $pathinfo['filename']; |
|
| 151 | + $dir = $pathinfo['dirname']; |
|
| 152 | + |
|
| 153 | + $i = 2; |
|
| 154 | + $absolutePath = $this->recipientView->getAbsolutePath($path) . '/'; |
|
| 155 | + while ($view->file_exists($path) || isset($mountpoints[$absolutePath])) { |
|
| 156 | + $path = Filesystem::normalizePath($dir . '/' . $name . ' (' . $i . ')' . $ext); |
|
| 157 | + $absolutePath = $this->recipientView->getAbsolutePath($path) . '/'; |
|
| 158 | + $i++; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + return $path; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Format a path to be relative to the /user/files/ directory |
|
| 166 | + * |
|
| 167 | + * @param string $path the absolute path |
|
| 168 | + * @return string e.g. turns '/admin/files/test.txt' into '/test.txt' |
|
| 169 | + * @throws \OCA\Files_Sharing\Exceptions\BrokenPath |
|
| 170 | + */ |
|
| 171 | + protected function stripUserFilesPath($path) { |
|
| 172 | + $trimmed = ltrim($path, '/'); |
|
| 173 | + $split = explode('/', $trimmed); |
|
| 174 | + |
|
| 175 | + // it is not a file relative to data/user/files |
|
| 176 | + if (count($split) < 3 || $split[1] !== 'files') { |
|
| 177 | + \OC::$server->getLogger()->error('Can not strip userid and "files/" from path: ' . $path, ['app' => 'files_sharing']); |
|
| 178 | + throw new \OCA\Files_Sharing\Exceptions\BrokenPath('Path does not start with /user/files', 10); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + // skip 'user' and 'files' |
|
| 182 | + $sliced = array_slice($split, 2); |
|
| 183 | + $relPath = implode('/', $sliced); |
|
| 184 | + |
|
| 185 | + return '/' . $relPath; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * Move the mount point to $target |
|
| 190 | + * |
|
| 191 | + * @param string $target the target mount point |
|
| 192 | + * @return bool |
|
| 193 | + */ |
|
| 194 | + public function moveMount($target) { |
|
| 195 | + $relTargetPath = $this->stripUserFilesPath($target); |
|
| 196 | + $share = $this->storage->getShare(); |
|
| 197 | + |
|
| 198 | + $result = true; |
|
| 199 | + |
|
| 200 | + try { |
|
| 201 | + $this->updateFileTarget($relTargetPath, $share); |
|
| 202 | + $this->setMountPoint($target); |
|
| 203 | + $this->storage->setMountPoint($relTargetPath); |
|
| 204 | + } catch (\Exception $e) { |
|
| 205 | + \OC::$server->getLogger()->logException($e, ['app' => 'files_sharing', 'message' => 'Could not rename mount point for shared folder "' . $this->getMountPoint() . '" to "' . $target . '"']); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + return $result; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * Remove the mount points |
|
| 213 | + * |
|
| 214 | + * @return bool |
|
| 215 | + */ |
|
| 216 | + public function removeMount() { |
|
| 217 | + $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
| 218 | + /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
| 219 | + $storage = $this->getStorage(); |
|
| 220 | + $result = $storage->unshareStorage(); |
|
| 221 | + $mountManager->removeMount($this->mountPoint); |
|
| 222 | + |
|
| 223 | + return $result; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * @return \OCP\Share\IShare |
|
| 228 | + */ |
|
| 229 | + public function getShare() { |
|
| 230 | + return $this->superShare; |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * Get the file id of the root of the storage |
|
| 235 | + * |
|
| 236 | + * @return int |
|
| 237 | + */ |
|
| 238 | + public function getStorageRootId() { |
|
| 239 | + return $this->getShare()->getNodeId(); |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * @return int |
|
| 244 | + */ |
|
| 245 | + public function getNumericStorageId() { |
|
| 246 | + if (!is_null($this->getShare()->getNodeCacheEntry())) { |
|
| 247 | + return $this->getShare()->getNodeCacheEntry()->getStorageId(); |
|
| 248 | + } else { |
|
| 249 | + $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 250 | + |
|
| 251 | + $query = $builder->select('storage') |
|
| 252 | + ->from('filecache') |
|
| 253 | + ->where($builder->expr()->eq('fileid', $builder->createNamedParameter($this->getStorageRootId()))); |
|
| 254 | + |
|
| 255 | + $result = $query->execute(); |
|
| 256 | + $row = $result->fetch(); |
|
| 257 | + $result->closeCursor(); |
|
| 258 | + if ($row) { |
|
| 259 | + return (int)$row['storage']; |
|
| 260 | + } |
|
| 261 | + return -1; |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + public function getMountType() { |
|
| 266 | + return 'shared'; |
|
| 267 | + } |
|
| 268 | 268 | } |
@@ -32,166 +32,166 @@ |
||
| 32 | 32 | use OCP\Files\Mount\IMountPoint; |
| 33 | 33 | |
| 34 | 34 | class Manager implements IMountManager { |
| 35 | - /** @var MountPoint[] */ |
|
| 36 | - private $mounts = []; |
|
| 37 | - |
|
| 38 | - /** @var CappedMemoryCache */ |
|
| 39 | - private $pathCache; |
|
| 40 | - |
|
| 41 | - /** @var CappedMemoryCache */ |
|
| 42 | - private $inPathCache; |
|
| 43 | - |
|
| 44 | - public function __construct() { |
|
| 45 | - $this->pathCache = new CappedMemoryCache(); |
|
| 46 | - $this->inPathCache = new CappedMemoryCache(); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @param IMountPoint $mount |
|
| 51 | - */ |
|
| 52 | - public function addMount(IMountPoint $mount) { |
|
| 53 | - $this->mounts[$mount->getMountPoint()] = $mount; |
|
| 54 | - $this->pathCache->clear(); |
|
| 55 | - $this->inPathCache->clear(); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @param string $mountPoint |
|
| 60 | - */ |
|
| 61 | - public function removeMount(string $mountPoint) { |
|
| 62 | - $mountPoint = Filesystem::normalizePath($mountPoint); |
|
| 63 | - if (\strlen($mountPoint) > 1) { |
|
| 64 | - $mountPoint .= '/'; |
|
| 65 | - } |
|
| 66 | - unset($this->mounts[$mountPoint]); |
|
| 67 | - $this->pathCache->clear(); |
|
| 68 | - $this->inPathCache->clear(); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @param string $mountPoint |
|
| 73 | - * @param string $target |
|
| 74 | - */ |
|
| 75 | - public function moveMount(string $mountPoint, string $target) { |
|
| 76 | - $this->mounts[$target] = $this->mounts[$mountPoint]; |
|
| 77 | - unset($this->mounts[$mountPoint]); |
|
| 78 | - $this->pathCache->clear(); |
|
| 79 | - $this->inPathCache->clear(); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Find the mount for $path |
|
| 84 | - * |
|
| 85 | - * @param string $path |
|
| 86 | - * @return MountPoint|null |
|
| 87 | - */ |
|
| 88 | - public function find(string $path) { |
|
| 89 | - \OC_Util::setupFS(); |
|
| 90 | - $path = Filesystem::normalizePath($path); |
|
| 91 | - |
|
| 92 | - if (isset($this->pathCache[$path])) { |
|
| 93 | - return $this->pathCache[$path]; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - $current = $path; |
|
| 97 | - while (true) { |
|
| 98 | - $mountPoint = $current . '/'; |
|
| 99 | - if (isset($this->mounts[$mountPoint])) { |
|
| 100 | - $this->pathCache[$path] = $this->mounts[$mountPoint]; |
|
| 101 | - return $this->mounts[$mountPoint]; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - if ($current === '') { |
|
| 105 | - return null; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - $current = dirname($current); |
|
| 109 | - if ($current === '.' || $current === '/') { |
|
| 110 | - $current = ''; |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Find all mounts in $path |
|
| 117 | - * |
|
| 118 | - * @param string $path |
|
| 119 | - * @return MountPoint[] |
|
| 120 | - */ |
|
| 121 | - public function findIn(string $path): array { |
|
| 122 | - \OC_Util::setupFS(); |
|
| 123 | - $path = $this->formatPath($path); |
|
| 124 | - |
|
| 125 | - if (isset($this->inPathCache[$path])) { |
|
| 126 | - return $this->inPathCache[$path]; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - $result = []; |
|
| 130 | - $pathLength = \strlen($path); |
|
| 131 | - $mountPoints = array_keys($this->mounts); |
|
| 132 | - foreach ($mountPoints as $mountPoint) { |
|
| 133 | - if (substr($mountPoint, 0, $pathLength) === $path && \strlen($mountPoint) > $pathLength) { |
|
| 134 | - $result[] = $this->mounts[$mountPoint]; |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - $this->inPathCache[$path] = $result; |
|
| 139 | - return $result; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - public function clear() { |
|
| 143 | - $this->mounts = []; |
|
| 144 | - $this->pathCache->clear(); |
|
| 145 | - $this->inPathCache->clear(); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Find mounts by storage id |
|
| 150 | - * |
|
| 151 | - * @param string $id |
|
| 152 | - * @return MountPoint[] |
|
| 153 | - */ |
|
| 154 | - public function findByStorageId(string $id): array { |
|
| 155 | - \OC_Util::setupFS(); |
|
| 156 | - if (\strlen($id) > 64) { |
|
| 157 | - $id = md5($id); |
|
| 158 | - } |
|
| 159 | - $result = []; |
|
| 160 | - foreach ($this->mounts as $mount) { |
|
| 161 | - if ($mount->getStorageId() === $id) { |
|
| 162 | - $result[] = $mount; |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - return $result; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * @return MountPoint[] |
|
| 170 | - */ |
|
| 171 | - public function getAll(): array { |
|
| 172 | - return $this->mounts; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Find mounts by numeric storage id |
|
| 177 | - * |
|
| 178 | - * @param int $id |
|
| 179 | - * @return MountPoint[] |
|
| 180 | - */ |
|
| 181 | - public function findByNumericId(int $id): array { |
|
| 182 | - $storageId = \OC\Files\Cache\Storage::getStorageId($id); |
|
| 183 | - return $this->findByStorageId($storageId); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * @param string $path |
|
| 188 | - * @return string |
|
| 189 | - */ |
|
| 190 | - private function formatPath(string $path): string { |
|
| 191 | - $path = Filesystem::normalizePath($path); |
|
| 192 | - if (\strlen($path) > 1) { |
|
| 193 | - $path .= '/'; |
|
| 194 | - } |
|
| 195 | - return $path; |
|
| 196 | - } |
|
| 35 | + /** @var MountPoint[] */ |
|
| 36 | + private $mounts = []; |
|
| 37 | + |
|
| 38 | + /** @var CappedMemoryCache */ |
|
| 39 | + private $pathCache; |
|
| 40 | + |
|
| 41 | + /** @var CappedMemoryCache */ |
|
| 42 | + private $inPathCache; |
|
| 43 | + |
|
| 44 | + public function __construct() { |
|
| 45 | + $this->pathCache = new CappedMemoryCache(); |
|
| 46 | + $this->inPathCache = new CappedMemoryCache(); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @param IMountPoint $mount |
|
| 51 | + */ |
|
| 52 | + public function addMount(IMountPoint $mount) { |
|
| 53 | + $this->mounts[$mount->getMountPoint()] = $mount; |
|
| 54 | + $this->pathCache->clear(); |
|
| 55 | + $this->inPathCache->clear(); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @param string $mountPoint |
|
| 60 | + */ |
|
| 61 | + public function removeMount(string $mountPoint) { |
|
| 62 | + $mountPoint = Filesystem::normalizePath($mountPoint); |
|
| 63 | + if (\strlen($mountPoint) > 1) { |
|
| 64 | + $mountPoint .= '/'; |
|
| 65 | + } |
|
| 66 | + unset($this->mounts[$mountPoint]); |
|
| 67 | + $this->pathCache->clear(); |
|
| 68 | + $this->inPathCache->clear(); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @param string $mountPoint |
|
| 73 | + * @param string $target |
|
| 74 | + */ |
|
| 75 | + public function moveMount(string $mountPoint, string $target) { |
|
| 76 | + $this->mounts[$target] = $this->mounts[$mountPoint]; |
|
| 77 | + unset($this->mounts[$mountPoint]); |
|
| 78 | + $this->pathCache->clear(); |
|
| 79 | + $this->inPathCache->clear(); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Find the mount for $path |
|
| 84 | + * |
|
| 85 | + * @param string $path |
|
| 86 | + * @return MountPoint|null |
|
| 87 | + */ |
|
| 88 | + public function find(string $path) { |
|
| 89 | + \OC_Util::setupFS(); |
|
| 90 | + $path = Filesystem::normalizePath($path); |
|
| 91 | + |
|
| 92 | + if (isset($this->pathCache[$path])) { |
|
| 93 | + return $this->pathCache[$path]; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + $current = $path; |
|
| 97 | + while (true) { |
|
| 98 | + $mountPoint = $current . '/'; |
|
| 99 | + if (isset($this->mounts[$mountPoint])) { |
|
| 100 | + $this->pathCache[$path] = $this->mounts[$mountPoint]; |
|
| 101 | + return $this->mounts[$mountPoint]; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + if ($current === '') { |
|
| 105 | + return null; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + $current = dirname($current); |
|
| 109 | + if ($current === '.' || $current === '/') { |
|
| 110 | + $current = ''; |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Find all mounts in $path |
|
| 117 | + * |
|
| 118 | + * @param string $path |
|
| 119 | + * @return MountPoint[] |
|
| 120 | + */ |
|
| 121 | + public function findIn(string $path): array { |
|
| 122 | + \OC_Util::setupFS(); |
|
| 123 | + $path = $this->formatPath($path); |
|
| 124 | + |
|
| 125 | + if (isset($this->inPathCache[$path])) { |
|
| 126 | + return $this->inPathCache[$path]; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + $result = []; |
|
| 130 | + $pathLength = \strlen($path); |
|
| 131 | + $mountPoints = array_keys($this->mounts); |
|
| 132 | + foreach ($mountPoints as $mountPoint) { |
|
| 133 | + if (substr($mountPoint, 0, $pathLength) === $path && \strlen($mountPoint) > $pathLength) { |
|
| 134 | + $result[] = $this->mounts[$mountPoint]; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + $this->inPathCache[$path] = $result; |
|
| 139 | + return $result; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + public function clear() { |
|
| 143 | + $this->mounts = []; |
|
| 144 | + $this->pathCache->clear(); |
|
| 145 | + $this->inPathCache->clear(); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Find mounts by storage id |
|
| 150 | + * |
|
| 151 | + * @param string $id |
|
| 152 | + * @return MountPoint[] |
|
| 153 | + */ |
|
| 154 | + public function findByStorageId(string $id): array { |
|
| 155 | + \OC_Util::setupFS(); |
|
| 156 | + if (\strlen($id) > 64) { |
|
| 157 | + $id = md5($id); |
|
| 158 | + } |
|
| 159 | + $result = []; |
|
| 160 | + foreach ($this->mounts as $mount) { |
|
| 161 | + if ($mount->getStorageId() === $id) { |
|
| 162 | + $result[] = $mount; |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + return $result; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * @return MountPoint[] |
|
| 170 | + */ |
|
| 171 | + public function getAll(): array { |
|
| 172 | + return $this->mounts; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Find mounts by numeric storage id |
|
| 177 | + * |
|
| 178 | + * @param int $id |
|
| 179 | + * @return MountPoint[] |
|
| 180 | + */ |
|
| 181 | + public function findByNumericId(int $id): array { |
|
| 182 | + $storageId = \OC\Files\Cache\Storage::getStorageId($id); |
|
| 183 | + return $this->findByStorageId($storageId); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * @param string $path |
|
| 188 | + * @return string |
|
| 189 | + */ |
|
| 190 | + private function formatPath(string $path): string { |
|
| 191 | + $path = Filesystem::normalizePath($path); |
|
| 192 | + if (\strlen($path) > 1) { |
|
| 193 | + $path .= '/'; |
|
| 194 | + } |
|
| 195 | + return $path; |
|
| 196 | + } |
|
| 197 | 197 | } |
@@ -95,7 +95,7 @@ |
||
| 95 | 95 | |
| 96 | 96 | $current = $path; |
| 97 | 97 | while (true) { |
| 98 | - $mountPoint = $current . '/'; |
|
| 98 | + $mountPoint = $current.'/'; |
|
| 99 | 99 | if (isset($this->mounts[$mountPoint])) { |
| 100 | 100 | $this->pathCache[$path] = $this->mounts[$mountPoint]; |
| 101 | 101 | return $this->mounts[$mountPoint]; |
@@ -29,15 +29,15 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | interface ICollectBreadcrumbs extends IReporter { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Collect breadcrumbs for crash reports |
|
| 34 | - * |
|
| 35 | - * @param string $message |
|
| 36 | - * @param string $category |
|
| 37 | - * @param array $context |
|
| 38 | - * |
|
| 39 | - * @since 15.0.0 |
|
| 40 | - */ |
|
| 41 | - public function collect(string $message, string $category, array $context = []); |
|
| 32 | + /** |
|
| 33 | + * Collect breadcrumbs for crash reports |
|
| 34 | + * |
|
| 35 | + * @param string $message |
|
| 36 | + * @param string $category |
|
| 37 | + * @param array $context |
|
| 38 | + * |
|
| 39 | + * @since 15.0.0 |
|
| 40 | + */ |
|
| 41 | + public function collect(string $message, string $category, array $context = []); |
|
| 42 | 42 | |
| 43 | 43 | } |
@@ -32,76 +32,76 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | interface ICloudFederationProviderManager { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Registers an callback function which must return an cloud federation provider |
|
| 37 | - * |
|
| 38 | - * @param string $resourceType which resource type does the provider handles |
|
| 39 | - * @param string $displayName user facing name of the federated share provider |
|
| 40 | - * @param callable $callback |
|
| 41 | - * @throws Exceptions\ProviderAlreadyExistsException |
|
| 42 | - * |
|
| 43 | - * @since 14.0.0 |
|
| 44 | - */ |
|
| 45 | - public function addCloudFederationProvider($resourceType, $displayName, callable $callback); |
|
| 35 | + /** |
|
| 36 | + * Registers an callback function which must return an cloud federation provider |
|
| 37 | + * |
|
| 38 | + * @param string $resourceType which resource type does the provider handles |
|
| 39 | + * @param string $displayName user facing name of the federated share provider |
|
| 40 | + * @param callable $callback |
|
| 41 | + * @throws Exceptions\ProviderAlreadyExistsException |
|
| 42 | + * |
|
| 43 | + * @since 14.0.0 |
|
| 44 | + */ |
|
| 45 | + public function addCloudFederationProvider($resourceType, $displayName, callable $callback); |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * remove cloud federation provider |
|
| 49 | - * |
|
| 50 | - * @param string $resourceType |
|
| 51 | - * |
|
| 52 | - * @since 14.0.0 |
|
| 53 | - */ |
|
| 54 | - public function removeCloudFederationProvider($resourceType); |
|
| 47 | + /** |
|
| 48 | + * remove cloud federation provider |
|
| 49 | + * |
|
| 50 | + * @param string $resourceType |
|
| 51 | + * |
|
| 52 | + * @since 14.0.0 |
|
| 53 | + */ |
|
| 54 | + public function removeCloudFederationProvider($resourceType); |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * get a list of all cloudFederationProviders |
|
| 58 | - * |
|
| 59 | - * @return array [resourceType => ['resourceType' => $resourceType, 'displayName' => $displayName, 'callback' => callback]] |
|
| 60 | - * |
|
| 61 | - * @since 14.0.0 |
|
| 62 | - */ |
|
| 63 | - public function getAllCloudFederationProviders(); |
|
| 56 | + /** |
|
| 57 | + * get a list of all cloudFederationProviders |
|
| 58 | + * |
|
| 59 | + * @return array [resourceType => ['resourceType' => $resourceType, 'displayName' => $displayName, 'callback' => callback]] |
|
| 60 | + * |
|
| 61 | + * @since 14.0.0 |
|
| 62 | + */ |
|
| 63 | + public function getAllCloudFederationProviders(); |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * get a specific cloud federation provider |
|
| 67 | - * |
|
| 68 | - * @param string $resourceType |
|
| 69 | - * @return ICloudFederationProvider |
|
| 70 | - * @throws Exceptions\ProviderDoesNotExistsException |
|
| 71 | - * |
|
| 72 | - * @since 14.0.0 |
|
| 73 | - */ |
|
| 74 | - public function getCloudFederationProvider($resourceType); |
|
| 65 | + /** |
|
| 66 | + * get a specific cloud federation provider |
|
| 67 | + * |
|
| 68 | + * @param string $resourceType |
|
| 69 | + * @return ICloudFederationProvider |
|
| 70 | + * @throws Exceptions\ProviderDoesNotExistsException |
|
| 71 | + * |
|
| 72 | + * @since 14.0.0 |
|
| 73 | + */ |
|
| 74 | + public function getCloudFederationProvider($resourceType); |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * send federated share |
|
| 78 | - * |
|
| 79 | - * @param ICloudFederationShare $share |
|
| 80 | - * @return mixed |
|
| 81 | - * |
|
| 82 | - * @since 14.0.0 |
|
| 83 | - */ |
|
| 84 | - public function sendShare(ICloudFederationShare $share); |
|
| 76 | + /** |
|
| 77 | + * send federated share |
|
| 78 | + * |
|
| 79 | + * @param ICloudFederationShare $share |
|
| 80 | + * @return mixed |
|
| 81 | + * |
|
| 82 | + * @since 14.0.0 |
|
| 83 | + */ |
|
| 84 | + public function sendShare(ICloudFederationShare $share); |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * send notification about existing share |
|
| 88 | - * |
|
| 89 | - * @param string $url |
|
| 90 | - * @param ICloudFederationNotification $notification |
|
| 91 | - * @return mixed |
|
| 92 | - * |
|
| 93 | - * @since 14.0.0 |
|
| 94 | - */ |
|
| 95 | - public function sendNotification($url, ICloudFederationNotification $notification); |
|
| 86 | + /** |
|
| 87 | + * send notification about existing share |
|
| 88 | + * |
|
| 89 | + * @param string $url |
|
| 90 | + * @param ICloudFederationNotification $notification |
|
| 91 | + * @return mixed |
|
| 92 | + * |
|
| 93 | + * @since 14.0.0 |
|
| 94 | + */ |
|
| 95 | + public function sendNotification($url, ICloudFederationNotification $notification); |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * check if the new cloud federation API is ready to be used |
|
| 99 | - * |
|
| 100 | - * @return bool |
|
| 101 | - * |
|
| 102 | - * @since 14.0.0 |
|
| 103 | - */ |
|
| 104 | - public function isReady(); |
|
| 97 | + /** |
|
| 98 | + * check if the new cloud federation API is ready to be used |
|
| 99 | + * |
|
| 100 | + * @return bool |
|
| 101 | + * |
|
| 102 | + * @since 14.0.0 |
|
| 103 | + */ |
|
| 104 | + public function isReady(); |
|
| 105 | 105 | |
| 106 | 106 | |
| 107 | 107 | } |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | $notification->setParsedSubject($l->t('Update to %1$s is available.', [$parameters['version']])); |
| 109 | 109 | |
| 110 | 110 | if ($this->isAdmin()) { |
| 111 | - $notification->setLink($this->url->linkToRouteAbsolute('settings.AdminSettings.index', ['section' => 'overview']) . '#version'); |
|
| 111 | + $notification->setLink($this->url->linkToRouteAbsolute('settings.AdminSettings.index', ['section' => 'overview']).'#version'); |
|
| 112 | 112 | } |
| 113 | 113 | } else { |
| 114 | 114 | $appInfo = $this->getAppInfo($notification->getObjectType()); |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | ]); |
| 129 | 129 | |
| 130 | 130 | if ($this->isAdmin()) { |
| 131 | - $notification->setLink($this->url->linkToRouteAbsolute('settings.AppSettings.viewApps', ['category' => 'updates']) . '#app-' . $notification->getObjectType()); |
|
| 131 | + $notification->setLink($this->url->linkToRouteAbsolute('settings.AppSettings.viewApps', ['category' => 'updates']).'#app-'.$notification->getObjectType()); |
|
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | |
@@ -39,161 +39,161 @@ |
||
| 39 | 39 | |
| 40 | 40 | class Notifier implements INotifier { |
| 41 | 41 | |
| 42 | - /** @var IURLGenerator */ |
|
| 43 | - protected $url; |
|
| 44 | - |
|
| 45 | - /** @var IConfig */ |
|
| 46 | - protected $config; |
|
| 47 | - |
|
| 48 | - /** @var IManager */ |
|
| 49 | - protected $notificationManager; |
|
| 50 | - |
|
| 51 | - /** @var IFactory */ |
|
| 52 | - protected $l10NFactory; |
|
| 53 | - |
|
| 54 | - /** @var IUserSession */ |
|
| 55 | - protected $userSession; |
|
| 56 | - |
|
| 57 | - /** @var IGroupManager */ |
|
| 58 | - protected $groupManager; |
|
| 59 | - |
|
| 60 | - /** @var string[] */ |
|
| 61 | - protected $appVersions; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Notifier constructor. |
|
| 65 | - * |
|
| 66 | - * @param IURLGenerator $url |
|
| 67 | - * @param IConfig $config |
|
| 68 | - * @param IManager $notificationManager |
|
| 69 | - * @param IFactory $l10NFactory |
|
| 70 | - * @param IUserSession $userSession |
|
| 71 | - * @param IGroupManager $groupManager |
|
| 72 | - */ |
|
| 73 | - public function __construct(IURLGenerator $url, IConfig $config, IManager $notificationManager, IFactory $l10NFactory, IUserSession $userSession, IGroupManager $groupManager) { |
|
| 74 | - $this->url = $url; |
|
| 75 | - $this->notificationManager = $notificationManager; |
|
| 76 | - $this->config = $config; |
|
| 77 | - $this->l10NFactory = $l10NFactory; |
|
| 78 | - $this->userSession = $userSession; |
|
| 79 | - $this->groupManager = $groupManager; |
|
| 80 | - $this->appVersions = $this->getAppVersions(); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Identifier of the notifier, only use [a-z0-9_] |
|
| 85 | - * |
|
| 86 | - * @return string |
|
| 87 | - * @since 17.0.0 |
|
| 88 | - */ |
|
| 89 | - public function getID(): string { |
|
| 90 | - return 'updatenotification'; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Human readable name describing the notifier |
|
| 95 | - * |
|
| 96 | - * @return string |
|
| 97 | - * @since 17.0.0 |
|
| 98 | - */ |
|
| 99 | - public function getName(): string { |
|
| 100 | - return $this->l10NFactory->get('updatenotification')->t('Update notifications'); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @param INotification $notification |
|
| 105 | - * @param string $languageCode The code of the language that should be used to prepare the notification |
|
| 106 | - * @return INotification |
|
| 107 | - * @throws \InvalidArgumentException When the notification was not prepared by a notifier |
|
| 108 | - * @throws AlreadyProcessedException When the notification is not needed anymore and should be deleted |
|
| 109 | - * @since 9.0.0 |
|
| 110 | - */ |
|
| 111 | - public function prepare(INotification $notification, string $languageCode): INotification { |
|
| 112 | - if ($notification->getApp() !== 'updatenotification') { |
|
| 113 | - throw new \InvalidArgumentException('Unknown app id'); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - $l = $this->l10NFactory->get('updatenotification', $languageCode); |
|
| 117 | - if ($notification->getSubject() === 'connection_error') { |
|
| 118 | - $errors = (int) $this->config->getAppValue('updatenotification', 'update_check_errors', 0); |
|
| 119 | - if ($errors === 0) { |
|
| 120 | - $this->notificationManager->markProcessed($notification); |
|
| 121 | - throw new \InvalidArgumentException('Update checked worked again'); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - $notification->setParsedSubject($l->t('The update server could not be reached since %d days to check for new updates.', [$errors])) |
|
| 125 | - ->setParsedMessage($l->t('Please check the Nextcloud and server log files for errors.')); |
|
| 126 | - } elseif ($notification->getObjectType() === 'core') { |
|
| 127 | - $this->updateAlreadyInstalledCheck($notification, $this->getCoreVersions()); |
|
| 128 | - |
|
| 129 | - $parameters = $notification->getSubjectParameters(); |
|
| 130 | - $notification->setParsedSubject($l->t('Update to %1$s is available.', [$parameters['version']])); |
|
| 131 | - |
|
| 132 | - if ($this->isAdmin()) { |
|
| 133 | - $notification->setLink($this->url->linkToRouteAbsolute('settings.AdminSettings.index', ['section' => 'overview']) . '#version'); |
|
| 134 | - } |
|
| 135 | - } else { |
|
| 136 | - $appInfo = $this->getAppInfo($notification->getObjectType()); |
|
| 137 | - $appName = ($appInfo === null) ? $notification->getObjectType() : $appInfo['name']; |
|
| 138 | - |
|
| 139 | - if (isset($this->appVersions[$notification->getObjectType()])) { |
|
| 140 | - $this->updateAlreadyInstalledCheck($notification, $this->appVersions[$notification->getObjectType()]); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - $notification->setParsedSubject($l->t('Update for %1$s to version %2$s is available.', [$appName, $notification->getObjectId()])) |
|
| 144 | - ->setRichSubject($l->t('Update for {app} to version %s is available.', [$notification->getObjectId()]), [ |
|
| 145 | - 'app' => [ |
|
| 146 | - 'type' => 'app', |
|
| 147 | - 'id' => $notification->getObjectType(), |
|
| 148 | - 'name' => $appName, |
|
| 149 | - ] |
|
| 150 | - ]); |
|
| 151 | - |
|
| 152 | - if ($this->isAdmin()) { |
|
| 153 | - $notification->setLink($this->url->linkToRouteAbsolute('settings.AppSettings.viewApps', ['category' => 'updates']) . '#app-' . $notification->getObjectType()); |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('updatenotification', 'notification.svg'))); |
|
| 158 | - |
|
| 159 | - return $notification; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Remove the notification and prevent rendering, when the update is installed |
|
| 164 | - * |
|
| 165 | - * @param INotification $notification |
|
| 166 | - * @param string $installedVersion |
|
| 167 | - * @throws AlreadyProcessedException When the update is already installed |
|
| 168 | - */ |
|
| 169 | - protected function updateAlreadyInstalledCheck(INotification $notification, $installedVersion) { |
|
| 170 | - if (version_compare($notification->getObjectId(), $installedVersion, '<=')) { |
|
| 171 | - throw new AlreadyProcessedException(); |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * @return bool |
|
| 177 | - */ |
|
| 178 | - protected function isAdmin(): bool { |
|
| 179 | - $user = $this->userSession->getUser(); |
|
| 180 | - |
|
| 181 | - if ($user instanceof IUser) { |
|
| 182 | - return $this->groupManager->isAdmin($user->getUID()); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - return false; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - protected function getCoreVersions(): string { |
|
| 189 | - return implode('.', Util::getVersion()); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - protected function getAppVersions(): array { |
|
| 193 | - return \OC_App::getAppVersions(); |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - protected function getAppInfo($appId) { |
|
| 197 | - return \OC_App::getAppInfo($appId); |
|
| 198 | - } |
|
| 42 | + /** @var IURLGenerator */ |
|
| 43 | + protected $url; |
|
| 44 | + |
|
| 45 | + /** @var IConfig */ |
|
| 46 | + protected $config; |
|
| 47 | + |
|
| 48 | + /** @var IManager */ |
|
| 49 | + protected $notificationManager; |
|
| 50 | + |
|
| 51 | + /** @var IFactory */ |
|
| 52 | + protected $l10NFactory; |
|
| 53 | + |
|
| 54 | + /** @var IUserSession */ |
|
| 55 | + protected $userSession; |
|
| 56 | + |
|
| 57 | + /** @var IGroupManager */ |
|
| 58 | + protected $groupManager; |
|
| 59 | + |
|
| 60 | + /** @var string[] */ |
|
| 61 | + protected $appVersions; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Notifier constructor. |
|
| 65 | + * |
|
| 66 | + * @param IURLGenerator $url |
|
| 67 | + * @param IConfig $config |
|
| 68 | + * @param IManager $notificationManager |
|
| 69 | + * @param IFactory $l10NFactory |
|
| 70 | + * @param IUserSession $userSession |
|
| 71 | + * @param IGroupManager $groupManager |
|
| 72 | + */ |
|
| 73 | + public function __construct(IURLGenerator $url, IConfig $config, IManager $notificationManager, IFactory $l10NFactory, IUserSession $userSession, IGroupManager $groupManager) { |
|
| 74 | + $this->url = $url; |
|
| 75 | + $this->notificationManager = $notificationManager; |
|
| 76 | + $this->config = $config; |
|
| 77 | + $this->l10NFactory = $l10NFactory; |
|
| 78 | + $this->userSession = $userSession; |
|
| 79 | + $this->groupManager = $groupManager; |
|
| 80 | + $this->appVersions = $this->getAppVersions(); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Identifier of the notifier, only use [a-z0-9_] |
|
| 85 | + * |
|
| 86 | + * @return string |
|
| 87 | + * @since 17.0.0 |
|
| 88 | + */ |
|
| 89 | + public function getID(): string { |
|
| 90 | + return 'updatenotification'; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Human readable name describing the notifier |
|
| 95 | + * |
|
| 96 | + * @return string |
|
| 97 | + * @since 17.0.0 |
|
| 98 | + */ |
|
| 99 | + public function getName(): string { |
|
| 100 | + return $this->l10NFactory->get('updatenotification')->t('Update notifications'); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @param INotification $notification |
|
| 105 | + * @param string $languageCode The code of the language that should be used to prepare the notification |
|
| 106 | + * @return INotification |
|
| 107 | + * @throws \InvalidArgumentException When the notification was not prepared by a notifier |
|
| 108 | + * @throws AlreadyProcessedException When the notification is not needed anymore and should be deleted |
|
| 109 | + * @since 9.0.0 |
|
| 110 | + */ |
|
| 111 | + public function prepare(INotification $notification, string $languageCode): INotification { |
|
| 112 | + if ($notification->getApp() !== 'updatenotification') { |
|
| 113 | + throw new \InvalidArgumentException('Unknown app id'); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + $l = $this->l10NFactory->get('updatenotification', $languageCode); |
|
| 117 | + if ($notification->getSubject() === 'connection_error') { |
|
| 118 | + $errors = (int) $this->config->getAppValue('updatenotification', 'update_check_errors', 0); |
|
| 119 | + if ($errors === 0) { |
|
| 120 | + $this->notificationManager->markProcessed($notification); |
|
| 121 | + throw new \InvalidArgumentException('Update checked worked again'); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + $notification->setParsedSubject($l->t('The update server could not be reached since %d days to check for new updates.', [$errors])) |
|
| 125 | + ->setParsedMessage($l->t('Please check the Nextcloud and server log files for errors.')); |
|
| 126 | + } elseif ($notification->getObjectType() === 'core') { |
|
| 127 | + $this->updateAlreadyInstalledCheck($notification, $this->getCoreVersions()); |
|
| 128 | + |
|
| 129 | + $parameters = $notification->getSubjectParameters(); |
|
| 130 | + $notification->setParsedSubject($l->t('Update to %1$s is available.', [$parameters['version']])); |
|
| 131 | + |
|
| 132 | + if ($this->isAdmin()) { |
|
| 133 | + $notification->setLink($this->url->linkToRouteAbsolute('settings.AdminSettings.index', ['section' => 'overview']) . '#version'); |
|
| 134 | + } |
|
| 135 | + } else { |
|
| 136 | + $appInfo = $this->getAppInfo($notification->getObjectType()); |
|
| 137 | + $appName = ($appInfo === null) ? $notification->getObjectType() : $appInfo['name']; |
|
| 138 | + |
|
| 139 | + if (isset($this->appVersions[$notification->getObjectType()])) { |
|
| 140 | + $this->updateAlreadyInstalledCheck($notification, $this->appVersions[$notification->getObjectType()]); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + $notification->setParsedSubject($l->t('Update for %1$s to version %2$s is available.', [$appName, $notification->getObjectId()])) |
|
| 144 | + ->setRichSubject($l->t('Update for {app} to version %s is available.', [$notification->getObjectId()]), [ |
|
| 145 | + 'app' => [ |
|
| 146 | + 'type' => 'app', |
|
| 147 | + 'id' => $notification->getObjectType(), |
|
| 148 | + 'name' => $appName, |
|
| 149 | + ] |
|
| 150 | + ]); |
|
| 151 | + |
|
| 152 | + if ($this->isAdmin()) { |
|
| 153 | + $notification->setLink($this->url->linkToRouteAbsolute('settings.AppSettings.viewApps', ['category' => 'updates']) . '#app-' . $notification->getObjectType()); |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('updatenotification', 'notification.svg'))); |
|
| 158 | + |
|
| 159 | + return $notification; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Remove the notification and prevent rendering, when the update is installed |
|
| 164 | + * |
|
| 165 | + * @param INotification $notification |
|
| 166 | + * @param string $installedVersion |
|
| 167 | + * @throws AlreadyProcessedException When the update is already installed |
|
| 168 | + */ |
|
| 169 | + protected function updateAlreadyInstalledCheck(INotification $notification, $installedVersion) { |
|
| 170 | + if (version_compare($notification->getObjectId(), $installedVersion, '<=')) { |
|
| 171 | + throw new AlreadyProcessedException(); |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * @return bool |
|
| 177 | + */ |
|
| 178 | + protected function isAdmin(): bool { |
|
| 179 | + $user = $this->userSession->getUser(); |
|
| 180 | + |
|
| 181 | + if ($user instanceof IUser) { |
|
| 182 | + return $this->groupManager->isAdmin($user->getUID()); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + return false; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + protected function getCoreVersions(): string { |
|
| 189 | + return implode('.', Util::getVersion()); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + protected function getAppVersions(): array { |
|
| 193 | + return \OC_App::getAppVersions(); |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + protected function getAppInfo($appId) { |
|
| 197 | + return \OC_App::getAppInfo($appId); |
|
| 198 | + } |
|
| 199 | 199 | } |