@@ -75,1290 +75,1290 @@ |
||
| 75 | 75 | use Psr\Log\LoggerInterface; |
| 76 | 76 | |
| 77 | 77 | class OC_Util { |
| 78 | - public static $scripts = []; |
|
| 79 | - public static $styles = []; |
|
| 80 | - public static $headers = []; |
|
| 81 | - private static $rootFsSetup = false; |
|
| 82 | - private static $fsSetup = false; |
|
| 83 | - |
|
| 84 | - /** @var array Local cache of version.php */ |
|
| 85 | - private static $versionCache = null; |
|
| 86 | - |
|
| 87 | - protected static function getAppManager() { |
|
| 88 | - return \OC::$server->getAppManager(); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Can be set up |
|
| 93 | - * |
|
| 94 | - * @param string $user |
|
| 95 | - * @return boolean |
|
| 96 | - * @description configure the initial filesystem based on the configuration |
|
| 97 | - * @suppress PhanDeprecatedFunction |
|
| 98 | - * @suppress PhanAccessMethodInternal |
|
| 99 | - */ |
|
| 100 | - public static function setupRootFS(string $user = '') { |
|
| 101 | - //setting up the filesystem twice can only lead to trouble |
|
| 102 | - if (self::$rootFsSetup) { |
|
| 103 | - return false; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - \OC::$server->getEventLogger()->start('setup_root_fs', 'Setup root filesystem'); |
|
| 107 | - |
|
| 108 | - // load all filesystem apps before, so no setup-hook gets lost |
|
| 109 | - OC_App::loadApps(['filesystem']); |
|
| 110 | - |
|
| 111 | - self::$rootFsSetup = true; |
|
| 112 | - |
|
| 113 | - \OC\Files\Filesystem::initMountManager(); |
|
| 114 | - |
|
| 115 | - $prevLogging = \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); |
|
| 116 | - \OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 117 | - if ($storage->instanceOfStorage('\OC\Files\Storage\Common')) { |
|
| 118 | - /** @var \OC\Files\Storage\Common $storage */ |
|
| 119 | - $storage->setMountOptions($mount->getOptions()); |
|
| 120 | - } |
|
| 121 | - return $storage; |
|
| 122 | - }); |
|
| 123 | - |
|
| 124 | - \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 125 | - if (!$mount->getOption('enable_sharing', true)) { |
|
| 126 | - return new \OC\Files\Storage\Wrapper\PermissionsMask([ |
|
| 127 | - 'storage' => $storage, |
|
| 128 | - 'mask' => \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_SHARE |
|
| 129 | - ]); |
|
| 130 | - } |
|
| 131 | - return $storage; |
|
| 132 | - }); |
|
| 133 | - |
|
| 134 | - // install storage availability wrapper, before most other wrappers |
|
| 135 | - \OC\Files\Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, \OCP\Files\Storage\IStorage $storage) { |
|
| 136 | - if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
| 137 | - return new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]); |
|
| 138 | - } |
|
| 139 | - return $storage; |
|
| 140 | - }); |
|
| 141 | - |
|
| 142 | - \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 143 | - if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
| 144 | - return new \OC\Files\Storage\Wrapper\Encoding(['storage' => $storage]); |
|
| 145 | - } |
|
| 146 | - return $storage; |
|
| 147 | - }); |
|
| 148 | - |
|
| 149 | - \OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) { |
|
| 150 | - // set up quota for home storages, even for other users |
|
| 151 | - // which can happen when using sharing |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * @var \OC\Files\Storage\Storage $storage |
|
| 155 | - */ |
|
| 156 | - if ($storage->instanceOfStorage('\OC\Files\Storage\Home') |
|
| 157 | - || $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage') |
|
| 158 | - ) { |
|
| 159 | - /** @var \OC\Files\Storage\Home $storage */ |
|
| 160 | - if (is_object($storage->getUser())) { |
|
| 161 | - $quota = OC_Util::getUserQuota($storage->getUser()); |
|
| 162 | - if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
| 163 | - return new \OC\Files\Storage\Wrapper\Quota(['storage' => $storage, 'quota' => $quota, 'root' => 'files']); |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - return $storage; |
|
| 169 | - }); |
|
| 170 | - |
|
| 171 | - \OC\Files\Filesystem::addStorageWrapper('readonly', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 172 | - /* |
|
| 78 | + public static $scripts = []; |
|
| 79 | + public static $styles = []; |
|
| 80 | + public static $headers = []; |
|
| 81 | + private static $rootFsSetup = false; |
|
| 82 | + private static $fsSetup = false; |
|
| 83 | + |
|
| 84 | + /** @var array Local cache of version.php */ |
|
| 85 | + private static $versionCache = null; |
|
| 86 | + |
|
| 87 | + protected static function getAppManager() { |
|
| 88 | + return \OC::$server->getAppManager(); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Can be set up |
|
| 93 | + * |
|
| 94 | + * @param string $user |
|
| 95 | + * @return boolean |
|
| 96 | + * @description configure the initial filesystem based on the configuration |
|
| 97 | + * @suppress PhanDeprecatedFunction |
|
| 98 | + * @suppress PhanAccessMethodInternal |
|
| 99 | + */ |
|
| 100 | + public static function setupRootFS(string $user = '') { |
|
| 101 | + //setting up the filesystem twice can only lead to trouble |
|
| 102 | + if (self::$rootFsSetup) { |
|
| 103 | + return false; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + \OC::$server->getEventLogger()->start('setup_root_fs', 'Setup root filesystem'); |
|
| 107 | + |
|
| 108 | + // load all filesystem apps before, so no setup-hook gets lost |
|
| 109 | + OC_App::loadApps(['filesystem']); |
|
| 110 | + |
|
| 111 | + self::$rootFsSetup = true; |
|
| 112 | + |
|
| 113 | + \OC\Files\Filesystem::initMountManager(); |
|
| 114 | + |
|
| 115 | + $prevLogging = \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); |
|
| 116 | + \OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 117 | + if ($storage->instanceOfStorage('\OC\Files\Storage\Common')) { |
|
| 118 | + /** @var \OC\Files\Storage\Common $storage */ |
|
| 119 | + $storage->setMountOptions($mount->getOptions()); |
|
| 120 | + } |
|
| 121 | + return $storage; |
|
| 122 | + }); |
|
| 123 | + |
|
| 124 | + \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 125 | + if (!$mount->getOption('enable_sharing', true)) { |
|
| 126 | + return new \OC\Files\Storage\Wrapper\PermissionsMask([ |
|
| 127 | + 'storage' => $storage, |
|
| 128 | + 'mask' => \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_SHARE |
|
| 129 | + ]); |
|
| 130 | + } |
|
| 131 | + return $storage; |
|
| 132 | + }); |
|
| 133 | + |
|
| 134 | + // install storage availability wrapper, before most other wrappers |
|
| 135 | + \OC\Files\Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, \OCP\Files\Storage\IStorage $storage) { |
|
| 136 | + if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
| 137 | + return new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]); |
|
| 138 | + } |
|
| 139 | + return $storage; |
|
| 140 | + }); |
|
| 141 | + |
|
| 142 | + \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 143 | + if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
|
| 144 | + return new \OC\Files\Storage\Wrapper\Encoding(['storage' => $storage]); |
|
| 145 | + } |
|
| 146 | + return $storage; |
|
| 147 | + }); |
|
| 148 | + |
|
| 149 | + \OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) { |
|
| 150 | + // set up quota for home storages, even for other users |
|
| 151 | + // which can happen when using sharing |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * @var \OC\Files\Storage\Storage $storage |
|
| 155 | + */ |
|
| 156 | + if ($storage->instanceOfStorage('\OC\Files\Storage\Home') |
|
| 157 | + || $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage') |
|
| 158 | + ) { |
|
| 159 | + /** @var \OC\Files\Storage\Home $storage */ |
|
| 160 | + if (is_object($storage->getUser())) { |
|
| 161 | + $quota = OC_Util::getUserQuota($storage->getUser()); |
|
| 162 | + if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) { |
|
| 163 | + return new \OC\Files\Storage\Wrapper\Quota(['storage' => $storage, 'quota' => $quota, 'root' => 'files']); |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + return $storage; |
|
| 169 | + }); |
|
| 170 | + |
|
| 171 | + \OC\Files\Filesystem::addStorageWrapper('readonly', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 172 | + /* |
|
| 173 | 173 | * Do not allow any operations that modify the storage |
| 174 | 174 | */ |
| 175 | - if ($mount->getOption('readonly', false)) { |
|
| 176 | - return new \OC\Files\Storage\Wrapper\PermissionsMask([ |
|
| 177 | - 'storage' => $storage, |
|
| 178 | - 'mask' => \OCP\Constants::PERMISSION_ALL & ~( |
|
| 179 | - \OCP\Constants::PERMISSION_UPDATE | |
|
| 180 | - \OCP\Constants::PERMISSION_CREATE | |
|
| 181 | - \OCP\Constants::PERMISSION_DELETE |
|
| 182 | - ), |
|
| 183 | - ]); |
|
| 184 | - } |
|
| 185 | - return $storage; |
|
| 186 | - }); |
|
| 187 | - |
|
| 188 | - OC_Hook::emit('OC_Filesystem', 'preSetup', ['user' => $user]); |
|
| 189 | - |
|
| 190 | - \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper($prevLogging); |
|
| 191 | - |
|
| 192 | - /** @var \OCP\Files\Config\IMountProviderCollection $mountProviderCollection */ |
|
| 193 | - $mountProviderCollection = \OC::$server->query(\OCP\Files\Config\IMountProviderCollection::class); |
|
| 194 | - $rootMountProviders = $mountProviderCollection->getRootMounts(); |
|
| 195 | - |
|
| 196 | - /** @var \OC\Files\Mount\Manager $mountManager */ |
|
| 197 | - $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
| 198 | - foreach ($rootMountProviders as $rootMountProvider) { |
|
| 199 | - $mountManager->addMount($rootMountProvider); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - \OC::$server->getEventLogger()->end('setup_root_fs'); |
|
| 203 | - |
|
| 204 | - return true; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * Setup the file system |
|
| 209 | - * |
|
| 210 | - * @param string|null $user |
|
| 211 | - * @return boolean |
|
| 212 | - * @description configure the initial filesystem based on the configuration |
|
| 213 | - * @suppress PhanDeprecatedFunction |
|
| 214 | - * @suppress PhanAccessMethodInternal |
|
| 215 | - */ |
|
| 216 | - public static function setupFS(?string $user = '') { |
|
| 217 | - self::setupRootFS($user ?? ''); |
|
| 218 | - |
|
| 219 | - if (self::$fsSetup) { |
|
| 220 | - return false; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - \OC::$server->getEventLogger()->start('setup_fs', 'Setup filesystem'); |
|
| 224 | - |
|
| 225 | - // If we are not forced to load a specific user we load the one that is logged in |
|
| 226 | - if ($user === '') { |
|
| 227 | - $userObject = \OC::$server->get(\OCP\IUserSession::class)->getUser(); |
|
| 228 | - } else { |
|
| 229 | - $userObject = \OC::$server->get(\OCP\IUserManager::class)->get($user); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - //if we aren't logged in, or the user doesn't exist, there is no use to set up the filesystem |
|
| 233 | - if ($userObject) { |
|
| 234 | - self::$fsSetup = true; |
|
| 235 | - |
|
| 236 | - $userDir = '/' . $userObject->getUID() . '/files'; |
|
| 237 | - |
|
| 238 | - //jail the user into his "home" directory |
|
| 239 | - \OC\Files\Filesystem::init($userObject, $userDir); |
|
| 240 | - |
|
| 241 | - OC_Hook::emit('OC_Filesystem', 'setup', ['user' => $userObject->getUID(), 'user_dir' => $userDir]); |
|
| 242 | - } |
|
| 243 | - \OC::$server->getEventLogger()->end('setup_fs'); |
|
| 244 | - return true; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * check if a password is required for each public link |
|
| 249 | - * |
|
| 250 | - * @return boolean |
|
| 251 | - * @suppress PhanDeprecatedFunction |
|
| 252 | - */ |
|
| 253 | - public static function isPublicLinkPasswordRequired() { |
|
| 254 | - /** @var IManager $shareManager */ |
|
| 255 | - $shareManager = \OC::$server->get(IManager::class); |
|
| 256 | - return $shareManager->shareApiLinkEnforcePassword(); |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * check if sharing is disabled for the current user |
|
| 261 | - * @param IConfig $config |
|
| 262 | - * @param IGroupManager $groupManager |
|
| 263 | - * @param IUser|null $user |
|
| 264 | - * @return bool |
|
| 265 | - */ |
|
| 266 | - public static function isSharingDisabledForUser(IConfig $config, IGroupManager $groupManager, $user) { |
|
| 267 | - /** @var IManager $shareManager */ |
|
| 268 | - $shareManager = \OC::$server->get(IManager::class); |
|
| 269 | - $userId = $user ? $user->getUID() : null; |
|
| 270 | - return $shareManager->sharingDisabledForUser($userId); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * check if share API enforces a default expire date |
|
| 275 | - * |
|
| 276 | - * @return boolean |
|
| 277 | - * @suppress PhanDeprecatedFunction |
|
| 278 | - */ |
|
| 279 | - public static function isDefaultExpireDateEnforced() { |
|
| 280 | - /** @var IManager $shareManager */ |
|
| 281 | - $shareManager = \OC::$server->get(IManager::class); |
|
| 282 | - return $shareManager->shareApiLinkDefaultExpireDateEnforced(); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * Get the quota of a user |
|
| 287 | - * |
|
| 288 | - * @param IUser|null $user |
|
| 289 | - * @return float Quota bytes |
|
| 290 | - */ |
|
| 291 | - public static function getUserQuota(?IUser $user) { |
|
| 292 | - if (is_null($user)) { |
|
| 293 | - return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
| 294 | - } |
|
| 295 | - $userQuota = $user->getQuota(); |
|
| 296 | - if ($userQuota === 'none') { |
|
| 297 | - return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
| 298 | - } |
|
| 299 | - return OC_Helper::computerFileSize($userQuota); |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * copies the skeleton to the users /files |
|
| 304 | - * |
|
| 305 | - * @param string $userId |
|
| 306 | - * @param \OCP\Files\Folder $userDirectory |
|
| 307 | - * @throws \OCP\Files\NotFoundException |
|
| 308 | - * @throws \OCP\Files\NotPermittedException |
|
| 309 | - * @suppress PhanDeprecatedFunction |
|
| 310 | - */ |
|
| 311 | - public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) { |
|
| 312 | - /** @var LoggerInterface $logger */ |
|
| 313 | - $logger = \OC::$server->get(LoggerInterface::class); |
|
| 314 | - |
|
| 315 | - $plainSkeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton'); |
|
| 316 | - $userLang = \OC::$server->getL10NFactory()->findLanguage(); |
|
| 317 | - $skeletonDirectory = str_replace('{lang}', $userLang, $plainSkeletonDirectory); |
|
| 318 | - |
|
| 319 | - if (!file_exists($skeletonDirectory)) { |
|
| 320 | - $dialectStart = strpos($userLang, '_'); |
|
| 321 | - if ($dialectStart !== false) { |
|
| 322 | - $skeletonDirectory = str_replace('{lang}', substr($userLang, 0, $dialectStart), $plainSkeletonDirectory); |
|
| 323 | - } |
|
| 324 | - if ($dialectStart === false || !file_exists($skeletonDirectory)) { |
|
| 325 | - $skeletonDirectory = str_replace('{lang}', 'default', $plainSkeletonDirectory); |
|
| 326 | - } |
|
| 327 | - if (!file_exists($skeletonDirectory)) { |
|
| 328 | - $skeletonDirectory = ''; |
|
| 329 | - } |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - $instanceId = \OC::$server->getConfig()->getSystemValue('instanceid', ''); |
|
| 333 | - |
|
| 334 | - if ($instanceId === null) { |
|
| 335 | - throw new \RuntimeException('no instance id!'); |
|
| 336 | - } |
|
| 337 | - $appdata = 'appdata_' . $instanceId; |
|
| 338 | - if ($userId === $appdata) { |
|
| 339 | - throw new \RuntimeException('username is reserved name: ' . $appdata); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - if (!empty($skeletonDirectory)) { |
|
| 343 | - $logger->debug('copying skeleton for '.$userId.' from '.$skeletonDirectory.' to '.$userDirectory->getFullPath('/'), ['app' => 'files_skeleton']); |
|
| 344 | - self::copyr($skeletonDirectory, $userDirectory); |
|
| 345 | - // update the file cache |
|
| 346 | - $userDirectory->getStorage()->getScanner()->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE); |
|
| 347 | - |
|
| 348 | - /** @var ITemplateManager $templateManager */ |
|
| 349 | - $templateManager = \OC::$server->get(ITemplateManager::class); |
|
| 350 | - $templateManager->initializeTemplateDirectory(null, $userId); |
|
| 351 | - } |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - /** |
|
| 355 | - * copies a directory recursively by using streams |
|
| 356 | - * |
|
| 357 | - * @param string $source |
|
| 358 | - * @param \OCP\Files\Folder $target |
|
| 359 | - * @return void |
|
| 360 | - */ |
|
| 361 | - public static function copyr($source, \OCP\Files\Folder $target) { |
|
| 362 | - $logger = \OC::$server->getLogger(); |
|
| 363 | - |
|
| 364 | - // Verify if folder exists |
|
| 365 | - $dir = opendir($source); |
|
| 366 | - if ($dir === false) { |
|
| 367 | - $logger->error(sprintf('Could not opendir "%s"', $source), ['app' => 'core']); |
|
| 368 | - return; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - // Copy the files |
|
| 372 | - while (false !== ($file = readdir($dir))) { |
|
| 373 | - if (!\OC\Files\Filesystem::isIgnoredDir($file)) { |
|
| 374 | - if (is_dir($source . '/' . $file)) { |
|
| 375 | - $child = $target->newFolder($file); |
|
| 376 | - self::copyr($source . '/' . $file, $child); |
|
| 377 | - } else { |
|
| 378 | - $child = $target->newFile($file); |
|
| 379 | - $sourceStream = fopen($source . '/' . $file, 'r'); |
|
| 380 | - if ($sourceStream === false) { |
|
| 381 | - $logger->error(sprintf('Could not fopen "%s"', $source . '/' . $file), ['app' => 'core']); |
|
| 382 | - closedir($dir); |
|
| 383 | - return; |
|
| 384 | - } |
|
| 385 | - stream_copy_to_stream($sourceStream, $child->fopen('w')); |
|
| 386 | - } |
|
| 387 | - } |
|
| 388 | - } |
|
| 389 | - closedir($dir); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * @return void |
|
| 394 | - * @suppress PhanUndeclaredMethod |
|
| 395 | - */ |
|
| 396 | - public static function tearDownFS() { |
|
| 397 | - \OC\Files\Filesystem::tearDown(); |
|
| 398 | - \OC::$server->getRootFolder()->clearCache(); |
|
| 399 | - self::$fsSetup = false; |
|
| 400 | - self::$rootFsSetup = false; |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * get the current installed version of ownCloud |
|
| 405 | - * |
|
| 406 | - * @return array |
|
| 407 | - */ |
|
| 408 | - public static function getVersion() { |
|
| 409 | - OC_Util::loadVersion(); |
|
| 410 | - return self::$versionCache['OC_Version']; |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * get the current installed version string of ownCloud |
|
| 415 | - * |
|
| 416 | - * @return string |
|
| 417 | - */ |
|
| 418 | - public static function getVersionString() { |
|
| 419 | - OC_Util::loadVersion(); |
|
| 420 | - return self::$versionCache['OC_VersionString']; |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - /** |
|
| 424 | - * @deprecated the value is of no use anymore |
|
| 425 | - * @return string |
|
| 426 | - */ |
|
| 427 | - public static function getEditionString() { |
|
| 428 | - return ''; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - /** |
|
| 432 | - * @description get the update channel of the current installed of ownCloud. |
|
| 433 | - * @return string |
|
| 434 | - */ |
|
| 435 | - public static function getChannel() { |
|
| 436 | - OC_Util::loadVersion(); |
|
| 437 | - return \OC::$server->getConfig()->getSystemValue('updater.release.channel', self::$versionCache['OC_Channel']); |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - /** |
|
| 441 | - * @description get the build number of the current installed of ownCloud. |
|
| 442 | - * @return string |
|
| 443 | - */ |
|
| 444 | - public static function getBuild() { |
|
| 445 | - OC_Util::loadVersion(); |
|
| 446 | - return self::$versionCache['OC_Build']; |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - /** |
|
| 450 | - * @description load the version.php into the session as cache |
|
| 451 | - * @suppress PhanUndeclaredVariable |
|
| 452 | - */ |
|
| 453 | - private static function loadVersion() { |
|
| 454 | - if (self::$versionCache !== null) { |
|
| 455 | - return; |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - $timestamp = filemtime(OC::$SERVERROOT . '/version.php'); |
|
| 459 | - require OC::$SERVERROOT . '/version.php'; |
|
| 460 | - /** @var int $timestamp */ |
|
| 461 | - self::$versionCache['OC_Version_Timestamp'] = $timestamp; |
|
| 462 | - /** @var string $OC_Version */ |
|
| 463 | - self::$versionCache['OC_Version'] = $OC_Version; |
|
| 464 | - /** @var string $OC_VersionString */ |
|
| 465 | - self::$versionCache['OC_VersionString'] = $OC_VersionString; |
|
| 466 | - /** @var string $OC_Build */ |
|
| 467 | - self::$versionCache['OC_Build'] = $OC_Build; |
|
| 468 | - |
|
| 469 | - /** @var string $OC_Channel */ |
|
| 470 | - self::$versionCache['OC_Channel'] = $OC_Channel; |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - /** |
|
| 474 | - * generates a path for JS/CSS files. If no application is provided it will create the path for core. |
|
| 475 | - * |
|
| 476 | - * @param string $application application to get the files from |
|
| 477 | - * @param string $directory directory within this application (css, js, vendor, etc) |
|
| 478 | - * @param string $file the file inside of the above folder |
|
| 479 | - * @return string the path |
|
| 480 | - */ |
|
| 481 | - private static function generatePath($application, $directory, $file) { |
|
| 482 | - if (is_null($file)) { |
|
| 483 | - $file = $application; |
|
| 484 | - $application = ""; |
|
| 485 | - } |
|
| 486 | - if (!empty($application)) { |
|
| 487 | - return "$application/$directory/$file"; |
|
| 488 | - } else { |
|
| 489 | - return "$directory/$file"; |
|
| 490 | - } |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - /** |
|
| 494 | - * add a javascript file |
|
| 495 | - * |
|
| 496 | - * @deprecated 24.0.0 - Use \OCP\Util::addScript |
|
| 497 | - * |
|
| 498 | - * @param string $application application id |
|
| 499 | - * @param string|null $file filename |
|
| 500 | - * @param bool $prepend prepend the Script to the beginning of the list |
|
| 501 | - * @return void |
|
| 502 | - */ |
|
| 503 | - public static function addScript($application, $file = null, $prepend = false) { |
|
| 504 | - $path = OC_Util::generatePath($application, 'js', $file); |
|
| 505 | - |
|
| 506 | - // core js files need separate handling |
|
| 507 | - if ($application !== 'core' && $file !== null) { |
|
| 508 | - self::addTranslations($application); |
|
| 509 | - } |
|
| 510 | - self::addExternalResource($application, $prepend, $path, "script"); |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - /** |
|
| 514 | - * add a javascript file from the vendor sub folder |
|
| 515 | - * |
|
| 516 | - * @param string $application application id |
|
| 517 | - * @param string|null $file filename |
|
| 518 | - * @param bool $prepend prepend the Script to the beginning of the list |
|
| 519 | - * @return void |
|
| 520 | - */ |
|
| 521 | - public static function addVendorScript($application, $file = null, $prepend = false) { |
|
| 522 | - $path = OC_Util::generatePath($application, 'vendor', $file); |
|
| 523 | - self::addExternalResource($application, $prepend, $path, "script"); |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - /** |
|
| 527 | - * add a translation JS file |
|
| 528 | - * |
|
| 529 | - * @deprecated 24.0.0 |
|
| 530 | - * |
|
| 531 | - * @param string $application application id |
|
| 532 | - * @param string|null $languageCode language code, defaults to the current language |
|
| 533 | - * @param bool|null $prepend prepend the Script to the beginning of the list |
|
| 534 | - */ |
|
| 535 | - public static function addTranslations($application, $languageCode = null, $prepend = false) { |
|
| 536 | - if (is_null($languageCode)) { |
|
| 537 | - $languageCode = \OC::$server->getL10NFactory()->findLanguage($application); |
|
| 538 | - } |
|
| 539 | - if (!empty($application)) { |
|
| 540 | - $path = "$application/l10n/$languageCode"; |
|
| 541 | - } else { |
|
| 542 | - $path = "l10n/$languageCode"; |
|
| 543 | - } |
|
| 544 | - self::addExternalResource($application, $prepend, $path, "script"); |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - /** |
|
| 548 | - * add a css file |
|
| 549 | - * |
|
| 550 | - * @param string $application application id |
|
| 551 | - * @param string|null $file filename |
|
| 552 | - * @param bool $prepend prepend the Style to the beginning of the list |
|
| 553 | - * @return void |
|
| 554 | - */ |
|
| 555 | - public static function addStyle($application, $file = null, $prepend = false) { |
|
| 556 | - $path = OC_Util::generatePath($application, 'css', $file); |
|
| 557 | - self::addExternalResource($application, $prepend, $path, "style"); |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - /** |
|
| 561 | - * add a css file from the vendor sub folder |
|
| 562 | - * |
|
| 563 | - * @param string $application application id |
|
| 564 | - * @param string|null $file filename |
|
| 565 | - * @param bool $prepend prepend the Style to the beginning of the list |
|
| 566 | - * @return void |
|
| 567 | - */ |
|
| 568 | - public static function addVendorStyle($application, $file = null, $prepend = false) { |
|
| 569 | - $path = OC_Util::generatePath($application, 'vendor', $file); |
|
| 570 | - self::addExternalResource($application, $prepend, $path, "style"); |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - /** |
|
| 574 | - * add an external resource css/js file |
|
| 575 | - * |
|
| 576 | - * @param string $application application id |
|
| 577 | - * @param bool $prepend prepend the file to the beginning of the list |
|
| 578 | - * @param string $path |
|
| 579 | - * @param string $type (script or style) |
|
| 580 | - * @return void |
|
| 581 | - */ |
|
| 582 | - private static function addExternalResource($application, $prepend, $path, $type = "script") { |
|
| 583 | - if ($type === "style") { |
|
| 584 | - if (!in_array($path, self::$styles)) { |
|
| 585 | - if ($prepend === true) { |
|
| 586 | - array_unshift(self::$styles, $path); |
|
| 587 | - } else { |
|
| 588 | - self::$styles[] = $path; |
|
| 589 | - } |
|
| 590 | - } |
|
| 591 | - } elseif ($type === "script") { |
|
| 592 | - if (!in_array($path, self::$scripts)) { |
|
| 593 | - if ($prepend === true) { |
|
| 594 | - array_unshift(self::$scripts, $path); |
|
| 595 | - } else { |
|
| 596 | - self::$scripts [] = $path; |
|
| 597 | - } |
|
| 598 | - } |
|
| 599 | - } |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - /** |
|
| 603 | - * Add a custom element to the header |
|
| 604 | - * If $text is null then the element will be written as empty element. |
|
| 605 | - * So use "" to get a closing tag. |
|
| 606 | - * @param string $tag tag name of the element |
|
| 607 | - * @param array $attributes array of attributes for the element |
|
| 608 | - * @param string $text the text content for the element |
|
| 609 | - * @param bool $prepend prepend the header to the beginning of the list |
|
| 610 | - */ |
|
| 611 | - public static function addHeader($tag, $attributes, $text = null, $prepend = false) { |
|
| 612 | - $header = [ |
|
| 613 | - 'tag' => $tag, |
|
| 614 | - 'attributes' => $attributes, |
|
| 615 | - 'text' => $text |
|
| 616 | - ]; |
|
| 617 | - if ($prepend === true) { |
|
| 618 | - array_unshift(self::$headers, $header); |
|
| 619 | - } else { |
|
| 620 | - self::$headers[] = $header; |
|
| 621 | - } |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - /** |
|
| 625 | - * check if the current server configuration is suitable for ownCloud |
|
| 626 | - * |
|
| 627 | - * @param \OC\SystemConfig $config |
|
| 628 | - * @return array arrays with error messages and hints |
|
| 629 | - */ |
|
| 630 | - public static function checkServer(\OC\SystemConfig $config) { |
|
| 631 | - $l = \OC::$server->getL10N('lib'); |
|
| 632 | - $errors = []; |
|
| 633 | - $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT . '/data'); |
|
| 634 | - |
|
| 635 | - if (!self::needUpgrade($config) && $config->getValue('installed', false)) { |
|
| 636 | - // this check needs to be done every time |
|
| 637 | - $errors = self::checkDataDirectoryValidity($CONFIG_DATADIRECTORY); |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - // Assume that if checkServer() succeeded before in this session, then all is fine. |
|
| 641 | - if (\OC::$server->getSession()->exists('checkServer_succeeded') && \OC::$server->getSession()->get('checkServer_succeeded')) { |
|
| 642 | - return $errors; |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - $webServerRestart = false; |
|
| 646 | - $setup = new \OC\Setup( |
|
| 647 | - $config, |
|
| 648 | - \OC::$server->get(IniGetWrapper::class), |
|
| 649 | - \OC::$server->getL10N('lib'), |
|
| 650 | - \OC::$server->get(\OCP\Defaults::class), |
|
| 651 | - \OC::$server->get(LoggerInterface::class), |
|
| 652 | - \OC::$server->getSecureRandom(), |
|
| 653 | - \OC::$server->get(\OC\Installer::class) |
|
| 654 | - ); |
|
| 655 | - |
|
| 656 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 657 | - |
|
| 658 | - $availableDatabases = $setup->getSupportedDatabases(); |
|
| 659 | - if (empty($availableDatabases)) { |
|
| 660 | - $errors[] = [ |
|
| 661 | - 'error' => $l->t('No database drivers (sqlite, mysql, or postgresql) installed.'), |
|
| 662 | - 'hint' => '' //TODO: sane hint |
|
| 663 | - ]; |
|
| 664 | - $webServerRestart = true; |
|
| 665 | - } |
|
| 666 | - |
|
| 667 | - // Check if config folder is writable. |
|
| 668 | - if (!OC_Helper::isReadOnlyConfigEnabled()) { |
|
| 669 | - if (!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) { |
|
| 670 | - $errors[] = [ |
|
| 671 | - 'error' => $l->t('Cannot write into "config" directory.'), |
|
| 672 | - 'hint' => $l->t('This can usually be fixed by giving the web server write access to the config directory. See %s', |
|
| 673 | - [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) . '. ' |
|
| 674 | - . $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it. See %s', |
|
| 675 | - [ $urlGenerator->linkToDocs('admin-config') ]) |
|
| 676 | - ]; |
|
| 677 | - } |
|
| 678 | - } |
|
| 679 | - |
|
| 680 | - // Check if there is a writable install folder. |
|
| 681 | - if ($config->getValue('appstoreenabled', true)) { |
|
| 682 | - if (OC_App::getInstallPath() === null |
|
| 683 | - || !is_writable(OC_App::getInstallPath()) |
|
| 684 | - || !is_readable(OC_App::getInstallPath()) |
|
| 685 | - ) { |
|
| 686 | - $errors[] = [ |
|
| 687 | - 'error' => $l->t('Cannot write into "apps" directory.'), |
|
| 688 | - 'hint' => $l->t('This can usually be fixed by giving the web server write access to the apps directory' |
|
| 689 | - . ' or disabling the App Store in the config file.') |
|
| 690 | - ]; |
|
| 691 | - } |
|
| 692 | - } |
|
| 693 | - // Create root dir. |
|
| 694 | - if ($config->getValue('installed', false)) { |
|
| 695 | - if (!is_dir($CONFIG_DATADIRECTORY)) { |
|
| 696 | - $success = @mkdir($CONFIG_DATADIRECTORY); |
|
| 697 | - if ($success) { |
|
| 698 | - $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
| 699 | - } else { |
|
| 700 | - $errors[] = [ |
|
| 701 | - 'error' => $l->t('Cannot create "data" directory.'), |
|
| 702 | - 'hint' => $l->t('This can usually be fixed by giving the web server write access to the root directory. See %s', |
|
| 703 | - [$urlGenerator->linkToDocs('admin-dir_permissions')]) |
|
| 704 | - ]; |
|
| 705 | - } |
|
| 706 | - } elseif (!is_writable($CONFIG_DATADIRECTORY) or !is_readable($CONFIG_DATADIRECTORY)) { |
|
| 707 | - // is_writable doesn't work for NFS mounts, so try to write a file and check if it exists. |
|
| 708 | - $testFile = sprintf('%s/%s.tmp', $CONFIG_DATADIRECTORY, uniqid('data_dir_writability_test_')); |
|
| 709 | - $handle = fopen($testFile, 'w'); |
|
| 710 | - if (!$handle || fwrite($handle, 'Test write operation') === false) { |
|
| 711 | - $permissionsHint = $l->t('Permissions can usually be fixed by giving the web server write access to the root directory. See %s.', |
|
| 712 | - [$urlGenerator->linkToDocs('admin-dir_permissions')]); |
|
| 713 | - $errors[] = [ |
|
| 714 | - 'error' => $l->t('Your data directory is not writable.'), |
|
| 715 | - 'hint' => $permissionsHint |
|
| 716 | - ]; |
|
| 717 | - } else { |
|
| 718 | - fclose($handle); |
|
| 719 | - unlink($testFile); |
|
| 720 | - } |
|
| 721 | - } else { |
|
| 722 | - $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
| 723 | - } |
|
| 724 | - } |
|
| 725 | - |
|
| 726 | - if (!OC_Util::isSetLocaleWorking()) { |
|
| 727 | - $errors[] = [ |
|
| 728 | - 'error' => $l->t('Setting locale to %s failed.', |
|
| 729 | - ['en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/' |
|
| 730 | - . 'pt_BR.UTF-8/it_IT.UTF-8/ja_JP.UTF-8/zh_CN.UTF-8']), |
|
| 731 | - 'hint' => $l->t('Please install one of these locales on your system and restart your web server.') |
|
| 732 | - ]; |
|
| 733 | - } |
|
| 734 | - |
|
| 735 | - // Contains the dependencies that should be checked against |
|
| 736 | - // classes = class_exists |
|
| 737 | - // functions = function_exists |
|
| 738 | - // defined = defined |
|
| 739 | - // ini = ini_get |
|
| 740 | - // If the dependency is not found the missing module name is shown to the EndUser |
|
| 741 | - // When adding new checks always verify that they pass on Travis as well |
|
| 742 | - // for ini settings, see https://github.com/owncloud/administration/blob/master/travis-ci/custom.ini |
|
| 743 | - $dependencies = [ |
|
| 744 | - 'classes' => [ |
|
| 745 | - 'ZipArchive' => 'zip', |
|
| 746 | - 'DOMDocument' => 'dom', |
|
| 747 | - 'XMLWriter' => 'XMLWriter', |
|
| 748 | - 'XMLReader' => 'XMLReader', |
|
| 749 | - ], |
|
| 750 | - 'functions' => [ |
|
| 751 | - 'xml_parser_create' => 'libxml', |
|
| 752 | - 'mb_strcut' => 'mbstring', |
|
| 753 | - 'ctype_digit' => 'ctype', |
|
| 754 | - 'json_encode' => 'JSON', |
|
| 755 | - 'gd_info' => 'GD', |
|
| 756 | - 'gzencode' => 'zlib', |
|
| 757 | - 'simplexml_load_string' => 'SimpleXML', |
|
| 758 | - 'hash' => 'HASH Message Digest Framework', |
|
| 759 | - 'curl_init' => 'cURL', |
|
| 760 | - 'openssl_verify' => 'OpenSSL', |
|
| 761 | - ], |
|
| 762 | - 'defined' => [ |
|
| 763 | - 'PDO::ATTR_DRIVER_NAME' => 'PDO' |
|
| 764 | - ], |
|
| 765 | - 'ini' => [ |
|
| 766 | - 'default_charset' => 'UTF-8', |
|
| 767 | - ], |
|
| 768 | - ]; |
|
| 769 | - $missingDependencies = []; |
|
| 770 | - $invalidIniSettings = []; |
|
| 771 | - |
|
| 772 | - $iniWrapper = \OC::$server->get(IniGetWrapper::class); |
|
| 773 | - foreach ($dependencies['classes'] as $class => $module) { |
|
| 774 | - if (!class_exists($class)) { |
|
| 775 | - $missingDependencies[] = $module; |
|
| 776 | - } |
|
| 777 | - } |
|
| 778 | - foreach ($dependencies['functions'] as $function => $module) { |
|
| 779 | - if (!function_exists($function)) { |
|
| 780 | - $missingDependencies[] = $module; |
|
| 781 | - } |
|
| 782 | - } |
|
| 783 | - foreach ($dependencies['defined'] as $defined => $module) { |
|
| 784 | - if (!defined($defined)) { |
|
| 785 | - $missingDependencies[] = $module; |
|
| 786 | - } |
|
| 787 | - } |
|
| 788 | - foreach ($dependencies['ini'] as $setting => $expected) { |
|
| 789 | - if (is_bool($expected)) { |
|
| 790 | - if ($iniWrapper->getBool($setting) !== $expected) { |
|
| 791 | - $invalidIniSettings[] = [$setting, $expected]; |
|
| 792 | - } |
|
| 793 | - } |
|
| 794 | - if (is_int($expected)) { |
|
| 795 | - if ($iniWrapper->getNumeric($setting) !== $expected) { |
|
| 796 | - $invalidIniSettings[] = [$setting, $expected]; |
|
| 797 | - } |
|
| 798 | - } |
|
| 799 | - if (is_string($expected)) { |
|
| 800 | - if (strtolower($iniWrapper->getString($setting)) !== strtolower($expected)) { |
|
| 801 | - $invalidIniSettings[] = [$setting, $expected]; |
|
| 802 | - } |
|
| 803 | - } |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - foreach ($missingDependencies as $missingDependency) { |
|
| 807 | - $errors[] = [ |
|
| 808 | - 'error' => $l->t('PHP module %s not installed.', [$missingDependency]), |
|
| 809 | - 'hint' => $l->t('Please ask your server administrator to install the module.'), |
|
| 810 | - ]; |
|
| 811 | - $webServerRestart = true; |
|
| 812 | - } |
|
| 813 | - foreach ($invalidIniSettings as $setting) { |
|
| 814 | - if (is_bool($setting[1])) { |
|
| 815 | - $setting[1] = $setting[1] ? 'on' : 'off'; |
|
| 816 | - } |
|
| 817 | - $errors[] = [ |
|
| 818 | - 'error' => $l->t('PHP setting "%s" is not set to "%s".', [$setting[0], var_export($setting[1], true)]), |
|
| 819 | - 'hint' => $l->t('Adjusting this setting in php.ini will make Nextcloud run again') |
|
| 820 | - ]; |
|
| 821 | - $webServerRestart = true; |
|
| 822 | - } |
|
| 823 | - |
|
| 824 | - /** |
|
| 825 | - * The mbstring.func_overload check can only be performed if the mbstring |
|
| 826 | - * module is installed as it will return null if the checking setting is |
|
| 827 | - * not available and thus a check on the boolean value fails. |
|
| 828 | - * |
|
| 829 | - * TODO: Should probably be implemented in the above generic dependency |
|
| 830 | - * check somehow in the long-term. |
|
| 831 | - */ |
|
| 832 | - if ($iniWrapper->getBool('mbstring.func_overload') !== null && |
|
| 833 | - $iniWrapper->getBool('mbstring.func_overload') === true) { |
|
| 834 | - $errors[] = [ |
|
| 835 | - 'error' => $l->t('<code>mbstring.func_overload</code> is set to <code>%s</code> instead of the expected value <code>0</code>.', [$iniWrapper->getString('mbstring.func_overload')]), |
|
| 836 | - 'hint' => $l->t('To fix this issue set <code>mbstring.func_overload</code> to <code>0</code> in your php.ini.') |
|
| 837 | - ]; |
|
| 838 | - } |
|
| 839 | - |
|
| 840 | - if (function_exists('xml_parser_create') && |
|
| 841 | - LIBXML_LOADED_VERSION < 20700) { |
|
| 842 | - $version = LIBXML_LOADED_VERSION; |
|
| 843 | - $major = floor($version / 10000); |
|
| 844 | - $version -= ($major * 10000); |
|
| 845 | - $minor = floor($version / 100); |
|
| 846 | - $version -= ($minor * 100); |
|
| 847 | - $patch = $version; |
|
| 848 | - $errors[] = [ |
|
| 849 | - 'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major . '.' . $minor . '.' . $patch]), |
|
| 850 | - 'hint' => $l->t('To fix this issue update your libxml2 version and restart your web server.') |
|
| 851 | - ]; |
|
| 852 | - } |
|
| 853 | - |
|
| 854 | - if (!self::isAnnotationsWorking()) { |
|
| 855 | - $errors[] = [ |
|
| 856 | - 'error' => $l->t('PHP is apparently set up to strip inline doc blocks. This will make several core apps inaccessible.'), |
|
| 857 | - 'hint' => $l->t('This is probably caused by a cache/accelerator such as Zend OPcache or eAccelerator.') |
|
| 858 | - ]; |
|
| 859 | - } |
|
| 860 | - |
|
| 861 | - if (!\OC::$CLI && $webServerRestart) { |
|
| 862 | - $errors[] = [ |
|
| 863 | - 'error' => $l->t('PHP modules have been installed, but they are still listed as missing?'), |
|
| 864 | - 'hint' => $l->t('Please ask your server administrator to restart the web server.') |
|
| 865 | - ]; |
|
| 866 | - } |
|
| 867 | - |
|
| 868 | - $errors = array_merge($errors, self::checkDatabaseVersion()); |
|
| 869 | - |
|
| 870 | - // Cache the result of this function |
|
| 871 | - \OC::$server->getSession()->set('checkServer_succeeded', count($errors) == 0); |
|
| 872 | - |
|
| 873 | - return $errors; |
|
| 874 | - } |
|
| 875 | - |
|
| 876 | - /** |
|
| 877 | - * Check the database version |
|
| 878 | - * |
|
| 879 | - * @return array errors array |
|
| 880 | - */ |
|
| 881 | - public static function checkDatabaseVersion() { |
|
| 882 | - $l = \OC::$server->getL10N('lib'); |
|
| 883 | - $errors = []; |
|
| 884 | - $dbType = \OC::$server->getSystemConfig()->getValue('dbtype', 'sqlite'); |
|
| 885 | - if ($dbType === 'pgsql') { |
|
| 886 | - // check PostgreSQL version |
|
| 887 | - try { |
|
| 888 | - $result = \OC_DB::executeAudited('SHOW SERVER_VERSION'); |
|
| 889 | - $data = $result->fetchRow(); |
|
| 890 | - $result->closeCursor(); |
|
| 891 | - if (isset($data['server_version'])) { |
|
| 892 | - $version = $data['server_version']; |
|
| 893 | - if (version_compare($version, '9.0.0', '<')) { |
|
| 894 | - $errors[] = [ |
|
| 895 | - 'error' => $l->t('PostgreSQL >= 9 required.'), |
|
| 896 | - 'hint' => $l->t('Please upgrade your database version.') |
|
| 897 | - ]; |
|
| 898 | - } |
|
| 899 | - } |
|
| 900 | - } catch (\Doctrine\DBAL\Exception $e) { |
|
| 901 | - $logger = \OC::$server->getLogger(); |
|
| 902 | - $logger->warning('Error occurred while checking PostgreSQL version, assuming >= 9'); |
|
| 903 | - $logger->logException($e); |
|
| 904 | - } |
|
| 905 | - } |
|
| 906 | - return $errors; |
|
| 907 | - } |
|
| 908 | - |
|
| 909 | - /** |
|
| 910 | - * Check for correct file permissions of data directory |
|
| 911 | - * |
|
| 912 | - * @param string $dataDirectory |
|
| 913 | - * @return array arrays with error messages and hints |
|
| 914 | - */ |
|
| 915 | - public static function checkDataDirectoryPermissions($dataDirectory) { |
|
| 916 | - if (\OC::$server->getConfig()->getSystemValue('check_data_directory_permissions', true) === false) { |
|
| 917 | - return []; |
|
| 918 | - } |
|
| 919 | - |
|
| 920 | - $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
| 921 | - if (substr($perms, -1) !== '0') { |
|
| 922 | - chmod($dataDirectory, 0770); |
|
| 923 | - clearstatcache(); |
|
| 924 | - $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
| 925 | - if ($perms[2] !== '0') { |
|
| 926 | - $l = \OC::$server->getL10N('lib'); |
|
| 927 | - return [[ |
|
| 928 | - 'error' => $l->t('Your data directory is readable by other users.'), |
|
| 929 | - 'hint' => $l->t('Please change the permissions to 0770 so that the directory cannot be listed by other users.'), |
|
| 930 | - ]]; |
|
| 931 | - } |
|
| 932 | - } |
|
| 933 | - return []; |
|
| 934 | - } |
|
| 935 | - |
|
| 936 | - /** |
|
| 937 | - * Check that the data directory exists and is valid by |
|
| 938 | - * checking the existence of the ".ocdata" file. |
|
| 939 | - * |
|
| 940 | - * @param string $dataDirectory data directory path |
|
| 941 | - * @return array errors found |
|
| 942 | - */ |
|
| 943 | - public static function checkDataDirectoryValidity($dataDirectory) { |
|
| 944 | - $l = \OC::$server->getL10N('lib'); |
|
| 945 | - $errors = []; |
|
| 946 | - if ($dataDirectory[0] !== '/') { |
|
| 947 | - $errors[] = [ |
|
| 948 | - 'error' => $l->t('Your data directory must be an absolute path.'), |
|
| 949 | - 'hint' => $l->t('Check the value of "datadirectory" in your configuration.') |
|
| 950 | - ]; |
|
| 951 | - } |
|
| 952 | - if (!file_exists($dataDirectory . '/.ocdata')) { |
|
| 953 | - $errors[] = [ |
|
| 954 | - 'error' => $l->t('Your data directory is invalid.'), |
|
| 955 | - 'hint' => $l->t('Ensure there is a file called ".ocdata"' . |
|
| 956 | - ' in the root of the data directory.') |
|
| 957 | - ]; |
|
| 958 | - } |
|
| 959 | - return $errors; |
|
| 960 | - } |
|
| 961 | - |
|
| 962 | - /** |
|
| 963 | - * Check if the user is logged in, redirects to home if not. With |
|
| 964 | - * redirect URL parameter to the request URI. |
|
| 965 | - * |
|
| 966 | - * @return void |
|
| 967 | - */ |
|
| 968 | - public static function checkLoggedIn() { |
|
| 969 | - // Check if we are a user |
|
| 970 | - if (!\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 971 | - header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute( |
|
| 972 | - 'core.login.showLoginForm', |
|
| 973 | - [ |
|
| 974 | - 'redirect_url' => \OC::$server->getRequest()->getRequestUri(), |
|
| 975 | - ] |
|
| 976 | - ) |
|
| 977 | - ); |
|
| 978 | - exit(); |
|
| 979 | - } |
|
| 980 | - // Redirect to 2FA challenge selection if 2FA challenge was not solved yet |
|
| 981 | - if (\OC::$server->getTwoFactorAuthManager()->needsSecondFactor(\OC::$server->getUserSession()->getUser())) { |
|
| 982 | - header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge')); |
|
| 983 | - exit(); |
|
| 984 | - } |
|
| 985 | - } |
|
| 986 | - |
|
| 987 | - /** |
|
| 988 | - * Check if the user is a admin, redirects to home if not |
|
| 989 | - * |
|
| 990 | - * @return void |
|
| 991 | - */ |
|
| 992 | - public static function checkAdminUser() { |
|
| 993 | - OC_Util::checkLoggedIn(); |
|
| 994 | - if (!OC_User::isAdminUser(OC_User::getUser())) { |
|
| 995 | - header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 996 | - exit(); |
|
| 997 | - } |
|
| 998 | - } |
|
| 999 | - |
|
| 1000 | - /** |
|
| 1001 | - * Returns the URL of the default page |
|
| 1002 | - * based on the system configuration and |
|
| 1003 | - * the apps visible for the current user |
|
| 1004 | - * |
|
| 1005 | - * @return string URL |
|
| 1006 | - * @suppress PhanDeprecatedFunction |
|
| 1007 | - */ |
|
| 1008 | - public static function getDefaultPageUrl() { |
|
| 1009 | - /** @var IURLGenerator $urlGenerator */ |
|
| 1010 | - $urlGenerator = \OC::$server->get(IURLGenerator::class); |
|
| 1011 | - return $urlGenerator->linkToDefaultPageUrl(); |
|
| 1012 | - } |
|
| 1013 | - |
|
| 1014 | - /** |
|
| 1015 | - * Redirect to the user default page |
|
| 1016 | - * |
|
| 1017 | - * @return void |
|
| 1018 | - */ |
|
| 1019 | - public static function redirectToDefaultPage() { |
|
| 1020 | - $location = self::getDefaultPageUrl(); |
|
| 1021 | - header('Location: ' . $location); |
|
| 1022 | - exit(); |
|
| 1023 | - } |
|
| 1024 | - |
|
| 1025 | - /** |
|
| 1026 | - * get an id unique for this instance |
|
| 1027 | - * |
|
| 1028 | - * @return string |
|
| 1029 | - */ |
|
| 1030 | - public static function getInstanceId() { |
|
| 1031 | - $id = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
| 1032 | - if (is_null($id)) { |
|
| 1033 | - // We need to guarantee at least one letter in instanceid so it can be used as the session_name |
|
| 1034 | - $id = 'oc' . \OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
| 1035 | - \OC::$server->getSystemConfig()->setValue('instanceid', $id); |
|
| 1036 | - } |
|
| 1037 | - return $id; |
|
| 1038 | - } |
|
| 1039 | - |
|
| 1040 | - /** |
|
| 1041 | - * Public function to sanitize HTML |
|
| 1042 | - * |
|
| 1043 | - * This function is used to sanitize HTML and should be applied on any |
|
| 1044 | - * string or array of strings before displaying it on a web page. |
|
| 1045 | - * |
|
| 1046 | - * @param string|string[] $value |
|
| 1047 | - * @return string|string[] an array of sanitized strings or a single sanitized string, depends on the input parameter. |
|
| 1048 | - */ |
|
| 1049 | - public static function sanitizeHTML($value) { |
|
| 1050 | - if (is_array($value)) { |
|
| 1051 | - /** @var string[] $value */ |
|
| 1052 | - $value = array_map(function ($value) { |
|
| 1053 | - return self::sanitizeHTML($value); |
|
| 1054 | - }, $value); |
|
| 1055 | - } else { |
|
| 1056 | - // Specify encoding for PHP<5.4 |
|
| 1057 | - $value = htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 1058 | - } |
|
| 1059 | - return $value; |
|
| 1060 | - } |
|
| 1061 | - |
|
| 1062 | - /** |
|
| 1063 | - * Public function to encode url parameters |
|
| 1064 | - * |
|
| 1065 | - * This function is used to encode path to file before output. |
|
| 1066 | - * Encoding is done according to RFC 3986 with one exception: |
|
| 1067 | - * Character '/' is preserved as is. |
|
| 1068 | - * |
|
| 1069 | - * @param string $component part of URI to encode |
|
| 1070 | - * @return string |
|
| 1071 | - */ |
|
| 1072 | - public static function encodePath($component) { |
|
| 1073 | - $encoded = rawurlencode($component); |
|
| 1074 | - $encoded = str_replace('%2F', '/', $encoded); |
|
| 1075 | - return $encoded; |
|
| 1076 | - } |
|
| 1077 | - |
|
| 1078 | - |
|
| 1079 | - public function createHtaccessTestFile(\OCP\IConfig $config) { |
|
| 1080 | - // php dev server does not support htaccess |
|
| 1081 | - if (php_sapi_name() === 'cli-server') { |
|
| 1082 | - return false; |
|
| 1083 | - } |
|
| 1084 | - |
|
| 1085 | - // testdata |
|
| 1086 | - $fileName = '/htaccesstest.txt'; |
|
| 1087 | - $testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.'; |
|
| 1088 | - |
|
| 1089 | - // creating a test file |
|
| 1090 | - $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1091 | - |
|
| 1092 | - if (file_exists($testFile)) {// already running this test, possible recursive call |
|
| 1093 | - return false; |
|
| 1094 | - } |
|
| 1095 | - |
|
| 1096 | - $fp = @fopen($testFile, 'w'); |
|
| 1097 | - if (!$fp) { |
|
| 1098 | - throw new \OCP\HintException('Can\'t create test file to check for working .htaccess file.', |
|
| 1099 | - 'Make sure it is possible for the web server to write to ' . $testFile); |
|
| 1100 | - } |
|
| 1101 | - fwrite($fp, $testContent); |
|
| 1102 | - fclose($fp); |
|
| 1103 | - |
|
| 1104 | - return $testContent; |
|
| 1105 | - } |
|
| 1106 | - |
|
| 1107 | - /** |
|
| 1108 | - * Check if the .htaccess file is working |
|
| 1109 | - * |
|
| 1110 | - * @param \OCP\IConfig $config |
|
| 1111 | - * @return bool |
|
| 1112 | - * @throws Exception |
|
| 1113 | - * @throws \OCP\HintException If the test file can't get written. |
|
| 1114 | - */ |
|
| 1115 | - public function isHtaccessWorking(\OCP\IConfig $config) { |
|
| 1116 | - if (\OC::$CLI || !$config->getSystemValue('check_for_working_htaccess', true)) { |
|
| 1117 | - return true; |
|
| 1118 | - } |
|
| 1119 | - |
|
| 1120 | - $testContent = $this->createHtaccessTestFile($config); |
|
| 1121 | - if ($testContent === false) { |
|
| 1122 | - return false; |
|
| 1123 | - } |
|
| 1124 | - |
|
| 1125 | - $fileName = '/htaccesstest.txt'; |
|
| 1126 | - $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1127 | - |
|
| 1128 | - // accessing the file via http |
|
| 1129 | - $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT . '/data' . $fileName); |
|
| 1130 | - try { |
|
| 1131 | - $content = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody(); |
|
| 1132 | - } catch (\Exception $e) { |
|
| 1133 | - $content = false; |
|
| 1134 | - } |
|
| 1135 | - |
|
| 1136 | - if (strpos($url, 'https:') === 0) { |
|
| 1137 | - $url = 'http:' . substr($url, 6); |
|
| 1138 | - } else { |
|
| 1139 | - $url = 'https:' . substr($url, 5); |
|
| 1140 | - } |
|
| 1141 | - |
|
| 1142 | - try { |
|
| 1143 | - $fallbackContent = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody(); |
|
| 1144 | - } catch (\Exception $e) { |
|
| 1145 | - $fallbackContent = false; |
|
| 1146 | - } |
|
| 1147 | - |
|
| 1148 | - // cleanup |
|
| 1149 | - @unlink($testFile); |
|
| 1150 | - |
|
| 1151 | - /* |
|
| 175 | + if ($mount->getOption('readonly', false)) { |
|
| 176 | + return new \OC\Files\Storage\Wrapper\PermissionsMask([ |
|
| 177 | + 'storage' => $storage, |
|
| 178 | + 'mask' => \OCP\Constants::PERMISSION_ALL & ~( |
|
| 179 | + \OCP\Constants::PERMISSION_UPDATE | |
|
| 180 | + \OCP\Constants::PERMISSION_CREATE | |
|
| 181 | + \OCP\Constants::PERMISSION_DELETE |
|
| 182 | + ), |
|
| 183 | + ]); |
|
| 184 | + } |
|
| 185 | + return $storage; |
|
| 186 | + }); |
|
| 187 | + |
|
| 188 | + OC_Hook::emit('OC_Filesystem', 'preSetup', ['user' => $user]); |
|
| 189 | + |
|
| 190 | + \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper($prevLogging); |
|
| 191 | + |
|
| 192 | + /** @var \OCP\Files\Config\IMountProviderCollection $mountProviderCollection */ |
|
| 193 | + $mountProviderCollection = \OC::$server->query(\OCP\Files\Config\IMountProviderCollection::class); |
|
| 194 | + $rootMountProviders = $mountProviderCollection->getRootMounts(); |
|
| 195 | + |
|
| 196 | + /** @var \OC\Files\Mount\Manager $mountManager */ |
|
| 197 | + $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
| 198 | + foreach ($rootMountProviders as $rootMountProvider) { |
|
| 199 | + $mountManager->addMount($rootMountProvider); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + \OC::$server->getEventLogger()->end('setup_root_fs'); |
|
| 203 | + |
|
| 204 | + return true; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * Setup the file system |
|
| 209 | + * |
|
| 210 | + * @param string|null $user |
|
| 211 | + * @return boolean |
|
| 212 | + * @description configure the initial filesystem based on the configuration |
|
| 213 | + * @suppress PhanDeprecatedFunction |
|
| 214 | + * @suppress PhanAccessMethodInternal |
|
| 215 | + */ |
|
| 216 | + public static function setupFS(?string $user = '') { |
|
| 217 | + self::setupRootFS($user ?? ''); |
|
| 218 | + |
|
| 219 | + if (self::$fsSetup) { |
|
| 220 | + return false; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + \OC::$server->getEventLogger()->start('setup_fs', 'Setup filesystem'); |
|
| 224 | + |
|
| 225 | + // If we are not forced to load a specific user we load the one that is logged in |
|
| 226 | + if ($user === '') { |
|
| 227 | + $userObject = \OC::$server->get(\OCP\IUserSession::class)->getUser(); |
|
| 228 | + } else { |
|
| 229 | + $userObject = \OC::$server->get(\OCP\IUserManager::class)->get($user); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + //if we aren't logged in, or the user doesn't exist, there is no use to set up the filesystem |
|
| 233 | + if ($userObject) { |
|
| 234 | + self::$fsSetup = true; |
|
| 235 | + |
|
| 236 | + $userDir = '/' . $userObject->getUID() . '/files'; |
|
| 237 | + |
|
| 238 | + //jail the user into his "home" directory |
|
| 239 | + \OC\Files\Filesystem::init($userObject, $userDir); |
|
| 240 | + |
|
| 241 | + OC_Hook::emit('OC_Filesystem', 'setup', ['user' => $userObject->getUID(), 'user_dir' => $userDir]); |
|
| 242 | + } |
|
| 243 | + \OC::$server->getEventLogger()->end('setup_fs'); |
|
| 244 | + return true; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * check if a password is required for each public link |
|
| 249 | + * |
|
| 250 | + * @return boolean |
|
| 251 | + * @suppress PhanDeprecatedFunction |
|
| 252 | + */ |
|
| 253 | + public static function isPublicLinkPasswordRequired() { |
|
| 254 | + /** @var IManager $shareManager */ |
|
| 255 | + $shareManager = \OC::$server->get(IManager::class); |
|
| 256 | + return $shareManager->shareApiLinkEnforcePassword(); |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * check if sharing is disabled for the current user |
|
| 261 | + * @param IConfig $config |
|
| 262 | + * @param IGroupManager $groupManager |
|
| 263 | + * @param IUser|null $user |
|
| 264 | + * @return bool |
|
| 265 | + */ |
|
| 266 | + public static function isSharingDisabledForUser(IConfig $config, IGroupManager $groupManager, $user) { |
|
| 267 | + /** @var IManager $shareManager */ |
|
| 268 | + $shareManager = \OC::$server->get(IManager::class); |
|
| 269 | + $userId = $user ? $user->getUID() : null; |
|
| 270 | + return $shareManager->sharingDisabledForUser($userId); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * check if share API enforces a default expire date |
|
| 275 | + * |
|
| 276 | + * @return boolean |
|
| 277 | + * @suppress PhanDeprecatedFunction |
|
| 278 | + */ |
|
| 279 | + public static function isDefaultExpireDateEnforced() { |
|
| 280 | + /** @var IManager $shareManager */ |
|
| 281 | + $shareManager = \OC::$server->get(IManager::class); |
|
| 282 | + return $shareManager->shareApiLinkDefaultExpireDateEnforced(); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * Get the quota of a user |
|
| 287 | + * |
|
| 288 | + * @param IUser|null $user |
|
| 289 | + * @return float Quota bytes |
|
| 290 | + */ |
|
| 291 | + public static function getUserQuota(?IUser $user) { |
|
| 292 | + if (is_null($user)) { |
|
| 293 | + return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
| 294 | + } |
|
| 295 | + $userQuota = $user->getQuota(); |
|
| 296 | + if ($userQuota === 'none') { |
|
| 297 | + return \OCP\Files\FileInfo::SPACE_UNLIMITED; |
|
| 298 | + } |
|
| 299 | + return OC_Helper::computerFileSize($userQuota); |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * copies the skeleton to the users /files |
|
| 304 | + * |
|
| 305 | + * @param string $userId |
|
| 306 | + * @param \OCP\Files\Folder $userDirectory |
|
| 307 | + * @throws \OCP\Files\NotFoundException |
|
| 308 | + * @throws \OCP\Files\NotPermittedException |
|
| 309 | + * @suppress PhanDeprecatedFunction |
|
| 310 | + */ |
|
| 311 | + public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) { |
|
| 312 | + /** @var LoggerInterface $logger */ |
|
| 313 | + $logger = \OC::$server->get(LoggerInterface::class); |
|
| 314 | + |
|
| 315 | + $plainSkeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton'); |
|
| 316 | + $userLang = \OC::$server->getL10NFactory()->findLanguage(); |
|
| 317 | + $skeletonDirectory = str_replace('{lang}', $userLang, $plainSkeletonDirectory); |
|
| 318 | + |
|
| 319 | + if (!file_exists($skeletonDirectory)) { |
|
| 320 | + $dialectStart = strpos($userLang, '_'); |
|
| 321 | + if ($dialectStart !== false) { |
|
| 322 | + $skeletonDirectory = str_replace('{lang}', substr($userLang, 0, $dialectStart), $plainSkeletonDirectory); |
|
| 323 | + } |
|
| 324 | + if ($dialectStart === false || !file_exists($skeletonDirectory)) { |
|
| 325 | + $skeletonDirectory = str_replace('{lang}', 'default', $plainSkeletonDirectory); |
|
| 326 | + } |
|
| 327 | + if (!file_exists($skeletonDirectory)) { |
|
| 328 | + $skeletonDirectory = ''; |
|
| 329 | + } |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + $instanceId = \OC::$server->getConfig()->getSystemValue('instanceid', ''); |
|
| 333 | + |
|
| 334 | + if ($instanceId === null) { |
|
| 335 | + throw new \RuntimeException('no instance id!'); |
|
| 336 | + } |
|
| 337 | + $appdata = 'appdata_' . $instanceId; |
|
| 338 | + if ($userId === $appdata) { |
|
| 339 | + throw new \RuntimeException('username is reserved name: ' . $appdata); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + if (!empty($skeletonDirectory)) { |
|
| 343 | + $logger->debug('copying skeleton for '.$userId.' from '.$skeletonDirectory.' to '.$userDirectory->getFullPath('/'), ['app' => 'files_skeleton']); |
|
| 344 | + self::copyr($skeletonDirectory, $userDirectory); |
|
| 345 | + // update the file cache |
|
| 346 | + $userDirectory->getStorage()->getScanner()->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE); |
|
| 347 | + |
|
| 348 | + /** @var ITemplateManager $templateManager */ |
|
| 349 | + $templateManager = \OC::$server->get(ITemplateManager::class); |
|
| 350 | + $templateManager->initializeTemplateDirectory(null, $userId); |
|
| 351 | + } |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + /** |
|
| 355 | + * copies a directory recursively by using streams |
|
| 356 | + * |
|
| 357 | + * @param string $source |
|
| 358 | + * @param \OCP\Files\Folder $target |
|
| 359 | + * @return void |
|
| 360 | + */ |
|
| 361 | + public static function copyr($source, \OCP\Files\Folder $target) { |
|
| 362 | + $logger = \OC::$server->getLogger(); |
|
| 363 | + |
|
| 364 | + // Verify if folder exists |
|
| 365 | + $dir = opendir($source); |
|
| 366 | + if ($dir === false) { |
|
| 367 | + $logger->error(sprintf('Could not opendir "%s"', $source), ['app' => 'core']); |
|
| 368 | + return; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + // Copy the files |
|
| 372 | + while (false !== ($file = readdir($dir))) { |
|
| 373 | + if (!\OC\Files\Filesystem::isIgnoredDir($file)) { |
|
| 374 | + if (is_dir($source . '/' . $file)) { |
|
| 375 | + $child = $target->newFolder($file); |
|
| 376 | + self::copyr($source . '/' . $file, $child); |
|
| 377 | + } else { |
|
| 378 | + $child = $target->newFile($file); |
|
| 379 | + $sourceStream = fopen($source . '/' . $file, 'r'); |
|
| 380 | + if ($sourceStream === false) { |
|
| 381 | + $logger->error(sprintf('Could not fopen "%s"', $source . '/' . $file), ['app' => 'core']); |
|
| 382 | + closedir($dir); |
|
| 383 | + return; |
|
| 384 | + } |
|
| 385 | + stream_copy_to_stream($sourceStream, $child->fopen('w')); |
|
| 386 | + } |
|
| 387 | + } |
|
| 388 | + } |
|
| 389 | + closedir($dir); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * @return void |
|
| 394 | + * @suppress PhanUndeclaredMethod |
|
| 395 | + */ |
|
| 396 | + public static function tearDownFS() { |
|
| 397 | + \OC\Files\Filesystem::tearDown(); |
|
| 398 | + \OC::$server->getRootFolder()->clearCache(); |
|
| 399 | + self::$fsSetup = false; |
|
| 400 | + self::$rootFsSetup = false; |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * get the current installed version of ownCloud |
|
| 405 | + * |
|
| 406 | + * @return array |
|
| 407 | + */ |
|
| 408 | + public static function getVersion() { |
|
| 409 | + OC_Util::loadVersion(); |
|
| 410 | + return self::$versionCache['OC_Version']; |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * get the current installed version string of ownCloud |
|
| 415 | + * |
|
| 416 | + * @return string |
|
| 417 | + */ |
|
| 418 | + public static function getVersionString() { |
|
| 419 | + OC_Util::loadVersion(); |
|
| 420 | + return self::$versionCache['OC_VersionString']; |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * @deprecated the value is of no use anymore |
|
| 425 | + * @return string |
|
| 426 | + */ |
|
| 427 | + public static function getEditionString() { |
|
| 428 | + return ''; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + /** |
|
| 432 | + * @description get the update channel of the current installed of ownCloud. |
|
| 433 | + * @return string |
|
| 434 | + */ |
|
| 435 | + public static function getChannel() { |
|
| 436 | + OC_Util::loadVersion(); |
|
| 437 | + return \OC::$server->getConfig()->getSystemValue('updater.release.channel', self::$versionCache['OC_Channel']); |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + /** |
|
| 441 | + * @description get the build number of the current installed of ownCloud. |
|
| 442 | + * @return string |
|
| 443 | + */ |
|
| 444 | + public static function getBuild() { |
|
| 445 | + OC_Util::loadVersion(); |
|
| 446 | + return self::$versionCache['OC_Build']; |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + /** |
|
| 450 | + * @description load the version.php into the session as cache |
|
| 451 | + * @suppress PhanUndeclaredVariable |
|
| 452 | + */ |
|
| 453 | + private static function loadVersion() { |
|
| 454 | + if (self::$versionCache !== null) { |
|
| 455 | + return; |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + $timestamp = filemtime(OC::$SERVERROOT . '/version.php'); |
|
| 459 | + require OC::$SERVERROOT . '/version.php'; |
|
| 460 | + /** @var int $timestamp */ |
|
| 461 | + self::$versionCache['OC_Version_Timestamp'] = $timestamp; |
|
| 462 | + /** @var string $OC_Version */ |
|
| 463 | + self::$versionCache['OC_Version'] = $OC_Version; |
|
| 464 | + /** @var string $OC_VersionString */ |
|
| 465 | + self::$versionCache['OC_VersionString'] = $OC_VersionString; |
|
| 466 | + /** @var string $OC_Build */ |
|
| 467 | + self::$versionCache['OC_Build'] = $OC_Build; |
|
| 468 | + |
|
| 469 | + /** @var string $OC_Channel */ |
|
| 470 | + self::$versionCache['OC_Channel'] = $OC_Channel; |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + /** |
|
| 474 | + * generates a path for JS/CSS files. If no application is provided it will create the path for core. |
|
| 475 | + * |
|
| 476 | + * @param string $application application to get the files from |
|
| 477 | + * @param string $directory directory within this application (css, js, vendor, etc) |
|
| 478 | + * @param string $file the file inside of the above folder |
|
| 479 | + * @return string the path |
|
| 480 | + */ |
|
| 481 | + private static function generatePath($application, $directory, $file) { |
|
| 482 | + if (is_null($file)) { |
|
| 483 | + $file = $application; |
|
| 484 | + $application = ""; |
|
| 485 | + } |
|
| 486 | + if (!empty($application)) { |
|
| 487 | + return "$application/$directory/$file"; |
|
| 488 | + } else { |
|
| 489 | + return "$directory/$file"; |
|
| 490 | + } |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + /** |
|
| 494 | + * add a javascript file |
|
| 495 | + * |
|
| 496 | + * @deprecated 24.0.0 - Use \OCP\Util::addScript |
|
| 497 | + * |
|
| 498 | + * @param string $application application id |
|
| 499 | + * @param string|null $file filename |
|
| 500 | + * @param bool $prepend prepend the Script to the beginning of the list |
|
| 501 | + * @return void |
|
| 502 | + */ |
|
| 503 | + public static function addScript($application, $file = null, $prepend = false) { |
|
| 504 | + $path = OC_Util::generatePath($application, 'js', $file); |
|
| 505 | + |
|
| 506 | + // core js files need separate handling |
|
| 507 | + if ($application !== 'core' && $file !== null) { |
|
| 508 | + self::addTranslations($application); |
|
| 509 | + } |
|
| 510 | + self::addExternalResource($application, $prepend, $path, "script"); |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + /** |
|
| 514 | + * add a javascript file from the vendor sub folder |
|
| 515 | + * |
|
| 516 | + * @param string $application application id |
|
| 517 | + * @param string|null $file filename |
|
| 518 | + * @param bool $prepend prepend the Script to the beginning of the list |
|
| 519 | + * @return void |
|
| 520 | + */ |
|
| 521 | + public static function addVendorScript($application, $file = null, $prepend = false) { |
|
| 522 | + $path = OC_Util::generatePath($application, 'vendor', $file); |
|
| 523 | + self::addExternalResource($application, $prepend, $path, "script"); |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + /** |
|
| 527 | + * add a translation JS file |
|
| 528 | + * |
|
| 529 | + * @deprecated 24.0.0 |
|
| 530 | + * |
|
| 531 | + * @param string $application application id |
|
| 532 | + * @param string|null $languageCode language code, defaults to the current language |
|
| 533 | + * @param bool|null $prepend prepend the Script to the beginning of the list |
|
| 534 | + */ |
|
| 535 | + public static function addTranslations($application, $languageCode = null, $prepend = false) { |
|
| 536 | + if (is_null($languageCode)) { |
|
| 537 | + $languageCode = \OC::$server->getL10NFactory()->findLanguage($application); |
|
| 538 | + } |
|
| 539 | + if (!empty($application)) { |
|
| 540 | + $path = "$application/l10n/$languageCode"; |
|
| 541 | + } else { |
|
| 542 | + $path = "l10n/$languageCode"; |
|
| 543 | + } |
|
| 544 | + self::addExternalResource($application, $prepend, $path, "script"); |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + /** |
|
| 548 | + * add a css file |
|
| 549 | + * |
|
| 550 | + * @param string $application application id |
|
| 551 | + * @param string|null $file filename |
|
| 552 | + * @param bool $prepend prepend the Style to the beginning of the list |
|
| 553 | + * @return void |
|
| 554 | + */ |
|
| 555 | + public static function addStyle($application, $file = null, $prepend = false) { |
|
| 556 | + $path = OC_Util::generatePath($application, 'css', $file); |
|
| 557 | + self::addExternalResource($application, $prepend, $path, "style"); |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + /** |
|
| 561 | + * add a css file from the vendor sub folder |
|
| 562 | + * |
|
| 563 | + * @param string $application application id |
|
| 564 | + * @param string|null $file filename |
|
| 565 | + * @param bool $prepend prepend the Style to the beginning of the list |
|
| 566 | + * @return void |
|
| 567 | + */ |
|
| 568 | + public static function addVendorStyle($application, $file = null, $prepend = false) { |
|
| 569 | + $path = OC_Util::generatePath($application, 'vendor', $file); |
|
| 570 | + self::addExternalResource($application, $prepend, $path, "style"); |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + /** |
|
| 574 | + * add an external resource css/js file |
|
| 575 | + * |
|
| 576 | + * @param string $application application id |
|
| 577 | + * @param bool $prepend prepend the file to the beginning of the list |
|
| 578 | + * @param string $path |
|
| 579 | + * @param string $type (script or style) |
|
| 580 | + * @return void |
|
| 581 | + */ |
|
| 582 | + private static function addExternalResource($application, $prepend, $path, $type = "script") { |
|
| 583 | + if ($type === "style") { |
|
| 584 | + if (!in_array($path, self::$styles)) { |
|
| 585 | + if ($prepend === true) { |
|
| 586 | + array_unshift(self::$styles, $path); |
|
| 587 | + } else { |
|
| 588 | + self::$styles[] = $path; |
|
| 589 | + } |
|
| 590 | + } |
|
| 591 | + } elseif ($type === "script") { |
|
| 592 | + if (!in_array($path, self::$scripts)) { |
|
| 593 | + if ($prepend === true) { |
|
| 594 | + array_unshift(self::$scripts, $path); |
|
| 595 | + } else { |
|
| 596 | + self::$scripts [] = $path; |
|
| 597 | + } |
|
| 598 | + } |
|
| 599 | + } |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + /** |
|
| 603 | + * Add a custom element to the header |
|
| 604 | + * If $text is null then the element will be written as empty element. |
|
| 605 | + * So use "" to get a closing tag. |
|
| 606 | + * @param string $tag tag name of the element |
|
| 607 | + * @param array $attributes array of attributes for the element |
|
| 608 | + * @param string $text the text content for the element |
|
| 609 | + * @param bool $prepend prepend the header to the beginning of the list |
|
| 610 | + */ |
|
| 611 | + public static function addHeader($tag, $attributes, $text = null, $prepend = false) { |
|
| 612 | + $header = [ |
|
| 613 | + 'tag' => $tag, |
|
| 614 | + 'attributes' => $attributes, |
|
| 615 | + 'text' => $text |
|
| 616 | + ]; |
|
| 617 | + if ($prepend === true) { |
|
| 618 | + array_unshift(self::$headers, $header); |
|
| 619 | + } else { |
|
| 620 | + self::$headers[] = $header; |
|
| 621 | + } |
|
| 622 | + } |
|
| 623 | + |
|
| 624 | + /** |
|
| 625 | + * check if the current server configuration is suitable for ownCloud |
|
| 626 | + * |
|
| 627 | + * @param \OC\SystemConfig $config |
|
| 628 | + * @return array arrays with error messages and hints |
|
| 629 | + */ |
|
| 630 | + public static function checkServer(\OC\SystemConfig $config) { |
|
| 631 | + $l = \OC::$server->getL10N('lib'); |
|
| 632 | + $errors = []; |
|
| 633 | + $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT . '/data'); |
|
| 634 | + |
|
| 635 | + if (!self::needUpgrade($config) && $config->getValue('installed', false)) { |
|
| 636 | + // this check needs to be done every time |
|
| 637 | + $errors = self::checkDataDirectoryValidity($CONFIG_DATADIRECTORY); |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + // Assume that if checkServer() succeeded before in this session, then all is fine. |
|
| 641 | + if (\OC::$server->getSession()->exists('checkServer_succeeded') && \OC::$server->getSession()->get('checkServer_succeeded')) { |
|
| 642 | + return $errors; |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + $webServerRestart = false; |
|
| 646 | + $setup = new \OC\Setup( |
|
| 647 | + $config, |
|
| 648 | + \OC::$server->get(IniGetWrapper::class), |
|
| 649 | + \OC::$server->getL10N('lib'), |
|
| 650 | + \OC::$server->get(\OCP\Defaults::class), |
|
| 651 | + \OC::$server->get(LoggerInterface::class), |
|
| 652 | + \OC::$server->getSecureRandom(), |
|
| 653 | + \OC::$server->get(\OC\Installer::class) |
|
| 654 | + ); |
|
| 655 | + |
|
| 656 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 657 | + |
|
| 658 | + $availableDatabases = $setup->getSupportedDatabases(); |
|
| 659 | + if (empty($availableDatabases)) { |
|
| 660 | + $errors[] = [ |
|
| 661 | + 'error' => $l->t('No database drivers (sqlite, mysql, or postgresql) installed.'), |
|
| 662 | + 'hint' => '' //TODO: sane hint |
|
| 663 | + ]; |
|
| 664 | + $webServerRestart = true; |
|
| 665 | + } |
|
| 666 | + |
|
| 667 | + // Check if config folder is writable. |
|
| 668 | + if (!OC_Helper::isReadOnlyConfigEnabled()) { |
|
| 669 | + if (!is_writable(OC::$configDir) or !is_readable(OC::$configDir)) { |
|
| 670 | + $errors[] = [ |
|
| 671 | + 'error' => $l->t('Cannot write into "config" directory.'), |
|
| 672 | + 'hint' => $l->t('This can usually be fixed by giving the web server write access to the config directory. See %s', |
|
| 673 | + [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) . '. ' |
|
| 674 | + . $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it. See %s', |
|
| 675 | + [ $urlGenerator->linkToDocs('admin-config') ]) |
|
| 676 | + ]; |
|
| 677 | + } |
|
| 678 | + } |
|
| 679 | + |
|
| 680 | + // Check if there is a writable install folder. |
|
| 681 | + if ($config->getValue('appstoreenabled', true)) { |
|
| 682 | + if (OC_App::getInstallPath() === null |
|
| 683 | + || !is_writable(OC_App::getInstallPath()) |
|
| 684 | + || !is_readable(OC_App::getInstallPath()) |
|
| 685 | + ) { |
|
| 686 | + $errors[] = [ |
|
| 687 | + 'error' => $l->t('Cannot write into "apps" directory.'), |
|
| 688 | + 'hint' => $l->t('This can usually be fixed by giving the web server write access to the apps directory' |
|
| 689 | + . ' or disabling the App Store in the config file.') |
|
| 690 | + ]; |
|
| 691 | + } |
|
| 692 | + } |
|
| 693 | + // Create root dir. |
|
| 694 | + if ($config->getValue('installed', false)) { |
|
| 695 | + if (!is_dir($CONFIG_DATADIRECTORY)) { |
|
| 696 | + $success = @mkdir($CONFIG_DATADIRECTORY); |
|
| 697 | + if ($success) { |
|
| 698 | + $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
| 699 | + } else { |
|
| 700 | + $errors[] = [ |
|
| 701 | + 'error' => $l->t('Cannot create "data" directory.'), |
|
| 702 | + 'hint' => $l->t('This can usually be fixed by giving the web server write access to the root directory. See %s', |
|
| 703 | + [$urlGenerator->linkToDocs('admin-dir_permissions')]) |
|
| 704 | + ]; |
|
| 705 | + } |
|
| 706 | + } elseif (!is_writable($CONFIG_DATADIRECTORY) or !is_readable($CONFIG_DATADIRECTORY)) { |
|
| 707 | + // is_writable doesn't work for NFS mounts, so try to write a file and check if it exists. |
|
| 708 | + $testFile = sprintf('%s/%s.tmp', $CONFIG_DATADIRECTORY, uniqid('data_dir_writability_test_')); |
|
| 709 | + $handle = fopen($testFile, 'w'); |
|
| 710 | + if (!$handle || fwrite($handle, 'Test write operation') === false) { |
|
| 711 | + $permissionsHint = $l->t('Permissions can usually be fixed by giving the web server write access to the root directory. See %s.', |
|
| 712 | + [$urlGenerator->linkToDocs('admin-dir_permissions')]); |
|
| 713 | + $errors[] = [ |
|
| 714 | + 'error' => $l->t('Your data directory is not writable.'), |
|
| 715 | + 'hint' => $permissionsHint |
|
| 716 | + ]; |
|
| 717 | + } else { |
|
| 718 | + fclose($handle); |
|
| 719 | + unlink($testFile); |
|
| 720 | + } |
|
| 721 | + } else { |
|
| 722 | + $errors = array_merge($errors, self::checkDataDirectoryPermissions($CONFIG_DATADIRECTORY)); |
|
| 723 | + } |
|
| 724 | + } |
|
| 725 | + |
|
| 726 | + if (!OC_Util::isSetLocaleWorking()) { |
|
| 727 | + $errors[] = [ |
|
| 728 | + 'error' => $l->t('Setting locale to %s failed.', |
|
| 729 | + ['en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/' |
|
| 730 | + . 'pt_BR.UTF-8/it_IT.UTF-8/ja_JP.UTF-8/zh_CN.UTF-8']), |
|
| 731 | + 'hint' => $l->t('Please install one of these locales on your system and restart your web server.') |
|
| 732 | + ]; |
|
| 733 | + } |
|
| 734 | + |
|
| 735 | + // Contains the dependencies that should be checked against |
|
| 736 | + // classes = class_exists |
|
| 737 | + // functions = function_exists |
|
| 738 | + // defined = defined |
|
| 739 | + // ini = ini_get |
|
| 740 | + // If the dependency is not found the missing module name is shown to the EndUser |
|
| 741 | + // When adding new checks always verify that they pass on Travis as well |
|
| 742 | + // for ini settings, see https://github.com/owncloud/administration/blob/master/travis-ci/custom.ini |
|
| 743 | + $dependencies = [ |
|
| 744 | + 'classes' => [ |
|
| 745 | + 'ZipArchive' => 'zip', |
|
| 746 | + 'DOMDocument' => 'dom', |
|
| 747 | + 'XMLWriter' => 'XMLWriter', |
|
| 748 | + 'XMLReader' => 'XMLReader', |
|
| 749 | + ], |
|
| 750 | + 'functions' => [ |
|
| 751 | + 'xml_parser_create' => 'libxml', |
|
| 752 | + 'mb_strcut' => 'mbstring', |
|
| 753 | + 'ctype_digit' => 'ctype', |
|
| 754 | + 'json_encode' => 'JSON', |
|
| 755 | + 'gd_info' => 'GD', |
|
| 756 | + 'gzencode' => 'zlib', |
|
| 757 | + 'simplexml_load_string' => 'SimpleXML', |
|
| 758 | + 'hash' => 'HASH Message Digest Framework', |
|
| 759 | + 'curl_init' => 'cURL', |
|
| 760 | + 'openssl_verify' => 'OpenSSL', |
|
| 761 | + ], |
|
| 762 | + 'defined' => [ |
|
| 763 | + 'PDO::ATTR_DRIVER_NAME' => 'PDO' |
|
| 764 | + ], |
|
| 765 | + 'ini' => [ |
|
| 766 | + 'default_charset' => 'UTF-8', |
|
| 767 | + ], |
|
| 768 | + ]; |
|
| 769 | + $missingDependencies = []; |
|
| 770 | + $invalidIniSettings = []; |
|
| 771 | + |
|
| 772 | + $iniWrapper = \OC::$server->get(IniGetWrapper::class); |
|
| 773 | + foreach ($dependencies['classes'] as $class => $module) { |
|
| 774 | + if (!class_exists($class)) { |
|
| 775 | + $missingDependencies[] = $module; |
|
| 776 | + } |
|
| 777 | + } |
|
| 778 | + foreach ($dependencies['functions'] as $function => $module) { |
|
| 779 | + if (!function_exists($function)) { |
|
| 780 | + $missingDependencies[] = $module; |
|
| 781 | + } |
|
| 782 | + } |
|
| 783 | + foreach ($dependencies['defined'] as $defined => $module) { |
|
| 784 | + if (!defined($defined)) { |
|
| 785 | + $missingDependencies[] = $module; |
|
| 786 | + } |
|
| 787 | + } |
|
| 788 | + foreach ($dependencies['ini'] as $setting => $expected) { |
|
| 789 | + if (is_bool($expected)) { |
|
| 790 | + if ($iniWrapper->getBool($setting) !== $expected) { |
|
| 791 | + $invalidIniSettings[] = [$setting, $expected]; |
|
| 792 | + } |
|
| 793 | + } |
|
| 794 | + if (is_int($expected)) { |
|
| 795 | + if ($iniWrapper->getNumeric($setting) !== $expected) { |
|
| 796 | + $invalidIniSettings[] = [$setting, $expected]; |
|
| 797 | + } |
|
| 798 | + } |
|
| 799 | + if (is_string($expected)) { |
|
| 800 | + if (strtolower($iniWrapper->getString($setting)) !== strtolower($expected)) { |
|
| 801 | + $invalidIniSettings[] = [$setting, $expected]; |
|
| 802 | + } |
|
| 803 | + } |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + foreach ($missingDependencies as $missingDependency) { |
|
| 807 | + $errors[] = [ |
|
| 808 | + 'error' => $l->t('PHP module %s not installed.', [$missingDependency]), |
|
| 809 | + 'hint' => $l->t('Please ask your server administrator to install the module.'), |
|
| 810 | + ]; |
|
| 811 | + $webServerRestart = true; |
|
| 812 | + } |
|
| 813 | + foreach ($invalidIniSettings as $setting) { |
|
| 814 | + if (is_bool($setting[1])) { |
|
| 815 | + $setting[1] = $setting[1] ? 'on' : 'off'; |
|
| 816 | + } |
|
| 817 | + $errors[] = [ |
|
| 818 | + 'error' => $l->t('PHP setting "%s" is not set to "%s".', [$setting[0], var_export($setting[1], true)]), |
|
| 819 | + 'hint' => $l->t('Adjusting this setting in php.ini will make Nextcloud run again') |
|
| 820 | + ]; |
|
| 821 | + $webServerRestart = true; |
|
| 822 | + } |
|
| 823 | + |
|
| 824 | + /** |
|
| 825 | + * The mbstring.func_overload check can only be performed if the mbstring |
|
| 826 | + * module is installed as it will return null if the checking setting is |
|
| 827 | + * not available and thus a check on the boolean value fails. |
|
| 828 | + * |
|
| 829 | + * TODO: Should probably be implemented in the above generic dependency |
|
| 830 | + * check somehow in the long-term. |
|
| 831 | + */ |
|
| 832 | + if ($iniWrapper->getBool('mbstring.func_overload') !== null && |
|
| 833 | + $iniWrapper->getBool('mbstring.func_overload') === true) { |
|
| 834 | + $errors[] = [ |
|
| 835 | + 'error' => $l->t('<code>mbstring.func_overload</code> is set to <code>%s</code> instead of the expected value <code>0</code>.', [$iniWrapper->getString('mbstring.func_overload')]), |
|
| 836 | + 'hint' => $l->t('To fix this issue set <code>mbstring.func_overload</code> to <code>0</code> in your php.ini.') |
|
| 837 | + ]; |
|
| 838 | + } |
|
| 839 | + |
|
| 840 | + if (function_exists('xml_parser_create') && |
|
| 841 | + LIBXML_LOADED_VERSION < 20700) { |
|
| 842 | + $version = LIBXML_LOADED_VERSION; |
|
| 843 | + $major = floor($version / 10000); |
|
| 844 | + $version -= ($major * 10000); |
|
| 845 | + $minor = floor($version / 100); |
|
| 846 | + $version -= ($minor * 100); |
|
| 847 | + $patch = $version; |
|
| 848 | + $errors[] = [ |
|
| 849 | + 'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major . '.' . $minor . '.' . $patch]), |
|
| 850 | + 'hint' => $l->t('To fix this issue update your libxml2 version and restart your web server.') |
|
| 851 | + ]; |
|
| 852 | + } |
|
| 853 | + |
|
| 854 | + if (!self::isAnnotationsWorking()) { |
|
| 855 | + $errors[] = [ |
|
| 856 | + 'error' => $l->t('PHP is apparently set up to strip inline doc blocks. This will make several core apps inaccessible.'), |
|
| 857 | + 'hint' => $l->t('This is probably caused by a cache/accelerator such as Zend OPcache or eAccelerator.') |
|
| 858 | + ]; |
|
| 859 | + } |
|
| 860 | + |
|
| 861 | + if (!\OC::$CLI && $webServerRestart) { |
|
| 862 | + $errors[] = [ |
|
| 863 | + 'error' => $l->t('PHP modules have been installed, but they are still listed as missing?'), |
|
| 864 | + 'hint' => $l->t('Please ask your server administrator to restart the web server.') |
|
| 865 | + ]; |
|
| 866 | + } |
|
| 867 | + |
|
| 868 | + $errors = array_merge($errors, self::checkDatabaseVersion()); |
|
| 869 | + |
|
| 870 | + // Cache the result of this function |
|
| 871 | + \OC::$server->getSession()->set('checkServer_succeeded', count($errors) == 0); |
|
| 872 | + |
|
| 873 | + return $errors; |
|
| 874 | + } |
|
| 875 | + |
|
| 876 | + /** |
|
| 877 | + * Check the database version |
|
| 878 | + * |
|
| 879 | + * @return array errors array |
|
| 880 | + */ |
|
| 881 | + public static function checkDatabaseVersion() { |
|
| 882 | + $l = \OC::$server->getL10N('lib'); |
|
| 883 | + $errors = []; |
|
| 884 | + $dbType = \OC::$server->getSystemConfig()->getValue('dbtype', 'sqlite'); |
|
| 885 | + if ($dbType === 'pgsql') { |
|
| 886 | + // check PostgreSQL version |
|
| 887 | + try { |
|
| 888 | + $result = \OC_DB::executeAudited('SHOW SERVER_VERSION'); |
|
| 889 | + $data = $result->fetchRow(); |
|
| 890 | + $result->closeCursor(); |
|
| 891 | + if (isset($data['server_version'])) { |
|
| 892 | + $version = $data['server_version']; |
|
| 893 | + if (version_compare($version, '9.0.0', '<')) { |
|
| 894 | + $errors[] = [ |
|
| 895 | + 'error' => $l->t('PostgreSQL >= 9 required.'), |
|
| 896 | + 'hint' => $l->t('Please upgrade your database version.') |
|
| 897 | + ]; |
|
| 898 | + } |
|
| 899 | + } |
|
| 900 | + } catch (\Doctrine\DBAL\Exception $e) { |
|
| 901 | + $logger = \OC::$server->getLogger(); |
|
| 902 | + $logger->warning('Error occurred while checking PostgreSQL version, assuming >= 9'); |
|
| 903 | + $logger->logException($e); |
|
| 904 | + } |
|
| 905 | + } |
|
| 906 | + return $errors; |
|
| 907 | + } |
|
| 908 | + |
|
| 909 | + /** |
|
| 910 | + * Check for correct file permissions of data directory |
|
| 911 | + * |
|
| 912 | + * @param string $dataDirectory |
|
| 913 | + * @return array arrays with error messages and hints |
|
| 914 | + */ |
|
| 915 | + public static function checkDataDirectoryPermissions($dataDirectory) { |
|
| 916 | + if (\OC::$server->getConfig()->getSystemValue('check_data_directory_permissions', true) === false) { |
|
| 917 | + return []; |
|
| 918 | + } |
|
| 919 | + |
|
| 920 | + $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
| 921 | + if (substr($perms, -1) !== '0') { |
|
| 922 | + chmod($dataDirectory, 0770); |
|
| 923 | + clearstatcache(); |
|
| 924 | + $perms = substr(decoct(@fileperms($dataDirectory)), -3); |
|
| 925 | + if ($perms[2] !== '0') { |
|
| 926 | + $l = \OC::$server->getL10N('lib'); |
|
| 927 | + return [[ |
|
| 928 | + 'error' => $l->t('Your data directory is readable by other users.'), |
|
| 929 | + 'hint' => $l->t('Please change the permissions to 0770 so that the directory cannot be listed by other users.'), |
|
| 930 | + ]]; |
|
| 931 | + } |
|
| 932 | + } |
|
| 933 | + return []; |
|
| 934 | + } |
|
| 935 | + |
|
| 936 | + /** |
|
| 937 | + * Check that the data directory exists and is valid by |
|
| 938 | + * checking the existence of the ".ocdata" file. |
|
| 939 | + * |
|
| 940 | + * @param string $dataDirectory data directory path |
|
| 941 | + * @return array errors found |
|
| 942 | + */ |
|
| 943 | + public static function checkDataDirectoryValidity($dataDirectory) { |
|
| 944 | + $l = \OC::$server->getL10N('lib'); |
|
| 945 | + $errors = []; |
|
| 946 | + if ($dataDirectory[0] !== '/') { |
|
| 947 | + $errors[] = [ |
|
| 948 | + 'error' => $l->t('Your data directory must be an absolute path.'), |
|
| 949 | + 'hint' => $l->t('Check the value of "datadirectory" in your configuration.') |
|
| 950 | + ]; |
|
| 951 | + } |
|
| 952 | + if (!file_exists($dataDirectory . '/.ocdata')) { |
|
| 953 | + $errors[] = [ |
|
| 954 | + 'error' => $l->t('Your data directory is invalid.'), |
|
| 955 | + 'hint' => $l->t('Ensure there is a file called ".ocdata"' . |
|
| 956 | + ' in the root of the data directory.') |
|
| 957 | + ]; |
|
| 958 | + } |
|
| 959 | + return $errors; |
|
| 960 | + } |
|
| 961 | + |
|
| 962 | + /** |
|
| 963 | + * Check if the user is logged in, redirects to home if not. With |
|
| 964 | + * redirect URL parameter to the request URI. |
|
| 965 | + * |
|
| 966 | + * @return void |
|
| 967 | + */ |
|
| 968 | + public static function checkLoggedIn() { |
|
| 969 | + // Check if we are a user |
|
| 970 | + if (!\OC::$server->getUserSession()->isLoggedIn()) { |
|
| 971 | + header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute( |
|
| 972 | + 'core.login.showLoginForm', |
|
| 973 | + [ |
|
| 974 | + 'redirect_url' => \OC::$server->getRequest()->getRequestUri(), |
|
| 975 | + ] |
|
| 976 | + ) |
|
| 977 | + ); |
|
| 978 | + exit(); |
|
| 979 | + } |
|
| 980 | + // Redirect to 2FA challenge selection if 2FA challenge was not solved yet |
|
| 981 | + if (\OC::$server->getTwoFactorAuthManager()->needsSecondFactor(\OC::$server->getUserSession()->getUser())) { |
|
| 982 | + header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge')); |
|
| 983 | + exit(); |
|
| 984 | + } |
|
| 985 | + } |
|
| 986 | + |
|
| 987 | + /** |
|
| 988 | + * Check if the user is a admin, redirects to home if not |
|
| 989 | + * |
|
| 990 | + * @return void |
|
| 991 | + */ |
|
| 992 | + public static function checkAdminUser() { |
|
| 993 | + OC_Util::checkLoggedIn(); |
|
| 994 | + if (!OC_User::isAdminUser(OC_User::getUser())) { |
|
| 995 | + header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 996 | + exit(); |
|
| 997 | + } |
|
| 998 | + } |
|
| 999 | + |
|
| 1000 | + /** |
|
| 1001 | + * Returns the URL of the default page |
|
| 1002 | + * based on the system configuration and |
|
| 1003 | + * the apps visible for the current user |
|
| 1004 | + * |
|
| 1005 | + * @return string URL |
|
| 1006 | + * @suppress PhanDeprecatedFunction |
|
| 1007 | + */ |
|
| 1008 | + public static function getDefaultPageUrl() { |
|
| 1009 | + /** @var IURLGenerator $urlGenerator */ |
|
| 1010 | + $urlGenerator = \OC::$server->get(IURLGenerator::class); |
|
| 1011 | + return $urlGenerator->linkToDefaultPageUrl(); |
|
| 1012 | + } |
|
| 1013 | + |
|
| 1014 | + /** |
|
| 1015 | + * Redirect to the user default page |
|
| 1016 | + * |
|
| 1017 | + * @return void |
|
| 1018 | + */ |
|
| 1019 | + public static function redirectToDefaultPage() { |
|
| 1020 | + $location = self::getDefaultPageUrl(); |
|
| 1021 | + header('Location: ' . $location); |
|
| 1022 | + exit(); |
|
| 1023 | + } |
|
| 1024 | + |
|
| 1025 | + /** |
|
| 1026 | + * get an id unique for this instance |
|
| 1027 | + * |
|
| 1028 | + * @return string |
|
| 1029 | + */ |
|
| 1030 | + public static function getInstanceId() { |
|
| 1031 | + $id = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
|
| 1032 | + if (is_null($id)) { |
|
| 1033 | + // We need to guarantee at least one letter in instanceid so it can be used as the session_name |
|
| 1034 | + $id = 'oc' . \OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
| 1035 | + \OC::$server->getSystemConfig()->setValue('instanceid', $id); |
|
| 1036 | + } |
|
| 1037 | + return $id; |
|
| 1038 | + } |
|
| 1039 | + |
|
| 1040 | + /** |
|
| 1041 | + * Public function to sanitize HTML |
|
| 1042 | + * |
|
| 1043 | + * This function is used to sanitize HTML and should be applied on any |
|
| 1044 | + * string or array of strings before displaying it on a web page. |
|
| 1045 | + * |
|
| 1046 | + * @param string|string[] $value |
|
| 1047 | + * @return string|string[] an array of sanitized strings or a single sanitized string, depends on the input parameter. |
|
| 1048 | + */ |
|
| 1049 | + public static function sanitizeHTML($value) { |
|
| 1050 | + if (is_array($value)) { |
|
| 1051 | + /** @var string[] $value */ |
|
| 1052 | + $value = array_map(function ($value) { |
|
| 1053 | + return self::sanitizeHTML($value); |
|
| 1054 | + }, $value); |
|
| 1055 | + } else { |
|
| 1056 | + // Specify encoding for PHP<5.4 |
|
| 1057 | + $value = htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 1058 | + } |
|
| 1059 | + return $value; |
|
| 1060 | + } |
|
| 1061 | + |
|
| 1062 | + /** |
|
| 1063 | + * Public function to encode url parameters |
|
| 1064 | + * |
|
| 1065 | + * This function is used to encode path to file before output. |
|
| 1066 | + * Encoding is done according to RFC 3986 with one exception: |
|
| 1067 | + * Character '/' is preserved as is. |
|
| 1068 | + * |
|
| 1069 | + * @param string $component part of URI to encode |
|
| 1070 | + * @return string |
|
| 1071 | + */ |
|
| 1072 | + public static function encodePath($component) { |
|
| 1073 | + $encoded = rawurlencode($component); |
|
| 1074 | + $encoded = str_replace('%2F', '/', $encoded); |
|
| 1075 | + return $encoded; |
|
| 1076 | + } |
|
| 1077 | + |
|
| 1078 | + |
|
| 1079 | + public function createHtaccessTestFile(\OCP\IConfig $config) { |
|
| 1080 | + // php dev server does not support htaccess |
|
| 1081 | + if (php_sapi_name() === 'cli-server') { |
|
| 1082 | + return false; |
|
| 1083 | + } |
|
| 1084 | + |
|
| 1085 | + // testdata |
|
| 1086 | + $fileName = '/htaccesstest.txt'; |
|
| 1087 | + $testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.'; |
|
| 1088 | + |
|
| 1089 | + // creating a test file |
|
| 1090 | + $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1091 | + |
|
| 1092 | + if (file_exists($testFile)) {// already running this test, possible recursive call |
|
| 1093 | + return false; |
|
| 1094 | + } |
|
| 1095 | + |
|
| 1096 | + $fp = @fopen($testFile, 'w'); |
|
| 1097 | + if (!$fp) { |
|
| 1098 | + throw new \OCP\HintException('Can\'t create test file to check for working .htaccess file.', |
|
| 1099 | + 'Make sure it is possible for the web server to write to ' . $testFile); |
|
| 1100 | + } |
|
| 1101 | + fwrite($fp, $testContent); |
|
| 1102 | + fclose($fp); |
|
| 1103 | + |
|
| 1104 | + return $testContent; |
|
| 1105 | + } |
|
| 1106 | + |
|
| 1107 | + /** |
|
| 1108 | + * Check if the .htaccess file is working |
|
| 1109 | + * |
|
| 1110 | + * @param \OCP\IConfig $config |
|
| 1111 | + * @return bool |
|
| 1112 | + * @throws Exception |
|
| 1113 | + * @throws \OCP\HintException If the test file can't get written. |
|
| 1114 | + */ |
|
| 1115 | + public function isHtaccessWorking(\OCP\IConfig $config) { |
|
| 1116 | + if (\OC::$CLI || !$config->getSystemValue('check_for_working_htaccess', true)) { |
|
| 1117 | + return true; |
|
| 1118 | + } |
|
| 1119 | + |
|
| 1120 | + $testContent = $this->createHtaccessTestFile($config); |
|
| 1121 | + if ($testContent === false) { |
|
| 1122 | + return false; |
|
| 1123 | + } |
|
| 1124 | + |
|
| 1125 | + $fileName = '/htaccesstest.txt'; |
|
| 1126 | + $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1127 | + |
|
| 1128 | + // accessing the file via http |
|
| 1129 | + $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT . '/data' . $fileName); |
|
| 1130 | + try { |
|
| 1131 | + $content = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody(); |
|
| 1132 | + } catch (\Exception $e) { |
|
| 1133 | + $content = false; |
|
| 1134 | + } |
|
| 1135 | + |
|
| 1136 | + if (strpos($url, 'https:') === 0) { |
|
| 1137 | + $url = 'http:' . substr($url, 6); |
|
| 1138 | + } else { |
|
| 1139 | + $url = 'https:' . substr($url, 5); |
|
| 1140 | + } |
|
| 1141 | + |
|
| 1142 | + try { |
|
| 1143 | + $fallbackContent = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody(); |
|
| 1144 | + } catch (\Exception $e) { |
|
| 1145 | + $fallbackContent = false; |
|
| 1146 | + } |
|
| 1147 | + |
|
| 1148 | + // cleanup |
|
| 1149 | + @unlink($testFile); |
|
| 1150 | + |
|
| 1151 | + /* |
|
| 1152 | 1152 | * If the content is not equal to test content our .htaccess |
| 1153 | 1153 | * is working as required |
| 1154 | 1154 | */ |
| 1155 | - return $content !== $testContent && $fallbackContent !== $testContent; |
|
| 1156 | - } |
|
| 1157 | - |
|
| 1158 | - /** |
|
| 1159 | - * Check if current locale is non-UTF8 |
|
| 1160 | - * |
|
| 1161 | - * @return bool |
|
| 1162 | - */ |
|
| 1163 | - private static function isNonUTF8Locale() { |
|
| 1164 | - if (function_exists('escapeshellcmd')) { |
|
| 1165 | - return '' === escapeshellcmd('§'); |
|
| 1166 | - } elseif (function_exists('escapeshellarg')) { |
|
| 1167 | - return '\'\'' === escapeshellarg('§'); |
|
| 1168 | - } else { |
|
| 1169 | - return 0 === preg_match('/utf-?8/i', setlocale(LC_CTYPE, 0)); |
|
| 1170 | - } |
|
| 1171 | - } |
|
| 1172 | - |
|
| 1173 | - /** |
|
| 1174 | - * Check if the setlocale call does not work. This can happen if the right |
|
| 1175 | - * local packages are not available on the server. |
|
| 1176 | - * |
|
| 1177 | - * @return bool |
|
| 1178 | - */ |
|
| 1179 | - public static function isSetLocaleWorking() { |
|
| 1180 | - if (self::isNonUTF8Locale()) { |
|
| 1181 | - // Borrowed from \Patchwork\Utf8\Bootup::initLocale |
|
| 1182 | - setlocale(LC_ALL, 'C.UTF-8', 'C'); |
|
| 1183 | - setlocale(LC_CTYPE, 'en_US.UTF-8', 'fr_FR.UTF-8', 'es_ES.UTF-8', 'de_DE.UTF-8', 'ru_RU.UTF-8', 'pt_BR.UTF-8', 'it_IT.UTF-8', 'ja_JP.UTF-8', 'zh_CN.UTF-8', '0'); |
|
| 1184 | - |
|
| 1185 | - // Check again |
|
| 1186 | - if (self::isNonUTF8Locale()) { |
|
| 1187 | - return false; |
|
| 1188 | - } |
|
| 1189 | - } |
|
| 1190 | - |
|
| 1191 | - return true; |
|
| 1192 | - } |
|
| 1193 | - |
|
| 1194 | - /** |
|
| 1195 | - * Check if it's possible to get the inline annotations |
|
| 1196 | - * |
|
| 1197 | - * @return bool |
|
| 1198 | - */ |
|
| 1199 | - public static function isAnnotationsWorking() { |
|
| 1200 | - $reflection = new \ReflectionMethod(__METHOD__); |
|
| 1201 | - $docs = $reflection->getDocComment(); |
|
| 1202 | - |
|
| 1203 | - return (is_string($docs) && strlen($docs) > 50); |
|
| 1204 | - } |
|
| 1205 | - |
|
| 1206 | - /** |
|
| 1207 | - * Check if the PHP module fileinfo is loaded. |
|
| 1208 | - * |
|
| 1209 | - * @return bool |
|
| 1210 | - */ |
|
| 1211 | - public static function fileInfoLoaded() { |
|
| 1212 | - return function_exists('finfo_open'); |
|
| 1213 | - } |
|
| 1214 | - |
|
| 1215 | - /** |
|
| 1216 | - * clear all levels of output buffering |
|
| 1217 | - * |
|
| 1218 | - * @return void |
|
| 1219 | - */ |
|
| 1220 | - public static function obEnd() { |
|
| 1221 | - while (ob_get_level()) { |
|
| 1222 | - ob_end_clean(); |
|
| 1223 | - } |
|
| 1224 | - } |
|
| 1225 | - |
|
| 1226 | - /** |
|
| 1227 | - * Checks whether the server is running on Mac OS X |
|
| 1228 | - * |
|
| 1229 | - * @return bool true if running on Mac OS X, false otherwise |
|
| 1230 | - */ |
|
| 1231 | - public static function runningOnMac() { |
|
| 1232 | - return (strtoupper(substr(PHP_OS, 0, 6)) === 'DARWIN'); |
|
| 1233 | - } |
|
| 1234 | - |
|
| 1235 | - /** |
|
| 1236 | - * Handles the case that there may not be a theme, then check if a "default" |
|
| 1237 | - * theme exists and take that one |
|
| 1238 | - * |
|
| 1239 | - * @return string the theme |
|
| 1240 | - */ |
|
| 1241 | - public static function getTheme() { |
|
| 1242 | - $theme = \OC::$server->getSystemConfig()->getValue("theme", ''); |
|
| 1243 | - |
|
| 1244 | - if ($theme === '') { |
|
| 1245 | - if (is_dir(OC::$SERVERROOT . '/themes/default')) { |
|
| 1246 | - $theme = 'default'; |
|
| 1247 | - } |
|
| 1248 | - } |
|
| 1249 | - |
|
| 1250 | - return $theme; |
|
| 1251 | - } |
|
| 1252 | - |
|
| 1253 | - /** |
|
| 1254 | - * Normalize a unicode string |
|
| 1255 | - * |
|
| 1256 | - * @param string $value a not normalized string |
|
| 1257 | - * @return bool|string |
|
| 1258 | - */ |
|
| 1259 | - public static function normalizeUnicode($value) { |
|
| 1260 | - if (Normalizer::isNormalized($value)) { |
|
| 1261 | - return $value; |
|
| 1262 | - } |
|
| 1263 | - |
|
| 1264 | - $normalizedValue = Normalizer::normalize($value); |
|
| 1265 | - if ($normalizedValue === null || $normalizedValue === false) { |
|
| 1266 | - \OC::$server->getLogger()->warning('normalizing failed for "' . $value . '"', ['app' => 'core']); |
|
| 1267 | - return $value; |
|
| 1268 | - } |
|
| 1269 | - |
|
| 1270 | - return $normalizedValue; |
|
| 1271 | - } |
|
| 1272 | - |
|
| 1273 | - /** |
|
| 1274 | - * A human readable string is generated based on version and build number |
|
| 1275 | - * |
|
| 1276 | - * @return string |
|
| 1277 | - */ |
|
| 1278 | - public static function getHumanVersion() { |
|
| 1279 | - $version = OC_Util::getVersionString(); |
|
| 1280 | - $build = OC_Util::getBuild(); |
|
| 1281 | - if (!empty($build) and OC_Util::getChannel() === 'daily') { |
|
| 1282 | - $version .= ' Build:' . $build; |
|
| 1283 | - } |
|
| 1284 | - return $version; |
|
| 1285 | - } |
|
| 1286 | - |
|
| 1287 | - /** |
|
| 1288 | - * Returns whether the given file name is valid |
|
| 1289 | - * |
|
| 1290 | - * @param string $file file name to check |
|
| 1291 | - * @return bool true if the file name is valid, false otherwise |
|
| 1292 | - * @deprecated use \OC\Files\View::verifyPath() |
|
| 1293 | - */ |
|
| 1294 | - public static function isValidFileName($file) { |
|
| 1295 | - $trimmed = trim($file); |
|
| 1296 | - if ($trimmed === '') { |
|
| 1297 | - return false; |
|
| 1298 | - } |
|
| 1299 | - if (\OC\Files\Filesystem::isIgnoredDir($trimmed)) { |
|
| 1300 | - return false; |
|
| 1301 | - } |
|
| 1302 | - |
|
| 1303 | - // detect part files |
|
| 1304 | - if (preg_match('/' . \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX . '/', $trimmed) !== 0) { |
|
| 1305 | - return false; |
|
| 1306 | - } |
|
| 1307 | - |
|
| 1308 | - foreach (str_split($trimmed) as $char) { |
|
| 1309 | - if (strpos(\OCP\Constants::FILENAME_INVALID_CHARS, $char) !== false) { |
|
| 1310 | - return false; |
|
| 1311 | - } |
|
| 1312 | - } |
|
| 1313 | - return true; |
|
| 1314 | - } |
|
| 1315 | - |
|
| 1316 | - /** |
|
| 1317 | - * Check whether the instance needs to perform an upgrade, |
|
| 1318 | - * either when the core version is higher or any app requires |
|
| 1319 | - * an upgrade. |
|
| 1320 | - * |
|
| 1321 | - * @param \OC\SystemConfig $config |
|
| 1322 | - * @return bool whether the core or any app needs an upgrade |
|
| 1323 | - * @throws \OCP\HintException When the upgrade from the given version is not allowed |
|
| 1324 | - */ |
|
| 1325 | - public static function needUpgrade(\OC\SystemConfig $config) { |
|
| 1326 | - if ($config->getValue('installed', false)) { |
|
| 1327 | - $installedVersion = $config->getValue('version', '0.0.0'); |
|
| 1328 | - $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 1329 | - $versionDiff = version_compare($currentVersion, $installedVersion); |
|
| 1330 | - if ($versionDiff > 0) { |
|
| 1331 | - return true; |
|
| 1332 | - } elseif ($config->getValue('debug', false) && $versionDiff < 0) { |
|
| 1333 | - // downgrade with debug |
|
| 1334 | - $installedMajor = explode('.', $installedVersion); |
|
| 1335 | - $installedMajor = $installedMajor[0] . '.' . $installedMajor[1]; |
|
| 1336 | - $currentMajor = explode('.', $currentVersion); |
|
| 1337 | - $currentMajor = $currentMajor[0] . '.' . $currentMajor[1]; |
|
| 1338 | - if ($installedMajor === $currentMajor) { |
|
| 1339 | - // Same major, allow downgrade for developers |
|
| 1340 | - return true; |
|
| 1341 | - } else { |
|
| 1342 | - // downgrade attempt, throw exception |
|
| 1343 | - throw new \OCP\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1344 | - } |
|
| 1345 | - } elseif ($versionDiff < 0) { |
|
| 1346 | - // downgrade attempt, throw exception |
|
| 1347 | - throw new \OCP\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1348 | - } |
|
| 1349 | - |
|
| 1350 | - // also check for upgrades for apps (independently from the user) |
|
| 1351 | - $apps = \OC_App::getEnabledApps(false, true); |
|
| 1352 | - $shouldUpgrade = false; |
|
| 1353 | - foreach ($apps as $app) { |
|
| 1354 | - if (\OC_App::shouldUpgrade($app)) { |
|
| 1355 | - $shouldUpgrade = true; |
|
| 1356 | - break; |
|
| 1357 | - } |
|
| 1358 | - } |
|
| 1359 | - return $shouldUpgrade; |
|
| 1360 | - } else { |
|
| 1361 | - return false; |
|
| 1362 | - } |
|
| 1363 | - } |
|
| 1155 | + return $content !== $testContent && $fallbackContent !== $testContent; |
|
| 1156 | + } |
|
| 1157 | + |
|
| 1158 | + /** |
|
| 1159 | + * Check if current locale is non-UTF8 |
|
| 1160 | + * |
|
| 1161 | + * @return bool |
|
| 1162 | + */ |
|
| 1163 | + private static function isNonUTF8Locale() { |
|
| 1164 | + if (function_exists('escapeshellcmd')) { |
|
| 1165 | + return '' === escapeshellcmd('§'); |
|
| 1166 | + } elseif (function_exists('escapeshellarg')) { |
|
| 1167 | + return '\'\'' === escapeshellarg('§'); |
|
| 1168 | + } else { |
|
| 1169 | + return 0 === preg_match('/utf-?8/i', setlocale(LC_CTYPE, 0)); |
|
| 1170 | + } |
|
| 1171 | + } |
|
| 1172 | + |
|
| 1173 | + /** |
|
| 1174 | + * Check if the setlocale call does not work. This can happen if the right |
|
| 1175 | + * local packages are not available on the server. |
|
| 1176 | + * |
|
| 1177 | + * @return bool |
|
| 1178 | + */ |
|
| 1179 | + public static function isSetLocaleWorking() { |
|
| 1180 | + if (self::isNonUTF8Locale()) { |
|
| 1181 | + // Borrowed from \Patchwork\Utf8\Bootup::initLocale |
|
| 1182 | + setlocale(LC_ALL, 'C.UTF-8', 'C'); |
|
| 1183 | + setlocale(LC_CTYPE, 'en_US.UTF-8', 'fr_FR.UTF-8', 'es_ES.UTF-8', 'de_DE.UTF-8', 'ru_RU.UTF-8', 'pt_BR.UTF-8', 'it_IT.UTF-8', 'ja_JP.UTF-8', 'zh_CN.UTF-8', '0'); |
|
| 1184 | + |
|
| 1185 | + // Check again |
|
| 1186 | + if (self::isNonUTF8Locale()) { |
|
| 1187 | + return false; |
|
| 1188 | + } |
|
| 1189 | + } |
|
| 1190 | + |
|
| 1191 | + return true; |
|
| 1192 | + } |
|
| 1193 | + |
|
| 1194 | + /** |
|
| 1195 | + * Check if it's possible to get the inline annotations |
|
| 1196 | + * |
|
| 1197 | + * @return bool |
|
| 1198 | + */ |
|
| 1199 | + public static function isAnnotationsWorking() { |
|
| 1200 | + $reflection = new \ReflectionMethod(__METHOD__); |
|
| 1201 | + $docs = $reflection->getDocComment(); |
|
| 1202 | + |
|
| 1203 | + return (is_string($docs) && strlen($docs) > 50); |
|
| 1204 | + } |
|
| 1205 | + |
|
| 1206 | + /** |
|
| 1207 | + * Check if the PHP module fileinfo is loaded. |
|
| 1208 | + * |
|
| 1209 | + * @return bool |
|
| 1210 | + */ |
|
| 1211 | + public static function fileInfoLoaded() { |
|
| 1212 | + return function_exists('finfo_open'); |
|
| 1213 | + } |
|
| 1214 | + |
|
| 1215 | + /** |
|
| 1216 | + * clear all levels of output buffering |
|
| 1217 | + * |
|
| 1218 | + * @return void |
|
| 1219 | + */ |
|
| 1220 | + public static function obEnd() { |
|
| 1221 | + while (ob_get_level()) { |
|
| 1222 | + ob_end_clean(); |
|
| 1223 | + } |
|
| 1224 | + } |
|
| 1225 | + |
|
| 1226 | + /** |
|
| 1227 | + * Checks whether the server is running on Mac OS X |
|
| 1228 | + * |
|
| 1229 | + * @return bool true if running on Mac OS X, false otherwise |
|
| 1230 | + */ |
|
| 1231 | + public static function runningOnMac() { |
|
| 1232 | + return (strtoupper(substr(PHP_OS, 0, 6)) === 'DARWIN'); |
|
| 1233 | + } |
|
| 1234 | + |
|
| 1235 | + /** |
|
| 1236 | + * Handles the case that there may not be a theme, then check if a "default" |
|
| 1237 | + * theme exists and take that one |
|
| 1238 | + * |
|
| 1239 | + * @return string the theme |
|
| 1240 | + */ |
|
| 1241 | + public static function getTheme() { |
|
| 1242 | + $theme = \OC::$server->getSystemConfig()->getValue("theme", ''); |
|
| 1243 | + |
|
| 1244 | + if ($theme === '') { |
|
| 1245 | + if (is_dir(OC::$SERVERROOT . '/themes/default')) { |
|
| 1246 | + $theme = 'default'; |
|
| 1247 | + } |
|
| 1248 | + } |
|
| 1249 | + |
|
| 1250 | + return $theme; |
|
| 1251 | + } |
|
| 1252 | + |
|
| 1253 | + /** |
|
| 1254 | + * Normalize a unicode string |
|
| 1255 | + * |
|
| 1256 | + * @param string $value a not normalized string |
|
| 1257 | + * @return bool|string |
|
| 1258 | + */ |
|
| 1259 | + public static function normalizeUnicode($value) { |
|
| 1260 | + if (Normalizer::isNormalized($value)) { |
|
| 1261 | + return $value; |
|
| 1262 | + } |
|
| 1263 | + |
|
| 1264 | + $normalizedValue = Normalizer::normalize($value); |
|
| 1265 | + if ($normalizedValue === null || $normalizedValue === false) { |
|
| 1266 | + \OC::$server->getLogger()->warning('normalizing failed for "' . $value . '"', ['app' => 'core']); |
|
| 1267 | + return $value; |
|
| 1268 | + } |
|
| 1269 | + |
|
| 1270 | + return $normalizedValue; |
|
| 1271 | + } |
|
| 1272 | + |
|
| 1273 | + /** |
|
| 1274 | + * A human readable string is generated based on version and build number |
|
| 1275 | + * |
|
| 1276 | + * @return string |
|
| 1277 | + */ |
|
| 1278 | + public static function getHumanVersion() { |
|
| 1279 | + $version = OC_Util::getVersionString(); |
|
| 1280 | + $build = OC_Util::getBuild(); |
|
| 1281 | + if (!empty($build) and OC_Util::getChannel() === 'daily') { |
|
| 1282 | + $version .= ' Build:' . $build; |
|
| 1283 | + } |
|
| 1284 | + return $version; |
|
| 1285 | + } |
|
| 1286 | + |
|
| 1287 | + /** |
|
| 1288 | + * Returns whether the given file name is valid |
|
| 1289 | + * |
|
| 1290 | + * @param string $file file name to check |
|
| 1291 | + * @return bool true if the file name is valid, false otherwise |
|
| 1292 | + * @deprecated use \OC\Files\View::verifyPath() |
|
| 1293 | + */ |
|
| 1294 | + public static function isValidFileName($file) { |
|
| 1295 | + $trimmed = trim($file); |
|
| 1296 | + if ($trimmed === '') { |
|
| 1297 | + return false; |
|
| 1298 | + } |
|
| 1299 | + if (\OC\Files\Filesystem::isIgnoredDir($trimmed)) { |
|
| 1300 | + return false; |
|
| 1301 | + } |
|
| 1302 | + |
|
| 1303 | + // detect part files |
|
| 1304 | + if (preg_match('/' . \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX . '/', $trimmed) !== 0) { |
|
| 1305 | + return false; |
|
| 1306 | + } |
|
| 1307 | + |
|
| 1308 | + foreach (str_split($trimmed) as $char) { |
|
| 1309 | + if (strpos(\OCP\Constants::FILENAME_INVALID_CHARS, $char) !== false) { |
|
| 1310 | + return false; |
|
| 1311 | + } |
|
| 1312 | + } |
|
| 1313 | + return true; |
|
| 1314 | + } |
|
| 1315 | + |
|
| 1316 | + /** |
|
| 1317 | + * Check whether the instance needs to perform an upgrade, |
|
| 1318 | + * either when the core version is higher or any app requires |
|
| 1319 | + * an upgrade. |
|
| 1320 | + * |
|
| 1321 | + * @param \OC\SystemConfig $config |
|
| 1322 | + * @return bool whether the core or any app needs an upgrade |
|
| 1323 | + * @throws \OCP\HintException When the upgrade from the given version is not allowed |
|
| 1324 | + */ |
|
| 1325 | + public static function needUpgrade(\OC\SystemConfig $config) { |
|
| 1326 | + if ($config->getValue('installed', false)) { |
|
| 1327 | + $installedVersion = $config->getValue('version', '0.0.0'); |
|
| 1328 | + $currentVersion = implode('.', \OCP\Util::getVersion()); |
|
| 1329 | + $versionDiff = version_compare($currentVersion, $installedVersion); |
|
| 1330 | + if ($versionDiff > 0) { |
|
| 1331 | + return true; |
|
| 1332 | + } elseif ($config->getValue('debug', false) && $versionDiff < 0) { |
|
| 1333 | + // downgrade with debug |
|
| 1334 | + $installedMajor = explode('.', $installedVersion); |
|
| 1335 | + $installedMajor = $installedMajor[0] . '.' . $installedMajor[1]; |
|
| 1336 | + $currentMajor = explode('.', $currentVersion); |
|
| 1337 | + $currentMajor = $currentMajor[0] . '.' . $currentMajor[1]; |
|
| 1338 | + if ($installedMajor === $currentMajor) { |
|
| 1339 | + // Same major, allow downgrade for developers |
|
| 1340 | + return true; |
|
| 1341 | + } else { |
|
| 1342 | + // downgrade attempt, throw exception |
|
| 1343 | + throw new \OCP\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1344 | + } |
|
| 1345 | + } elseif ($versionDiff < 0) { |
|
| 1346 | + // downgrade attempt, throw exception |
|
| 1347 | + throw new \OCP\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1348 | + } |
|
| 1349 | + |
|
| 1350 | + // also check for upgrades for apps (independently from the user) |
|
| 1351 | + $apps = \OC_App::getEnabledApps(false, true); |
|
| 1352 | + $shouldUpgrade = false; |
|
| 1353 | + foreach ($apps as $app) { |
|
| 1354 | + if (\OC_App::shouldUpgrade($app)) { |
|
| 1355 | + $shouldUpgrade = true; |
|
| 1356 | + break; |
|
| 1357 | + } |
|
| 1358 | + } |
|
| 1359 | + return $shouldUpgrade; |
|
| 1360 | + } else { |
|
| 1361 | + return false; |
|
| 1362 | + } |
|
| 1363 | + } |
|
| 1364 | 1364 | } |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | \OC\Files\Filesystem::initMountManager(); |
| 114 | 114 | |
| 115 | 115 | $prevLogging = \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); |
| 116 | - \OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 116 | + \OC\Files\Filesystem::addStorageWrapper('mount_options', function($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 117 | 117 | if ($storage->instanceOfStorage('\OC\Files\Storage\Common')) { |
| 118 | 118 | /** @var \OC\Files\Storage\Common $storage */ |
| 119 | 119 | $storage->setMountOptions($mount->getOptions()); |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | return $storage; |
| 122 | 122 | }); |
| 123 | 123 | |
| 124 | - \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 124 | + \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 125 | 125 | if (!$mount->getOption('enable_sharing', true)) { |
| 126 | 126 | return new \OC\Files\Storage\Wrapper\PermissionsMask([ |
| 127 | 127 | 'storage' => $storage, |
@@ -132,21 +132,21 @@ discard block |
||
| 132 | 132 | }); |
| 133 | 133 | |
| 134 | 134 | // install storage availability wrapper, before most other wrappers |
| 135 | - \OC\Files\Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, \OCP\Files\Storage\IStorage $storage) { |
|
| 135 | + \OC\Files\Filesystem::addStorageWrapper('oc_availability', function($mountPoint, \OCP\Files\Storage\IStorage $storage) { |
|
| 136 | 136 | if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
| 137 | 137 | return new \OC\Files\Storage\Wrapper\Availability(['storage' => $storage]); |
| 138 | 138 | } |
| 139 | 139 | return $storage; |
| 140 | 140 | }); |
| 141 | 141 | |
| 142 | - \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 142 | + \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 143 | 143 | if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { |
| 144 | 144 | return new \OC\Files\Storage\Wrapper\Encoding(['storage' => $storage]); |
| 145 | 145 | } |
| 146 | 146 | return $storage; |
| 147 | 147 | }); |
| 148 | 148 | |
| 149 | - \OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) { |
|
| 149 | + \OC\Files\Filesystem::addStorageWrapper('oc_quota', function($mountPoint, $storage) { |
|
| 150 | 150 | // set up quota for home storages, even for other users |
| 151 | 151 | // which can happen when using sharing |
| 152 | 152 | |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | return $storage; |
| 169 | 169 | }); |
| 170 | 170 | |
| 171 | - \OC\Files\Filesystem::addStorageWrapper('readonly', function ($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 171 | + \OC\Files\Filesystem::addStorageWrapper('readonly', function($mountPoint, \OCP\Files\Storage\IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { |
|
| 172 | 172 | /* |
| 173 | 173 | * Do not allow any operations that modify the storage |
| 174 | 174 | */ |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | if ($userObject) { |
| 234 | 234 | self::$fsSetup = true; |
| 235 | 235 | |
| 236 | - $userDir = '/' . $userObject->getUID() . '/files'; |
|
| 236 | + $userDir = '/'.$userObject->getUID().'/files'; |
|
| 237 | 237 | |
| 238 | 238 | //jail the user into his "home" directory |
| 239 | 239 | \OC\Files\Filesystem::init($userObject, $userDir); |
@@ -312,7 +312,7 @@ discard block |
||
| 312 | 312 | /** @var LoggerInterface $logger */ |
| 313 | 313 | $logger = \OC::$server->get(LoggerInterface::class); |
| 314 | 314 | |
| 315 | - $plainSkeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT . '/core/skeleton'); |
|
| 315 | + $plainSkeletonDirectory = \OC::$server->getConfig()->getSystemValue('skeletondirectory', \OC::$SERVERROOT.'/core/skeleton'); |
|
| 316 | 316 | $userLang = \OC::$server->getL10NFactory()->findLanguage(); |
| 317 | 317 | $skeletonDirectory = str_replace('{lang}', $userLang, $plainSkeletonDirectory); |
| 318 | 318 | |
@@ -334,9 +334,9 @@ discard block |
||
| 334 | 334 | if ($instanceId === null) { |
| 335 | 335 | throw new \RuntimeException('no instance id!'); |
| 336 | 336 | } |
| 337 | - $appdata = 'appdata_' . $instanceId; |
|
| 337 | + $appdata = 'appdata_'.$instanceId; |
|
| 338 | 338 | if ($userId === $appdata) { |
| 339 | - throw new \RuntimeException('username is reserved name: ' . $appdata); |
|
| 339 | + throw new \RuntimeException('username is reserved name: '.$appdata); |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | if (!empty($skeletonDirectory)) { |
@@ -371,14 +371,14 @@ discard block |
||
| 371 | 371 | // Copy the files |
| 372 | 372 | while (false !== ($file = readdir($dir))) { |
| 373 | 373 | if (!\OC\Files\Filesystem::isIgnoredDir($file)) { |
| 374 | - if (is_dir($source . '/' . $file)) { |
|
| 374 | + if (is_dir($source.'/'.$file)) { |
|
| 375 | 375 | $child = $target->newFolder($file); |
| 376 | - self::copyr($source . '/' . $file, $child); |
|
| 376 | + self::copyr($source.'/'.$file, $child); |
|
| 377 | 377 | } else { |
| 378 | 378 | $child = $target->newFile($file); |
| 379 | - $sourceStream = fopen($source . '/' . $file, 'r'); |
|
| 379 | + $sourceStream = fopen($source.'/'.$file, 'r'); |
|
| 380 | 380 | if ($sourceStream === false) { |
| 381 | - $logger->error(sprintf('Could not fopen "%s"', $source . '/' . $file), ['app' => 'core']); |
|
| 381 | + $logger->error(sprintf('Could not fopen "%s"', $source.'/'.$file), ['app' => 'core']); |
|
| 382 | 382 | closedir($dir); |
| 383 | 383 | return; |
| 384 | 384 | } |
@@ -455,8 +455,8 @@ discard block |
||
| 455 | 455 | return; |
| 456 | 456 | } |
| 457 | 457 | |
| 458 | - $timestamp = filemtime(OC::$SERVERROOT . '/version.php'); |
|
| 459 | - require OC::$SERVERROOT . '/version.php'; |
|
| 458 | + $timestamp = filemtime(OC::$SERVERROOT.'/version.php'); |
|
| 459 | + require OC::$SERVERROOT.'/version.php'; |
|
| 460 | 460 | /** @var int $timestamp */ |
| 461 | 461 | self::$versionCache['OC_Version_Timestamp'] = $timestamp; |
| 462 | 462 | /** @var string $OC_Version */ |
@@ -630,7 +630,7 @@ discard block |
||
| 630 | 630 | public static function checkServer(\OC\SystemConfig $config) { |
| 631 | 631 | $l = \OC::$server->getL10N('lib'); |
| 632 | 632 | $errors = []; |
| 633 | - $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT . '/data'); |
|
| 633 | + $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT.'/data'); |
|
| 634 | 634 | |
| 635 | 635 | if (!self::needUpgrade($config) && $config->getValue('installed', false)) { |
| 636 | 636 | // this check needs to be done every time |
@@ -670,9 +670,9 @@ discard block |
||
| 670 | 670 | $errors[] = [ |
| 671 | 671 | 'error' => $l->t('Cannot write into "config" directory.'), |
| 672 | 672 | 'hint' => $l->t('This can usually be fixed by giving the web server write access to the config directory. See %s', |
| 673 | - [ $urlGenerator->linkToDocs('admin-dir_permissions') ]) . '. ' |
|
| 673 | + [$urlGenerator->linkToDocs('admin-dir_permissions')]).'. ' |
|
| 674 | 674 | . $l->t('Or, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it. See %s', |
| 675 | - [ $urlGenerator->linkToDocs('admin-config') ]) |
|
| 675 | + [$urlGenerator->linkToDocs('admin-config')]) |
|
| 676 | 676 | ]; |
| 677 | 677 | } |
| 678 | 678 | } |
@@ -846,7 +846,7 @@ discard block |
||
| 846 | 846 | $version -= ($minor * 100); |
| 847 | 847 | $patch = $version; |
| 848 | 848 | $errors[] = [ |
| 849 | - 'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major . '.' . $minor . '.' . $patch]), |
|
| 849 | + 'error' => $l->t('libxml2 2.7.0 is at least required. Currently %s is installed.', [$major.'.'.$minor.'.'.$patch]), |
|
| 850 | 850 | 'hint' => $l->t('To fix this issue update your libxml2 version and restart your web server.') |
| 851 | 851 | ]; |
| 852 | 852 | } |
@@ -949,10 +949,10 @@ discard block |
||
| 949 | 949 | 'hint' => $l->t('Check the value of "datadirectory" in your configuration.') |
| 950 | 950 | ]; |
| 951 | 951 | } |
| 952 | - if (!file_exists($dataDirectory . '/.ocdata')) { |
|
| 952 | + if (!file_exists($dataDirectory.'/.ocdata')) { |
|
| 953 | 953 | $errors[] = [ |
| 954 | 954 | 'error' => $l->t('Your data directory is invalid.'), |
| 955 | - 'hint' => $l->t('Ensure there is a file called ".ocdata"' . |
|
| 955 | + 'hint' => $l->t('Ensure there is a file called ".ocdata"'. |
|
| 956 | 956 | ' in the root of the data directory.') |
| 957 | 957 | ]; |
| 958 | 958 | } |
@@ -968,7 +968,7 @@ discard block |
||
| 968 | 968 | public static function checkLoggedIn() { |
| 969 | 969 | // Check if we are a user |
| 970 | 970 | if (!\OC::$server->getUserSession()->isLoggedIn()) { |
| 971 | - header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute( |
|
| 971 | + header('Location: '.\OC::$server->getURLGenerator()->linkToRoute( |
|
| 972 | 972 | 'core.login.showLoginForm', |
| 973 | 973 | [ |
| 974 | 974 | 'redirect_url' => \OC::$server->getRequest()->getRequestUri(), |
@@ -979,7 +979,7 @@ discard block |
||
| 979 | 979 | } |
| 980 | 980 | // Redirect to 2FA challenge selection if 2FA challenge was not solved yet |
| 981 | 981 | if (\OC::$server->getTwoFactorAuthManager()->needsSecondFactor(\OC::$server->getUserSession()->getUser())) { |
| 982 | - header('Location: ' . \OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge')); |
|
| 982 | + header('Location: '.\OC::$server->getURLGenerator()->linkToRoute('core.TwoFactorChallenge.selectChallenge')); |
|
| 983 | 983 | exit(); |
| 984 | 984 | } |
| 985 | 985 | } |
@@ -992,7 +992,7 @@ discard block |
||
| 992 | 992 | public static function checkAdminUser() { |
| 993 | 993 | OC_Util::checkLoggedIn(); |
| 994 | 994 | if (!OC_User::isAdminUser(OC_User::getUser())) { |
| 995 | - header('Location: ' . \OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 995 | + header('Location: '.\OCP\Util::linkToAbsolute('', 'index.php')); |
|
| 996 | 996 | exit(); |
| 997 | 997 | } |
| 998 | 998 | } |
@@ -1018,7 +1018,7 @@ discard block |
||
| 1018 | 1018 | */ |
| 1019 | 1019 | public static function redirectToDefaultPage() { |
| 1020 | 1020 | $location = self::getDefaultPageUrl(); |
| 1021 | - header('Location: ' . $location); |
|
| 1021 | + header('Location: '.$location); |
|
| 1022 | 1022 | exit(); |
| 1023 | 1023 | } |
| 1024 | 1024 | |
@@ -1031,7 +1031,7 @@ discard block |
||
| 1031 | 1031 | $id = \OC::$server->getSystemConfig()->getValue('instanceid', null); |
| 1032 | 1032 | if (is_null($id)) { |
| 1033 | 1033 | // We need to guarantee at least one letter in instanceid so it can be used as the session_name |
| 1034 | - $id = 'oc' . \OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
| 1034 | + $id = 'oc'.\OC::$server->getSecureRandom()->generate(10, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
| 1035 | 1035 | \OC::$server->getSystemConfig()->setValue('instanceid', $id); |
| 1036 | 1036 | } |
| 1037 | 1037 | return $id; |
@@ -1049,12 +1049,12 @@ discard block |
||
| 1049 | 1049 | public static function sanitizeHTML($value) { |
| 1050 | 1050 | if (is_array($value)) { |
| 1051 | 1051 | /** @var string[] $value */ |
| 1052 | - $value = array_map(function ($value) { |
|
| 1052 | + $value = array_map(function($value) { |
|
| 1053 | 1053 | return self::sanitizeHTML($value); |
| 1054 | 1054 | }, $value); |
| 1055 | 1055 | } else { |
| 1056 | 1056 | // Specify encoding for PHP<5.4 |
| 1057 | - $value = htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 1057 | + $value = htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8'); |
|
| 1058 | 1058 | } |
| 1059 | 1059 | return $value; |
| 1060 | 1060 | } |
@@ -1087,7 +1087,7 @@ discard block |
||
| 1087 | 1087 | $testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.'; |
| 1088 | 1088 | |
| 1089 | 1089 | // creating a test file |
| 1090 | - $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1090 | + $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT.'/data').'/'.$fileName; |
|
| 1091 | 1091 | |
| 1092 | 1092 | if (file_exists($testFile)) {// already running this test, possible recursive call |
| 1093 | 1093 | return false; |
@@ -1096,7 +1096,7 @@ discard block |
||
| 1096 | 1096 | $fp = @fopen($testFile, 'w'); |
| 1097 | 1097 | if (!$fp) { |
| 1098 | 1098 | throw new \OCP\HintException('Can\'t create test file to check for working .htaccess file.', |
| 1099 | - 'Make sure it is possible for the web server to write to ' . $testFile); |
|
| 1099 | + 'Make sure it is possible for the web server to write to '.$testFile); |
|
| 1100 | 1100 | } |
| 1101 | 1101 | fwrite($fp, $testContent); |
| 1102 | 1102 | fclose($fp); |
@@ -1123,10 +1123,10 @@ discard block |
||
| 1123 | 1123 | } |
| 1124 | 1124 | |
| 1125 | 1125 | $fileName = '/htaccesstest.txt'; |
| 1126 | - $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $fileName; |
|
| 1126 | + $testFile = $config->getSystemValue('datadirectory', OC::$SERVERROOT.'/data').'/'.$fileName; |
|
| 1127 | 1127 | |
| 1128 | 1128 | // accessing the file via http |
| 1129 | - $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT . '/data' . $fileName); |
|
| 1129 | + $url = \OC::$server->getURLGenerator()->getAbsoluteURL(OC::$WEBROOT.'/data'.$fileName); |
|
| 1130 | 1130 | try { |
| 1131 | 1131 | $content = \OC::$server->getHTTPClientService()->newClient()->get($url)->getBody(); |
| 1132 | 1132 | } catch (\Exception $e) { |
@@ -1134,9 +1134,9 @@ discard block |
||
| 1134 | 1134 | } |
| 1135 | 1135 | |
| 1136 | 1136 | if (strpos($url, 'https:') === 0) { |
| 1137 | - $url = 'http:' . substr($url, 6); |
|
| 1137 | + $url = 'http:'.substr($url, 6); |
|
| 1138 | 1138 | } else { |
| 1139 | - $url = 'https:' . substr($url, 5); |
|
| 1139 | + $url = 'https:'.substr($url, 5); |
|
| 1140 | 1140 | } |
| 1141 | 1141 | |
| 1142 | 1142 | try { |
@@ -1242,7 +1242,7 @@ discard block |
||
| 1242 | 1242 | $theme = \OC::$server->getSystemConfig()->getValue("theme", ''); |
| 1243 | 1243 | |
| 1244 | 1244 | if ($theme === '') { |
| 1245 | - if (is_dir(OC::$SERVERROOT . '/themes/default')) { |
|
| 1245 | + if (is_dir(OC::$SERVERROOT.'/themes/default')) { |
|
| 1246 | 1246 | $theme = 'default'; |
| 1247 | 1247 | } |
| 1248 | 1248 | } |
@@ -1263,7 +1263,7 @@ discard block |
||
| 1263 | 1263 | |
| 1264 | 1264 | $normalizedValue = Normalizer::normalize($value); |
| 1265 | 1265 | if ($normalizedValue === null || $normalizedValue === false) { |
| 1266 | - \OC::$server->getLogger()->warning('normalizing failed for "' . $value . '"', ['app' => 'core']); |
|
| 1266 | + \OC::$server->getLogger()->warning('normalizing failed for "'.$value.'"', ['app' => 'core']); |
|
| 1267 | 1267 | return $value; |
| 1268 | 1268 | } |
| 1269 | 1269 | |
@@ -1279,7 +1279,7 @@ discard block |
||
| 1279 | 1279 | $version = OC_Util::getVersionString(); |
| 1280 | 1280 | $build = OC_Util::getBuild(); |
| 1281 | 1281 | if (!empty($build) and OC_Util::getChannel() === 'daily') { |
| 1282 | - $version .= ' Build:' . $build; |
|
| 1282 | + $version .= ' Build:'.$build; |
|
| 1283 | 1283 | } |
| 1284 | 1284 | return $version; |
| 1285 | 1285 | } |
@@ -1301,7 +1301,7 @@ discard block |
||
| 1301 | 1301 | } |
| 1302 | 1302 | |
| 1303 | 1303 | // detect part files |
| 1304 | - if (preg_match('/' . \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX . '/', $trimmed) !== 0) { |
|
| 1304 | + if (preg_match('/'.\OCP\Files\FileInfo::BLACKLIST_FILES_REGEX.'/', $trimmed) !== 0) { |
|
| 1305 | 1305 | return false; |
| 1306 | 1306 | } |
| 1307 | 1307 | |
@@ -1332,19 +1332,19 @@ discard block |
||
| 1332 | 1332 | } elseif ($config->getValue('debug', false) && $versionDiff < 0) { |
| 1333 | 1333 | // downgrade with debug |
| 1334 | 1334 | $installedMajor = explode('.', $installedVersion); |
| 1335 | - $installedMajor = $installedMajor[0] . '.' . $installedMajor[1]; |
|
| 1335 | + $installedMajor = $installedMajor[0].'.'.$installedMajor[1]; |
|
| 1336 | 1336 | $currentMajor = explode('.', $currentVersion); |
| 1337 | - $currentMajor = $currentMajor[0] . '.' . $currentMajor[1]; |
|
| 1337 | + $currentMajor = $currentMajor[0].'.'.$currentMajor[1]; |
|
| 1338 | 1338 | if ($installedMajor === $currentMajor) { |
| 1339 | 1339 | // Same major, allow downgrade for developers |
| 1340 | 1340 | return true; |
| 1341 | 1341 | } else { |
| 1342 | 1342 | // downgrade attempt, throw exception |
| 1343 | - throw new \OCP\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1343 | + throw new \OCP\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from '.$installedVersion.' to '.$currentVersion.')'); |
|
| 1344 | 1344 | } |
| 1345 | 1345 | } elseif ($versionDiff < 0) { |
| 1346 | 1346 | // downgrade attempt, throw exception |
| 1347 | - throw new \OCP\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from ' . $installedVersion . ' to ' . $currentVersion . ')'); |
|
| 1347 | + throw new \OCP\HintException('Downgrading is not supported and is likely to cause unpredictable issues (from '.$installedVersion.' to '.$currentVersion.')'); |
|
| 1348 | 1348 | } |
| 1349 | 1349 | |
| 1350 | 1350 | // also check for upgrades for apps (independently from the user) |
@@ -264,2089 +264,2089 @@ |
||
| 264 | 264 | */ |
| 265 | 265 | class Server extends ServerContainer implements IServerContainer { |
| 266 | 266 | |
| 267 | - /** @var string */ |
|
| 268 | - private $webRoot; |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * @param string $webRoot |
|
| 272 | - * @param \OC\Config $config |
|
| 273 | - */ |
|
| 274 | - public function __construct($webRoot, \OC\Config $config) { |
|
| 275 | - parent::__construct(); |
|
| 276 | - $this->webRoot = $webRoot; |
|
| 277 | - |
|
| 278 | - // To find out if we are running from CLI or not |
|
| 279 | - $this->registerParameter('isCLI', \OC::$CLI); |
|
| 280 | - $this->registerParameter('serverRoot', \OC::$SERVERROOT); |
|
| 281 | - |
|
| 282 | - $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
| 283 | - return $c; |
|
| 284 | - }); |
|
| 285 | - $this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) { |
|
| 286 | - return $c; |
|
| 287 | - }); |
|
| 288 | - |
|
| 289 | - $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
| 290 | - /** @deprecated 19.0.0 */ |
|
| 291 | - $this->registerDeprecatedAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
| 292 | - |
|
| 293 | - $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
| 294 | - /** @deprecated 19.0.0 */ |
|
| 295 | - $this->registerDeprecatedAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class); |
|
| 296 | - |
|
| 297 | - $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
| 298 | - /** @deprecated 19.0.0 */ |
|
| 299 | - $this->registerDeprecatedAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class); |
|
| 300 | - |
|
| 301 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
| 302 | - /** @deprecated 19.0.0 */ |
|
| 303 | - $this->registerDeprecatedAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
| 304 | - |
|
| 305 | - $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class); |
|
| 306 | - $this->registerAlias(ITemplateManager::class, TemplateManager::class); |
|
| 307 | - |
|
| 308 | - $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
| 309 | - |
|
| 310 | - $this->registerService(View::class, function (Server $c) { |
|
| 311 | - return new View(); |
|
| 312 | - }, false); |
|
| 313 | - |
|
| 314 | - $this->registerService(IPreview::class, function (ContainerInterface $c) { |
|
| 315 | - return new PreviewManager( |
|
| 316 | - $c->get(\OCP\IConfig::class), |
|
| 317 | - $c->get(IRootFolder::class), |
|
| 318 | - new \OC\Preview\Storage\Root( |
|
| 319 | - $c->get(IRootFolder::class), |
|
| 320 | - $c->get(SystemConfig::class) |
|
| 321 | - ), |
|
| 322 | - $c->get(SymfonyAdapter::class), |
|
| 323 | - $c->get(GeneratorHelper::class), |
|
| 324 | - $c->get(ISession::class)->get('user_id'), |
|
| 325 | - $c->get(Coordinator::class), |
|
| 326 | - $c->get(IServerContainer::class) |
|
| 327 | - ); |
|
| 328 | - }); |
|
| 329 | - /** @deprecated 19.0.0 */ |
|
| 330 | - $this->registerDeprecatedAlias('PreviewManager', IPreview::class); |
|
| 331 | - |
|
| 332 | - $this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) { |
|
| 333 | - return new \OC\Preview\Watcher( |
|
| 334 | - new \OC\Preview\Storage\Root( |
|
| 335 | - $c->get(IRootFolder::class), |
|
| 336 | - $c->get(SystemConfig::class) |
|
| 337 | - ) |
|
| 338 | - ); |
|
| 339 | - }); |
|
| 340 | - |
|
| 341 | - $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) { |
|
| 342 | - $view = new View(); |
|
| 343 | - $util = new Encryption\Util( |
|
| 344 | - $view, |
|
| 345 | - $c->get(IUserManager::class), |
|
| 346 | - $c->get(IGroupManager::class), |
|
| 347 | - $c->get(\OCP\IConfig::class) |
|
| 348 | - ); |
|
| 349 | - return new Encryption\Manager( |
|
| 350 | - $c->get(\OCP\IConfig::class), |
|
| 351 | - $c->get(ILogger::class), |
|
| 352 | - $c->getL10N('core'), |
|
| 353 | - new View(), |
|
| 354 | - $util, |
|
| 355 | - new ArrayCache() |
|
| 356 | - ); |
|
| 357 | - }); |
|
| 358 | - /** @deprecated 19.0.0 */ |
|
| 359 | - $this->registerDeprecatedAlias('EncryptionManager', \OCP\Encryption\IManager::class); |
|
| 360 | - |
|
| 361 | - /** @deprecated 21.0.0 */ |
|
| 362 | - $this->registerDeprecatedAlias('EncryptionFileHelper', IFile::class); |
|
| 363 | - $this->registerService(IFile::class, function (ContainerInterface $c) { |
|
| 364 | - $util = new Encryption\Util( |
|
| 365 | - new View(), |
|
| 366 | - $c->get(IUserManager::class), |
|
| 367 | - $c->get(IGroupManager::class), |
|
| 368 | - $c->get(\OCP\IConfig::class) |
|
| 369 | - ); |
|
| 370 | - return new Encryption\File( |
|
| 371 | - $util, |
|
| 372 | - $c->get(IRootFolder::class), |
|
| 373 | - $c->get(\OCP\Share\IManager::class) |
|
| 374 | - ); |
|
| 375 | - }); |
|
| 376 | - |
|
| 377 | - /** @deprecated 21.0.0 */ |
|
| 378 | - $this->registerDeprecatedAlias('EncryptionKeyStorage', IStorage::class); |
|
| 379 | - $this->registerService(IStorage::class, function (ContainerInterface $c) { |
|
| 380 | - $view = new View(); |
|
| 381 | - $util = new Encryption\Util( |
|
| 382 | - $view, |
|
| 383 | - $c->get(IUserManager::class), |
|
| 384 | - $c->get(IGroupManager::class), |
|
| 385 | - $c->get(\OCP\IConfig::class) |
|
| 386 | - ); |
|
| 387 | - |
|
| 388 | - return new Encryption\Keys\Storage( |
|
| 389 | - $view, |
|
| 390 | - $util, |
|
| 391 | - $c->get(ICrypto::class), |
|
| 392 | - $c->get(\OCP\IConfig::class) |
|
| 393 | - ); |
|
| 394 | - }); |
|
| 395 | - /** @deprecated 20.0.0 */ |
|
| 396 | - $this->registerDeprecatedAlias('TagMapper', TagMapper::class); |
|
| 397 | - |
|
| 398 | - $this->registerAlias(\OCP\ITagManager::class, TagManager::class); |
|
| 399 | - /** @deprecated 19.0.0 */ |
|
| 400 | - $this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class); |
|
| 401 | - |
|
| 402 | - $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) { |
|
| 403 | - /** @var \OCP\IConfig $config */ |
|
| 404 | - $config = $c->get(\OCP\IConfig::class); |
|
| 405 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
| 406 | - return new $factoryClass($this); |
|
| 407 | - }); |
|
| 408 | - $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) { |
|
| 409 | - return $c->get('SystemTagManagerFactory')->getManager(); |
|
| 410 | - }); |
|
| 411 | - /** @deprecated 19.0.0 */ |
|
| 412 | - $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
|
| 413 | - |
|
| 414 | - $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) { |
|
| 415 | - return $c->get('SystemTagManagerFactory')->getObjectMapper(); |
|
| 416 | - }); |
|
| 417 | - $this->registerService('RootFolder', function (ContainerInterface $c) { |
|
| 418 | - $manager = \OC\Files\Filesystem::getMountManager(null); |
|
| 419 | - $view = new View(); |
|
| 420 | - $root = new Root( |
|
| 421 | - $manager, |
|
| 422 | - $view, |
|
| 423 | - null, |
|
| 424 | - $c->get(IUserMountCache::class), |
|
| 425 | - $this->get(ILogger::class), |
|
| 426 | - $this->get(IUserManager::class) |
|
| 427 | - ); |
|
| 428 | - |
|
| 429 | - $previewConnector = new \OC\Preview\WatcherConnector( |
|
| 430 | - $root, |
|
| 431 | - $c->get(SystemConfig::class) |
|
| 432 | - ); |
|
| 433 | - $previewConnector->connectWatcher(); |
|
| 434 | - |
|
| 435 | - return $root; |
|
| 436 | - }); |
|
| 437 | - $this->registerService(HookConnector::class, function (ContainerInterface $c) { |
|
| 438 | - return new HookConnector( |
|
| 439 | - $c->get(IRootFolder::class), |
|
| 440 | - new View(), |
|
| 441 | - $c->get(\OC\EventDispatcher\SymfonyAdapter::class), |
|
| 442 | - $c->get(IEventDispatcher::class) |
|
| 443 | - ); |
|
| 444 | - }); |
|
| 445 | - |
|
| 446 | - /** @deprecated 19.0.0 */ |
|
| 447 | - $this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class); |
|
| 448 | - |
|
| 449 | - $this->registerService(IRootFolder::class, function (ContainerInterface $c) { |
|
| 450 | - return new LazyRoot(function () use ($c) { |
|
| 451 | - return $c->get('RootFolder'); |
|
| 452 | - }); |
|
| 453 | - }); |
|
| 454 | - /** @deprecated 19.0.0 */ |
|
| 455 | - $this->registerDeprecatedAlias('LazyRootFolder', IRootFolder::class); |
|
| 456 | - |
|
| 457 | - /** @deprecated 19.0.0 */ |
|
| 458 | - $this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class); |
|
| 459 | - $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
| 460 | - |
|
| 461 | - $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) { |
|
| 462 | - $groupManager = new \OC\Group\Manager($this->get(IUserManager::class), $c->get(SymfonyAdapter::class), $this->get(ILogger::class)); |
|
| 463 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
| 464 | - /** @var IEventDispatcher $dispatcher */ |
|
| 465 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 466 | - $dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid)); |
|
| 467 | - }); |
|
| 468 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) { |
|
| 469 | - /** @var IEventDispatcher $dispatcher */ |
|
| 470 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 471 | - $dispatcher->dispatchTyped(new GroupCreatedEvent($group)); |
|
| 472 | - }); |
|
| 473 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
| 474 | - /** @var IEventDispatcher $dispatcher */ |
|
| 475 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 476 | - $dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group)); |
|
| 477 | - }); |
|
| 478 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
| 479 | - /** @var IEventDispatcher $dispatcher */ |
|
| 480 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 481 | - $dispatcher->dispatchTyped(new GroupDeletedEvent($group)); |
|
| 482 | - }); |
|
| 483 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 484 | - /** @var IEventDispatcher $dispatcher */ |
|
| 485 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 486 | - $dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user)); |
|
| 487 | - }); |
|
| 488 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 489 | - /** @var IEventDispatcher $dispatcher */ |
|
| 490 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 491 | - $dispatcher->dispatchTyped(new UserAddedEvent($group, $user)); |
|
| 492 | - }); |
|
| 493 | - $groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 494 | - /** @var IEventDispatcher $dispatcher */ |
|
| 495 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 496 | - $dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user)); |
|
| 497 | - }); |
|
| 498 | - $groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 499 | - /** @var IEventDispatcher $dispatcher */ |
|
| 500 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 501 | - $dispatcher->dispatchTyped(new UserRemovedEvent($group, $user)); |
|
| 502 | - }); |
|
| 503 | - return $groupManager; |
|
| 504 | - }); |
|
| 505 | - /** @deprecated 19.0.0 */ |
|
| 506 | - $this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class); |
|
| 507 | - |
|
| 508 | - $this->registerService(Store::class, function (ContainerInterface $c) { |
|
| 509 | - $session = $c->get(ISession::class); |
|
| 510 | - if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 511 | - $tokenProvider = $c->get(IProvider::class); |
|
| 512 | - } else { |
|
| 513 | - $tokenProvider = null; |
|
| 514 | - } |
|
| 515 | - $logger = $c->get(LoggerInterface::class); |
|
| 516 | - return new Store($session, $logger, $tokenProvider); |
|
| 517 | - }); |
|
| 518 | - $this->registerAlias(IStore::class, Store::class); |
|
| 519 | - $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
| 520 | - |
|
| 521 | - $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
| 522 | - $manager = $c->get(IUserManager::class); |
|
| 523 | - $session = new \OC\Session\Memory(''); |
|
| 524 | - $timeFactory = new TimeFactory(); |
|
| 525 | - // Token providers might require a working database. This code |
|
| 526 | - // might however be called when Nextcloud is not yet setup. |
|
| 527 | - if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 528 | - $provider = $c->get(IProvider::class); |
|
| 529 | - } else { |
|
| 530 | - $provider = null; |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - $legacyDispatcher = $c->get(SymfonyAdapter::class); |
|
| 534 | - |
|
| 535 | - $userSession = new \OC\User\Session( |
|
| 536 | - $manager, |
|
| 537 | - $session, |
|
| 538 | - $timeFactory, |
|
| 539 | - $provider, |
|
| 540 | - $c->get(\OCP\IConfig::class), |
|
| 541 | - $c->get(ISecureRandom::class), |
|
| 542 | - $c->getLockdownManager(), |
|
| 543 | - $c->get(ILogger::class), |
|
| 544 | - $c->get(IEventDispatcher::class) |
|
| 545 | - ); |
|
| 546 | - /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */ |
|
| 547 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 548 | - \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 549 | - }); |
|
| 550 | - /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */ |
|
| 551 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 552 | - /** @var \OC\User\User $user */ |
|
| 553 | - \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
|
| 554 | - }); |
|
| 555 | - /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */ |
|
| 556 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) { |
|
| 557 | - /** @var \OC\User\User $user */ |
|
| 558 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
|
| 559 | - $legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
| 560 | - }); |
|
| 561 | - /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ |
|
| 562 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 563 | - /** @var \OC\User\User $user */ |
|
| 564 | - \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
|
| 565 | - }); |
|
| 566 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 567 | - /** @var \OC\User\User $user */ |
|
| 568 | - \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 569 | - |
|
| 570 | - /** @var IEventDispatcher $dispatcher */ |
|
| 571 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 572 | - $dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
| 573 | - }); |
|
| 574 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 575 | - /** @var \OC\User\User $user */ |
|
| 576 | - \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 577 | - |
|
| 578 | - /** @var IEventDispatcher $dispatcher */ |
|
| 579 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 580 | - $dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
| 581 | - }); |
|
| 582 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 583 | - \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 584 | - |
|
| 585 | - /** @var IEventDispatcher $dispatcher */ |
|
| 586 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 587 | - $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
|
| 588 | - }); |
|
| 589 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) { |
|
| 590 | - /** @var \OC\User\User $user */ |
|
| 591 | - \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
|
| 592 | - |
|
| 593 | - /** @var IEventDispatcher $dispatcher */ |
|
| 594 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 595 | - $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin)); |
|
| 596 | - }); |
|
| 597 | - $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
| 598 | - /** @var IEventDispatcher $dispatcher */ |
|
| 599 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 600 | - $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
|
| 601 | - }); |
|
| 602 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
| 603 | - /** @var \OC\User\User $user */ |
|
| 604 | - \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
|
| 605 | - |
|
| 606 | - /** @var IEventDispatcher $dispatcher */ |
|
| 607 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 608 | - $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
|
| 609 | - }); |
|
| 610 | - $userSession->listen('\OC\User', 'logout', function ($user) { |
|
| 611 | - \OC_Hook::emit('OC_User', 'logout', []); |
|
| 612 | - |
|
| 613 | - /** @var IEventDispatcher $dispatcher */ |
|
| 614 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 615 | - $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
|
| 616 | - }); |
|
| 617 | - $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
| 618 | - /** @var IEventDispatcher $dispatcher */ |
|
| 619 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 620 | - $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
|
| 621 | - }); |
|
| 622 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 623 | - /** @var \OC\User\User $user */ |
|
| 624 | - \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
|
| 625 | - |
|
| 626 | - /** @var IEventDispatcher $dispatcher */ |
|
| 627 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 628 | - $dispatcher->dispatchTyped(new UserChangedEvent($user, $feature, $value, $oldValue)); |
|
| 629 | - }); |
|
| 630 | - return $userSession; |
|
| 631 | - }); |
|
| 632 | - $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
| 633 | - /** @deprecated 19.0.0 */ |
|
| 634 | - $this->registerDeprecatedAlias('UserSession', \OC\User\Session::class); |
|
| 635 | - |
|
| 636 | - $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
| 637 | - |
|
| 638 | - $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class); |
|
| 639 | - /** @deprecated 19.0.0 */ |
|
| 640 | - $this->registerDeprecatedAlias('NavigationManager', INavigationManager::class); |
|
| 641 | - |
|
| 642 | - /** @deprecated 19.0.0 */ |
|
| 643 | - $this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class); |
|
| 644 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
| 645 | - |
|
| 646 | - $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
| 647 | - return new \OC\SystemConfig($config); |
|
| 648 | - }); |
|
| 649 | - /** @deprecated 19.0.0 */ |
|
| 650 | - $this->registerDeprecatedAlias('SystemConfig', \OC\SystemConfig::class); |
|
| 651 | - |
|
| 652 | - /** @deprecated 19.0.0 */ |
|
| 653 | - $this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class); |
|
| 654 | - $this->registerAlias(IAppConfig::class, \OC\AppConfig::class); |
|
| 655 | - |
|
| 656 | - $this->registerService(IFactory::class, function (Server $c) { |
|
| 657 | - return new \OC\L10N\Factory( |
|
| 658 | - $c->get(\OCP\IConfig::class), |
|
| 659 | - $c->getRequest(), |
|
| 660 | - $c->get(IUserSession::class), |
|
| 661 | - \OC::$SERVERROOT |
|
| 662 | - ); |
|
| 663 | - }); |
|
| 664 | - /** @deprecated 19.0.0 */ |
|
| 665 | - $this->registerDeprecatedAlias('L10NFactory', IFactory::class); |
|
| 666 | - |
|
| 667 | - $this->registerAlias(IURLGenerator::class, URLGenerator::class); |
|
| 668 | - /** @deprecated 19.0.0 */ |
|
| 669 | - $this->registerDeprecatedAlias('URLGenerator', IURLGenerator::class); |
|
| 670 | - |
|
| 671 | - /** @deprecated 19.0.0 */ |
|
| 672 | - $this->registerDeprecatedAlias('AppFetcher', AppFetcher::class); |
|
| 673 | - /** @deprecated 19.0.0 */ |
|
| 674 | - $this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class); |
|
| 675 | - |
|
| 676 | - $this->registerService(ICache::class, function ($c) { |
|
| 677 | - return new Cache\File(); |
|
| 678 | - }); |
|
| 679 | - /** @deprecated 19.0.0 */ |
|
| 680 | - $this->registerDeprecatedAlias('UserCache', ICache::class); |
|
| 681 | - |
|
| 682 | - $this->registerService(Factory::class, function (Server $c) { |
|
| 683 | - $arrayCacheFactory = new \OC\Memcache\Factory('', $c->get(ILogger::class), |
|
| 684 | - ArrayCache::class, |
|
| 685 | - ArrayCache::class, |
|
| 686 | - ArrayCache::class |
|
| 687 | - ); |
|
| 688 | - /** @var \OCP\IConfig $config */ |
|
| 689 | - $config = $c->get(\OCP\IConfig::class); |
|
| 690 | - |
|
| 691 | - if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 692 | - if (!$config->getSystemValueBool('log_query')) { |
|
| 693 | - $v = \OC_App::getAppVersions(); |
|
| 694 | - } else { |
|
| 695 | - // If the log_query is enabled, we can not get the app versions |
|
| 696 | - // as that does a query, which will be logged and the logging |
|
| 697 | - // depends on redis and here we are back again in the same function. |
|
| 698 | - $v = [ |
|
| 699 | - 'log_query' => 'enabled', |
|
| 700 | - ]; |
|
| 701 | - } |
|
| 702 | - $v['core'] = implode(',', \OC_Util::getVersion()); |
|
| 703 | - $version = implode(',', $v); |
|
| 704 | - $instanceId = \OC_Util::getInstanceId(); |
|
| 705 | - $path = \OC::$SERVERROOT; |
|
| 706 | - $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
| 707 | - return new \OC\Memcache\Factory($prefix, $c->get(ILogger::class), |
|
| 708 | - $config->getSystemValue('memcache.local', null), |
|
| 709 | - $config->getSystemValue('memcache.distributed', null), |
|
| 710 | - $config->getSystemValue('memcache.locking', null), |
|
| 711 | - $config->getSystemValueString('redis_log_file') |
|
| 712 | - ); |
|
| 713 | - } |
|
| 714 | - return $arrayCacheFactory; |
|
| 715 | - }); |
|
| 716 | - /** @deprecated 19.0.0 */ |
|
| 717 | - $this->registerDeprecatedAlias('MemCacheFactory', Factory::class); |
|
| 718 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
| 719 | - |
|
| 720 | - $this->registerService('RedisFactory', function (Server $c) { |
|
| 721 | - $systemConfig = $c->get(SystemConfig::class); |
|
| 722 | - return new RedisFactory($systemConfig, $c->getEventLogger()); |
|
| 723 | - }); |
|
| 724 | - |
|
| 725 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 726 | - $l10n = $this->get(IFactory::class)->get('lib'); |
|
| 727 | - return new \OC\Activity\Manager( |
|
| 728 | - $c->getRequest(), |
|
| 729 | - $c->get(IUserSession::class), |
|
| 730 | - $c->get(\OCP\IConfig::class), |
|
| 731 | - $c->get(IValidator::class), |
|
| 732 | - $l10n |
|
| 733 | - ); |
|
| 734 | - }); |
|
| 735 | - /** @deprecated 19.0.0 */ |
|
| 736 | - $this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
| 737 | - |
|
| 738 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 739 | - return new \OC\Activity\EventMerger( |
|
| 740 | - $c->getL10N('lib') |
|
| 741 | - ); |
|
| 742 | - }); |
|
| 743 | - $this->registerAlias(IValidator::class, Validator::class); |
|
| 744 | - |
|
| 745 | - $this->registerService(AvatarManager::class, function (Server $c) { |
|
| 746 | - return new AvatarManager( |
|
| 747 | - $c->get(IUserSession::class), |
|
| 748 | - $c->get(\OC\User\Manager::class), |
|
| 749 | - $c->getAppDataDir('avatar'), |
|
| 750 | - $c->getL10N('lib'), |
|
| 751 | - $c->get(LoggerInterface::class), |
|
| 752 | - $c->get(\OCP\IConfig::class), |
|
| 753 | - $c->get(IAccountManager::class), |
|
| 754 | - $c->get(KnownUserService::class) |
|
| 755 | - ); |
|
| 756 | - }); |
|
| 757 | - $this->registerAlias(IAvatarManager::class, AvatarManager::class); |
|
| 758 | - /** @deprecated 19.0.0 */ |
|
| 759 | - $this->registerDeprecatedAlias('AvatarManager', AvatarManager::class); |
|
| 760 | - |
|
| 761 | - $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
| 762 | - $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
| 763 | - |
|
| 764 | - $this->registerService(\OC\Log::class, function (Server $c) { |
|
| 765 | - $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file'); |
|
| 766 | - $factory = new LogFactory($c, $this->get(SystemConfig::class)); |
|
| 767 | - $logger = $factory->get($logType); |
|
| 768 | - $registry = $c->get(\OCP\Support\CrashReport\IRegistry::class); |
|
| 769 | - |
|
| 770 | - return new Log($logger, $this->get(SystemConfig::class), null, $registry); |
|
| 771 | - }); |
|
| 772 | - $this->registerAlias(ILogger::class, \OC\Log::class); |
|
| 773 | - /** @deprecated 19.0.0 */ |
|
| 774 | - $this->registerDeprecatedAlias('Logger', \OC\Log::class); |
|
| 775 | - // PSR-3 logger |
|
| 776 | - $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
|
| 777 | - |
|
| 778 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
| 779 | - return new LogFactory($c, $this->get(SystemConfig::class)); |
|
| 780 | - }); |
|
| 781 | - |
|
| 782 | - $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class); |
|
| 783 | - /** @deprecated 19.0.0 */ |
|
| 784 | - $this->registerDeprecatedAlias('JobList', IJobList::class); |
|
| 785 | - |
|
| 786 | - $this->registerService(Router::class, function (Server $c) { |
|
| 787 | - $cacheFactory = $c->get(ICacheFactory::class); |
|
| 788 | - $logger = $c->get(ILogger::class); |
|
| 789 | - if ($cacheFactory->isLocalCacheAvailable()) { |
|
| 790 | - $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
| 791 | - } else { |
|
| 792 | - $router = new \OC\Route\Router($logger); |
|
| 793 | - } |
|
| 794 | - return $router; |
|
| 795 | - }); |
|
| 796 | - $this->registerAlias(IRouter::class, Router::class); |
|
| 797 | - /** @deprecated 19.0.0 */ |
|
| 798 | - $this->registerDeprecatedAlias('Router', IRouter::class); |
|
| 799 | - |
|
| 800 | - $this->registerAlias(ISearch::class, Search::class); |
|
| 801 | - /** @deprecated 19.0.0 */ |
|
| 802 | - $this->registerDeprecatedAlias('Search', ISearch::class); |
|
| 803 | - |
|
| 804 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
| 805 | - $cacheFactory = $c->get(ICacheFactory::class); |
|
| 806 | - if ($cacheFactory->isAvailable()) { |
|
| 807 | - $backend = new \OC\Security\RateLimiting\Backend\MemoryCacheBackend( |
|
| 808 | - $this->get(ICacheFactory::class), |
|
| 809 | - new \OC\AppFramework\Utility\TimeFactory() |
|
| 810 | - ); |
|
| 811 | - } else { |
|
| 812 | - $backend = new \OC\Security\RateLimiting\Backend\DatabaseBackend( |
|
| 813 | - $c->get(IDBConnection::class), |
|
| 814 | - new \OC\AppFramework\Utility\TimeFactory() |
|
| 815 | - ); |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - return $backend; |
|
| 819 | - }); |
|
| 820 | - |
|
| 821 | - $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class); |
|
| 822 | - /** @deprecated 19.0.0 */ |
|
| 823 | - $this->registerDeprecatedAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
| 824 | - |
|
| 825 | - $this->registerAlias(IVerificationToken::class, VerificationToken::class); |
|
| 826 | - |
|
| 827 | - $this->registerAlias(ICrypto::class, Crypto::class); |
|
| 828 | - /** @deprecated 19.0.0 */ |
|
| 829 | - $this->registerDeprecatedAlias('Crypto', ICrypto::class); |
|
| 830 | - |
|
| 831 | - $this->registerAlias(IHasher::class, Hasher::class); |
|
| 832 | - /** @deprecated 19.0.0 */ |
|
| 833 | - $this->registerDeprecatedAlias('Hasher', IHasher::class); |
|
| 834 | - |
|
| 835 | - $this->registerAlias(ICredentialsManager::class, CredentialsManager::class); |
|
| 836 | - /** @deprecated 19.0.0 */ |
|
| 837 | - $this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class); |
|
| 838 | - |
|
| 839 | - $this->registerAlias(IDBConnection::class, ConnectionAdapter::class); |
|
| 840 | - $this->registerService(Connection::class, function (Server $c) { |
|
| 841 | - $systemConfig = $c->get(SystemConfig::class); |
|
| 842 | - $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
| 843 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
| 844 | - if (!$factory->isValidType($type)) { |
|
| 845 | - throw new \OC\DatabaseException('Invalid database type'); |
|
| 846 | - } |
|
| 847 | - $connectionParams = $factory->createConnectionParams(); |
|
| 848 | - $connection = $factory->getConnection($type, $connectionParams); |
|
| 849 | - $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
| 850 | - return $connection; |
|
| 851 | - }); |
|
| 852 | - /** @deprecated 19.0.0 */ |
|
| 853 | - $this->registerDeprecatedAlias('DatabaseConnection', IDBConnection::class); |
|
| 854 | - |
|
| 855 | - $this->registerAlias(ICertificateManager::class, CertificateManager::class); |
|
| 856 | - $this->registerAlias(IClientService::class, ClientService::class); |
|
| 857 | - $this->registerService(LocalAddressChecker::class, function (ContainerInterface $c) { |
|
| 858 | - return new LocalAddressChecker( |
|
| 859 | - $c->get(ILogger::class), |
|
| 860 | - ); |
|
| 861 | - }); |
|
| 862 | - $this->registerService(NegativeDnsCache::class, function (ContainerInterface $c) { |
|
| 863 | - return new NegativeDnsCache( |
|
| 864 | - $c->get(ICacheFactory::class), |
|
| 865 | - ); |
|
| 866 | - }); |
|
| 867 | - $this->registerService(DnsPinMiddleware::class, function (ContainerInterface $c) { |
|
| 868 | - return new DnsPinMiddleware( |
|
| 869 | - $c->get(NegativeDnsCache::class), |
|
| 870 | - $c->get(LocalAddressChecker::class) |
|
| 871 | - ); |
|
| 872 | - }); |
|
| 873 | - $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
|
| 874 | - $this->registerService(IEventLogger::class, function (ContainerInterface $c) { |
|
| 875 | - return new EventLogger($c->get(SystemConfig::class), $c->get(LoggerInterface::class), $c->get(Log::class)); |
|
| 876 | - }); |
|
| 877 | - /** @deprecated 19.0.0 */ |
|
| 878 | - $this->registerDeprecatedAlias('EventLogger', IEventLogger::class); |
|
| 879 | - |
|
| 880 | - $this->registerService(IQueryLogger::class, function (ContainerInterface $c) { |
|
| 881 | - $queryLogger = new QueryLogger(); |
|
| 882 | - if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
|
| 883 | - // In debug mode, module is being activated by default |
|
| 884 | - $queryLogger->activate(); |
|
| 885 | - } |
|
| 886 | - return $queryLogger; |
|
| 887 | - }); |
|
| 888 | - /** @deprecated 19.0.0 */ |
|
| 889 | - $this->registerDeprecatedAlias('QueryLogger', IQueryLogger::class); |
|
| 890 | - |
|
| 891 | - /** @deprecated 19.0.0 */ |
|
| 892 | - $this->registerDeprecatedAlias('TempManager', TempManager::class); |
|
| 893 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
| 894 | - |
|
| 895 | - $this->registerService(AppManager::class, function (ContainerInterface $c) { |
|
| 896 | - // TODO: use auto-wiring |
|
| 897 | - return new \OC\App\AppManager( |
|
| 898 | - $c->get(IUserSession::class), |
|
| 899 | - $c->get(\OCP\IConfig::class), |
|
| 900 | - $c->get(\OC\AppConfig::class), |
|
| 901 | - $c->get(IGroupManager::class), |
|
| 902 | - $c->get(ICacheFactory::class), |
|
| 903 | - $c->get(SymfonyAdapter::class), |
|
| 904 | - $c->get(LoggerInterface::class) |
|
| 905 | - ); |
|
| 906 | - }); |
|
| 907 | - /** @deprecated 19.0.0 */ |
|
| 908 | - $this->registerDeprecatedAlias('AppManager', AppManager::class); |
|
| 909 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
| 910 | - |
|
| 911 | - $this->registerAlias(IDateTimeZone::class, DateTimeZone::class); |
|
| 912 | - /** @deprecated 19.0.0 */ |
|
| 913 | - $this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class); |
|
| 914 | - |
|
| 915 | - $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
| 916 | - $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null); |
|
| 917 | - |
|
| 918 | - return new DateTimeFormatter( |
|
| 919 | - $c->get(IDateTimeZone::class)->getTimeZone(), |
|
| 920 | - $c->getL10N('lib', $language) |
|
| 921 | - ); |
|
| 922 | - }); |
|
| 923 | - /** @deprecated 19.0.0 */ |
|
| 924 | - $this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class); |
|
| 925 | - |
|
| 926 | - $this->registerService(IUserMountCache::class, function (ContainerInterface $c) { |
|
| 927 | - $mountCache = new UserMountCache( |
|
| 928 | - $c->get(IDBConnection::class), |
|
| 929 | - $c->get(IUserManager::class), |
|
| 930 | - $c->get(ILogger::class) |
|
| 931 | - ); |
|
| 932 | - $listener = new UserMountCacheListener($mountCache); |
|
| 933 | - $listener->listen($c->get(IUserManager::class)); |
|
| 934 | - return $mountCache; |
|
| 935 | - }); |
|
| 936 | - /** @deprecated 19.0.0 */ |
|
| 937 | - $this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class); |
|
| 938 | - |
|
| 939 | - $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) { |
|
| 940 | - $loader = \OC\Files\Filesystem::getLoader(); |
|
| 941 | - $mountCache = $c->get(IUserMountCache::class); |
|
| 942 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
| 943 | - |
|
| 944 | - // builtin providers |
|
| 945 | - |
|
| 946 | - $config = $c->get(\OCP\IConfig::class); |
|
| 947 | - $logger = $c->get(ILogger::class); |
|
| 948 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
| 949 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
| 950 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
| 951 | - $manager->registerRootProvider(new RootMountProvider($config, $c->get(LoggerInterface::class))); |
|
| 952 | - $manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config)); |
|
| 953 | - |
|
| 954 | - return $manager; |
|
| 955 | - }); |
|
| 956 | - /** @deprecated 19.0.0 */ |
|
| 957 | - $this->registerDeprecatedAlias('MountConfigManager', IMountProviderCollection::class); |
|
| 958 | - |
|
| 959 | - /** @deprecated 20.0.0 */ |
|
| 960 | - $this->registerDeprecatedAlias('IniWrapper', IniGetWrapper::class); |
|
| 961 | - $this->registerService(IBus::class, function (ContainerInterface $c) { |
|
| 962 | - $busClass = $c->get(\OCP\IConfig::class)->getSystemValue('commandbus'); |
|
| 963 | - if ($busClass) { |
|
| 964 | - [$app, $class] = explode('::', $busClass, 2); |
|
| 965 | - if ($c->get(IAppManager::class)->isInstalled($app)) { |
|
| 966 | - \OC_App::loadApp($app); |
|
| 967 | - return $c->get($class); |
|
| 968 | - } else { |
|
| 969 | - throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
| 970 | - } |
|
| 971 | - } else { |
|
| 972 | - $jobList = $c->get(IJobList::class); |
|
| 973 | - return new CronBus($jobList); |
|
| 974 | - } |
|
| 975 | - }); |
|
| 976 | - $this->registerDeprecatedAlias('AsyncCommandBus', IBus::class); |
|
| 977 | - /** @deprecated 20.0.0 */ |
|
| 978 | - $this->registerDeprecatedAlias('TrustedDomainHelper', TrustedDomainHelper::class); |
|
| 979 | - $this->registerAlias(ITrustedDomainHelper::class, TrustedDomainHelper::class); |
|
| 980 | - /** @deprecated 19.0.0 */ |
|
| 981 | - $this->registerDeprecatedAlias('Throttler', Throttler::class); |
|
| 982 | - $this->registerService('IntegrityCodeChecker', function (ContainerInterface $c) { |
|
| 983 | - // IConfig and IAppManager requires a working database. This code |
|
| 984 | - // might however be called when ownCloud is not yet setup. |
|
| 985 | - if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 986 | - $config = $c->get(\OCP\IConfig::class); |
|
| 987 | - $appManager = $c->get(IAppManager::class); |
|
| 988 | - } else { |
|
| 989 | - $config = null; |
|
| 990 | - $appManager = null; |
|
| 991 | - } |
|
| 992 | - |
|
| 993 | - return new Checker( |
|
| 994 | - new EnvironmentHelper(), |
|
| 995 | - new FileAccessHelper(), |
|
| 996 | - new AppLocator(), |
|
| 997 | - $config, |
|
| 998 | - $c->get(ICacheFactory::class), |
|
| 999 | - $appManager, |
|
| 1000 | - $c->get(IMimeTypeDetector::class) |
|
| 1001 | - ); |
|
| 1002 | - }); |
|
| 1003 | - $this->registerService(\OCP\IRequest::class, function (ContainerInterface $c) { |
|
| 1004 | - if (isset($this['urlParams'])) { |
|
| 1005 | - $urlParams = $this['urlParams']; |
|
| 1006 | - } else { |
|
| 1007 | - $urlParams = []; |
|
| 1008 | - } |
|
| 1009 | - |
|
| 1010 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
| 1011 | - && in_array('fakeinput', stream_get_wrappers()) |
|
| 1012 | - ) { |
|
| 1013 | - $stream = 'fakeinput://data'; |
|
| 1014 | - } else { |
|
| 1015 | - $stream = 'php://input'; |
|
| 1016 | - } |
|
| 1017 | - |
|
| 1018 | - return new Request( |
|
| 1019 | - [ |
|
| 1020 | - 'get' => $_GET, |
|
| 1021 | - 'post' => $_POST, |
|
| 1022 | - 'files' => $_FILES, |
|
| 1023 | - 'server' => $_SERVER, |
|
| 1024 | - 'env' => $_ENV, |
|
| 1025 | - 'cookies' => $_COOKIE, |
|
| 1026 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 1027 | - ? $_SERVER['REQUEST_METHOD'] |
|
| 1028 | - : '', |
|
| 1029 | - 'urlParams' => $urlParams, |
|
| 1030 | - ], |
|
| 1031 | - $this->get(ISecureRandom::class), |
|
| 1032 | - $this->get(\OCP\IConfig::class), |
|
| 1033 | - $this->get(CsrfTokenManager::class), |
|
| 1034 | - $stream |
|
| 1035 | - ); |
|
| 1036 | - }); |
|
| 1037 | - /** @deprecated 19.0.0 */ |
|
| 1038 | - $this->registerDeprecatedAlias('Request', \OCP\IRequest::class); |
|
| 1039 | - |
|
| 1040 | - $this->registerService(IMailer::class, function (Server $c) { |
|
| 1041 | - return new Mailer( |
|
| 1042 | - $c->get(\OCP\IConfig::class), |
|
| 1043 | - $c->get(ILogger::class), |
|
| 1044 | - $c->get(Defaults::class), |
|
| 1045 | - $c->get(IURLGenerator::class), |
|
| 1046 | - $c->getL10N('lib'), |
|
| 1047 | - $c->get(IEventDispatcher::class), |
|
| 1048 | - $c->get(IFactory::class) |
|
| 1049 | - ); |
|
| 1050 | - }); |
|
| 1051 | - /** @deprecated 19.0.0 */ |
|
| 1052 | - $this->registerDeprecatedAlias('Mailer', IMailer::class); |
|
| 1053 | - |
|
| 1054 | - /** @deprecated 21.0.0 */ |
|
| 1055 | - $this->registerDeprecatedAlias('LDAPProvider', ILDAPProvider::class); |
|
| 1056 | - |
|
| 1057 | - $this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) { |
|
| 1058 | - $config = $c->get(\OCP\IConfig::class); |
|
| 1059 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
| 1060 | - if (is_null($factoryClass) || !class_exists($factoryClass)) { |
|
| 1061 | - return new NullLDAPProviderFactory($this); |
|
| 1062 | - } |
|
| 1063 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
| 1064 | - return new $factoryClass($this); |
|
| 1065 | - }); |
|
| 1066 | - $this->registerService(ILDAPProvider::class, function (ContainerInterface $c) { |
|
| 1067 | - $factory = $c->get(ILDAPProviderFactory::class); |
|
| 1068 | - return $factory->getLDAPProvider(); |
|
| 1069 | - }); |
|
| 1070 | - $this->registerService(ILockingProvider::class, function (ContainerInterface $c) { |
|
| 1071 | - $ini = $c->get(IniGetWrapper::class); |
|
| 1072 | - $config = $c->get(\OCP\IConfig::class); |
|
| 1073 | - $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
| 1074 | - if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 1075 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
| 1076 | - $memcacheFactory = $c->get(ICacheFactory::class); |
|
| 1077 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
| 1078 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
| 1079 | - return new MemcacheLockingProvider($memcache, $ttl); |
|
| 1080 | - } |
|
| 1081 | - return new DBLockingProvider( |
|
| 1082 | - $c->get(IDBConnection::class), |
|
| 1083 | - $c->get(ILogger::class), |
|
| 1084 | - new TimeFactory(), |
|
| 1085 | - $ttl, |
|
| 1086 | - !\OC::$CLI |
|
| 1087 | - ); |
|
| 1088 | - } |
|
| 1089 | - return new NoopLockingProvider(); |
|
| 1090 | - }); |
|
| 1091 | - /** @deprecated 19.0.0 */ |
|
| 1092 | - $this->registerDeprecatedAlias('LockingProvider', ILockingProvider::class); |
|
| 1093 | - |
|
| 1094 | - $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class); |
|
| 1095 | - /** @deprecated 19.0.0 */ |
|
| 1096 | - $this->registerDeprecatedAlias('MountManager', IMountManager::class); |
|
| 1097 | - |
|
| 1098 | - $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) { |
|
| 1099 | - return new \OC\Files\Type\Detection( |
|
| 1100 | - $c->get(IURLGenerator::class), |
|
| 1101 | - $c->get(ILogger::class), |
|
| 1102 | - \OC::$configDir, |
|
| 1103 | - \OC::$SERVERROOT . '/resources/config/' |
|
| 1104 | - ); |
|
| 1105 | - }); |
|
| 1106 | - /** @deprecated 19.0.0 */ |
|
| 1107 | - $this->registerDeprecatedAlias('MimeTypeDetector', IMimeTypeDetector::class); |
|
| 1108 | - |
|
| 1109 | - $this->registerAlias(IMimeTypeLoader::class, Loader::class); |
|
| 1110 | - /** @deprecated 19.0.0 */ |
|
| 1111 | - $this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class); |
|
| 1112 | - $this->registerService(BundleFetcher::class, function () { |
|
| 1113 | - return new BundleFetcher($this->getL10N('lib')); |
|
| 1114 | - }); |
|
| 1115 | - $this->registerAlias(\OCP\Notification\IManager::class, Manager::class); |
|
| 1116 | - /** @deprecated 19.0.0 */ |
|
| 1117 | - $this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
| 1118 | - |
|
| 1119 | - $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) { |
|
| 1120 | - $manager = new CapabilitiesManager($c->get(LoggerInterface::class)); |
|
| 1121 | - $manager->registerCapability(function () use ($c) { |
|
| 1122 | - return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class)); |
|
| 1123 | - }); |
|
| 1124 | - $manager->registerCapability(function () use ($c) { |
|
| 1125 | - return $c->get(\OC\Security\Bruteforce\Capabilities::class); |
|
| 1126 | - }); |
|
| 1127 | - return $manager; |
|
| 1128 | - }); |
|
| 1129 | - /** @deprecated 19.0.0 */ |
|
| 1130 | - $this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class); |
|
| 1131 | - |
|
| 1132 | - $this->registerService(ICommentsManager::class, function (Server $c) { |
|
| 1133 | - $config = $c->get(\OCP\IConfig::class); |
|
| 1134 | - $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
| 1135 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
| 1136 | - $factory = new $factoryClass($this); |
|
| 1137 | - $manager = $factory->getManager(); |
|
| 1138 | - |
|
| 1139 | - $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
| 1140 | - $manager = $c->get(IUserManager::class); |
|
| 1141 | - $user = $manager->get($id); |
|
| 1142 | - if (is_null($user)) { |
|
| 1143 | - $l = $c->getL10N('core'); |
|
| 1144 | - $displayName = $l->t('Unknown user'); |
|
| 1145 | - } else { |
|
| 1146 | - $displayName = $user->getDisplayName(); |
|
| 1147 | - } |
|
| 1148 | - return $displayName; |
|
| 1149 | - }); |
|
| 1150 | - |
|
| 1151 | - return $manager; |
|
| 1152 | - }); |
|
| 1153 | - /** @deprecated 19.0.0 */ |
|
| 1154 | - $this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class); |
|
| 1155 | - |
|
| 1156 | - $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults'); |
|
| 1157 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
| 1158 | - /* |
|
| 267 | + /** @var string */ |
|
| 268 | + private $webRoot; |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * @param string $webRoot |
|
| 272 | + * @param \OC\Config $config |
|
| 273 | + */ |
|
| 274 | + public function __construct($webRoot, \OC\Config $config) { |
|
| 275 | + parent::__construct(); |
|
| 276 | + $this->webRoot = $webRoot; |
|
| 277 | + |
|
| 278 | + // To find out if we are running from CLI or not |
|
| 279 | + $this->registerParameter('isCLI', \OC::$CLI); |
|
| 280 | + $this->registerParameter('serverRoot', \OC::$SERVERROOT); |
|
| 281 | + |
|
| 282 | + $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
| 283 | + return $c; |
|
| 284 | + }); |
|
| 285 | + $this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) { |
|
| 286 | + return $c; |
|
| 287 | + }); |
|
| 288 | + |
|
| 289 | + $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
| 290 | + /** @deprecated 19.0.0 */ |
|
| 291 | + $this->registerDeprecatedAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
| 292 | + |
|
| 293 | + $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
| 294 | + /** @deprecated 19.0.0 */ |
|
| 295 | + $this->registerDeprecatedAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class); |
|
| 296 | + |
|
| 297 | + $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
| 298 | + /** @deprecated 19.0.0 */ |
|
| 299 | + $this->registerDeprecatedAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class); |
|
| 300 | + |
|
| 301 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
| 302 | + /** @deprecated 19.0.0 */ |
|
| 303 | + $this->registerDeprecatedAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
| 304 | + |
|
| 305 | + $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class); |
|
| 306 | + $this->registerAlias(ITemplateManager::class, TemplateManager::class); |
|
| 307 | + |
|
| 308 | + $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
| 309 | + |
|
| 310 | + $this->registerService(View::class, function (Server $c) { |
|
| 311 | + return new View(); |
|
| 312 | + }, false); |
|
| 313 | + |
|
| 314 | + $this->registerService(IPreview::class, function (ContainerInterface $c) { |
|
| 315 | + return new PreviewManager( |
|
| 316 | + $c->get(\OCP\IConfig::class), |
|
| 317 | + $c->get(IRootFolder::class), |
|
| 318 | + new \OC\Preview\Storage\Root( |
|
| 319 | + $c->get(IRootFolder::class), |
|
| 320 | + $c->get(SystemConfig::class) |
|
| 321 | + ), |
|
| 322 | + $c->get(SymfonyAdapter::class), |
|
| 323 | + $c->get(GeneratorHelper::class), |
|
| 324 | + $c->get(ISession::class)->get('user_id'), |
|
| 325 | + $c->get(Coordinator::class), |
|
| 326 | + $c->get(IServerContainer::class) |
|
| 327 | + ); |
|
| 328 | + }); |
|
| 329 | + /** @deprecated 19.0.0 */ |
|
| 330 | + $this->registerDeprecatedAlias('PreviewManager', IPreview::class); |
|
| 331 | + |
|
| 332 | + $this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) { |
|
| 333 | + return new \OC\Preview\Watcher( |
|
| 334 | + new \OC\Preview\Storage\Root( |
|
| 335 | + $c->get(IRootFolder::class), |
|
| 336 | + $c->get(SystemConfig::class) |
|
| 337 | + ) |
|
| 338 | + ); |
|
| 339 | + }); |
|
| 340 | + |
|
| 341 | + $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) { |
|
| 342 | + $view = new View(); |
|
| 343 | + $util = new Encryption\Util( |
|
| 344 | + $view, |
|
| 345 | + $c->get(IUserManager::class), |
|
| 346 | + $c->get(IGroupManager::class), |
|
| 347 | + $c->get(\OCP\IConfig::class) |
|
| 348 | + ); |
|
| 349 | + return new Encryption\Manager( |
|
| 350 | + $c->get(\OCP\IConfig::class), |
|
| 351 | + $c->get(ILogger::class), |
|
| 352 | + $c->getL10N('core'), |
|
| 353 | + new View(), |
|
| 354 | + $util, |
|
| 355 | + new ArrayCache() |
|
| 356 | + ); |
|
| 357 | + }); |
|
| 358 | + /** @deprecated 19.0.0 */ |
|
| 359 | + $this->registerDeprecatedAlias('EncryptionManager', \OCP\Encryption\IManager::class); |
|
| 360 | + |
|
| 361 | + /** @deprecated 21.0.0 */ |
|
| 362 | + $this->registerDeprecatedAlias('EncryptionFileHelper', IFile::class); |
|
| 363 | + $this->registerService(IFile::class, function (ContainerInterface $c) { |
|
| 364 | + $util = new Encryption\Util( |
|
| 365 | + new View(), |
|
| 366 | + $c->get(IUserManager::class), |
|
| 367 | + $c->get(IGroupManager::class), |
|
| 368 | + $c->get(\OCP\IConfig::class) |
|
| 369 | + ); |
|
| 370 | + return new Encryption\File( |
|
| 371 | + $util, |
|
| 372 | + $c->get(IRootFolder::class), |
|
| 373 | + $c->get(\OCP\Share\IManager::class) |
|
| 374 | + ); |
|
| 375 | + }); |
|
| 376 | + |
|
| 377 | + /** @deprecated 21.0.0 */ |
|
| 378 | + $this->registerDeprecatedAlias('EncryptionKeyStorage', IStorage::class); |
|
| 379 | + $this->registerService(IStorage::class, function (ContainerInterface $c) { |
|
| 380 | + $view = new View(); |
|
| 381 | + $util = new Encryption\Util( |
|
| 382 | + $view, |
|
| 383 | + $c->get(IUserManager::class), |
|
| 384 | + $c->get(IGroupManager::class), |
|
| 385 | + $c->get(\OCP\IConfig::class) |
|
| 386 | + ); |
|
| 387 | + |
|
| 388 | + return new Encryption\Keys\Storage( |
|
| 389 | + $view, |
|
| 390 | + $util, |
|
| 391 | + $c->get(ICrypto::class), |
|
| 392 | + $c->get(\OCP\IConfig::class) |
|
| 393 | + ); |
|
| 394 | + }); |
|
| 395 | + /** @deprecated 20.0.0 */ |
|
| 396 | + $this->registerDeprecatedAlias('TagMapper', TagMapper::class); |
|
| 397 | + |
|
| 398 | + $this->registerAlias(\OCP\ITagManager::class, TagManager::class); |
|
| 399 | + /** @deprecated 19.0.0 */ |
|
| 400 | + $this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class); |
|
| 401 | + |
|
| 402 | + $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) { |
|
| 403 | + /** @var \OCP\IConfig $config */ |
|
| 404 | + $config = $c->get(\OCP\IConfig::class); |
|
| 405 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
| 406 | + return new $factoryClass($this); |
|
| 407 | + }); |
|
| 408 | + $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) { |
|
| 409 | + return $c->get('SystemTagManagerFactory')->getManager(); |
|
| 410 | + }); |
|
| 411 | + /** @deprecated 19.0.0 */ |
|
| 412 | + $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
|
| 413 | + |
|
| 414 | + $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) { |
|
| 415 | + return $c->get('SystemTagManagerFactory')->getObjectMapper(); |
|
| 416 | + }); |
|
| 417 | + $this->registerService('RootFolder', function (ContainerInterface $c) { |
|
| 418 | + $manager = \OC\Files\Filesystem::getMountManager(null); |
|
| 419 | + $view = new View(); |
|
| 420 | + $root = new Root( |
|
| 421 | + $manager, |
|
| 422 | + $view, |
|
| 423 | + null, |
|
| 424 | + $c->get(IUserMountCache::class), |
|
| 425 | + $this->get(ILogger::class), |
|
| 426 | + $this->get(IUserManager::class) |
|
| 427 | + ); |
|
| 428 | + |
|
| 429 | + $previewConnector = new \OC\Preview\WatcherConnector( |
|
| 430 | + $root, |
|
| 431 | + $c->get(SystemConfig::class) |
|
| 432 | + ); |
|
| 433 | + $previewConnector->connectWatcher(); |
|
| 434 | + |
|
| 435 | + return $root; |
|
| 436 | + }); |
|
| 437 | + $this->registerService(HookConnector::class, function (ContainerInterface $c) { |
|
| 438 | + return new HookConnector( |
|
| 439 | + $c->get(IRootFolder::class), |
|
| 440 | + new View(), |
|
| 441 | + $c->get(\OC\EventDispatcher\SymfonyAdapter::class), |
|
| 442 | + $c->get(IEventDispatcher::class) |
|
| 443 | + ); |
|
| 444 | + }); |
|
| 445 | + |
|
| 446 | + /** @deprecated 19.0.0 */ |
|
| 447 | + $this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class); |
|
| 448 | + |
|
| 449 | + $this->registerService(IRootFolder::class, function (ContainerInterface $c) { |
|
| 450 | + return new LazyRoot(function () use ($c) { |
|
| 451 | + return $c->get('RootFolder'); |
|
| 452 | + }); |
|
| 453 | + }); |
|
| 454 | + /** @deprecated 19.0.0 */ |
|
| 455 | + $this->registerDeprecatedAlias('LazyRootFolder', IRootFolder::class); |
|
| 456 | + |
|
| 457 | + /** @deprecated 19.0.0 */ |
|
| 458 | + $this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class); |
|
| 459 | + $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
| 460 | + |
|
| 461 | + $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) { |
|
| 462 | + $groupManager = new \OC\Group\Manager($this->get(IUserManager::class), $c->get(SymfonyAdapter::class), $this->get(ILogger::class)); |
|
| 463 | + $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
| 464 | + /** @var IEventDispatcher $dispatcher */ |
|
| 465 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 466 | + $dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid)); |
|
| 467 | + }); |
|
| 468 | + $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) { |
|
| 469 | + /** @var IEventDispatcher $dispatcher */ |
|
| 470 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 471 | + $dispatcher->dispatchTyped(new GroupCreatedEvent($group)); |
|
| 472 | + }); |
|
| 473 | + $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
| 474 | + /** @var IEventDispatcher $dispatcher */ |
|
| 475 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 476 | + $dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group)); |
|
| 477 | + }); |
|
| 478 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
| 479 | + /** @var IEventDispatcher $dispatcher */ |
|
| 480 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 481 | + $dispatcher->dispatchTyped(new GroupDeletedEvent($group)); |
|
| 482 | + }); |
|
| 483 | + $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 484 | + /** @var IEventDispatcher $dispatcher */ |
|
| 485 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 486 | + $dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user)); |
|
| 487 | + }); |
|
| 488 | + $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 489 | + /** @var IEventDispatcher $dispatcher */ |
|
| 490 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 491 | + $dispatcher->dispatchTyped(new UserAddedEvent($group, $user)); |
|
| 492 | + }); |
|
| 493 | + $groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 494 | + /** @var IEventDispatcher $dispatcher */ |
|
| 495 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 496 | + $dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user)); |
|
| 497 | + }); |
|
| 498 | + $groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 499 | + /** @var IEventDispatcher $dispatcher */ |
|
| 500 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 501 | + $dispatcher->dispatchTyped(new UserRemovedEvent($group, $user)); |
|
| 502 | + }); |
|
| 503 | + return $groupManager; |
|
| 504 | + }); |
|
| 505 | + /** @deprecated 19.0.0 */ |
|
| 506 | + $this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class); |
|
| 507 | + |
|
| 508 | + $this->registerService(Store::class, function (ContainerInterface $c) { |
|
| 509 | + $session = $c->get(ISession::class); |
|
| 510 | + if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 511 | + $tokenProvider = $c->get(IProvider::class); |
|
| 512 | + } else { |
|
| 513 | + $tokenProvider = null; |
|
| 514 | + } |
|
| 515 | + $logger = $c->get(LoggerInterface::class); |
|
| 516 | + return new Store($session, $logger, $tokenProvider); |
|
| 517 | + }); |
|
| 518 | + $this->registerAlias(IStore::class, Store::class); |
|
| 519 | + $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
| 520 | + |
|
| 521 | + $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
| 522 | + $manager = $c->get(IUserManager::class); |
|
| 523 | + $session = new \OC\Session\Memory(''); |
|
| 524 | + $timeFactory = new TimeFactory(); |
|
| 525 | + // Token providers might require a working database. This code |
|
| 526 | + // might however be called when Nextcloud is not yet setup. |
|
| 527 | + if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 528 | + $provider = $c->get(IProvider::class); |
|
| 529 | + } else { |
|
| 530 | + $provider = null; |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + $legacyDispatcher = $c->get(SymfonyAdapter::class); |
|
| 534 | + |
|
| 535 | + $userSession = new \OC\User\Session( |
|
| 536 | + $manager, |
|
| 537 | + $session, |
|
| 538 | + $timeFactory, |
|
| 539 | + $provider, |
|
| 540 | + $c->get(\OCP\IConfig::class), |
|
| 541 | + $c->get(ISecureRandom::class), |
|
| 542 | + $c->getLockdownManager(), |
|
| 543 | + $c->get(ILogger::class), |
|
| 544 | + $c->get(IEventDispatcher::class) |
|
| 545 | + ); |
|
| 546 | + /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */ |
|
| 547 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 548 | + \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 549 | + }); |
|
| 550 | + /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */ |
|
| 551 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 552 | + /** @var \OC\User\User $user */ |
|
| 553 | + \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
|
| 554 | + }); |
|
| 555 | + /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */ |
|
| 556 | + $userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) { |
|
| 557 | + /** @var \OC\User\User $user */ |
|
| 558 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
|
| 559 | + $legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
| 560 | + }); |
|
| 561 | + /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ |
|
| 562 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 563 | + /** @var \OC\User\User $user */ |
|
| 564 | + \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
|
| 565 | + }); |
|
| 566 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 567 | + /** @var \OC\User\User $user */ |
|
| 568 | + \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 569 | + |
|
| 570 | + /** @var IEventDispatcher $dispatcher */ |
|
| 571 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 572 | + $dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
| 573 | + }); |
|
| 574 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 575 | + /** @var \OC\User\User $user */ |
|
| 576 | + \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 577 | + |
|
| 578 | + /** @var IEventDispatcher $dispatcher */ |
|
| 579 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 580 | + $dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
| 581 | + }); |
|
| 582 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 583 | + \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 584 | + |
|
| 585 | + /** @var IEventDispatcher $dispatcher */ |
|
| 586 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 587 | + $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
|
| 588 | + }); |
|
| 589 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) { |
|
| 590 | + /** @var \OC\User\User $user */ |
|
| 591 | + \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
|
| 592 | + |
|
| 593 | + /** @var IEventDispatcher $dispatcher */ |
|
| 594 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 595 | + $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin)); |
|
| 596 | + }); |
|
| 597 | + $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
| 598 | + /** @var IEventDispatcher $dispatcher */ |
|
| 599 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 600 | + $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
|
| 601 | + }); |
|
| 602 | + $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
| 603 | + /** @var \OC\User\User $user */ |
|
| 604 | + \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
|
| 605 | + |
|
| 606 | + /** @var IEventDispatcher $dispatcher */ |
|
| 607 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 608 | + $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
|
| 609 | + }); |
|
| 610 | + $userSession->listen('\OC\User', 'logout', function ($user) { |
|
| 611 | + \OC_Hook::emit('OC_User', 'logout', []); |
|
| 612 | + |
|
| 613 | + /** @var IEventDispatcher $dispatcher */ |
|
| 614 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 615 | + $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
|
| 616 | + }); |
|
| 617 | + $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
| 618 | + /** @var IEventDispatcher $dispatcher */ |
|
| 619 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 620 | + $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
|
| 621 | + }); |
|
| 622 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 623 | + /** @var \OC\User\User $user */ |
|
| 624 | + \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
|
| 625 | + |
|
| 626 | + /** @var IEventDispatcher $dispatcher */ |
|
| 627 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 628 | + $dispatcher->dispatchTyped(new UserChangedEvent($user, $feature, $value, $oldValue)); |
|
| 629 | + }); |
|
| 630 | + return $userSession; |
|
| 631 | + }); |
|
| 632 | + $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
| 633 | + /** @deprecated 19.0.0 */ |
|
| 634 | + $this->registerDeprecatedAlias('UserSession', \OC\User\Session::class); |
|
| 635 | + |
|
| 636 | + $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
| 637 | + |
|
| 638 | + $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class); |
|
| 639 | + /** @deprecated 19.0.0 */ |
|
| 640 | + $this->registerDeprecatedAlias('NavigationManager', INavigationManager::class); |
|
| 641 | + |
|
| 642 | + /** @deprecated 19.0.0 */ |
|
| 643 | + $this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class); |
|
| 644 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
| 645 | + |
|
| 646 | + $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
| 647 | + return new \OC\SystemConfig($config); |
|
| 648 | + }); |
|
| 649 | + /** @deprecated 19.0.0 */ |
|
| 650 | + $this->registerDeprecatedAlias('SystemConfig', \OC\SystemConfig::class); |
|
| 651 | + |
|
| 652 | + /** @deprecated 19.0.0 */ |
|
| 653 | + $this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class); |
|
| 654 | + $this->registerAlias(IAppConfig::class, \OC\AppConfig::class); |
|
| 655 | + |
|
| 656 | + $this->registerService(IFactory::class, function (Server $c) { |
|
| 657 | + return new \OC\L10N\Factory( |
|
| 658 | + $c->get(\OCP\IConfig::class), |
|
| 659 | + $c->getRequest(), |
|
| 660 | + $c->get(IUserSession::class), |
|
| 661 | + \OC::$SERVERROOT |
|
| 662 | + ); |
|
| 663 | + }); |
|
| 664 | + /** @deprecated 19.0.0 */ |
|
| 665 | + $this->registerDeprecatedAlias('L10NFactory', IFactory::class); |
|
| 666 | + |
|
| 667 | + $this->registerAlias(IURLGenerator::class, URLGenerator::class); |
|
| 668 | + /** @deprecated 19.0.0 */ |
|
| 669 | + $this->registerDeprecatedAlias('URLGenerator', IURLGenerator::class); |
|
| 670 | + |
|
| 671 | + /** @deprecated 19.0.0 */ |
|
| 672 | + $this->registerDeprecatedAlias('AppFetcher', AppFetcher::class); |
|
| 673 | + /** @deprecated 19.0.0 */ |
|
| 674 | + $this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class); |
|
| 675 | + |
|
| 676 | + $this->registerService(ICache::class, function ($c) { |
|
| 677 | + return new Cache\File(); |
|
| 678 | + }); |
|
| 679 | + /** @deprecated 19.0.0 */ |
|
| 680 | + $this->registerDeprecatedAlias('UserCache', ICache::class); |
|
| 681 | + |
|
| 682 | + $this->registerService(Factory::class, function (Server $c) { |
|
| 683 | + $arrayCacheFactory = new \OC\Memcache\Factory('', $c->get(ILogger::class), |
|
| 684 | + ArrayCache::class, |
|
| 685 | + ArrayCache::class, |
|
| 686 | + ArrayCache::class |
|
| 687 | + ); |
|
| 688 | + /** @var \OCP\IConfig $config */ |
|
| 689 | + $config = $c->get(\OCP\IConfig::class); |
|
| 690 | + |
|
| 691 | + if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 692 | + if (!$config->getSystemValueBool('log_query')) { |
|
| 693 | + $v = \OC_App::getAppVersions(); |
|
| 694 | + } else { |
|
| 695 | + // If the log_query is enabled, we can not get the app versions |
|
| 696 | + // as that does a query, which will be logged and the logging |
|
| 697 | + // depends on redis and here we are back again in the same function. |
|
| 698 | + $v = [ |
|
| 699 | + 'log_query' => 'enabled', |
|
| 700 | + ]; |
|
| 701 | + } |
|
| 702 | + $v['core'] = implode(',', \OC_Util::getVersion()); |
|
| 703 | + $version = implode(',', $v); |
|
| 704 | + $instanceId = \OC_Util::getInstanceId(); |
|
| 705 | + $path = \OC::$SERVERROOT; |
|
| 706 | + $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
| 707 | + return new \OC\Memcache\Factory($prefix, $c->get(ILogger::class), |
|
| 708 | + $config->getSystemValue('memcache.local', null), |
|
| 709 | + $config->getSystemValue('memcache.distributed', null), |
|
| 710 | + $config->getSystemValue('memcache.locking', null), |
|
| 711 | + $config->getSystemValueString('redis_log_file') |
|
| 712 | + ); |
|
| 713 | + } |
|
| 714 | + return $arrayCacheFactory; |
|
| 715 | + }); |
|
| 716 | + /** @deprecated 19.0.0 */ |
|
| 717 | + $this->registerDeprecatedAlias('MemCacheFactory', Factory::class); |
|
| 718 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
| 719 | + |
|
| 720 | + $this->registerService('RedisFactory', function (Server $c) { |
|
| 721 | + $systemConfig = $c->get(SystemConfig::class); |
|
| 722 | + return new RedisFactory($systemConfig, $c->getEventLogger()); |
|
| 723 | + }); |
|
| 724 | + |
|
| 725 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 726 | + $l10n = $this->get(IFactory::class)->get('lib'); |
|
| 727 | + return new \OC\Activity\Manager( |
|
| 728 | + $c->getRequest(), |
|
| 729 | + $c->get(IUserSession::class), |
|
| 730 | + $c->get(\OCP\IConfig::class), |
|
| 731 | + $c->get(IValidator::class), |
|
| 732 | + $l10n |
|
| 733 | + ); |
|
| 734 | + }); |
|
| 735 | + /** @deprecated 19.0.0 */ |
|
| 736 | + $this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
| 737 | + |
|
| 738 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 739 | + return new \OC\Activity\EventMerger( |
|
| 740 | + $c->getL10N('lib') |
|
| 741 | + ); |
|
| 742 | + }); |
|
| 743 | + $this->registerAlias(IValidator::class, Validator::class); |
|
| 744 | + |
|
| 745 | + $this->registerService(AvatarManager::class, function (Server $c) { |
|
| 746 | + return new AvatarManager( |
|
| 747 | + $c->get(IUserSession::class), |
|
| 748 | + $c->get(\OC\User\Manager::class), |
|
| 749 | + $c->getAppDataDir('avatar'), |
|
| 750 | + $c->getL10N('lib'), |
|
| 751 | + $c->get(LoggerInterface::class), |
|
| 752 | + $c->get(\OCP\IConfig::class), |
|
| 753 | + $c->get(IAccountManager::class), |
|
| 754 | + $c->get(KnownUserService::class) |
|
| 755 | + ); |
|
| 756 | + }); |
|
| 757 | + $this->registerAlias(IAvatarManager::class, AvatarManager::class); |
|
| 758 | + /** @deprecated 19.0.0 */ |
|
| 759 | + $this->registerDeprecatedAlias('AvatarManager', AvatarManager::class); |
|
| 760 | + |
|
| 761 | + $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
| 762 | + $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
| 763 | + |
|
| 764 | + $this->registerService(\OC\Log::class, function (Server $c) { |
|
| 765 | + $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file'); |
|
| 766 | + $factory = new LogFactory($c, $this->get(SystemConfig::class)); |
|
| 767 | + $logger = $factory->get($logType); |
|
| 768 | + $registry = $c->get(\OCP\Support\CrashReport\IRegistry::class); |
|
| 769 | + |
|
| 770 | + return new Log($logger, $this->get(SystemConfig::class), null, $registry); |
|
| 771 | + }); |
|
| 772 | + $this->registerAlias(ILogger::class, \OC\Log::class); |
|
| 773 | + /** @deprecated 19.0.0 */ |
|
| 774 | + $this->registerDeprecatedAlias('Logger', \OC\Log::class); |
|
| 775 | + // PSR-3 logger |
|
| 776 | + $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
|
| 777 | + |
|
| 778 | + $this->registerService(ILogFactory::class, function (Server $c) { |
|
| 779 | + return new LogFactory($c, $this->get(SystemConfig::class)); |
|
| 780 | + }); |
|
| 781 | + |
|
| 782 | + $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class); |
|
| 783 | + /** @deprecated 19.0.0 */ |
|
| 784 | + $this->registerDeprecatedAlias('JobList', IJobList::class); |
|
| 785 | + |
|
| 786 | + $this->registerService(Router::class, function (Server $c) { |
|
| 787 | + $cacheFactory = $c->get(ICacheFactory::class); |
|
| 788 | + $logger = $c->get(ILogger::class); |
|
| 789 | + if ($cacheFactory->isLocalCacheAvailable()) { |
|
| 790 | + $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
| 791 | + } else { |
|
| 792 | + $router = new \OC\Route\Router($logger); |
|
| 793 | + } |
|
| 794 | + return $router; |
|
| 795 | + }); |
|
| 796 | + $this->registerAlias(IRouter::class, Router::class); |
|
| 797 | + /** @deprecated 19.0.0 */ |
|
| 798 | + $this->registerDeprecatedAlias('Router', IRouter::class); |
|
| 799 | + |
|
| 800 | + $this->registerAlias(ISearch::class, Search::class); |
|
| 801 | + /** @deprecated 19.0.0 */ |
|
| 802 | + $this->registerDeprecatedAlias('Search', ISearch::class); |
|
| 803 | + |
|
| 804 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
| 805 | + $cacheFactory = $c->get(ICacheFactory::class); |
|
| 806 | + if ($cacheFactory->isAvailable()) { |
|
| 807 | + $backend = new \OC\Security\RateLimiting\Backend\MemoryCacheBackend( |
|
| 808 | + $this->get(ICacheFactory::class), |
|
| 809 | + new \OC\AppFramework\Utility\TimeFactory() |
|
| 810 | + ); |
|
| 811 | + } else { |
|
| 812 | + $backend = new \OC\Security\RateLimiting\Backend\DatabaseBackend( |
|
| 813 | + $c->get(IDBConnection::class), |
|
| 814 | + new \OC\AppFramework\Utility\TimeFactory() |
|
| 815 | + ); |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + return $backend; |
|
| 819 | + }); |
|
| 820 | + |
|
| 821 | + $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class); |
|
| 822 | + /** @deprecated 19.0.0 */ |
|
| 823 | + $this->registerDeprecatedAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
| 824 | + |
|
| 825 | + $this->registerAlias(IVerificationToken::class, VerificationToken::class); |
|
| 826 | + |
|
| 827 | + $this->registerAlias(ICrypto::class, Crypto::class); |
|
| 828 | + /** @deprecated 19.0.0 */ |
|
| 829 | + $this->registerDeprecatedAlias('Crypto', ICrypto::class); |
|
| 830 | + |
|
| 831 | + $this->registerAlias(IHasher::class, Hasher::class); |
|
| 832 | + /** @deprecated 19.0.0 */ |
|
| 833 | + $this->registerDeprecatedAlias('Hasher', IHasher::class); |
|
| 834 | + |
|
| 835 | + $this->registerAlias(ICredentialsManager::class, CredentialsManager::class); |
|
| 836 | + /** @deprecated 19.0.0 */ |
|
| 837 | + $this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class); |
|
| 838 | + |
|
| 839 | + $this->registerAlias(IDBConnection::class, ConnectionAdapter::class); |
|
| 840 | + $this->registerService(Connection::class, function (Server $c) { |
|
| 841 | + $systemConfig = $c->get(SystemConfig::class); |
|
| 842 | + $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
| 843 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
| 844 | + if (!$factory->isValidType($type)) { |
|
| 845 | + throw new \OC\DatabaseException('Invalid database type'); |
|
| 846 | + } |
|
| 847 | + $connectionParams = $factory->createConnectionParams(); |
|
| 848 | + $connection = $factory->getConnection($type, $connectionParams); |
|
| 849 | + $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
| 850 | + return $connection; |
|
| 851 | + }); |
|
| 852 | + /** @deprecated 19.0.0 */ |
|
| 853 | + $this->registerDeprecatedAlias('DatabaseConnection', IDBConnection::class); |
|
| 854 | + |
|
| 855 | + $this->registerAlias(ICertificateManager::class, CertificateManager::class); |
|
| 856 | + $this->registerAlias(IClientService::class, ClientService::class); |
|
| 857 | + $this->registerService(LocalAddressChecker::class, function (ContainerInterface $c) { |
|
| 858 | + return new LocalAddressChecker( |
|
| 859 | + $c->get(ILogger::class), |
|
| 860 | + ); |
|
| 861 | + }); |
|
| 862 | + $this->registerService(NegativeDnsCache::class, function (ContainerInterface $c) { |
|
| 863 | + return new NegativeDnsCache( |
|
| 864 | + $c->get(ICacheFactory::class), |
|
| 865 | + ); |
|
| 866 | + }); |
|
| 867 | + $this->registerService(DnsPinMiddleware::class, function (ContainerInterface $c) { |
|
| 868 | + return new DnsPinMiddleware( |
|
| 869 | + $c->get(NegativeDnsCache::class), |
|
| 870 | + $c->get(LocalAddressChecker::class) |
|
| 871 | + ); |
|
| 872 | + }); |
|
| 873 | + $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
|
| 874 | + $this->registerService(IEventLogger::class, function (ContainerInterface $c) { |
|
| 875 | + return new EventLogger($c->get(SystemConfig::class), $c->get(LoggerInterface::class), $c->get(Log::class)); |
|
| 876 | + }); |
|
| 877 | + /** @deprecated 19.0.0 */ |
|
| 878 | + $this->registerDeprecatedAlias('EventLogger', IEventLogger::class); |
|
| 879 | + |
|
| 880 | + $this->registerService(IQueryLogger::class, function (ContainerInterface $c) { |
|
| 881 | + $queryLogger = new QueryLogger(); |
|
| 882 | + if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
|
| 883 | + // In debug mode, module is being activated by default |
|
| 884 | + $queryLogger->activate(); |
|
| 885 | + } |
|
| 886 | + return $queryLogger; |
|
| 887 | + }); |
|
| 888 | + /** @deprecated 19.0.0 */ |
|
| 889 | + $this->registerDeprecatedAlias('QueryLogger', IQueryLogger::class); |
|
| 890 | + |
|
| 891 | + /** @deprecated 19.0.0 */ |
|
| 892 | + $this->registerDeprecatedAlias('TempManager', TempManager::class); |
|
| 893 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
| 894 | + |
|
| 895 | + $this->registerService(AppManager::class, function (ContainerInterface $c) { |
|
| 896 | + // TODO: use auto-wiring |
|
| 897 | + return new \OC\App\AppManager( |
|
| 898 | + $c->get(IUserSession::class), |
|
| 899 | + $c->get(\OCP\IConfig::class), |
|
| 900 | + $c->get(\OC\AppConfig::class), |
|
| 901 | + $c->get(IGroupManager::class), |
|
| 902 | + $c->get(ICacheFactory::class), |
|
| 903 | + $c->get(SymfonyAdapter::class), |
|
| 904 | + $c->get(LoggerInterface::class) |
|
| 905 | + ); |
|
| 906 | + }); |
|
| 907 | + /** @deprecated 19.0.0 */ |
|
| 908 | + $this->registerDeprecatedAlias('AppManager', AppManager::class); |
|
| 909 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
| 910 | + |
|
| 911 | + $this->registerAlias(IDateTimeZone::class, DateTimeZone::class); |
|
| 912 | + /** @deprecated 19.0.0 */ |
|
| 913 | + $this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class); |
|
| 914 | + |
|
| 915 | + $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
| 916 | + $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null); |
|
| 917 | + |
|
| 918 | + return new DateTimeFormatter( |
|
| 919 | + $c->get(IDateTimeZone::class)->getTimeZone(), |
|
| 920 | + $c->getL10N('lib', $language) |
|
| 921 | + ); |
|
| 922 | + }); |
|
| 923 | + /** @deprecated 19.0.0 */ |
|
| 924 | + $this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class); |
|
| 925 | + |
|
| 926 | + $this->registerService(IUserMountCache::class, function (ContainerInterface $c) { |
|
| 927 | + $mountCache = new UserMountCache( |
|
| 928 | + $c->get(IDBConnection::class), |
|
| 929 | + $c->get(IUserManager::class), |
|
| 930 | + $c->get(ILogger::class) |
|
| 931 | + ); |
|
| 932 | + $listener = new UserMountCacheListener($mountCache); |
|
| 933 | + $listener->listen($c->get(IUserManager::class)); |
|
| 934 | + return $mountCache; |
|
| 935 | + }); |
|
| 936 | + /** @deprecated 19.0.0 */ |
|
| 937 | + $this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class); |
|
| 938 | + |
|
| 939 | + $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) { |
|
| 940 | + $loader = \OC\Files\Filesystem::getLoader(); |
|
| 941 | + $mountCache = $c->get(IUserMountCache::class); |
|
| 942 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
| 943 | + |
|
| 944 | + // builtin providers |
|
| 945 | + |
|
| 946 | + $config = $c->get(\OCP\IConfig::class); |
|
| 947 | + $logger = $c->get(ILogger::class); |
|
| 948 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
| 949 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
| 950 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
| 951 | + $manager->registerRootProvider(new RootMountProvider($config, $c->get(LoggerInterface::class))); |
|
| 952 | + $manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config)); |
|
| 953 | + |
|
| 954 | + return $manager; |
|
| 955 | + }); |
|
| 956 | + /** @deprecated 19.0.0 */ |
|
| 957 | + $this->registerDeprecatedAlias('MountConfigManager', IMountProviderCollection::class); |
|
| 958 | + |
|
| 959 | + /** @deprecated 20.0.0 */ |
|
| 960 | + $this->registerDeprecatedAlias('IniWrapper', IniGetWrapper::class); |
|
| 961 | + $this->registerService(IBus::class, function (ContainerInterface $c) { |
|
| 962 | + $busClass = $c->get(\OCP\IConfig::class)->getSystemValue('commandbus'); |
|
| 963 | + if ($busClass) { |
|
| 964 | + [$app, $class] = explode('::', $busClass, 2); |
|
| 965 | + if ($c->get(IAppManager::class)->isInstalled($app)) { |
|
| 966 | + \OC_App::loadApp($app); |
|
| 967 | + return $c->get($class); |
|
| 968 | + } else { |
|
| 969 | + throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
| 970 | + } |
|
| 971 | + } else { |
|
| 972 | + $jobList = $c->get(IJobList::class); |
|
| 973 | + return new CronBus($jobList); |
|
| 974 | + } |
|
| 975 | + }); |
|
| 976 | + $this->registerDeprecatedAlias('AsyncCommandBus', IBus::class); |
|
| 977 | + /** @deprecated 20.0.0 */ |
|
| 978 | + $this->registerDeprecatedAlias('TrustedDomainHelper', TrustedDomainHelper::class); |
|
| 979 | + $this->registerAlias(ITrustedDomainHelper::class, TrustedDomainHelper::class); |
|
| 980 | + /** @deprecated 19.0.0 */ |
|
| 981 | + $this->registerDeprecatedAlias('Throttler', Throttler::class); |
|
| 982 | + $this->registerService('IntegrityCodeChecker', function (ContainerInterface $c) { |
|
| 983 | + // IConfig and IAppManager requires a working database. This code |
|
| 984 | + // might however be called when ownCloud is not yet setup. |
|
| 985 | + if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 986 | + $config = $c->get(\OCP\IConfig::class); |
|
| 987 | + $appManager = $c->get(IAppManager::class); |
|
| 988 | + } else { |
|
| 989 | + $config = null; |
|
| 990 | + $appManager = null; |
|
| 991 | + } |
|
| 992 | + |
|
| 993 | + return new Checker( |
|
| 994 | + new EnvironmentHelper(), |
|
| 995 | + new FileAccessHelper(), |
|
| 996 | + new AppLocator(), |
|
| 997 | + $config, |
|
| 998 | + $c->get(ICacheFactory::class), |
|
| 999 | + $appManager, |
|
| 1000 | + $c->get(IMimeTypeDetector::class) |
|
| 1001 | + ); |
|
| 1002 | + }); |
|
| 1003 | + $this->registerService(\OCP\IRequest::class, function (ContainerInterface $c) { |
|
| 1004 | + if (isset($this['urlParams'])) { |
|
| 1005 | + $urlParams = $this['urlParams']; |
|
| 1006 | + } else { |
|
| 1007 | + $urlParams = []; |
|
| 1008 | + } |
|
| 1009 | + |
|
| 1010 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
| 1011 | + && in_array('fakeinput', stream_get_wrappers()) |
|
| 1012 | + ) { |
|
| 1013 | + $stream = 'fakeinput://data'; |
|
| 1014 | + } else { |
|
| 1015 | + $stream = 'php://input'; |
|
| 1016 | + } |
|
| 1017 | + |
|
| 1018 | + return new Request( |
|
| 1019 | + [ |
|
| 1020 | + 'get' => $_GET, |
|
| 1021 | + 'post' => $_POST, |
|
| 1022 | + 'files' => $_FILES, |
|
| 1023 | + 'server' => $_SERVER, |
|
| 1024 | + 'env' => $_ENV, |
|
| 1025 | + 'cookies' => $_COOKIE, |
|
| 1026 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 1027 | + ? $_SERVER['REQUEST_METHOD'] |
|
| 1028 | + : '', |
|
| 1029 | + 'urlParams' => $urlParams, |
|
| 1030 | + ], |
|
| 1031 | + $this->get(ISecureRandom::class), |
|
| 1032 | + $this->get(\OCP\IConfig::class), |
|
| 1033 | + $this->get(CsrfTokenManager::class), |
|
| 1034 | + $stream |
|
| 1035 | + ); |
|
| 1036 | + }); |
|
| 1037 | + /** @deprecated 19.0.0 */ |
|
| 1038 | + $this->registerDeprecatedAlias('Request', \OCP\IRequest::class); |
|
| 1039 | + |
|
| 1040 | + $this->registerService(IMailer::class, function (Server $c) { |
|
| 1041 | + return new Mailer( |
|
| 1042 | + $c->get(\OCP\IConfig::class), |
|
| 1043 | + $c->get(ILogger::class), |
|
| 1044 | + $c->get(Defaults::class), |
|
| 1045 | + $c->get(IURLGenerator::class), |
|
| 1046 | + $c->getL10N('lib'), |
|
| 1047 | + $c->get(IEventDispatcher::class), |
|
| 1048 | + $c->get(IFactory::class) |
|
| 1049 | + ); |
|
| 1050 | + }); |
|
| 1051 | + /** @deprecated 19.0.0 */ |
|
| 1052 | + $this->registerDeprecatedAlias('Mailer', IMailer::class); |
|
| 1053 | + |
|
| 1054 | + /** @deprecated 21.0.0 */ |
|
| 1055 | + $this->registerDeprecatedAlias('LDAPProvider', ILDAPProvider::class); |
|
| 1056 | + |
|
| 1057 | + $this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) { |
|
| 1058 | + $config = $c->get(\OCP\IConfig::class); |
|
| 1059 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
| 1060 | + if (is_null($factoryClass) || !class_exists($factoryClass)) { |
|
| 1061 | + return new NullLDAPProviderFactory($this); |
|
| 1062 | + } |
|
| 1063 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
| 1064 | + return new $factoryClass($this); |
|
| 1065 | + }); |
|
| 1066 | + $this->registerService(ILDAPProvider::class, function (ContainerInterface $c) { |
|
| 1067 | + $factory = $c->get(ILDAPProviderFactory::class); |
|
| 1068 | + return $factory->getLDAPProvider(); |
|
| 1069 | + }); |
|
| 1070 | + $this->registerService(ILockingProvider::class, function (ContainerInterface $c) { |
|
| 1071 | + $ini = $c->get(IniGetWrapper::class); |
|
| 1072 | + $config = $c->get(\OCP\IConfig::class); |
|
| 1073 | + $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
| 1074 | + if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 1075 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
| 1076 | + $memcacheFactory = $c->get(ICacheFactory::class); |
|
| 1077 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
| 1078 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
| 1079 | + return new MemcacheLockingProvider($memcache, $ttl); |
|
| 1080 | + } |
|
| 1081 | + return new DBLockingProvider( |
|
| 1082 | + $c->get(IDBConnection::class), |
|
| 1083 | + $c->get(ILogger::class), |
|
| 1084 | + new TimeFactory(), |
|
| 1085 | + $ttl, |
|
| 1086 | + !\OC::$CLI |
|
| 1087 | + ); |
|
| 1088 | + } |
|
| 1089 | + return new NoopLockingProvider(); |
|
| 1090 | + }); |
|
| 1091 | + /** @deprecated 19.0.0 */ |
|
| 1092 | + $this->registerDeprecatedAlias('LockingProvider', ILockingProvider::class); |
|
| 1093 | + |
|
| 1094 | + $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class); |
|
| 1095 | + /** @deprecated 19.0.0 */ |
|
| 1096 | + $this->registerDeprecatedAlias('MountManager', IMountManager::class); |
|
| 1097 | + |
|
| 1098 | + $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) { |
|
| 1099 | + return new \OC\Files\Type\Detection( |
|
| 1100 | + $c->get(IURLGenerator::class), |
|
| 1101 | + $c->get(ILogger::class), |
|
| 1102 | + \OC::$configDir, |
|
| 1103 | + \OC::$SERVERROOT . '/resources/config/' |
|
| 1104 | + ); |
|
| 1105 | + }); |
|
| 1106 | + /** @deprecated 19.0.0 */ |
|
| 1107 | + $this->registerDeprecatedAlias('MimeTypeDetector', IMimeTypeDetector::class); |
|
| 1108 | + |
|
| 1109 | + $this->registerAlias(IMimeTypeLoader::class, Loader::class); |
|
| 1110 | + /** @deprecated 19.0.0 */ |
|
| 1111 | + $this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class); |
|
| 1112 | + $this->registerService(BundleFetcher::class, function () { |
|
| 1113 | + return new BundleFetcher($this->getL10N('lib')); |
|
| 1114 | + }); |
|
| 1115 | + $this->registerAlias(\OCP\Notification\IManager::class, Manager::class); |
|
| 1116 | + /** @deprecated 19.0.0 */ |
|
| 1117 | + $this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
| 1118 | + |
|
| 1119 | + $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) { |
|
| 1120 | + $manager = new CapabilitiesManager($c->get(LoggerInterface::class)); |
|
| 1121 | + $manager->registerCapability(function () use ($c) { |
|
| 1122 | + return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class)); |
|
| 1123 | + }); |
|
| 1124 | + $manager->registerCapability(function () use ($c) { |
|
| 1125 | + return $c->get(\OC\Security\Bruteforce\Capabilities::class); |
|
| 1126 | + }); |
|
| 1127 | + return $manager; |
|
| 1128 | + }); |
|
| 1129 | + /** @deprecated 19.0.0 */ |
|
| 1130 | + $this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class); |
|
| 1131 | + |
|
| 1132 | + $this->registerService(ICommentsManager::class, function (Server $c) { |
|
| 1133 | + $config = $c->get(\OCP\IConfig::class); |
|
| 1134 | + $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
| 1135 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
| 1136 | + $factory = new $factoryClass($this); |
|
| 1137 | + $manager = $factory->getManager(); |
|
| 1138 | + |
|
| 1139 | + $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
| 1140 | + $manager = $c->get(IUserManager::class); |
|
| 1141 | + $user = $manager->get($id); |
|
| 1142 | + if (is_null($user)) { |
|
| 1143 | + $l = $c->getL10N('core'); |
|
| 1144 | + $displayName = $l->t('Unknown user'); |
|
| 1145 | + } else { |
|
| 1146 | + $displayName = $user->getDisplayName(); |
|
| 1147 | + } |
|
| 1148 | + return $displayName; |
|
| 1149 | + }); |
|
| 1150 | + |
|
| 1151 | + return $manager; |
|
| 1152 | + }); |
|
| 1153 | + /** @deprecated 19.0.0 */ |
|
| 1154 | + $this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class); |
|
| 1155 | + |
|
| 1156 | + $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults'); |
|
| 1157 | + $this->registerService('ThemingDefaults', function (Server $c) { |
|
| 1158 | + /* |
|
| 1159 | 1159 | * Dark magic for autoloader. |
| 1160 | 1160 | * If we do a class_exists it will try to load the class which will |
| 1161 | 1161 | * make composer cache the result. Resulting in errors when enabling |
| 1162 | 1162 | * the theming app. |
| 1163 | 1163 | */ |
| 1164 | - $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
| 1165 | - if (isset($prefixes['OCA\\Theming\\'])) { |
|
| 1166 | - $classExists = true; |
|
| 1167 | - } else { |
|
| 1168 | - $classExists = false; |
|
| 1169 | - } |
|
| 1170 | - |
|
| 1171 | - if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValue('installed', false) && $c->get(IAppManager::class)->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
| 1172 | - return new ThemingDefaults( |
|
| 1173 | - $c->get(\OCP\IConfig::class), |
|
| 1174 | - $c->getL10N('theming'), |
|
| 1175 | - $c->get(IURLGenerator::class), |
|
| 1176 | - $c->get(ICacheFactory::class), |
|
| 1177 | - new Util($c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming')), |
|
| 1178 | - new ImageManager( |
|
| 1179 | - $c->get(\OCP\IConfig::class), |
|
| 1180 | - $c->getAppDataDir('theming'), |
|
| 1181 | - $c->get(IURLGenerator::class), |
|
| 1182 | - $this->get(ICacheFactory::class), |
|
| 1183 | - $this->get(ILogger::class), |
|
| 1184 | - $this->get(ITempManager::class) |
|
| 1185 | - ), |
|
| 1186 | - $c->get(IAppManager::class), |
|
| 1187 | - $c->get(INavigationManager::class) |
|
| 1188 | - ); |
|
| 1189 | - } |
|
| 1190 | - return new \OC_Defaults(); |
|
| 1191 | - }); |
|
| 1192 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
| 1193 | - return new JSCombiner( |
|
| 1194 | - $c->getAppDataDir('js'), |
|
| 1195 | - $c->get(IURLGenerator::class), |
|
| 1196 | - $this->get(ICacheFactory::class), |
|
| 1197 | - $c->get(SystemConfig::class), |
|
| 1198 | - $c->get(ILogger::class) |
|
| 1199 | - ); |
|
| 1200 | - }); |
|
| 1201 | - $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
| 1202 | - /** @deprecated 19.0.0 */ |
|
| 1203 | - $this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class); |
|
| 1204 | - $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class); |
|
| 1205 | - |
|
| 1206 | - $this->registerService('CryptoWrapper', function (ContainerInterface $c) { |
|
| 1207 | - // FIXME: Instantiiated here due to cyclic dependency |
|
| 1208 | - $request = new Request( |
|
| 1209 | - [ |
|
| 1210 | - 'get' => $_GET, |
|
| 1211 | - 'post' => $_POST, |
|
| 1212 | - 'files' => $_FILES, |
|
| 1213 | - 'server' => $_SERVER, |
|
| 1214 | - 'env' => $_ENV, |
|
| 1215 | - 'cookies' => $_COOKIE, |
|
| 1216 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 1217 | - ? $_SERVER['REQUEST_METHOD'] |
|
| 1218 | - : null, |
|
| 1219 | - ], |
|
| 1220 | - $c->get(ISecureRandom::class), |
|
| 1221 | - $c->get(\OCP\IConfig::class) |
|
| 1222 | - ); |
|
| 1223 | - |
|
| 1224 | - return new CryptoWrapper( |
|
| 1225 | - $c->get(\OCP\IConfig::class), |
|
| 1226 | - $c->get(ICrypto::class), |
|
| 1227 | - $c->get(ISecureRandom::class), |
|
| 1228 | - $request |
|
| 1229 | - ); |
|
| 1230 | - }); |
|
| 1231 | - /** @deprecated 19.0.0 */ |
|
| 1232 | - $this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class); |
|
| 1233 | - $this->registerService(SessionStorage::class, function (ContainerInterface $c) { |
|
| 1234 | - return new SessionStorage($c->get(ISession::class)); |
|
| 1235 | - }); |
|
| 1236 | - $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
|
| 1237 | - /** @deprecated 19.0.0 */ |
|
| 1238 | - $this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class); |
|
| 1239 | - |
|
| 1240 | - $this->registerService(\OCP\Share\IManager::class, function (IServerContainer $c) { |
|
| 1241 | - $config = $c->get(\OCP\IConfig::class); |
|
| 1242 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
| 1243 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
| 1244 | - $factory = new $factoryClass($this); |
|
| 1245 | - |
|
| 1246 | - $manager = new \OC\Share20\Manager( |
|
| 1247 | - $c->get(ILogger::class), |
|
| 1248 | - $c->get(\OCP\IConfig::class), |
|
| 1249 | - $c->get(ISecureRandom::class), |
|
| 1250 | - $c->get(IHasher::class), |
|
| 1251 | - $c->get(IMountManager::class), |
|
| 1252 | - $c->get(IGroupManager::class), |
|
| 1253 | - $c->getL10N('lib'), |
|
| 1254 | - $c->get(IFactory::class), |
|
| 1255 | - $factory, |
|
| 1256 | - $c->get(IUserManager::class), |
|
| 1257 | - $c->get(IRootFolder::class), |
|
| 1258 | - $c->get(SymfonyAdapter::class), |
|
| 1259 | - $c->get(IMailer::class), |
|
| 1260 | - $c->get(IURLGenerator::class), |
|
| 1261 | - $c->get('ThemingDefaults'), |
|
| 1262 | - $c->get(IEventDispatcher::class), |
|
| 1263 | - $c->get(IUserSession::class), |
|
| 1264 | - $c->get(KnownUserService::class) |
|
| 1265 | - ); |
|
| 1266 | - |
|
| 1267 | - return $manager; |
|
| 1268 | - }); |
|
| 1269 | - /** @deprecated 19.0.0 */ |
|
| 1270 | - $this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class); |
|
| 1271 | - |
|
| 1272 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
| 1273 | - $instance = new Collaboration\Collaborators\Search($c); |
|
| 1274 | - |
|
| 1275 | - // register default plugins |
|
| 1276 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
| 1277 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
| 1278 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
| 1279 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
| 1280 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
| 1281 | - |
|
| 1282 | - return $instance; |
|
| 1283 | - }); |
|
| 1284 | - /** @deprecated 19.0.0 */ |
|
| 1285 | - $this->registerDeprecatedAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
| 1286 | - $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
| 1287 | - |
|
| 1288 | - $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
| 1289 | - |
|
| 1290 | - $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class); |
|
| 1291 | - $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
| 1292 | - |
|
| 1293 | - $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class); |
|
| 1294 | - $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class); |
|
| 1295 | - $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) { |
|
| 1296 | - return new \OC\Files\AppData\Factory( |
|
| 1297 | - $c->get(IRootFolder::class), |
|
| 1298 | - $c->get(SystemConfig::class) |
|
| 1299 | - ); |
|
| 1300 | - }); |
|
| 1301 | - |
|
| 1302 | - $this->registerService('LockdownManager', function (ContainerInterface $c) { |
|
| 1303 | - return new LockdownManager(function () use ($c) { |
|
| 1304 | - return $c->get(ISession::class); |
|
| 1305 | - }); |
|
| 1306 | - }); |
|
| 1307 | - |
|
| 1308 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) { |
|
| 1309 | - return new DiscoveryService( |
|
| 1310 | - $c->get(ICacheFactory::class), |
|
| 1311 | - $c->get(IClientService::class) |
|
| 1312 | - ); |
|
| 1313 | - }); |
|
| 1314 | - |
|
| 1315 | - $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) { |
|
| 1316 | - return new CloudIdManager($c->get(\OCP\Contacts\IManager::class), $c->get(IURLGenerator::class), $c->get(IUserManager::class)); |
|
| 1317 | - }); |
|
| 1318 | - |
|
| 1319 | - $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); |
|
| 1320 | - |
|
| 1321 | - $this->registerService(ICloudFederationProviderManager::class, function (ContainerInterface $c) { |
|
| 1322 | - return new CloudFederationProviderManager( |
|
| 1323 | - $c->get(IAppManager::class), |
|
| 1324 | - $c->get(IClientService::class), |
|
| 1325 | - $c->get(ICloudIdManager::class), |
|
| 1326 | - $c->get(ILogger::class) |
|
| 1327 | - ); |
|
| 1328 | - }); |
|
| 1329 | - |
|
| 1330 | - $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
| 1331 | - return new CloudFederationFactory(); |
|
| 1332 | - }); |
|
| 1333 | - |
|
| 1334 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 1335 | - /** @deprecated 19.0.0 */ |
|
| 1336 | - $this->registerDeprecatedAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
| 1337 | - |
|
| 1338 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 1339 | - /** @deprecated 19.0.0 */ |
|
| 1340 | - $this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 1341 | - |
|
| 1342 | - $this->registerService(Defaults::class, function (Server $c) { |
|
| 1343 | - return new Defaults( |
|
| 1344 | - $c->getThemingDefaults() |
|
| 1345 | - ); |
|
| 1346 | - }); |
|
| 1347 | - /** @deprecated 19.0.0 */ |
|
| 1348 | - $this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class); |
|
| 1349 | - |
|
| 1350 | - $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) { |
|
| 1351 | - return $c->get(\OCP\IUserSession::class)->getSession(); |
|
| 1352 | - }, false); |
|
| 1353 | - |
|
| 1354 | - $this->registerService(IShareHelper::class, function (ContainerInterface $c) { |
|
| 1355 | - return new ShareHelper( |
|
| 1356 | - $c->get(\OCP\Share\IManager::class) |
|
| 1357 | - ); |
|
| 1358 | - }); |
|
| 1359 | - |
|
| 1360 | - $this->registerService(Installer::class, function (ContainerInterface $c) { |
|
| 1361 | - return new Installer( |
|
| 1362 | - $c->get(AppFetcher::class), |
|
| 1363 | - $c->get(IClientService::class), |
|
| 1364 | - $c->get(ITempManager::class), |
|
| 1365 | - $c->get(LoggerInterface::class), |
|
| 1366 | - $c->get(\OCP\IConfig::class), |
|
| 1367 | - \OC::$CLI |
|
| 1368 | - ); |
|
| 1369 | - }); |
|
| 1370 | - |
|
| 1371 | - $this->registerService(IApiFactory::class, function (ContainerInterface $c) { |
|
| 1372 | - return new ApiFactory($c->get(IClientService::class)); |
|
| 1373 | - }); |
|
| 1374 | - |
|
| 1375 | - $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) { |
|
| 1376 | - $memcacheFactory = $c->get(ICacheFactory::class); |
|
| 1377 | - return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class)); |
|
| 1378 | - }); |
|
| 1379 | - |
|
| 1380 | - $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
| 1381 | - $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
| 1382 | - |
|
| 1383 | - $this->registerAlias(IStorageFactory::class, StorageFactory::class); |
|
| 1384 | - |
|
| 1385 | - $this->registerAlias(IDashboardManager::class, DashboardManager::class); |
|
| 1386 | - $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class); |
|
| 1387 | - $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
| 1388 | - |
|
| 1389 | - $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
| 1390 | - |
|
| 1391 | - $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
| 1392 | - |
|
| 1393 | - $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class); |
|
| 1394 | - |
|
| 1395 | - $this->connectDispatcher(); |
|
| 1396 | - } |
|
| 1397 | - |
|
| 1398 | - public function boot() { |
|
| 1399 | - /** @var HookConnector $hookConnector */ |
|
| 1400 | - $hookConnector = $this->get(HookConnector::class); |
|
| 1401 | - $hookConnector->viewToNode(); |
|
| 1402 | - } |
|
| 1403 | - |
|
| 1404 | - /** |
|
| 1405 | - * @return \OCP\Calendar\IManager |
|
| 1406 | - * @deprecated 20.0.0 |
|
| 1407 | - */ |
|
| 1408 | - public function getCalendarManager() { |
|
| 1409 | - return $this->get(\OC\Calendar\Manager::class); |
|
| 1410 | - } |
|
| 1411 | - |
|
| 1412 | - /** |
|
| 1413 | - * @return \OCP\Calendar\Resource\IManager |
|
| 1414 | - * @deprecated 20.0.0 |
|
| 1415 | - */ |
|
| 1416 | - public function getCalendarResourceBackendManager() { |
|
| 1417 | - return $this->get(\OC\Calendar\Resource\Manager::class); |
|
| 1418 | - } |
|
| 1419 | - |
|
| 1420 | - /** |
|
| 1421 | - * @return \OCP\Calendar\Room\IManager |
|
| 1422 | - * @deprecated 20.0.0 |
|
| 1423 | - */ |
|
| 1424 | - public function getCalendarRoomBackendManager() { |
|
| 1425 | - return $this->get(\OC\Calendar\Room\Manager::class); |
|
| 1426 | - } |
|
| 1427 | - |
|
| 1428 | - private function connectDispatcher() { |
|
| 1429 | - $dispatcher = $this->get(SymfonyAdapter::class); |
|
| 1430 | - |
|
| 1431 | - // Delete avatar on user deletion |
|
| 1432 | - $dispatcher->addListener('OCP\IUser::preDelete', function (GenericEvent $e) { |
|
| 1433 | - $logger = $this->get(ILogger::class); |
|
| 1434 | - $manager = $this->getAvatarManager(); |
|
| 1435 | - /** @var IUser $user */ |
|
| 1436 | - $user = $e->getSubject(); |
|
| 1437 | - |
|
| 1438 | - try { |
|
| 1439 | - $avatar = $manager->getAvatar($user->getUID()); |
|
| 1440 | - $avatar->remove(); |
|
| 1441 | - } catch (NotFoundException $e) { |
|
| 1442 | - // no avatar to remove |
|
| 1443 | - } catch (\Exception $e) { |
|
| 1444 | - // Ignore exceptions |
|
| 1445 | - $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
| 1446 | - } |
|
| 1447 | - }); |
|
| 1448 | - |
|
| 1449 | - $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
| 1450 | - $manager = $this->getAvatarManager(); |
|
| 1451 | - /** @var IUser $user */ |
|
| 1452 | - $user = $e->getSubject(); |
|
| 1453 | - $feature = $e->getArgument('feature'); |
|
| 1454 | - $oldValue = $e->getArgument('oldValue'); |
|
| 1455 | - $value = $e->getArgument('value'); |
|
| 1456 | - |
|
| 1457 | - // We only change the avatar on display name changes |
|
| 1458 | - if ($feature !== 'displayName') { |
|
| 1459 | - return; |
|
| 1460 | - } |
|
| 1461 | - |
|
| 1462 | - try { |
|
| 1463 | - $avatar = $manager->getAvatar($user->getUID()); |
|
| 1464 | - $avatar->userChanged($feature, $oldValue, $value); |
|
| 1465 | - } catch (NotFoundException $e) { |
|
| 1466 | - // no avatar to remove |
|
| 1467 | - } |
|
| 1468 | - }); |
|
| 1469 | - |
|
| 1470 | - /** @var IEventDispatcher $eventDispatched */ |
|
| 1471 | - $eventDispatched = $this->get(IEventDispatcher::class); |
|
| 1472 | - $eventDispatched->addServiceListener(LoginFailed::class, LoginFailedListener::class); |
|
| 1473 | - $eventDispatched->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class); |
|
| 1474 | - } |
|
| 1475 | - |
|
| 1476 | - /** |
|
| 1477 | - * @return \OCP\Contacts\IManager |
|
| 1478 | - * @deprecated 20.0.0 |
|
| 1479 | - */ |
|
| 1480 | - public function getContactsManager() { |
|
| 1481 | - return $this->get(\OCP\Contacts\IManager::class); |
|
| 1482 | - } |
|
| 1483 | - |
|
| 1484 | - /** |
|
| 1485 | - * @return \OC\Encryption\Manager |
|
| 1486 | - * @deprecated 20.0.0 |
|
| 1487 | - */ |
|
| 1488 | - public function getEncryptionManager() { |
|
| 1489 | - return $this->get(\OCP\Encryption\IManager::class); |
|
| 1490 | - } |
|
| 1491 | - |
|
| 1492 | - /** |
|
| 1493 | - * @return \OC\Encryption\File |
|
| 1494 | - * @deprecated 20.0.0 |
|
| 1495 | - */ |
|
| 1496 | - public function getEncryptionFilesHelper() { |
|
| 1497 | - return $this->get(IFile::class); |
|
| 1498 | - } |
|
| 1499 | - |
|
| 1500 | - /** |
|
| 1501 | - * @return \OCP\Encryption\Keys\IStorage |
|
| 1502 | - * @deprecated 20.0.0 |
|
| 1503 | - */ |
|
| 1504 | - public function getEncryptionKeyStorage() { |
|
| 1505 | - return $this->get(IStorage::class); |
|
| 1506 | - } |
|
| 1507 | - |
|
| 1508 | - /** |
|
| 1509 | - * The current request object holding all information about the request |
|
| 1510 | - * currently being processed is returned from this method. |
|
| 1511 | - * In case the current execution was not initiated by a web request null is returned |
|
| 1512 | - * |
|
| 1513 | - * @return \OCP\IRequest |
|
| 1514 | - * @deprecated 20.0.0 |
|
| 1515 | - */ |
|
| 1516 | - public function getRequest() { |
|
| 1517 | - return $this->get(IRequest::class); |
|
| 1518 | - } |
|
| 1519 | - |
|
| 1520 | - /** |
|
| 1521 | - * Returns the preview manager which can create preview images for a given file |
|
| 1522 | - * |
|
| 1523 | - * @return IPreview |
|
| 1524 | - * @deprecated 20.0.0 |
|
| 1525 | - */ |
|
| 1526 | - public function getPreviewManager() { |
|
| 1527 | - return $this->get(IPreview::class); |
|
| 1528 | - } |
|
| 1529 | - |
|
| 1530 | - /** |
|
| 1531 | - * Returns the tag manager which can get and set tags for different object types |
|
| 1532 | - * |
|
| 1533 | - * @see \OCP\ITagManager::load() |
|
| 1534 | - * @return ITagManager |
|
| 1535 | - * @deprecated 20.0.0 |
|
| 1536 | - */ |
|
| 1537 | - public function getTagManager() { |
|
| 1538 | - return $this->get(ITagManager::class); |
|
| 1539 | - } |
|
| 1540 | - |
|
| 1541 | - /** |
|
| 1542 | - * Returns the system-tag manager |
|
| 1543 | - * |
|
| 1544 | - * @return ISystemTagManager |
|
| 1545 | - * |
|
| 1546 | - * @since 9.0.0 |
|
| 1547 | - * @deprecated 20.0.0 |
|
| 1548 | - */ |
|
| 1549 | - public function getSystemTagManager() { |
|
| 1550 | - return $this->get(ISystemTagManager::class); |
|
| 1551 | - } |
|
| 1552 | - |
|
| 1553 | - /** |
|
| 1554 | - * Returns the system-tag object mapper |
|
| 1555 | - * |
|
| 1556 | - * @return ISystemTagObjectMapper |
|
| 1557 | - * |
|
| 1558 | - * @since 9.0.0 |
|
| 1559 | - * @deprecated 20.0.0 |
|
| 1560 | - */ |
|
| 1561 | - public function getSystemTagObjectMapper() { |
|
| 1562 | - return $this->get(ISystemTagObjectMapper::class); |
|
| 1563 | - } |
|
| 1564 | - |
|
| 1565 | - /** |
|
| 1566 | - * Returns the avatar manager, used for avatar functionality |
|
| 1567 | - * |
|
| 1568 | - * @return IAvatarManager |
|
| 1569 | - * @deprecated 20.0.0 |
|
| 1570 | - */ |
|
| 1571 | - public function getAvatarManager() { |
|
| 1572 | - return $this->get(IAvatarManager::class); |
|
| 1573 | - } |
|
| 1574 | - |
|
| 1575 | - /** |
|
| 1576 | - * Returns the root folder of ownCloud's data directory |
|
| 1577 | - * |
|
| 1578 | - * @return IRootFolder |
|
| 1579 | - * @deprecated 20.0.0 |
|
| 1580 | - */ |
|
| 1581 | - public function getRootFolder() { |
|
| 1582 | - return $this->get(IRootFolder::class); |
|
| 1583 | - } |
|
| 1584 | - |
|
| 1585 | - /** |
|
| 1586 | - * Returns the root folder of ownCloud's data directory |
|
| 1587 | - * This is the lazy variant so this gets only initialized once it |
|
| 1588 | - * is actually used. |
|
| 1589 | - * |
|
| 1590 | - * @return IRootFolder |
|
| 1591 | - * @deprecated 20.0.0 |
|
| 1592 | - */ |
|
| 1593 | - public function getLazyRootFolder() { |
|
| 1594 | - return $this->get(IRootFolder::class); |
|
| 1595 | - } |
|
| 1596 | - |
|
| 1597 | - /** |
|
| 1598 | - * Returns a view to ownCloud's files folder |
|
| 1599 | - * |
|
| 1600 | - * @param string $userId user ID |
|
| 1601 | - * @return \OCP\Files\Folder|null |
|
| 1602 | - * @deprecated 20.0.0 |
|
| 1603 | - */ |
|
| 1604 | - public function getUserFolder($userId = null) { |
|
| 1605 | - if ($userId === null) { |
|
| 1606 | - $user = $this->get(IUserSession::class)->getUser(); |
|
| 1607 | - if (!$user) { |
|
| 1608 | - return null; |
|
| 1609 | - } |
|
| 1610 | - $userId = $user->getUID(); |
|
| 1611 | - } |
|
| 1612 | - $root = $this->get(IRootFolder::class); |
|
| 1613 | - return $root->getUserFolder($userId); |
|
| 1614 | - } |
|
| 1615 | - |
|
| 1616 | - /** |
|
| 1617 | - * @return \OC\User\Manager |
|
| 1618 | - * @deprecated 20.0.0 |
|
| 1619 | - */ |
|
| 1620 | - public function getUserManager() { |
|
| 1621 | - return $this->get(IUserManager::class); |
|
| 1622 | - } |
|
| 1623 | - |
|
| 1624 | - /** |
|
| 1625 | - * @return \OC\Group\Manager |
|
| 1626 | - * @deprecated 20.0.0 |
|
| 1627 | - */ |
|
| 1628 | - public function getGroupManager() { |
|
| 1629 | - return $this->get(IGroupManager::class); |
|
| 1630 | - } |
|
| 1631 | - |
|
| 1632 | - /** |
|
| 1633 | - * @return \OC\User\Session |
|
| 1634 | - * @deprecated 20.0.0 |
|
| 1635 | - */ |
|
| 1636 | - public function getUserSession() { |
|
| 1637 | - return $this->get(IUserSession::class); |
|
| 1638 | - } |
|
| 1639 | - |
|
| 1640 | - /** |
|
| 1641 | - * @return \OCP\ISession |
|
| 1642 | - * @deprecated 20.0.0 |
|
| 1643 | - */ |
|
| 1644 | - public function getSession() { |
|
| 1645 | - return $this->get(IUserSession::class)->getSession(); |
|
| 1646 | - } |
|
| 1647 | - |
|
| 1648 | - /** |
|
| 1649 | - * @param \OCP\ISession $session |
|
| 1650 | - */ |
|
| 1651 | - public function setSession(\OCP\ISession $session) { |
|
| 1652 | - $this->get(SessionStorage::class)->setSession($session); |
|
| 1653 | - $this->get(IUserSession::class)->setSession($session); |
|
| 1654 | - $this->get(Store::class)->setSession($session); |
|
| 1655 | - } |
|
| 1656 | - |
|
| 1657 | - /** |
|
| 1658 | - * @return \OC\Authentication\TwoFactorAuth\Manager |
|
| 1659 | - * @deprecated 20.0.0 |
|
| 1660 | - */ |
|
| 1661 | - public function getTwoFactorAuthManager() { |
|
| 1662 | - return $this->get(\OC\Authentication\TwoFactorAuth\Manager::class); |
|
| 1663 | - } |
|
| 1664 | - |
|
| 1665 | - /** |
|
| 1666 | - * @return \OC\NavigationManager |
|
| 1667 | - * @deprecated 20.0.0 |
|
| 1668 | - */ |
|
| 1669 | - public function getNavigationManager() { |
|
| 1670 | - return $this->get(INavigationManager::class); |
|
| 1671 | - } |
|
| 1672 | - |
|
| 1673 | - /** |
|
| 1674 | - * @return \OCP\IConfig |
|
| 1675 | - * @deprecated 20.0.0 |
|
| 1676 | - */ |
|
| 1677 | - public function getConfig() { |
|
| 1678 | - return $this->get(AllConfig::class); |
|
| 1679 | - } |
|
| 1680 | - |
|
| 1681 | - /** |
|
| 1682 | - * @return \OC\SystemConfig |
|
| 1683 | - * @deprecated 20.0.0 |
|
| 1684 | - */ |
|
| 1685 | - public function getSystemConfig() { |
|
| 1686 | - return $this->get(SystemConfig::class); |
|
| 1687 | - } |
|
| 1688 | - |
|
| 1689 | - /** |
|
| 1690 | - * Returns the app config manager |
|
| 1691 | - * |
|
| 1692 | - * @return IAppConfig |
|
| 1693 | - * @deprecated 20.0.0 |
|
| 1694 | - */ |
|
| 1695 | - public function getAppConfig() { |
|
| 1696 | - return $this->get(IAppConfig::class); |
|
| 1697 | - } |
|
| 1698 | - |
|
| 1699 | - /** |
|
| 1700 | - * @return IFactory |
|
| 1701 | - * @deprecated 20.0.0 |
|
| 1702 | - */ |
|
| 1703 | - public function getL10NFactory() { |
|
| 1704 | - return $this->get(IFactory::class); |
|
| 1705 | - } |
|
| 1706 | - |
|
| 1707 | - /** |
|
| 1708 | - * get an L10N instance |
|
| 1709 | - * |
|
| 1710 | - * @param string $app appid |
|
| 1711 | - * @param string $lang |
|
| 1712 | - * @return IL10N |
|
| 1713 | - * @deprecated 20.0.0 |
|
| 1714 | - */ |
|
| 1715 | - public function getL10N($app, $lang = null) { |
|
| 1716 | - return $this->get(IFactory::class)->get($app, $lang); |
|
| 1717 | - } |
|
| 1718 | - |
|
| 1719 | - /** |
|
| 1720 | - * @return IURLGenerator |
|
| 1721 | - * @deprecated 20.0.0 |
|
| 1722 | - */ |
|
| 1723 | - public function getURLGenerator() { |
|
| 1724 | - return $this->get(IURLGenerator::class); |
|
| 1725 | - } |
|
| 1726 | - |
|
| 1727 | - /** |
|
| 1728 | - * @return AppFetcher |
|
| 1729 | - * @deprecated 20.0.0 |
|
| 1730 | - */ |
|
| 1731 | - public function getAppFetcher() { |
|
| 1732 | - return $this->get(AppFetcher::class); |
|
| 1733 | - } |
|
| 1734 | - |
|
| 1735 | - /** |
|
| 1736 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
| 1737 | - * getMemCacheFactory() instead. |
|
| 1738 | - * |
|
| 1739 | - * @return ICache |
|
| 1740 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
| 1741 | - */ |
|
| 1742 | - public function getCache() { |
|
| 1743 | - return $this->get(ICache::class); |
|
| 1744 | - } |
|
| 1745 | - |
|
| 1746 | - /** |
|
| 1747 | - * Returns an \OCP\CacheFactory instance |
|
| 1748 | - * |
|
| 1749 | - * @return \OCP\ICacheFactory |
|
| 1750 | - * @deprecated 20.0.0 |
|
| 1751 | - */ |
|
| 1752 | - public function getMemCacheFactory() { |
|
| 1753 | - return $this->get(ICacheFactory::class); |
|
| 1754 | - } |
|
| 1755 | - |
|
| 1756 | - /** |
|
| 1757 | - * Returns an \OC\RedisFactory instance |
|
| 1758 | - * |
|
| 1759 | - * @return \OC\RedisFactory |
|
| 1760 | - * @deprecated 20.0.0 |
|
| 1761 | - */ |
|
| 1762 | - public function getGetRedisFactory() { |
|
| 1763 | - return $this->get('RedisFactory'); |
|
| 1764 | - } |
|
| 1765 | - |
|
| 1766 | - |
|
| 1767 | - /** |
|
| 1768 | - * Returns the current session |
|
| 1769 | - * |
|
| 1770 | - * @return \OCP\IDBConnection |
|
| 1771 | - * @deprecated 20.0.0 |
|
| 1772 | - */ |
|
| 1773 | - public function getDatabaseConnection() { |
|
| 1774 | - return $this->get(IDBConnection::class); |
|
| 1775 | - } |
|
| 1776 | - |
|
| 1777 | - /** |
|
| 1778 | - * Returns the activity manager |
|
| 1779 | - * |
|
| 1780 | - * @return \OCP\Activity\IManager |
|
| 1781 | - * @deprecated 20.0.0 |
|
| 1782 | - */ |
|
| 1783 | - public function getActivityManager() { |
|
| 1784 | - return $this->get(\OCP\Activity\IManager::class); |
|
| 1785 | - } |
|
| 1786 | - |
|
| 1787 | - /** |
|
| 1788 | - * Returns an job list for controlling background jobs |
|
| 1789 | - * |
|
| 1790 | - * @return IJobList |
|
| 1791 | - * @deprecated 20.0.0 |
|
| 1792 | - */ |
|
| 1793 | - public function getJobList() { |
|
| 1794 | - return $this->get(IJobList::class); |
|
| 1795 | - } |
|
| 1796 | - |
|
| 1797 | - /** |
|
| 1798 | - * Returns a logger instance |
|
| 1799 | - * |
|
| 1800 | - * @return ILogger |
|
| 1801 | - * @deprecated 20.0.0 |
|
| 1802 | - */ |
|
| 1803 | - public function getLogger() { |
|
| 1804 | - return $this->get(ILogger::class); |
|
| 1805 | - } |
|
| 1806 | - |
|
| 1807 | - /** |
|
| 1808 | - * @return ILogFactory |
|
| 1809 | - * @throws \OCP\AppFramework\QueryException |
|
| 1810 | - * @deprecated 20.0.0 |
|
| 1811 | - */ |
|
| 1812 | - public function getLogFactory() { |
|
| 1813 | - return $this->get(ILogFactory::class); |
|
| 1814 | - } |
|
| 1815 | - |
|
| 1816 | - /** |
|
| 1817 | - * Returns a router for generating and matching urls |
|
| 1818 | - * |
|
| 1819 | - * @return IRouter |
|
| 1820 | - * @deprecated 20.0.0 |
|
| 1821 | - */ |
|
| 1822 | - public function getRouter() { |
|
| 1823 | - return $this->get(IRouter::class); |
|
| 1824 | - } |
|
| 1825 | - |
|
| 1826 | - /** |
|
| 1827 | - * Returns a search instance |
|
| 1828 | - * |
|
| 1829 | - * @return ISearch |
|
| 1830 | - * @deprecated 20.0.0 |
|
| 1831 | - */ |
|
| 1832 | - public function getSearch() { |
|
| 1833 | - return $this->get(ISearch::class); |
|
| 1834 | - } |
|
| 1835 | - |
|
| 1836 | - /** |
|
| 1837 | - * Returns a SecureRandom instance |
|
| 1838 | - * |
|
| 1839 | - * @return \OCP\Security\ISecureRandom |
|
| 1840 | - * @deprecated 20.0.0 |
|
| 1841 | - */ |
|
| 1842 | - public function getSecureRandom() { |
|
| 1843 | - return $this->get(ISecureRandom::class); |
|
| 1844 | - } |
|
| 1845 | - |
|
| 1846 | - /** |
|
| 1847 | - * Returns a Crypto instance |
|
| 1848 | - * |
|
| 1849 | - * @return ICrypto |
|
| 1850 | - * @deprecated 20.0.0 |
|
| 1851 | - */ |
|
| 1852 | - public function getCrypto() { |
|
| 1853 | - return $this->get(ICrypto::class); |
|
| 1854 | - } |
|
| 1855 | - |
|
| 1856 | - /** |
|
| 1857 | - * Returns a Hasher instance |
|
| 1858 | - * |
|
| 1859 | - * @return IHasher |
|
| 1860 | - * @deprecated 20.0.0 |
|
| 1861 | - */ |
|
| 1862 | - public function getHasher() { |
|
| 1863 | - return $this->get(IHasher::class); |
|
| 1864 | - } |
|
| 1865 | - |
|
| 1866 | - /** |
|
| 1867 | - * Returns a CredentialsManager instance |
|
| 1868 | - * |
|
| 1869 | - * @return ICredentialsManager |
|
| 1870 | - * @deprecated 20.0.0 |
|
| 1871 | - */ |
|
| 1872 | - public function getCredentialsManager() { |
|
| 1873 | - return $this->get(ICredentialsManager::class); |
|
| 1874 | - } |
|
| 1875 | - |
|
| 1876 | - /** |
|
| 1877 | - * Get the certificate manager |
|
| 1878 | - * |
|
| 1879 | - * @return \OCP\ICertificateManager |
|
| 1880 | - */ |
|
| 1881 | - public function getCertificateManager() { |
|
| 1882 | - return $this->get(ICertificateManager::class); |
|
| 1883 | - } |
|
| 1884 | - |
|
| 1885 | - /** |
|
| 1886 | - * Returns an instance of the HTTP client service |
|
| 1887 | - * |
|
| 1888 | - * @return IClientService |
|
| 1889 | - * @deprecated 20.0.0 |
|
| 1890 | - */ |
|
| 1891 | - public function getHTTPClientService() { |
|
| 1892 | - return $this->get(IClientService::class); |
|
| 1893 | - } |
|
| 1894 | - |
|
| 1895 | - /** |
|
| 1896 | - * Create a new event source |
|
| 1897 | - * |
|
| 1898 | - * @return \OCP\IEventSource |
|
| 1899 | - * @deprecated 20.0.0 |
|
| 1900 | - */ |
|
| 1901 | - public function createEventSource() { |
|
| 1902 | - return new \OC_EventSource(); |
|
| 1903 | - } |
|
| 1904 | - |
|
| 1905 | - /** |
|
| 1906 | - * Get the active event logger |
|
| 1907 | - * |
|
| 1908 | - * The returned logger only logs data when debug mode is enabled |
|
| 1909 | - * |
|
| 1910 | - * @return IEventLogger |
|
| 1911 | - * @deprecated 20.0.0 |
|
| 1912 | - */ |
|
| 1913 | - public function getEventLogger() { |
|
| 1914 | - return $this->get(IEventLogger::class); |
|
| 1915 | - } |
|
| 1916 | - |
|
| 1917 | - /** |
|
| 1918 | - * Get the active query logger |
|
| 1919 | - * |
|
| 1920 | - * The returned logger only logs data when debug mode is enabled |
|
| 1921 | - * |
|
| 1922 | - * @return IQueryLogger |
|
| 1923 | - * @deprecated 20.0.0 |
|
| 1924 | - */ |
|
| 1925 | - public function getQueryLogger() { |
|
| 1926 | - return $this->get(IQueryLogger::class); |
|
| 1927 | - } |
|
| 1928 | - |
|
| 1929 | - /** |
|
| 1930 | - * Get the manager for temporary files and folders |
|
| 1931 | - * |
|
| 1932 | - * @return \OCP\ITempManager |
|
| 1933 | - * @deprecated 20.0.0 |
|
| 1934 | - */ |
|
| 1935 | - public function getTempManager() { |
|
| 1936 | - return $this->get(ITempManager::class); |
|
| 1937 | - } |
|
| 1938 | - |
|
| 1939 | - /** |
|
| 1940 | - * Get the app manager |
|
| 1941 | - * |
|
| 1942 | - * @return \OCP\App\IAppManager |
|
| 1943 | - * @deprecated 20.0.0 |
|
| 1944 | - */ |
|
| 1945 | - public function getAppManager() { |
|
| 1946 | - return $this->get(IAppManager::class); |
|
| 1947 | - } |
|
| 1948 | - |
|
| 1949 | - /** |
|
| 1950 | - * Creates a new mailer |
|
| 1951 | - * |
|
| 1952 | - * @return IMailer |
|
| 1953 | - * @deprecated 20.0.0 |
|
| 1954 | - */ |
|
| 1955 | - public function getMailer() { |
|
| 1956 | - return $this->get(IMailer::class); |
|
| 1957 | - } |
|
| 1958 | - |
|
| 1959 | - /** |
|
| 1960 | - * Get the webroot |
|
| 1961 | - * |
|
| 1962 | - * @return string |
|
| 1963 | - * @deprecated 20.0.0 |
|
| 1964 | - */ |
|
| 1965 | - public function getWebRoot() { |
|
| 1966 | - return $this->webRoot; |
|
| 1967 | - } |
|
| 1968 | - |
|
| 1969 | - /** |
|
| 1970 | - * @return \OC\OCSClient |
|
| 1971 | - * @deprecated 20.0.0 |
|
| 1972 | - */ |
|
| 1973 | - public function getOcsClient() { |
|
| 1974 | - return $this->get('OcsClient'); |
|
| 1975 | - } |
|
| 1976 | - |
|
| 1977 | - /** |
|
| 1978 | - * @return IDateTimeZone |
|
| 1979 | - * @deprecated 20.0.0 |
|
| 1980 | - */ |
|
| 1981 | - public function getDateTimeZone() { |
|
| 1982 | - return $this->get(IDateTimeZone::class); |
|
| 1983 | - } |
|
| 1984 | - |
|
| 1985 | - /** |
|
| 1986 | - * @return IDateTimeFormatter |
|
| 1987 | - * @deprecated 20.0.0 |
|
| 1988 | - */ |
|
| 1989 | - public function getDateTimeFormatter() { |
|
| 1990 | - return $this->get(IDateTimeFormatter::class); |
|
| 1991 | - } |
|
| 1992 | - |
|
| 1993 | - /** |
|
| 1994 | - * @return IMountProviderCollection |
|
| 1995 | - * @deprecated 20.0.0 |
|
| 1996 | - */ |
|
| 1997 | - public function getMountProviderCollection() { |
|
| 1998 | - return $this->get(IMountProviderCollection::class); |
|
| 1999 | - } |
|
| 2000 | - |
|
| 2001 | - /** |
|
| 2002 | - * Get the IniWrapper |
|
| 2003 | - * |
|
| 2004 | - * @return IniGetWrapper |
|
| 2005 | - * @deprecated 20.0.0 |
|
| 2006 | - */ |
|
| 2007 | - public function getIniWrapper() { |
|
| 2008 | - return $this->get(IniGetWrapper::class); |
|
| 2009 | - } |
|
| 2010 | - |
|
| 2011 | - /** |
|
| 2012 | - * @return \OCP\Command\IBus |
|
| 2013 | - * @deprecated 20.0.0 |
|
| 2014 | - */ |
|
| 2015 | - public function getCommandBus() { |
|
| 2016 | - return $this->get(IBus::class); |
|
| 2017 | - } |
|
| 2018 | - |
|
| 2019 | - /** |
|
| 2020 | - * Get the trusted domain helper |
|
| 2021 | - * |
|
| 2022 | - * @return TrustedDomainHelper |
|
| 2023 | - * @deprecated 20.0.0 |
|
| 2024 | - */ |
|
| 2025 | - public function getTrustedDomainHelper() { |
|
| 2026 | - return $this->get(TrustedDomainHelper::class); |
|
| 2027 | - } |
|
| 2028 | - |
|
| 2029 | - /** |
|
| 2030 | - * Get the locking provider |
|
| 2031 | - * |
|
| 2032 | - * @return ILockingProvider |
|
| 2033 | - * @since 8.1.0 |
|
| 2034 | - * @deprecated 20.0.0 |
|
| 2035 | - */ |
|
| 2036 | - public function getLockingProvider() { |
|
| 2037 | - return $this->get(ILockingProvider::class); |
|
| 2038 | - } |
|
| 2039 | - |
|
| 2040 | - /** |
|
| 2041 | - * @return IMountManager |
|
| 2042 | - * @deprecated 20.0.0 |
|
| 2043 | - **/ |
|
| 2044 | - public function getMountManager() { |
|
| 2045 | - return $this->get(IMountManager::class); |
|
| 2046 | - } |
|
| 2047 | - |
|
| 2048 | - /** |
|
| 2049 | - * @return IUserMountCache |
|
| 2050 | - * @deprecated 20.0.0 |
|
| 2051 | - */ |
|
| 2052 | - public function getUserMountCache() { |
|
| 2053 | - return $this->get(IUserMountCache::class); |
|
| 2054 | - } |
|
| 2055 | - |
|
| 2056 | - /** |
|
| 2057 | - * Get the MimeTypeDetector |
|
| 2058 | - * |
|
| 2059 | - * @return IMimeTypeDetector |
|
| 2060 | - * @deprecated 20.0.0 |
|
| 2061 | - */ |
|
| 2062 | - public function getMimeTypeDetector() { |
|
| 2063 | - return $this->get(IMimeTypeDetector::class); |
|
| 2064 | - } |
|
| 2065 | - |
|
| 2066 | - /** |
|
| 2067 | - * Get the MimeTypeLoader |
|
| 2068 | - * |
|
| 2069 | - * @return IMimeTypeLoader |
|
| 2070 | - * @deprecated 20.0.0 |
|
| 2071 | - */ |
|
| 2072 | - public function getMimeTypeLoader() { |
|
| 2073 | - return $this->get(IMimeTypeLoader::class); |
|
| 2074 | - } |
|
| 2075 | - |
|
| 2076 | - /** |
|
| 2077 | - * Get the manager of all the capabilities |
|
| 2078 | - * |
|
| 2079 | - * @return CapabilitiesManager |
|
| 2080 | - * @deprecated 20.0.0 |
|
| 2081 | - */ |
|
| 2082 | - public function getCapabilitiesManager() { |
|
| 2083 | - return $this->get(CapabilitiesManager::class); |
|
| 2084 | - } |
|
| 2085 | - |
|
| 2086 | - /** |
|
| 2087 | - * Get the EventDispatcher |
|
| 2088 | - * |
|
| 2089 | - * @return EventDispatcherInterface |
|
| 2090 | - * @since 8.2.0 |
|
| 2091 | - * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher |
|
| 2092 | - */ |
|
| 2093 | - public function getEventDispatcher() { |
|
| 2094 | - return $this->get(\OC\EventDispatcher\SymfonyAdapter::class); |
|
| 2095 | - } |
|
| 2096 | - |
|
| 2097 | - /** |
|
| 2098 | - * Get the Notification Manager |
|
| 2099 | - * |
|
| 2100 | - * @return \OCP\Notification\IManager |
|
| 2101 | - * @since 8.2.0 |
|
| 2102 | - * @deprecated 20.0.0 |
|
| 2103 | - */ |
|
| 2104 | - public function getNotificationManager() { |
|
| 2105 | - return $this->get(\OCP\Notification\IManager::class); |
|
| 2106 | - } |
|
| 2107 | - |
|
| 2108 | - /** |
|
| 2109 | - * @return ICommentsManager |
|
| 2110 | - * @deprecated 20.0.0 |
|
| 2111 | - */ |
|
| 2112 | - public function getCommentsManager() { |
|
| 2113 | - return $this->get(ICommentsManager::class); |
|
| 2114 | - } |
|
| 2115 | - |
|
| 2116 | - /** |
|
| 2117 | - * @return \OCA\Theming\ThemingDefaults |
|
| 2118 | - * @deprecated 20.0.0 |
|
| 2119 | - */ |
|
| 2120 | - public function getThemingDefaults() { |
|
| 2121 | - return $this->get('ThemingDefaults'); |
|
| 2122 | - } |
|
| 2123 | - |
|
| 2124 | - /** |
|
| 2125 | - * @return \OC\IntegrityCheck\Checker |
|
| 2126 | - * @deprecated 20.0.0 |
|
| 2127 | - */ |
|
| 2128 | - public function getIntegrityCodeChecker() { |
|
| 2129 | - return $this->get('IntegrityCodeChecker'); |
|
| 2130 | - } |
|
| 2131 | - |
|
| 2132 | - /** |
|
| 2133 | - * @return \OC\Session\CryptoWrapper |
|
| 2134 | - * @deprecated 20.0.0 |
|
| 2135 | - */ |
|
| 2136 | - public function getSessionCryptoWrapper() { |
|
| 2137 | - return $this->get('CryptoWrapper'); |
|
| 2138 | - } |
|
| 2139 | - |
|
| 2140 | - /** |
|
| 2141 | - * @return CsrfTokenManager |
|
| 2142 | - * @deprecated 20.0.0 |
|
| 2143 | - */ |
|
| 2144 | - public function getCsrfTokenManager() { |
|
| 2145 | - return $this->get(CsrfTokenManager::class); |
|
| 2146 | - } |
|
| 2147 | - |
|
| 2148 | - /** |
|
| 2149 | - * @return Throttler |
|
| 2150 | - * @deprecated 20.0.0 |
|
| 2151 | - */ |
|
| 2152 | - public function getBruteForceThrottler() { |
|
| 2153 | - return $this->get(Throttler::class); |
|
| 2154 | - } |
|
| 2155 | - |
|
| 2156 | - /** |
|
| 2157 | - * @return IContentSecurityPolicyManager |
|
| 2158 | - * @deprecated 20.0.0 |
|
| 2159 | - */ |
|
| 2160 | - public function getContentSecurityPolicyManager() { |
|
| 2161 | - return $this->get(ContentSecurityPolicyManager::class); |
|
| 2162 | - } |
|
| 2163 | - |
|
| 2164 | - /** |
|
| 2165 | - * @return ContentSecurityPolicyNonceManager |
|
| 2166 | - * @deprecated 20.0.0 |
|
| 2167 | - */ |
|
| 2168 | - public function getContentSecurityPolicyNonceManager() { |
|
| 2169 | - return $this->get(ContentSecurityPolicyNonceManager::class); |
|
| 2170 | - } |
|
| 2171 | - |
|
| 2172 | - /** |
|
| 2173 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 2174 | - * |
|
| 2175 | - * @return \OCA\Files_External\Service\BackendService |
|
| 2176 | - * @deprecated 20.0.0 |
|
| 2177 | - */ |
|
| 2178 | - public function getStoragesBackendService() { |
|
| 2179 | - return $this->get(BackendService::class); |
|
| 2180 | - } |
|
| 2181 | - |
|
| 2182 | - /** |
|
| 2183 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 2184 | - * |
|
| 2185 | - * @return \OCA\Files_External\Service\GlobalStoragesService |
|
| 2186 | - * @deprecated 20.0.0 |
|
| 2187 | - */ |
|
| 2188 | - public function getGlobalStoragesService() { |
|
| 2189 | - return $this->get(GlobalStoragesService::class); |
|
| 2190 | - } |
|
| 2191 | - |
|
| 2192 | - /** |
|
| 2193 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 2194 | - * |
|
| 2195 | - * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
| 2196 | - * @deprecated 20.0.0 |
|
| 2197 | - */ |
|
| 2198 | - public function getUserGlobalStoragesService() { |
|
| 2199 | - return $this->get(UserGlobalStoragesService::class); |
|
| 2200 | - } |
|
| 2201 | - |
|
| 2202 | - /** |
|
| 2203 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 2204 | - * |
|
| 2205 | - * @return \OCA\Files_External\Service\UserStoragesService |
|
| 2206 | - * @deprecated 20.0.0 |
|
| 2207 | - */ |
|
| 2208 | - public function getUserStoragesService() { |
|
| 2209 | - return $this->get(UserStoragesService::class); |
|
| 2210 | - } |
|
| 2211 | - |
|
| 2212 | - /** |
|
| 2213 | - * @return \OCP\Share\IManager |
|
| 2214 | - * @deprecated 20.0.0 |
|
| 2215 | - */ |
|
| 2216 | - public function getShareManager() { |
|
| 2217 | - return $this->get(\OCP\Share\IManager::class); |
|
| 2218 | - } |
|
| 2219 | - |
|
| 2220 | - /** |
|
| 2221 | - * @return \OCP\Collaboration\Collaborators\ISearch |
|
| 2222 | - * @deprecated 20.0.0 |
|
| 2223 | - */ |
|
| 2224 | - public function getCollaboratorSearch() { |
|
| 2225 | - return $this->get(\OCP\Collaboration\Collaborators\ISearch::class); |
|
| 2226 | - } |
|
| 2227 | - |
|
| 2228 | - /** |
|
| 2229 | - * @return \OCP\Collaboration\AutoComplete\IManager |
|
| 2230 | - * @deprecated 20.0.0 |
|
| 2231 | - */ |
|
| 2232 | - public function getAutoCompleteManager() { |
|
| 2233 | - return $this->get(IManager::class); |
|
| 2234 | - } |
|
| 2235 | - |
|
| 2236 | - /** |
|
| 2237 | - * Returns the LDAP Provider |
|
| 2238 | - * |
|
| 2239 | - * @return \OCP\LDAP\ILDAPProvider |
|
| 2240 | - * @deprecated 20.0.0 |
|
| 2241 | - */ |
|
| 2242 | - public function getLDAPProvider() { |
|
| 2243 | - return $this->get('LDAPProvider'); |
|
| 2244 | - } |
|
| 2245 | - |
|
| 2246 | - /** |
|
| 2247 | - * @return \OCP\Settings\IManager |
|
| 2248 | - * @deprecated 20.0.0 |
|
| 2249 | - */ |
|
| 2250 | - public function getSettingsManager() { |
|
| 2251 | - return $this->get(\OC\Settings\Manager::class); |
|
| 2252 | - } |
|
| 2253 | - |
|
| 2254 | - /** |
|
| 2255 | - * @return \OCP\Files\IAppData |
|
| 2256 | - * @deprecated 20.0.0 |
|
| 2257 | - */ |
|
| 2258 | - public function getAppDataDir($app) { |
|
| 2259 | - /** @var \OC\Files\AppData\Factory $factory */ |
|
| 2260 | - $factory = $this->get(\OC\Files\AppData\Factory::class); |
|
| 2261 | - return $factory->get($app); |
|
| 2262 | - } |
|
| 2263 | - |
|
| 2264 | - /** |
|
| 2265 | - * @return \OCP\Lockdown\ILockdownManager |
|
| 2266 | - * @deprecated 20.0.0 |
|
| 2267 | - */ |
|
| 2268 | - public function getLockdownManager() { |
|
| 2269 | - return $this->get('LockdownManager'); |
|
| 2270 | - } |
|
| 2271 | - |
|
| 2272 | - /** |
|
| 2273 | - * @return \OCP\Federation\ICloudIdManager |
|
| 2274 | - * @deprecated 20.0.0 |
|
| 2275 | - */ |
|
| 2276 | - public function getCloudIdManager() { |
|
| 2277 | - return $this->get(ICloudIdManager::class); |
|
| 2278 | - } |
|
| 2279 | - |
|
| 2280 | - /** |
|
| 2281 | - * @return \OCP\GlobalScale\IConfig |
|
| 2282 | - * @deprecated 20.0.0 |
|
| 2283 | - */ |
|
| 2284 | - public function getGlobalScaleConfig() { |
|
| 2285 | - return $this->get(IConfig::class); |
|
| 2286 | - } |
|
| 2287 | - |
|
| 2288 | - /** |
|
| 2289 | - * @return \OCP\Federation\ICloudFederationProviderManager |
|
| 2290 | - * @deprecated 20.0.0 |
|
| 2291 | - */ |
|
| 2292 | - public function getCloudFederationProviderManager() { |
|
| 2293 | - return $this->get(ICloudFederationProviderManager::class); |
|
| 2294 | - } |
|
| 2295 | - |
|
| 2296 | - /** |
|
| 2297 | - * @return \OCP\Remote\Api\IApiFactory |
|
| 2298 | - * @deprecated 20.0.0 |
|
| 2299 | - */ |
|
| 2300 | - public function getRemoteApiFactory() { |
|
| 2301 | - return $this->get(IApiFactory::class); |
|
| 2302 | - } |
|
| 2303 | - |
|
| 2304 | - /** |
|
| 2305 | - * @return \OCP\Federation\ICloudFederationFactory |
|
| 2306 | - * @deprecated 20.0.0 |
|
| 2307 | - */ |
|
| 2308 | - public function getCloudFederationFactory() { |
|
| 2309 | - return $this->get(ICloudFederationFactory::class); |
|
| 2310 | - } |
|
| 2311 | - |
|
| 2312 | - /** |
|
| 2313 | - * @return \OCP\Remote\IInstanceFactory |
|
| 2314 | - * @deprecated 20.0.0 |
|
| 2315 | - */ |
|
| 2316 | - public function getRemoteInstanceFactory() { |
|
| 2317 | - return $this->get(IInstanceFactory::class); |
|
| 2318 | - } |
|
| 2319 | - |
|
| 2320 | - /** |
|
| 2321 | - * @return IStorageFactory |
|
| 2322 | - * @deprecated 20.0.0 |
|
| 2323 | - */ |
|
| 2324 | - public function getStorageFactory() { |
|
| 2325 | - return $this->get(IStorageFactory::class); |
|
| 2326 | - } |
|
| 2327 | - |
|
| 2328 | - /** |
|
| 2329 | - * Get the Preview GeneratorHelper |
|
| 2330 | - * |
|
| 2331 | - * @return GeneratorHelper |
|
| 2332 | - * @since 17.0.0 |
|
| 2333 | - * @deprecated 20.0.0 |
|
| 2334 | - */ |
|
| 2335 | - public function getGeneratorHelper() { |
|
| 2336 | - return $this->get(\OC\Preview\GeneratorHelper::class); |
|
| 2337 | - } |
|
| 2338 | - |
|
| 2339 | - private function registerDeprecatedAlias(string $alias, string $target) { |
|
| 2340 | - $this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) { |
|
| 2341 | - try { |
|
| 2342 | - /** @var ILogger $logger */ |
|
| 2343 | - $logger = $container->get(ILogger::class); |
|
| 2344 | - $logger->debug('The requested alias "' . $alias . '" is deprecated. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']); |
|
| 2345 | - } catch (ContainerExceptionInterface $e) { |
|
| 2346 | - // Could not get logger. Continue |
|
| 2347 | - } |
|
| 2348 | - |
|
| 2349 | - return $container->get($target); |
|
| 2350 | - }, false); |
|
| 2351 | - } |
|
| 1164 | + $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
| 1165 | + if (isset($prefixes['OCA\\Theming\\'])) { |
|
| 1166 | + $classExists = true; |
|
| 1167 | + } else { |
|
| 1168 | + $classExists = false; |
|
| 1169 | + } |
|
| 1170 | + |
|
| 1171 | + if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValue('installed', false) && $c->get(IAppManager::class)->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
| 1172 | + return new ThemingDefaults( |
|
| 1173 | + $c->get(\OCP\IConfig::class), |
|
| 1174 | + $c->getL10N('theming'), |
|
| 1175 | + $c->get(IURLGenerator::class), |
|
| 1176 | + $c->get(ICacheFactory::class), |
|
| 1177 | + new Util($c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming')), |
|
| 1178 | + new ImageManager( |
|
| 1179 | + $c->get(\OCP\IConfig::class), |
|
| 1180 | + $c->getAppDataDir('theming'), |
|
| 1181 | + $c->get(IURLGenerator::class), |
|
| 1182 | + $this->get(ICacheFactory::class), |
|
| 1183 | + $this->get(ILogger::class), |
|
| 1184 | + $this->get(ITempManager::class) |
|
| 1185 | + ), |
|
| 1186 | + $c->get(IAppManager::class), |
|
| 1187 | + $c->get(INavigationManager::class) |
|
| 1188 | + ); |
|
| 1189 | + } |
|
| 1190 | + return new \OC_Defaults(); |
|
| 1191 | + }); |
|
| 1192 | + $this->registerService(JSCombiner::class, function (Server $c) { |
|
| 1193 | + return new JSCombiner( |
|
| 1194 | + $c->getAppDataDir('js'), |
|
| 1195 | + $c->get(IURLGenerator::class), |
|
| 1196 | + $this->get(ICacheFactory::class), |
|
| 1197 | + $c->get(SystemConfig::class), |
|
| 1198 | + $c->get(ILogger::class) |
|
| 1199 | + ); |
|
| 1200 | + }); |
|
| 1201 | + $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
| 1202 | + /** @deprecated 19.0.0 */ |
|
| 1203 | + $this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class); |
|
| 1204 | + $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class); |
|
| 1205 | + |
|
| 1206 | + $this->registerService('CryptoWrapper', function (ContainerInterface $c) { |
|
| 1207 | + // FIXME: Instantiiated here due to cyclic dependency |
|
| 1208 | + $request = new Request( |
|
| 1209 | + [ |
|
| 1210 | + 'get' => $_GET, |
|
| 1211 | + 'post' => $_POST, |
|
| 1212 | + 'files' => $_FILES, |
|
| 1213 | + 'server' => $_SERVER, |
|
| 1214 | + 'env' => $_ENV, |
|
| 1215 | + 'cookies' => $_COOKIE, |
|
| 1216 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 1217 | + ? $_SERVER['REQUEST_METHOD'] |
|
| 1218 | + : null, |
|
| 1219 | + ], |
|
| 1220 | + $c->get(ISecureRandom::class), |
|
| 1221 | + $c->get(\OCP\IConfig::class) |
|
| 1222 | + ); |
|
| 1223 | + |
|
| 1224 | + return new CryptoWrapper( |
|
| 1225 | + $c->get(\OCP\IConfig::class), |
|
| 1226 | + $c->get(ICrypto::class), |
|
| 1227 | + $c->get(ISecureRandom::class), |
|
| 1228 | + $request |
|
| 1229 | + ); |
|
| 1230 | + }); |
|
| 1231 | + /** @deprecated 19.0.0 */ |
|
| 1232 | + $this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class); |
|
| 1233 | + $this->registerService(SessionStorage::class, function (ContainerInterface $c) { |
|
| 1234 | + return new SessionStorage($c->get(ISession::class)); |
|
| 1235 | + }); |
|
| 1236 | + $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
|
| 1237 | + /** @deprecated 19.0.0 */ |
|
| 1238 | + $this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class); |
|
| 1239 | + |
|
| 1240 | + $this->registerService(\OCP\Share\IManager::class, function (IServerContainer $c) { |
|
| 1241 | + $config = $c->get(\OCP\IConfig::class); |
|
| 1242 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
| 1243 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
| 1244 | + $factory = new $factoryClass($this); |
|
| 1245 | + |
|
| 1246 | + $manager = new \OC\Share20\Manager( |
|
| 1247 | + $c->get(ILogger::class), |
|
| 1248 | + $c->get(\OCP\IConfig::class), |
|
| 1249 | + $c->get(ISecureRandom::class), |
|
| 1250 | + $c->get(IHasher::class), |
|
| 1251 | + $c->get(IMountManager::class), |
|
| 1252 | + $c->get(IGroupManager::class), |
|
| 1253 | + $c->getL10N('lib'), |
|
| 1254 | + $c->get(IFactory::class), |
|
| 1255 | + $factory, |
|
| 1256 | + $c->get(IUserManager::class), |
|
| 1257 | + $c->get(IRootFolder::class), |
|
| 1258 | + $c->get(SymfonyAdapter::class), |
|
| 1259 | + $c->get(IMailer::class), |
|
| 1260 | + $c->get(IURLGenerator::class), |
|
| 1261 | + $c->get('ThemingDefaults'), |
|
| 1262 | + $c->get(IEventDispatcher::class), |
|
| 1263 | + $c->get(IUserSession::class), |
|
| 1264 | + $c->get(KnownUserService::class) |
|
| 1265 | + ); |
|
| 1266 | + |
|
| 1267 | + return $manager; |
|
| 1268 | + }); |
|
| 1269 | + /** @deprecated 19.0.0 */ |
|
| 1270 | + $this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class); |
|
| 1271 | + |
|
| 1272 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
| 1273 | + $instance = new Collaboration\Collaborators\Search($c); |
|
| 1274 | + |
|
| 1275 | + // register default plugins |
|
| 1276 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
| 1277 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
| 1278 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
| 1279 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
| 1280 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
| 1281 | + |
|
| 1282 | + return $instance; |
|
| 1283 | + }); |
|
| 1284 | + /** @deprecated 19.0.0 */ |
|
| 1285 | + $this->registerDeprecatedAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
| 1286 | + $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
| 1287 | + |
|
| 1288 | + $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
| 1289 | + |
|
| 1290 | + $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class); |
|
| 1291 | + $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
| 1292 | + |
|
| 1293 | + $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class); |
|
| 1294 | + $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class); |
|
| 1295 | + $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) { |
|
| 1296 | + return new \OC\Files\AppData\Factory( |
|
| 1297 | + $c->get(IRootFolder::class), |
|
| 1298 | + $c->get(SystemConfig::class) |
|
| 1299 | + ); |
|
| 1300 | + }); |
|
| 1301 | + |
|
| 1302 | + $this->registerService('LockdownManager', function (ContainerInterface $c) { |
|
| 1303 | + return new LockdownManager(function () use ($c) { |
|
| 1304 | + return $c->get(ISession::class); |
|
| 1305 | + }); |
|
| 1306 | + }); |
|
| 1307 | + |
|
| 1308 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) { |
|
| 1309 | + return new DiscoveryService( |
|
| 1310 | + $c->get(ICacheFactory::class), |
|
| 1311 | + $c->get(IClientService::class) |
|
| 1312 | + ); |
|
| 1313 | + }); |
|
| 1314 | + |
|
| 1315 | + $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) { |
|
| 1316 | + return new CloudIdManager($c->get(\OCP\Contacts\IManager::class), $c->get(IURLGenerator::class), $c->get(IUserManager::class)); |
|
| 1317 | + }); |
|
| 1318 | + |
|
| 1319 | + $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); |
|
| 1320 | + |
|
| 1321 | + $this->registerService(ICloudFederationProviderManager::class, function (ContainerInterface $c) { |
|
| 1322 | + return new CloudFederationProviderManager( |
|
| 1323 | + $c->get(IAppManager::class), |
|
| 1324 | + $c->get(IClientService::class), |
|
| 1325 | + $c->get(ICloudIdManager::class), |
|
| 1326 | + $c->get(ILogger::class) |
|
| 1327 | + ); |
|
| 1328 | + }); |
|
| 1329 | + |
|
| 1330 | + $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
| 1331 | + return new CloudFederationFactory(); |
|
| 1332 | + }); |
|
| 1333 | + |
|
| 1334 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 1335 | + /** @deprecated 19.0.0 */ |
|
| 1336 | + $this->registerDeprecatedAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
| 1337 | + |
|
| 1338 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 1339 | + /** @deprecated 19.0.0 */ |
|
| 1340 | + $this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 1341 | + |
|
| 1342 | + $this->registerService(Defaults::class, function (Server $c) { |
|
| 1343 | + return new Defaults( |
|
| 1344 | + $c->getThemingDefaults() |
|
| 1345 | + ); |
|
| 1346 | + }); |
|
| 1347 | + /** @deprecated 19.0.0 */ |
|
| 1348 | + $this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class); |
|
| 1349 | + |
|
| 1350 | + $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) { |
|
| 1351 | + return $c->get(\OCP\IUserSession::class)->getSession(); |
|
| 1352 | + }, false); |
|
| 1353 | + |
|
| 1354 | + $this->registerService(IShareHelper::class, function (ContainerInterface $c) { |
|
| 1355 | + return new ShareHelper( |
|
| 1356 | + $c->get(\OCP\Share\IManager::class) |
|
| 1357 | + ); |
|
| 1358 | + }); |
|
| 1359 | + |
|
| 1360 | + $this->registerService(Installer::class, function (ContainerInterface $c) { |
|
| 1361 | + return new Installer( |
|
| 1362 | + $c->get(AppFetcher::class), |
|
| 1363 | + $c->get(IClientService::class), |
|
| 1364 | + $c->get(ITempManager::class), |
|
| 1365 | + $c->get(LoggerInterface::class), |
|
| 1366 | + $c->get(\OCP\IConfig::class), |
|
| 1367 | + \OC::$CLI |
|
| 1368 | + ); |
|
| 1369 | + }); |
|
| 1370 | + |
|
| 1371 | + $this->registerService(IApiFactory::class, function (ContainerInterface $c) { |
|
| 1372 | + return new ApiFactory($c->get(IClientService::class)); |
|
| 1373 | + }); |
|
| 1374 | + |
|
| 1375 | + $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) { |
|
| 1376 | + $memcacheFactory = $c->get(ICacheFactory::class); |
|
| 1377 | + return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class)); |
|
| 1378 | + }); |
|
| 1379 | + |
|
| 1380 | + $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
| 1381 | + $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
| 1382 | + |
|
| 1383 | + $this->registerAlias(IStorageFactory::class, StorageFactory::class); |
|
| 1384 | + |
|
| 1385 | + $this->registerAlias(IDashboardManager::class, DashboardManager::class); |
|
| 1386 | + $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class); |
|
| 1387 | + $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
| 1388 | + |
|
| 1389 | + $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
| 1390 | + |
|
| 1391 | + $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
| 1392 | + |
|
| 1393 | + $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class); |
|
| 1394 | + |
|
| 1395 | + $this->connectDispatcher(); |
|
| 1396 | + } |
|
| 1397 | + |
|
| 1398 | + public function boot() { |
|
| 1399 | + /** @var HookConnector $hookConnector */ |
|
| 1400 | + $hookConnector = $this->get(HookConnector::class); |
|
| 1401 | + $hookConnector->viewToNode(); |
|
| 1402 | + } |
|
| 1403 | + |
|
| 1404 | + /** |
|
| 1405 | + * @return \OCP\Calendar\IManager |
|
| 1406 | + * @deprecated 20.0.0 |
|
| 1407 | + */ |
|
| 1408 | + public function getCalendarManager() { |
|
| 1409 | + return $this->get(\OC\Calendar\Manager::class); |
|
| 1410 | + } |
|
| 1411 | + |
|
| 1412 | + /** |
|
| 1413 | + * @return \OCP\Calendar\Resource\IManager |
|
| 1414 | + * @deprecated 20.0.0 |
|
| 1415 | + */ |
|
| 1416 | + public function getCalendarResourceBackendManager() { |
|
| 1417 | + return $this->get(\OC\Calendar\Resource\Manager::class); |
|
| 1418 | + } |
|
| 1419 | + |
|
| 1420 | + /** |
|
| 1421 | + * @return \OCP\Calendar\Room\IManager |
|
| 1422 | + * @deprecated 20.0.0 |
|
| 1423 | + */ |
|
| 1424 | + public function getCalendarRoomBackendManager() { |
|
| 1425 | + return $this->get(\OC\Calendar\Room\Manager::class); |
|
| 1426 | + } |
|
| 1427 | + |
|
| 1428 | + private function connectDispatcher() { |
|
| 1429 | + $dispatcher = $this->get(SymfonyAdapter::class); |
|
| 1430 | + |
|
| 1431 | + // Delete avatar on user deletion |
|
| 1432 | + $dispatcher->addListener('OCP\IUser::preDelete', function (GenericEvent $e) { |
|
| 1433 | + $logger = $this->get(ILogger::class); |
|
| 1434 | + $manager = $this->getAvatarManager(); |
|
| 1435 | + /** @var IUser $user */ |
|
| 1436 | + $user = $e->getSubject(); |
|
| 1437 | + |
|
| 1438 | + try { |
|
| 1439 | + $avatar = $manager->getAvatar($user->getUID()); |
|
| 1440 | + $avatar->remove(); |
|
| 1441 | + } catch (NotFoundException $e) { |
|
| 1442 | + // no avatar to remove |
|
| 1443 | + } catch (\Exception $e) { |
|
| 1444 | + // Ignore exceptions |
|
| 1445 | + $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
| 1446 | + } |
|
| 1447 | + }); |
|
| 1448 | + |
|
| 1449 | + $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
| 1450 | + $manager = $this->getAvatarManager(); |
|
| 1451 | + /** @var IUser $user */ |
|
| 1452 | + $user = $e->getSubject(); |
|
| 1453 | + $feature = $e->getArgument('feature'); |
|
| 1454 | + $oldValue = $e->getArgument('oldValue'); |
|
| 1455 | + $value = $e->getArgument('value'); |
|
| 1456 | + |
|
| 1457 | + // We only change the avatar on display name changes |
|
| 1458 | + if ($feature !== 'displayName') { |
|
| 1459 | + return; |
|
| 1460 | + } |
|
| 1461 | + |
|
| 1462 | + try { |
|
| 1463 | + $avatar = $manager->getAvatar($user->getUID()); |
|
| 1464 | + $avatar->userChanged($feature, $oldValue, $value); |
|
| 1465 | + } catch (NotFoundException $e) { |
|
| 1466 | + // no avatar to remove |
|
| 1467 | + } |
|
| 1468 | + }); |
|
| 1469 | + |
|
| 1470 | + /** @var IEventDispatcher $eventDispatched */ |
|
| 1471 | + $eventDispatched = $this->get(IEventDispatcher::class); |
|
| 1472 | + $eventDispatched->addServiceListener(LoginFailed::class, LoginFailedListener::class); |
|
| 1473 | + $eventDispatched->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class); |
|
| 1474 | + } |
|
| 1475 | + |
|
| 1476 | + /** |
|
| 1477 | + * @return \OCP\Contacts\IManager |
|
| 1478 | + * @deprecated 20.0.0 |
|
| 1479 | + */ |
|
| 1480 | + public function getContactsManager() { |
|
| 1481 | + return $this->get(\OCP\Contacts\IManager::class); |
|
| 1482 | + } |
|
| 1483 | + |
|
| 1484 | + /** |
|
| 1485 | + * @return \OC\Encryption\Manager |
|
| 1486 | + * @deprecated 20.0.0 |
|
| 1487 | + */ |
|
| 1488 | + public function getEncryptionManager() { |
|
| 1489 | + return $this->get(\OCP\Encryption\IManager::class); |
|
| 1490 | + } |
|
| 1491 | + |
|
| 1492 | + /** |
|
| 1493 | + * @return \OC\Encryption\File |
|
| 1494 | + * @deprecated 20.0.0 |
|
| 1495 | + */ |
|
| 1496 | + public function getEncryptionFilesHelper() { |
|
| 1497 | + return $this->get(IFile::class); |
|
| 1498 | + } |
|
| 1499 | + |
|
| 1500 | + /** |
|
| 1501 | + * @return \OCP\Encryption\Keys\IStorage |
|
| 1502 | + * @deprecated 20.0.0 |
|
| 1503 | + */ |
|
| 1504 | + public function getEncryptionKeyStorage() { |
|
| 1505 | + return $this->get(IStorage::class); |
|
| 1506 | + } |
|
| 1507 | + |
|
| 1508 | + /** |
|
| 1509 | + * The current request object holding all information about the request |
|
| 1510 | + * currently being processed is returned from this method. |
|
| 1511 | + * In case the current execution was not initiated by a web request null is returned |
|
| 1512 | + * |
|
| 1513 | + * @return \OCP\IRequest |
|
| 1514 | + * @deprecated 20.0.0 |
|
| 1515 | + */ |
|
| 1516 | + public function getRequest() { |
|
| 1517 | + return $this->get(IRequest::class); |
|
| 1518 | + } |
|
| 1519 | + |
|
| 1520 | + /** |
|
| 1521 | + * Returns the preview manager which can create preview images for a given file |
|
| 1522 | + * |
|
| 1523 | + * @return IPreview |
|
| 1524 | + * @deprecated 20.0.0 |
|
| 1525 | + */ |
|
| 1526 | + public function getPreviewManager() { |
|
| 1527 | + return $this->get(IPreview::class); |
|
| 1528 | + } |
|
| 1529 | + |
|
| 1530 | + /** |
|
| 1531 | + * Returns the tag manager which can get and set tags for different object types |
|
| 1532 | + * |
|
| 1533 | + * @see \OCP\ITagManager::load() |
|
| 1534 | + * @return ITagManager |
|
| 1535 | + * @deprecated 20.0.0 |
|
| 1536 | + */ |
|
| 1537 | + public function getTagManager() { |
|
| 1538 | + return $this->get(ITagManager::class); |
|
| 1539 | + } |
|
| 1540 | + |
|
| 1541 | + /** |
|
| 1542 | + * Returns the system-tag manager |
|
| 1543 | + * |
|
| 1544 | + * @return ISystemTagManager |
|
| 1545 | + * |
|
| 1546 | + * @since 9.0.0 |
|
| 1547 | + * @deprecated 20.0.0 |
|
| 1548 | + */ |
|
| 1549 | + public function getSystemTagManager() { |
|
| 1550 | + return $this->get(ISystemTagManager::class); |
|
| 1551 | + } |
|
| 1552 | + |
|
| 1553 | + /** |
|
| 1554 | + * Returns the system-tag object mapper |
|
| 1555 | + * |
|
| 1556 | + * @return ISystemTagObjectMapper |
|
| 1557 | + * |
|
| 1558 | + * @since 9.0.0 |
|
| 1559 | + * @deprecated 20.0.0 |
|
| 1560 | + */ |
|
| 1561 | + public function getSystemTagObjectMapper() { |
|
| 1562 | + return $this->get(ISystemTagObjectMapper::class); |
|
| 1563 | + } |
|
| 1564 | + |
|
| 1565 | + /** |
|
| 1566 | + * Returns the avatar manager, used for avatar functionality |
|
| 1567 | + * |
|
| 1568 | + * @return IAvatarManager |
|
| 1569 | + * @deprecated 20.0.0 |
|
| 1570 | + */ |
|
| 1571 | + public function getAvatarManager() { |
|
| 1572 | + return $this->get(IAvatarManager::class); |
|
| 1573 | + } |
|
| 1574 | + |
|
| 1575 | + /** |
|
| 1576 | + * Returns the root folder of ownCloud's data directory |
|
| 1577 | + * |
|
| 1578 | + * @return IRootFolder |
|
| 1579 | + * @deprecated 20.0.0 |
|
| 1580 | + */ |
|
| 1581 | + public function getRootFolder() { |
|
| 1582 | + return $this->get(IRootFolder::class); |
|
| 1583 | + } |
|
| 1584 | + |
|
| 1585 | + /** |
|
| 1586 | + * Returns the root folder of ownCloud's data directory |
|
| 1587 | + * This is the lazy variant so this gets only initialized once it |
|
| 1588 | + * is actually used. |
|
| 1589 | + * |
|
| 1590 | + * @return IRootFolder |
|
| 1591 | + * @deprecated 20.0.0 |
|
| 1592 | + */ |
|
| 1593 | + public function getLazyRootFolder() { |
|
| 1594 | + return $this->get(IRootFolder::class); |
|
| 1595 | + } |
|
| 1596 | + |
|
| 1597 | + /** |
|
| 1598 | + * Returns a view to ownCloud's files folder |
|
| 1599 | + * |
|
| 1600 | + * @param string $userId user ID |
|
| 1601 | + * @return \OCP\Files\Folder|null |
|
| 1602 | + * @deprecated 20.0.0 |
|
| 1603 | + */ |
|
| 1604 | + public function getUserFolder($userId = null) { |
|
| 1605 | + if ($userId === null) { |
|
| 1606 | + $user = $this->get(IUserSession::class)->getUser(); |
|
| 1607 | + if (!$user) { |
|
| 1608 | + return null; |
|
| 1609 | + } |
|
| 1610 | + $userId = $user->getUID(); |
|
| 1611 | + } |
|
| 1612 | + $root = $this->get(IRootFolder::class); |
|
| 1613 | + return $root->getUserFolder($userId); |
|
| 1614 | + } |
|
| 1615 | + |
|
| 1616 | + /** |
|
| 1617 | + * @return \OC\User\Manager |
|
| 1618 | + * @deprecated 20.0.0 |
|
| 1619 | + */ |
|
| 1620 | + public function getUserManager() { |
|
| 1621 | + return $this->get(IUserManager::class); |
|
| 1622 | + } |
|
| 1623 | + |
|
| 1624 | + /** |
|
| 1625 | + * @return \OC\Group\Manager |
|
| 1626 | + * @deprecated 20.0.0 |
|
| 1627 | + */ |
|
| 1628 | + public function getGroupManager() { |
|
| 1629 | + return $this->get(IGroupManager::class); |
|
| 1630 | + } |
|
| 1631 | + |
|
| 1632 | + /** |
|
| 1633 | + * @return \OC\User\Session |
|
| 1634 | + * @deprecated 20.0.0 |
|
| 1635 | + */ |
|
| 1636 | + public function getUserSession() { |
|
| 1637 | + return $this->get(IUserSession::class); |
|
| 1638 | + } |
|
| 1639 | + |
|
| 1640 | + /** |
|
| 1641 | + * @return \OCP\ISession |
|
| 1642 | + * @deprecated 20.0.0 |
|
| 1643 | + */ |
|
| 1644 | + public function getSession() { |
|
| 1645 | + return $this->get(IUserSession::class)->getSession(); |
|
| 1646 | + } |
|
| 1647 | + |
|
| 1648 | + /** |
|
| 1649 | + * @param \OCP\ISession $session |
|
| 1650 | + */ |
|
| 1651 | + public function setSession(\OCP\ISession $session) { |
|
| 1652 | + $this->get(SessionStorage::class)->setSession($session); |
|
| 1653 | + $this->get(IUserSession::class)->setSession($session); |
|
| 1654 | + $this->get(Store::class)->setSession($session); |
|
| 1655 | + } |
|
| 1656 | + |
|
| 1657 | + /** |
|
| 1658 | + * @return \OC\Authentication\TwoFactorAuth\Manager |
|
| 1659 | + * @deprecated 20.0.0 |
|
| 1660 | + */ |
|
| 1661 | + public function getTwoFactorAuthManager() { |
|
| 1662 | + return $this->get(\OC\Authentication\TwoFactorAuth\Manager::class); |
|
| 1663 | + } |
|
| 1664 | + |
|
| 1665 | + /** |
|
| 1666 | + * @return \OC\NavigationManager |
|
| 1667 | + * @deprecated 20.0.0 |
|
| 1668 | + */ |
|
| 1669 | + public function getNavigationManager() { |
|
| 1670 | + return $this->get(INavigationManager::class); |
|
| 1671 | + } |
|
| 1672 | + |
|
| 1673 | + /** |
|
| 1674 | + * @return \OCP\IConfig |
|
| 1675 | + * @deprecated 20.0.0 |
|
| 1676 | + */ |
|
| 1677 | + public function getConfig() { |
|
| 1678 | + return $this->get(AllConfig::class); |
|
| 1679 | + } |
|
| 1680 | + |
|
| 1681 | + /** |
|
| 1682 | + * @return \OC\SystemConfig |
|
| 1683 | + * @deprecated 20.0.0 |
|
| 1684 | + */ |
|
| 1685 | + public function getSystemConfig() { |
|
| 1686 | + return $this->get(SystemConfig::class); |
|
| 1687 | + } |
|
| 1688 | + |
|
| 1689 | + /** |
|
| 1690 | + * Returns the app config manager |
|
| 1691 | + * |
|
| 1692 | + * @return IAppConfig |
|
| 1693 | + * @deprecated 20.0.0 |
|
| 1694 | + */ |
|
| 1695 | + public function getAppConfig() { |
|
| 1696 | + return $this->get(IAppConfig::class); |
|
| 1697 | + } |
|
| 1698 | + |
|
| 1699 | + /** |
|
| 1700 | + * @return IFactory |
|
| 1701 | + * @deprecated 20.0.0 |
|
| 1702 | + */ |
|
| 1703 | + public function getL10NFactory() { |
|
| 1704 | + return $this->get(IFactory::class); |
|
| 1705 | + } |
|
| 1706 | + |
|
| 1707 | + /** |
|
| 1708 | + * get an L10N instance |
|
| 1709 | + * |
|
| 1710 | + * @param string $app appid |
|
| 1711 | + * @param string $lang |
|
| 1712 | + * @return IL10N |
|
| 1713 | + * @deprecated 20.0.0 |
|
| 1714 | + */ |
|
| 1715 | + public function getL10N($app, $lang = null) { |
|
| 1716 | + return $this->get(IFactory::class)->get($app, $lang); |
|
| 1717 | + } |
|
| 1718 | + |
|
| 1719 | + /** |
|
| 1720 | + * @return IURLGenerator |
|
| 1721 | + * @deprecated 20.0.0 |
|
| 1722 | + */ |
|
| 1723 | + public function getURLGenerator() { |
|
| 1724 | + return $this->get(IURLGenerator::class); |
|
| 1725 | + } |
|
| 1726 | + |
|
| 1727 | + /** |
|
| 1728 | + * @return AppFetcher |
|
| 1729 | + * @deprecated 20.0.0 |
|
| 1730 | + */ |
|
| 1731 | + public function getAppFetcher() { |
|
| 1732 | + return $this->get(AppFetcher::class); |
|
| 1733 | + } |
|
| 1734 | + |
|
| 1735 | + /** |
|
| 1736 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
| 1737 | + * getMemCacheFactory() instead. |
|
| 1738 | + * |
|
| 1739 | + * @return ICache |
|
| 1740 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
| 1741 | + */ |
|
| 1742 | + public function getCache() { |
|
| 1743 | + return $this->get(ICache::class); |
|
| 1744 | + } |
|
| 1745 | + |
|
| 1746 | + /** |
|
| 1747 | + * Returns an \OCP\CacheFactory instance |
|
| 1748 | + * |
|
| 1749 | + * @return \OCP\ICacheFactory |
|
| 1750 | + * @deprecated 20.0.0 |
|
| 1751 | + */ |
|
| 1752 | + public function getMemCacheFactory() { |
|
| 1753 | + return $this->get(ICacheFactory::class); |
|
| 1754 | + } |
|
| 1755 | + |
|
| 1756 | + /** |
|
| 1757 | + * Returns an \OC\RedisFactory instance |
|
| 1758 | + * |
|
| 1759 | + * @return \OC\RedisFactory |
|
| 1760 | + * @deprecated 20.0.0 |
|
| 1761 | + */ |
|
| 1762 | + public function getGetRedisFactory() { |
|
| 1763 | + return $this->get('RedisFactory'); |
|
| 1764 | + } |
|
| 1765 | + |
|
| 1766 | + |
|
| 1767 | + /** |
|
| 1768 | + * Returns the current session |
|
| 1769 | + * |
|
| 1770 | + * @return \OCP\IDBConnection |
|
| 1771 | + * @deprecated 20.0.0 |
|
| 1772 | + */ |
|
| 1773 | + public function getDatabaseConnection() { |
|
| 1774 | + return $this->get(IDBConnection::class); |
|
| 1775 | + } |
|
| 1776 | + |
|
| 1777 | + /** |
|
| 1778 | + * Returns the activity manager |
|
| 1779 | + * |
|
| 1780 | + * @return \OCP\Activity\IManager |
|
| 1781 | + * @deprecated 20.0.0 |
|
| 1782 | + */ |
|
| 1783 | + public function getActivityManager() { |
|
| 1784 | + return $this->get(\OCP\Activity\IManager::class); |
|
| 1785 | + } |
|
| 1786 | + |
|
| 1787 | + /** |
|
| 1788 | + * Returns an job list for controlling background jobs |
|
| 1789 | + * |
|
| 1790 | + * @return IJobList |
|
| 1791 | + * @deprecated 20.0.0 |
|
| 1792 | + */ |
|
| 1793 | + public function getJobList() { |
|
| 1794 | + return $this->get(IJobList::class); |
|
| 1795 | + } |
|
| 1796 | + |
|
| 1797 | + /** |
|
| 1798 | + * Returns a logger instance |
|
| 1799 | + * |
|
| 1800 | + * @return ILogger |
|
| 1801 | + * @deprecated 20.0.0 |
|
| 1802 | + */ |
|
| 1803 | + public function getLogger() { |
|
| 1804 | + return $this->get(ILogger::class); |
|
| 1805 | + } |
|
| 1806 | + |
|
| 1807 | + /** |
|
| 1808 | + * @return ILogFactory |
|
| 1809 | + * @throws \OCP\AppFramework\QueryException |
|
| 1810 | + * @deprecated 20.0.0 |
|
| 1811 | + */ |
|
| 1812 | + public function getLogFactory() { |
|
| 1813 | + return $this->get(ILogFactory::class); |
|
| 1814 | + } |
|
| 1815 | + |
|
| 1816 | + /** |
|
| 1817 | + * Returns a router for generating and matching urls |
|
| 1818 | + * |
|
| 1819 | + * @return IRouter |
|
| 1820 | + * @deprecated 20.0.0 |
|
| 1821 | + */ |
|
| 1822 | + public function getRouter() { |
|
| 1823 | + return $this->get(IRouter::class); |
|
| 1824 | + } |
|
| 1825 | + |
|
| 1826 | + /** |
|
| 1827 | + * Returns a search instance |
|
| 1828 | + * |
|
| 1829 | + * @return ISearch |
|
| 1830 | + * @deprecated 20.0.0 |
|
| 1831 | + */ |
|
| 1832 | + public function getSearch() { |
|
| 1833 | + return $this->get(ISearch::class); |
|
| 1834 | + } |
|
| 1835 | + |
|
| 1836 | + /** |
|
| 1837 | + * Returns a SecureRandom instance |
|
| 1838 | + * |
|
| 1839 | + * @return \OCP\Security\ISecureRandom |
|
| 1840 | + * @deprecated 20.0.0 |
|
| 1841 | + */ |
|
| 1842 | + public function getSecureRandom() { |
|
| 1843 | + return $this->get(ISecureRandom::class); |
|
| 1844 | + } |
|
| 1845 | + |
|
| 1846 | + /** |
|
| 1847 | + * Returns a Crypto instance |
|
| 1848 | + * |
|
| 1849 | + * @return ICrypto |
|
| 1850 | + * @deprecated 20.0.0 |
|
| 1851 | + */ |
|
| 1852 | + public function getCrypto() { |
|
| 1853 | + return $this->get(ICrypto::class); |
|
| 1854 | + } |
|
| 1855 | + |
|
| 1856 | + /** |
|
| 1857 | + * Returns a Hasher instance |
|
| 1858 | + * |
|
| 1859 | + * @return IHasher |
|
| 1860 | + * @deprecated 20.0.0 |
|
| 1861 | + */ |
|
| 1862 | + public function getHasher() { |
|
| 1863 | + return $this->get(IHasher::class); |
|
| 1864 | + } |
|
| 1865 | + |
|
| 1866 | + /** |
|
| 1867 | + * Returns a CredentialsManager instance |
|
| 1868 | + * |
|
| 1869 | + * @return ICredentialsManager |
|
| 1870 | + * @deprecated 20.0.0 |
|
| 1871 | + */ |
|
| 1872 | + public function getCredentialsManager() { |
|
| 1873 | + return $this->get(ICredentialsManager::class); |
|
| 1874 | + } |
|
| 1875 | + |
|
| 1876 | + /** |
|
| 1877 | + * Get the certificate manager |
|
| 1878 | + * |
|
| 1879 | + * @return \OCP\ICertificateManager |
|
| 1880 | + */ |
|
| 1881 | + public function getCertificateManager() { |
|
| 1882 | + return $this->get(ICertificateManager::class); |
|
| 1883 | + } |
|
| 1884 | + |
|
| 1885 | + /** |
|
| 1886 | + * Returns an instance of the HTTP client service |
|
| 1887 | + * |
|
| 1888 | + * @return IClientService |
|
| 1889 | + * @deprecated 20.0.0 |
|
| 1890 | + */ |
|
| 1891 | + public function getHTTPClientService() { |
|
| 1892 | + return $this->get(IClientService::class); |
|
| 1893 | + } |
|
| 1894 | + |
|
| 1895 | + /** |
|
| 1896 | + * Create a new event source |
|
| 1897 | + * |
|
| 1898 | + * @return \OCP\IEventSource |
|
| 1899 | + * @deprecated 20.0.0 |
|
| 1900 | + */ |
|
| 1901 | + public function createEventSource() { |
|
| 1902 | + return new \OC_EventSource(); |
|
| 1903 | + } |
|
| 1904 | + |
|
| 1905 | + /** |
|
| 1906 | + * Get the active event logger |
|
| 1907 | + * |
|
| 1908 | + * The returned logger only logs data when debug mode is enabled |
|
| 1909 | + * |
|
| 1910 | + * @return IEventLogger |
|
| 1911 | + * @deprecated 20.0.0 |
|
| 1912 | + */ |
|
| 1913 | + public function getEventLogger() { |
|
| 1914 | + return $this->get(IEventLogger::class); |
|
| 1915 | + } |
|
| 1916 | + |
|
| 1917 | + /** |
|
| 1918 | + * Get the active query logger |
|
| 1919 | + * |
|
| 1920 | + * The returned logger only logs data when debug mode is enabled |
|
| 1921 | + * |
|
| 1922 | + * @return IQueryLogger |
|
| 1923 | + * @deprecated 20.0.0 |
|
| 1924 | + */ |
|
| 1925 | + public function getQueryLogger() { |
|
| 1926 | + return $this->get(IQueryLogger::class); |
|
| 1927 | + } |
|
| 1928 | + |
|
| 1929 | + /** |
|
| 1930 | + * Get the manager for temporary files and folders |
|
| 1931 | + * |
|
| 1932 | + * @return \OCP\ITempManager |
|
| 1933 | + * @deprecated 20.0.0 |
|
| 1934 | + */ |
|
| 1935 | + public function getTempManager() { |
|
| 1936 | + return $this->get(ITempManager::class); |
|
| 1937 | + } |
|
| 1938 | + |
|
| 1939 | + /** |
|
| 1940 | + * Get the app manager |
|
| 1941 | + * |
|
| 1942 | + * @return \OCP\App\IAppManager |
|
| 1943 | + * @deprecated 20.0.0 |
|
| 1944 | + */ |
|
| 1945 | + public function getAppManager() { |
|
| 1946 | + return $this->get(IAppManager::class); |
|
| 1947 | + } |
|
| 1948 | + |
|
| 1949 | + /** |
|
| 1950 | + * Creates a new mailer |
|
| 1951 | + * |
|
| 1952 | + * @return IMailer |
|
| 1953 | + * @deprecated 20.0.0 |
|
| 1954 | + */ |
|
| 1955 | + public function getMailer() { |
|
| 1956 | + return $this->get(IMailer::class); |
|
| 1957 | + } |
|
| 1958 | + |
|
| 1959 | + /** |
|
| 1960 | + * Get the webroot |
|
| 1961 | + * |
|
| 1962 | + * @return string |
|
| 1963 | + * @deprecated 20.0.0 |
|
| 1964 | + */ |
|
| 1965 | + public function getWebRoot() { |
|
| 1966 | + return $this->webRoot; |
|
| 1967 | + } |
|
| 1968 | + |
|
| 1969 | + /** |
|
| 1970 | + * @return \OC\OCSClient |
|
| 1971 | + * @deprecated 20.0.0 |
|
| 1972 | + */ |
|
| 1973 | + public function getOcsClient() { |
|
| 1974 | + return $this->get('OcsClient'); |
|
| 1975 | + } |
|
| 1976 | + |
|
| 1977 | + /** |
|
| 1978 | + * @return IDateTimeZone |
|
| 1979 | + * @deprecated 20.0.0 |
|
| 1980 | + */ |
|
| 1981 | + public function getDateTimeZone() { |
|
| 1982 | + return $this->get(IDateTimeZone::class); |
|
| 1983 | + } |
|
| 1984 | + |
|
| 1985 | + /** |
|
| 1986 | + * @return IDateTimeFormatter |
|
| 1987 | + * @deprecated 20.0.0 |
|
| 1988 | + */ |
|
| 1989 | + public function getDateTimeFormatter() { |
|
| 1990 | + return $this->get(IDateTimeFormatter::class); |
|
| 1991 | + } |
|
| 1992 | + |
|
| 1993 | + /** |
|
| 1994 | + * @return IMountProviderCollection |
|
| 1995 | + * @deprecated 20.0.0 |
|
| 1996 | + */ |
|
| 1997 | + public function getMountProviderCollection() { |
|
| 1998 | + return $this->get(IMountProviderCollection::class); |
|
| 1999 | + } |
|
| 2000 | + |
|
| 2001 | + /** |
|
| 2002 | + * Get the IniWrapper |
|
| 2003 | + * |
|
| 2004 | + * @return IniGetWrapper |
|
| 2005 | + * @deprecated 20.0.0 |
|
| 2006 | + */ |
|
| 2007 | + public function getIniWrapper() { |
|
| 2008 | + return $this->get(IniGetWrapper::class); |
|
| 2009 | + } |
|
| 2010 | + |
|
| 2011 | + /** |
|
| 2012 | + * @return \OCP\Command\IBus |
|
| 2013 | + * @deprecated 20.0.0 |
|
| 2014 | + */ |
|
| 2015 | + public function getCommandBus() { |
|
| 2016 | + return $this->get(IBus::class); |
|
| 2017 | + } |
|
| 2018 | + |
|
| 2019 | + /** |
|
| 2020 | + * Get the trusted domain helper |
|
| 2021 | + * |
|
| 2022 | + * @return TrustedDomainHelper |
|
| 2023 | + * @deprecated 20.0.0 |
|
| 2024 | + */ |
|
| 2025 | + public function getTrustedDomainHelper() { |
|
| 2026 | + return $this->get(TrustedDomainHelper::class); |
|
| 2027 | + } |
|
| 2028 | + |
|
| 2029 | + /** |
|
| 2030 | + * Get the locking provider |
|
| 2031 | + * |
|
| 2032 | + * @return ILockingProvider |
|
| 2033 | + * @since 8.1.0 |
|
| 2034 | + * @deprecated 20.0.0 |
|
| 2035 | + */ |
|
| 2036 | + public function getLockingProvider() { |
|
| 2037 | + return $this->get(ILockingProvider::class); |
|
| 2038 | + } |
|
| 2039 | + |
|
| 2040 | + /** |
|
| 2041 | + * @return IMountManager |
|
| 2042 | + * @deprecated 20.0.0 |
|
| 2043 | + **/ |
|
| 2044 | + public function getMountManager() { |
|
| 2045 | + return $this->get(IMountManager::class); |
|
| 2046 | + } |
|
| 2047 | + |
|
| 2048 | + /** |
|
| 2049 | + * @return IUserMountCache |
|
| 2050 | + * @deprecated 20.0.0 |
|
| 2051 | + */ |
|
| 2052 | + public function getUserMountCache() { |
|
| 2053 | + return $this->get(IUserMountCache::class); |
|
| 2054 | + } |
|
| 2055 | + |
|
| 2056 | + /** |
|
| 2057 | + * Get the MimeTypeDetector |
|
| 2058 | + * |
|
| 2059 | + * @return IMimeTypeDetector |
|
| 2060 | + * @deprecated 20.0.0 |
|
| 2061 | + */ |
|
| 2062 | + public function getMimeTypeDetector() { |
|
| 2063 | + return $this->get(IMimeTypeDetector::class); |
|
| 2064 | + } |
|
| 2065 | + |
|
| 2066 | + /** |
|
| 2067 | + * Get the MimeTypeLoader |
|
| 2068 | + * |
|
| 2069 | + * @return IMimeTypeLoader |
|
| 2070 | + * @deprecated 20.0.0 |
|
| 2071 | + */ |
|
| 2072 | + public function getMimeTypeLoader() { |
|
| 2073 | + return $this->get(IMimeTypeLoader::class); |
|
| 2074 | + } |
|
| 2075 | + |
|
| 2076 | + /** |
|
| 2077 | + * Get the manager of all the capabilities |
|
| 2078 | + * |
|
| 2079 | + * @return CapabilitiesManager |
|
| 2080 | + * @deprecated 20.0.0 |
|
| 2081 | + */ |
|
| 2082 | + public function getCapabilitiesManager() { |
|
| 2083 | + return $this->get(CapabilitiesManager::class); |
|
| 2084 | + } |
|
| 2085 | + |
|
| 2086 | + /** |
|
| 2087 | + * Get the EventDispatcher |
|
| 2088 | + * |
|
| 2089 | + * @return EventDispatcherInterface |
|
| 2090 | + * @since 8.2.0 |
|
| 2091 | + * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher |
|
| 2092 | + */ |
|
| 2093 | + public function getEventDispatcher() { |
|
| 2094 | + return $this->get(\OC\EventDispatcher\SymfonyAdapter::class); |
|
| 2095 | + } |
|
| 2096 | + |
|
| 2097 | + /** |
|
| 2098 | + * Get the Notification Manager |
|
| 2099 | + * |
|
| 2100 | + * @return \OCP\Notification\IManager |
|
| 2101 | + * @since 8.2.0 |
|
| 2102 | + * @deprecated 20.0.0 |
|
| 2103 | + */ |
|
| 2104 | + public function getNotificationManager() { |
|
| 2105 | + return $this->get(\OCP\Notification\IManager::class); |
|
| 2106 | + } |
|
| 2107 | + |
|
| 2108 | + /** |
|
| 2109 | + * @return ICommentsManager |
|
| 2110 | + * @deprecated 20.0.0 |
|
| 2111 | + */ |
|
| 2112 | + public function getCommentsManager() { |
|
| 2113 | + return $this->get(ICommentsManager::class); |
|
| 2114 | + } |
|
| 2115 | + |
|
| 2116 | + /** |
|
| 2117 | + * @return \OCA\Theming\ThemingDefaults |
|
| 2118 | + * @deprecated 20.0.0 |
|
| 2119 | + */ |
|
| 2120 | + public function getThemingDefaults() { |
|
| 2121 | + return $this->get('ThemingDefaults'); |
|
| 2122 | + } |
|
| 2123 | + |
|
| 2124 | + /** |
|
| 2125 | + * @return \OC\IntegrityCheck\Checker |
|
| 2126 | + * @deprecated 20.0.0 |
|
| 2127 | + */ |
|
| 2128 | + public function getIntegrityCodeChecker() { |
|
| 2129 | + return $this->get('IntegrityCodeChecker'); |
|
| 2130 | + } |
|
| 2131 | + |
|
| 2132 | + /** |
|
| 2133 | + * @return \OC\Session\CryptoWrapper |
|
| 2134 | + * @deprecated 20.0.0 |
|
| 2135 | + */ |
|
| 2136 | + public function getSessionCryptoWrapper() { |
|
| 2137 | + return $this->get('CryptoWrapper'); |
|
| 2138 | + } |
|
| 2139 | + |
|
| 2140 | + /** |
|
| 2141 | + * @return CsrfTokenManager |
|
| 2142 | + * @deprecated 20.0.0 |
|
| 2143 | + */ |
|
| 2144 | + public function getCsrfTokenManager() { |
|
| 2145 | + return $this->get(CsrfTokenManager::class); |
|
| 2146 | + } |
|
| 2147 | + |
|
| 2148 | + /** |
|
| 2149 | + * @return Throttler |
|
| 2150 | + * @deprecated 20.0.0 |
|
| 2151 | + */ |
|
| 2152 | + public function getBruteForceThrottler() { |
|
| 2153 | + return $this->get(Throttler::class); |
|
| 2154 | + } |
|
| 2155 | + |
|
| 2156 | + /** |
|
| 2157 | + * @return IContentSecurityPolicyManager |
|
| 2158 | + * @deprecated 20.0.0 |
|
| 2159 | + */ |
|
| 2160 | + public function getContentSecurityPolicyManager() { |
|
| 2161 | + return $this->get(ContentSecurityPolicyManager::class); |
|
| 2162 | + } |
|
| 2163 | + |
|
| 2164 | + /** |
|
| 2165 | + * @return ContentSecurityPolicyNonceManager |
|
| 2166 | + * @deprecated 20.0.0 |
|
| 2167 | + */ |
|
| 2168 | + public function getContentSecurityPolicyNonceManager() { |
|
| 2169 | + return $this->get(ContentSecurityPolicyNonceManager::class); |
|
| 2170 | + } |
|
| 2171 | + |
|
| 2172 | + /** |
|
| 2173 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 2174 | + * |
|
| 2175 | + * @return \OCA\Files_External\Service\BackendService |
|
| 2176 | + * @deprecated 20.0.0 |
|
| 2177 | + */ |
|
| 2178 | + public function getStoragesBackendService() { |
|
| 2179 | + return $this->get(BackendService::class); |
|
| 2180 | + } |
|
| 2181 | + |
|
| 2182 | + /** |
|
| 2183 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 2184 | + * |
|
| 2185 | + * @return \OCA\Files_External\Service\GlobalStoragesService |
|
| 2186 | + * @deprecated 20.0.0 |
|
| 2187 | + */ |
|
| 2188 | + public function getGlobalStoragesService() { |
|
| 2189 | + return $this->get(GlobalStoragesService::class); |
|
| 2190 | + } |
|
| 2191 | + |
|
| 2192 | + /** |
|
| 2193 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 2194 | + * |
|
| 2195 | + * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
| 2196 | + * @deprecated 20.0.0 |
|
| 2197 | + */ |
|
| 2198 | + public function getUserGlobalStoragesService() { |
|
| 2199 | + return $this->get(UserGlobalStoragesService::class); |
|
| 2200 | + } |
|
| 2201 | + |
|
| 2202 | + /** |
|
| 2203 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 2204 | + * |
|
| 2205 | + * @return \OCA\Files_External\Service\UserStoragesService |
|
| 2206 | + * @deprecated 20.0.0 |
|
| 2207 | + */ |
|
| 2208 | + public function getUserStoragesService() { |
|
| 2209 | + return $this->get(UserStoragesService::class); |
|
| 2210 | + } |
|
| 2211 | + |
|
| 2212 | + /** |
|
| 2213 | + * @return \OCP\Share\IManager |
|
| 2214 | + * @deprecated 20.0.0 |
|
| 2215 | + */ |
|
| 2216 | + public function getShareManager() { |
|
| 2217 | + return $this->get(\OCP\Share\IManager::class); |
|
| 2218 | + } |
|
| 2219 | + |
|
| 2220 | + /** |
|
| 2221 | + * @return \OCP\Collaboration\Collaborators\ISearch |
|
| 2222 | + * @deprecated 20.0.0 |
|
| 2223 | + */ |
|
| 2224 | + public function getCollaboratorSearch() { |
|
| 2225 | + return $this->get(\OCP\Collaboration\Collaborators\ISearch::class); |
|
| 2226 | + } |
|
| 2227 | + |
|
| 2228 | + /** |
|
| 2229 | + * @return \OCP\Collaboration\AutoComplete\IManager |
|
| 2230 | + * @deprecated 20.0.0 |
|
| 2231 | + */ |
|
| 2232 | + public function getAutoCompleteManager() { |
|
| 2233 | + return $this->get(IManager::class); |
|
| 2234 | + } |
|
| 2235 | + |
|
| 2236 | + /** |
|
| 2237 | + * Returns the LDAP Provider |
|
| 2238 | + * |
|
| 2239 | + * @return \OCP\LDAP\ILDAPProvider |
|
| 2240 | + * @deprecated 20.0.0 |
|
| 2241 | + */ |
|
| 2242 | + public function getLDAPProvider() { |
|
| 2243 | + return $this->get('LDAPProvider'); |
|
| 2244 | + } |
|
| 2245 | + |
|
| 2246 | + /** |
|
| 2247 | + * @return \OCP\Settings\IManager |
|
| 2248 | + * @deprecated 20.0.0 |
|
| 2249 | + */ |
|
| 2250 | + public function getSettingsManager() { |
|
| 2251 | + return $this->get(\OC\Settings\Manager::class); |
|
| 2252 | + } |
|
| 2253 | + |
|
| 2254 | + /** |
|
| 2255 | + * @return \OCP\Files\IAppData |
|
| 2256 | + * @deprecated 20.0.0 |
|
| 2257 | + */ |
|
| 2258 | + public function getAppDataDir($app) { |
|
| 2259 | + /** @var \OC\Files\AppData\Factory $factory */ |
|
| 2260 | + $factory = $this->get(\OC\Files\AppData\Factory::class); |
|
| 2261 | + return $factory->get($app); |
|
| 2262 | + } |
|
| 2263 | + |
|
| 2264 | + /** |
|
| 2265 | + * @return \OCP\Lockdown\ILockdownManager |
|
| 2266 | + * @deprecated 20.0.0 |
|
| 2267 | + */ |
|
| 2268 | + public function getLockdownManager() { |
|
| 2269 | + return $this->get('LockdownManager'); |
|
| 2270 | + } |
|
| 2271 | + |
|
| 2272 | + /** |
|
| 2273 | + * @return \OCP\Federation\ICloudIdManager |
|
| 2274 | + * @deprecated 20.0.0 |
|
| 2275 | + */ |
|
| 2276 | + public function getCloudIdManager() { |
|
| 2277 | + return $this->get(ICloudIdManager::class); |
|
| 2278 | + } |
|
| 2279 | + |
|
| 2280 | + /** |
|
| 2281 | + * @return \OCP\GlobalScale\IConfig |
|
| 2282 | + * @deprecated 20.0.0 |
|
| 2283 | + */ |
|
| 2284 | + public function getGlobalScaleConfig() { |
|
| 2285 | + return $this->get(IConfig::class); |
|
| 2286 | + } |
|
| 2287 | + |
|
| 2288 | + /** |
|
| 2289 | + * @return \OCP\Federation\ICloudFederationProviderManager |
|
| 2290 | + * @deprecated 20.0.0 |
|
| 2291 | + */ |
|
| 2292 | + public function getCloudFederationProviderManager() { |
|
| 2293 | + return $this->get(ICloudFederationProviderManager::class); |
|
| 2294 | + } |
|
| 2295 | + |
|
| 2296 | + /** |
|
| 2297 | + * @return \OCP\Remote\Api\IApiFactory |
|
| 2298 | + * @deprecated 20.0.0 |
|
| 2299 | + */ |
|
| 2300 | + public function getRemoteApiFactory() { |
|
| 2301 | + return $this->get(IApiFactory::class); |
|
| 2302 | + } |
|
| 2303 | + |
|
| 2304 | + /** |
|
| 2305 | + * @return \OCP\Federation\ICloudFederationFactory |
|
| 2306 | + * @deprecated 20.0.0 |
|
| 2307 | + */ |
|
| 2308 | + public function getCloudFederationFactory() { |
|
| 2309 | + return $this->get(ICloudFederationFactory::class); |
|
| 2310 | + } |
|
| 2311 | + |
|
| 2312 | + /** |
|
| 2313 | + * @return \OCP\Remote\IInstanceFactory |
|
| 2314 | + * @deprecated 20.0.0 |
|
| 2315 | + */ |
|
| 2316 | + public function getRemoteInstanceFactory() { |
|
| 2317 | + return $this->get(IInstanceFactory::class); |
|
| 2318 | + } |
|
| 2319 | + |
|
| 2320 | + /** |
|
| 2321 | + * @return IStorageFactory |
|
| 2322 | + * @deprecated 20.0.0 |
|
| 2323 | + */ |
|
| 2324 | + public function getStorageFactory() { |
|
| 2325 | + return $this->get(IStorageFactory::class); |
|
| 2326 | + } |
|
| 2327 | + |
|
| 2328 | + /** |
|
| 2329 | + * Get the Preview GeneratorHelper |
|
| 2330 | + * |
|
| 2331 | + * @return GeneratorHelper |
|
| 2332 | + * @since 17.0.0 |
|
| 2333 | + * @deprecated 20.0.0 |
|
| 2334 | + */ |
|
| 2335 | + public function getGeneratorHelper() { |
|
| 2336 | + return $this->get(\OC\Preview\GeneratorHelper::class); |
|
| 2337 | + } |
|
| 2338 | + |
|
| 2339 | + private function registerDeprecatedAlias(string $alias, string $target) { |
|
| 2340 | + $this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) { |
|
| 2341 | + try { |
|
| 2342 | + /** @var ILogger $logger */ |
|
| 2343 | + $logger = $container->get(ILogger::class); |
|
| 2344 | + $logger->debug('The requested alias "' . $alias . '" is deprecated. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']); |
|
| 2345 | + } catch (ContainerExceptionInterface $e) { |
|
| 2346 | + // Could not get logger. Continue |
|
| 2347 | + } |
|
| 2348 | + |
|
| 2349 | + return $container->get($target); |
|
| 2350 | + }, false); |
|
| 2351 | + } |
|
| 2352 | 2352 | } |
@@ -45,221 +45,221 @@ |
||
| 45 | 45 | * @package OC\Files\Cache |
| 46 | 46 | */ |
| 47 | 47 | class Storage { |
| 48 | - /** @var StorageGlobal|null */ |
|
| 49 | - private static $globalCache = null; |
|
| 50 | - private $storageId; |
|
| 51 | - private $numericId; |
|
| 48 | + /** @var StorageGlobal|null */ |
|
| 49 | + private static $globalCache = null; |
|
| 50 | + private $storageId; |
|
| 51 | + private $numericId; |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @return StorageGlobal |
|
| 55 | - */ |
|
| 56 | - public static function getGlobalCache() { |
|
| 57 | - if (is_null(self::$globalCache)) { |
|
| 58 | - self::$globalCache = new StorageGlobal(\OC::$server->getDatabaseConnection()); |
|
| 59 | - } |
|
| 60 | - return self::$globalCache; |
|
| 61 | - } |
|
| 53 | + /** |
|
| 54 | + * @return StorageGlobal |
|
| 55 | + */ |
|
| 56 | + public static function getGlobalCache() { |
|
| 57 | + if (is_null(self::$globalCache)) { |
|
| 58 | + self::$globalCache = new StorageGlobal(\OC::$server->getDatabaseConnection()); |
|
| 59 | + } |
|
| 60 | + return self::$globalCache; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @param \OC\Files\Storage\Storage|string $storage |
|
| 65 | - * @param bool $isAvailable |
|
| 66 | - * @throws \RuntimeException |
|
| 67 | - */ |
|
| 68 | - public function __construct($storage, $isAvailable = true) { |
|
| 69 | - if ($storage instanceof IStorage) { |
|
| 70 | - $this->storageId = $storage->getId(); |
|
| 71 | - } else { |
|
| 72 | - $this->storageId = $storage; |
|
| 73 | - } |
|
| 74 | - $this->storageId = self::adjustStorageId($this->storageId); |
|
| 63 | + /** |
|
| 64 | + * @param \OC\Files\Storage\Storage|string $storage |
|
| 65 | + * @param bool $isAvailable |
|
| 66 | + * @throws \RuntimeException |
|
| 67 | + */ |
|
| 68 | + public function __construct($storage, $isAvailable = true) { |
|
| 69 | + if ($storage instanceof IStorage) { |
|
| 70 | + $this->storageId = $storage->getId(); |
|
| 71 | + } else { |
|
| 72 | + $this->storageId = $storage; |
|
| 73 | + } |
|
| 74 | + $this->storageId = self::adjustStorageId($this->storageId); |
|
| 75 | 75 | |
| 76 | - if ($row = self::getStorageById($this->storageId)) { |
|
| 77 | - $this->numericId = (int)$row['numeric_id']; |
|
| 78 | - } else { |
|
| 79 | - $connection = \OC::$server->getDatabaseConnection(); |
|
| 80 | - $available = $isAvailable ? 1 : 0; |
|
| 81 | - if ($connection->insertIfNotExist('*PREFIX*storages', ['id' => $this->storageId, 'available' => $available])) { |
|
| 82 | - $this->numericId = $connection->lastInsertId('*PREFIX*storages'); |
|
| 83 | - } else { |
|
| 84 | - if ($row = self::getStorageById($this->storageId)) { |
|
| 85 | - $this->numericId = (int)$row['numeric_id']; |
|
| 86 | - } else { |
|
| 87 | - throw new \RuntimeException('Storage could neither be inserted nor be selected from the database: ' . $this->storageId); |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - } |
|
| 76 | + if ($row = self::getStorageById($this->storageId)) { |
|
| 77 | + $this->numericId = (int)$row['numeric_id']; |
|
| 78 | + } else { |
|
| 79 | + $connection = \OC::$server->getDatabaseConnection(); |
|
| 80 | + $available = $isAvailable ? 1 : 0; |
|
| 81 | + if ($connection->insertIfNotExist('*PREFIX*storages', ['id' => $this->storageId, 'available' => $available])) { |
|
| 82 | + $this->numericId = $connection->lastInsertId('*PREFIX*storages'); |
|
| 83 | + } else { |
|
| 84 | + if ($row = self::getStorageById($this->storageId)) { |
|
| 85 | + $this->numericId = (int)$row['numeric_id']; |
|
| 86 | + } else { |
|
| 87 | + throw new \RuntimeException('Storage could neither be inserted nor be selected from the database: ' . $this->storageId); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * @param string $storageId |
|
| 95 | - * @return array |
|
| 96 | - */ |
|
| 97 | - public static function getStorageById($storageId) { |
|
| 98 | - return self::getGlobalCache()->getStorageInfo($storageId); |
|
| 99 | - } |
|
| 93 | + /** |
|
| 94 | + * @param string $storageId |
|
| 95 | + * @return array |
|
| 96 | + */ |
|
| 97 | + public static function getStorageById($storageId) { |
|
| 98 | + return self::getGlobalCache()->getStorageInfo($storageId); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * Adjusts the storage id to use md5 if too long |
|
| 103 | - * @param string $storageId storage id |
|
| 104 | - * @return string unchanged $storageId if its length is less than 64 characters, |
|
| 105 | - * else returns the md5 of $storageId |
|
| 106 | - */ |
|
| 107 | - public static function adjustStorageId($storageId) { |
|
| 108 | - if (strlen($storageId) > 64) { |
|
| 109 | - return md5($storageId); |
|
| 110 | - } |
|
| 111 | - return $storageId; |
|
| 112 | - } |
|
| 101 | + /** |
|
| 102 | + * Adjusts the storage id to use md5 if too long |
|
| 103 | + * @param string $storageId storage id |
|
| 104 | + * @return string unchanged $storageId if its length is less than 64 characters, |
|
| 105 | + * else returns the md5 of $storageId |
|
| 106 | + */ |
|
| 107 | + public static function adjustStorageId($storageId) { |
|
| 108 | + if (strlen($storageId) > 64) { |
|
| 109 | + return md5($storageId); |
|
| 110 | + } |
|
| 111 | + return $storageId; |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * Get the numeric id for the storage |
|
| 116 | - * |
|
| 117 | - * @return int |
|
| 118 | - */ |
|
| 119 | - public function getNumericId() { |
|
| 120 | - return $this->numericId; |
|
| 121 | - } |
|
| 114 | + /** |
|
| 115 | + * Get the numeric id for the storage |
|
| 116 | + * |
|
| 117 | + * @return int |
|
| 118 | + */ |
|
| 119 | + public function getNumericId() { |
|
| 120 | + return $this->numericId; |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * Get the string id for the storage |
|
| 125 | - * |
|
| 126 | - * @param int $numericId |
|
| 127 | - * @return string|null either the storage id string or null if the numeric id is not known |
|
| 128 | - */ |
|
| 129 | - public static function getStorageId($numericId) { |
|
| 130 | - $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 131 | - $query->select('id') |
|
| 132 | - ->from('storages') |
|
| 133 | - ->where($query->expr()->eq('numeric_id', $query->createNamedParameter($numericId))); |
|
| 134 | - $result = $query->execute(); |
|
| 135 | - $row = $result->fetch(); |
|
| 136 | - $result->closeCursor(); |
|
| 137 | - if ($row) { |
|
| 138 | - return $row['id']; |
|
| 139 | - } else { |
|
| 140 | - return null; |
|
| 141 | - } |
|
| 142 | - } |
|
| 123 | + /** |
|
| 124 | + * Get the string id for the storage |
|
| 125 | + * |
|
| 126 | + * @param int $numericId |
|
| 127 | + * @return string|null either the storage id string or null if the numeric id is not known |
|
| 128 | + */ |
|
| 129 | + public static function getStorageId($numericId) { |
|
| 130 | + $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 131 | + $query->select('id') |
|
| 132 | + ->from('storages') |
|
| 133 | + ->where($query->expr()->eq('numeric_id', $query->createNamedParameter($numericId))); |
|
| 134 | + $result = $query->execute(); |
|
| 135 | + $row = $result->fetch(); |
|
| 136 | + $result->closeCursor(); |
|
| 137 | + if ($row) { |
|
| 138 | + return $row['id']; |
|
| 139 | + } else { |
|
| 140 | + return null; |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * Get the numeric of the storage with the provided string id |
|
| 146 | - * |
|
| 147 | - * @param $storageId |
|
| 148 | - * @return int|null either the numeric storage id or null if the storage id is not knwon |
|
| 149 | - */ |
|
| 150 | - public static function getNumericStorageId($storageId) { |
|
| 151 | - $storageId = self::adjustStorageId($storageId); |
|
| 144 | + /** |
|
| 145 | + * Get the numeric of the storage with the provided string id |
|
| 146 | + * |
|
| 147 | + * @param $storageId |
|
| 148 | + * @return int|null either the numeric storage id or null if the storage id is not knwon |
|
| 149 | + */ |
|
| 150 | + public static function getNumericStorageId($storageId) { |
|
| 151 | + $storageId = self::adjustStorageId($storageId); |
|
| 152 | 152 | |
| 153 | - if ($row = self::getStorageById($storageId)) { |
|
| 154 | - return (int)$row['numeric_id']; |
|
| 155 | - } else { |
|
| 156 | - return null; |
|
| 157 | - } |
|
| 158 | - } |
|
| 153 | + if ($row = self::getStorageById($storageId)) { |
|
| 154 | + return (int)$row['numeric_id']; |
|
| 155 | + } else { |
|
| 156 | + return null; |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | - /** |
|
| 161 | - * @return array [ available, last_checked ] |
|
| 162 | - */ |
|
| 163 | - public function getAvailability() { |
|
| 164 | - if ($row = self::getStorageById($this->storageId)) { |
|
| 165 | - return [ |
|
| 166 | - 'available' => (int)$row['available'] === 1, |
|
| 167 | - 'last_checked' => $row['last_checked'] |
|
| 168 | - ]; |
|
| 169 | - } else { |
|
| 170 | - return [ |
|
| 171 | - 'available' => true, |
|
| 172 | - 'last_checked' => time(), |
|
| 173 | - ]; |
|
| 174 | - } |
|
| 175 | - } |
|
| 160 | + /** |
|
| 161 | + * @return array [ available, last_checked ] |
|
| 162 | + */ |
|
| 163 | + public function getAvailability() { |
|
| 164 | + if ($row = self::getStorageById($this->storageId)) { |
|
| 165 | + return [ |
|
| 166 | + 'available' => (int)$row['available'] === 1, |
|
| 167 | + 'last_checked' => $row['last_checked'] |
|
| 168 | + ]; |
|
| 169 | + } else { |
|
| 170 | + return [ |
|
| 171 | + 'available' => true, |
|
| 172 | + 'last_checked' => time(), |
|
| 173 | + ]; |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * @param bool $isAvailable |
|
| 179 | - * @param int $delay amount of seconds to delay reconsidering that storage further |
|
| 180 | - */ |
|
| 181 | - public function setAvailability($isAvailable, int $delay = 0) { |
|
| 182 | - $available = $isAvailable ? 1 : 0; |
|
| 183 | - if (!$isAvailable) { |
|
| 184 | - \OC::$server->get(LoggerInterface::class)->info('Storage with ' . $this->storageId . ' marked as unavailable', ['app' => 'lib']); |
|
| 185 | - } |
|
| 177 | + /** |
|
| 178 | + * @param bool $isAvailable |
|
| 179 | + * @param int $delay amount of seconds to delay reconsidering that storage further |
|
| 180 | + */ |
|
| 181 | + public function setAvailability($isAvailable, int $delay = 0) { |
|
| 182 | + $available = $isAvailable ? 1 : 0; |
|
| 183 | + if (!$isAvailable) { |
|
| 184 | + \OC::$server->get(LoggerInterface::class)->info('Storage with ' . $this->storageId . ' marked as unavailable', ['app' => 'lib']); |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | - $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 188 | - $query->update('storages') |
|
| 189 | - ->set('available', $query->createNamedParameter($available)) |
|
| 190 | - ->set('last_checked', $query->createNamedParameter(time() + $delay)) |
|
| 191 | - ->where($query->expr()->eq('id', $query->createNamedParameter($this->storageId))); |
|
| 192 | - $query->execute(); |
|
| 193 | - } |
|
| 187 | + $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 188 | + $query->update('storages') |
|
| 189 | + ->set('available', $query->createNamedParameter($available)) |
|
| 190 | + ->set('last_checked', $query->createNamedParameter(time() + $delay)) |
|
| 191 | + ->where($query->expr()->eq('id', $query->createNamedParameter($this->storageId))); |
|
| 192 | + $query->execute(); |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - /** |
|
| 196 | - * Check if a string storage id is known |
|
| 197 | - * |
|
| 198 | - * @param string $storageId |
|
| 199 | - * @return bool |
|
| 200 | - */ |
|
| 201 | - public static function exists($storageId) { |
|
| 202 | - return !is_null(self::getNumericStorageId($storageId)); |
|
| 203 | - } |
|
| 195 | + /** |
|
| 196 | + * Check if a string storage id is known |
|
| 197 | + * |
|
| 198 | + * @param string $storageId |
|
| 199 | + * @return bool |
|
| 200 | + */ |
|
| 201 | + public static function exists($storageId) { |
|
| 202 | + return !is_null(self::getNumericStorageId($storageId)); |
|
| 203 | + } |
|
| 204 | 204 | |
| 205 | - /** |
|
| 206 | - * remove the entry for the storage |
|
| 207 | - * |
|
| 208 | - * @param string $storageId |
|
| 209 | - */ |
|
| 210 | - public static function remove($storageId) { |
|
| 211 | - $storageId = self::adjustStorageId($storageId); |
|
| 212 | - $numericId = self::getNumericStorageId($storageId); |
|
| 205 | + /** |
|
| 206 | + * remove the entry for the storage |
|
| 207 | + * |
|
| 208 | + * @param string $storageId |
|
| 209 | + */ |
|
| 210 | + public static function remove($storageId) { |
|
| 211 | + $storageId = self::adjustStorageId($storageId); |
|
| 212 | + $numericId = self::getNumericStorageId($storageId); |
|
| 213 | 213 | |
| 214 | - $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 215 | - $query->delete('storages') |
|
| 216 | - ->where($query->expr()->eq('id', $query->createNamedParameter($storageId))); |
|
| 217 | - $query->execute(); |
|
| 214 | + $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 215 | + $query->delete('storages') |
|
| 216 | + ->where($query->expr()->eq('id', $query->createNamedParameter($storageId))); |
|
| 217 | + $query->execute(); |
|
| 218 | 218 | |
| 219 | - if (!is_null($numericId)) { |
|
| 220 | - $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 221 | - $query->delete('filecache') |
|
| 222 | - ->where($query->expr()->eq('storage', $query->createNamedParameter($numericId))); |
|
| 223 | - $query->execute(); |
|
| 224 | - } |
|
| 225 | - } |
|
| 219 | + if (!is_null($numericId)) { |
|
| 220 | + $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 221 | + $query->delete('filecache') |
|
| 222 | + ->where($query->expr()->eq('storage', $query->createNamedParameter($numericId))); |
|
| 223 | + $query->execute(); |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | 226 | |
| 227 | - /** |
|
| 228 | - * remove the entry for the storage by the mount id |
|
| 229 | - * |
|
| 230 | - * @param int $mountId |
|
| 231 | - */ |
|
| 232 | - public static function cleanByMountId(int $mountId) { |
|
| 233 | - $db = \OC::$server->getDatabaseConnection(); |
|
| 227 | + /** |
|
| 228 | + * remove the entry for the storage by the mount id |
|
| 229 | + * |
|
| 230 | + * @param int $mountId |
|
| 231 | + */ |
|
| 232 | + public static function cleanByMountId(int $mountId) { |
|
| 233 | + $db = \OC::$server->getDatabaseConnection(); |
|
| 234 | 234 | |
| 235 | - try { |
|
| 236 | - $db->beginTransaction(); |
|
| 235 | + try { |
|
| 236 | + $db->beginTransaction(); |
|
| 237 | 237 | |
| 238 | - $query = $db->getQueryBuilder(); |
|
| 239 | - $query->select('storage_id') |
|
| 240 | - ->from('mounts') |
|
| 241 | - ->where($query->expr()->eq('mount_id', $query->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
| 242 | - $storageIds = $query->executeQuery()->fetchAll(\PDO::FETCH_COLUMN); |
|
| 238 | + $query = $db->getQueryBuilder(); |
|
| 239 | + $query->select('storage_id') |
|
| 240 | + ->from('mounts') |
|
| 241 | + ->where($query->expr()->eq('mount_id', $query->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
| 242 | + $storageIds = $query->executeQuery()->fetchAll(\PDO::FETCH_COLUMN); |
|
| 243 | 243 | |
| 244 | - $query = $db->getQueryBuilder(); |
|
| 245 | - $query->delete('filecache') |
|
| 246 | - ->where($query->expr()->in('storage', $query->createNamedParameter($storageIds, IQueryBuilder::PARAM_INT_ARRAY))); |
|
| 247 | - $query->executeStatement(); |
|
| 244 | + $query = $db->getQueryBuilder(); |
|
| 245 | + $query->delete('filecache') |
|
| 246 | + ->where($query->expr()->in('storage', $query->createNamedParameter($storageIds, IQueryBuilder::PARAM_INT_ARRAY))); |
|
| 247 | + $query->executeStatement(); |
|
| 248 | 248 | |
| 249 | - $query = $db->getQueryBuilder(); |
|
| 250 | - $query->delete('storages') |
|
| 251 | - ->where($query->expr()->eq('numeric_id', $query->createNamedParameter($storageIds, IQueryBuilder::PARAM_INT_ARRAY))); |
|
| 252 | - $query->executeStatement(); |
|
| 249 | + $query = $db->getQueryBuilder(); |
|
| 250 | + $query->delete('storages') |
|
| 251 | + ->where($query->expr()->eq('numeric_id', $query->createNamedParameter($storageIds, IQueryBuilder::PARAM_INT_ARRAY))); |
|
| 252 | + $query->executeStatement(); |
|
| 253 | 253 | |
| 254 | - $query = $db->getQueryBuilder(); |
|
| 255 | - $query->delete('mounts') |
|
| 256 | - ->where($query->expr()->eq('mount_id', $query->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
| 257 | - $query->executeStatement(); |
|
| 254 | + $query = $db->getQueryBuilder(); |
|
| 255 | + $query->delete('mounts') |
|
| 256 | + ->where($query->expr()->eq('mount_id', $query->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
| 257 | + $query->executeStatement(); |
|
| 258 | 258 | |
| 259 | - $db->commit(); |
|
| 260 | - } catch (\Exception $e) { |
|
| 261 | - $db->rollBack(); |
|
| 262 | - throw $e; |
|
| 263 | - } |
|
| 264 | - } |
|
| 259 | + $db->commit(); |
|
| 260 | + } catch (\Exception $e) { |
|
| 261 | + $db->rollBack(); |
|
| 262 | + throw $e; |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | 265 | } |
@@ -33,71 +33,71 @@ |
||
| 33 | 33 | use Psr\Log\LoggerInterface; |
| 34 | 34 | |
| 35 | 35 | class RootMountProvider implements IRootMountProvider { |
| 36 | - private IConfig $config; |
|
| 37 | - private LoggerInterface $logger; |
|
| 38 | - |
|
| 39 | - public function __construct(IConfig $config, LoggerInterface $logger) { |
|
| 40 | - $this->config = $config; |
|
| 41 | - $this->logger = $logger; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - public function getRootMounts(IStorageFactory $loader): array { |
|
| 45 | - $objectStore = $this->config->getSystemValue('objectstore', null); |
|
| 46 | - $objectStoreMultiBucket = $this->config->getSystemValue('objectstore_multibucket', null); |
|
| 47 | - |
|
| 48 | - if ($objectStoreMultiBucket) { |
|
| 49 | - return [$this->getMultiBucketStoreRootMount($loader, $objectStoreMultiBucket)]; |
|
| 50 | - } elseif ($objectStore) { |
|
| 51 | - return [$this->getObjectStoreRootMount($loader, $objectStore)]; |
|
| 52 | - } else { |
|
| 53 | - return [$this->getLocalRootMount($loader)]; |
|
| 54 | - } |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - private function validateObjectStoreConfig(array &$config) { |
|
| 58 | - if (empty($config['class'])) { |
|
| 59 | - $this->logger->error('No class given for objectstore', ['app' => 'files']); |
|
| 60 | - } |
|
| 61 | - if (!isset($config['arguments'])) { |
|
| 62 | - $config['arguments'] = []; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - // instantiate object store implementation |
|
| 66 | - $name = $config['class']; |
|
| 67 | - if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
| 68 | - $segments = explode('\\', $name); |
|
| 69 | - OC_App::loadApp(strtolower($segments[1])); |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - private function getLocalRootMount(IStorageFactory $loader): MountPoint { |
|
| 74 | - $configDataDirectory = $this->config->getSystemValue("datadirectory", OC::$SERVERROOT . "/data"); |
|
| 75 | - return new MountPoint(LocalRootStorage::class, '/', ['datadir' => $configDataDirectory], $loader, null, null, self::class); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - private function getObjectStoreRootMount(IStorageFactory $loader, array $config): MountPoint { |
|
| 79 | - $this->validateObjectStoreConfig($config); |
|
| 80 | - |
|
| 81 | - $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
| 82 | - // mount with plain / root object store implementation |
|
| 83 | - $config['class'] = ObjectStoreStorage::class; |
|
| 84 | - |
|
| 85 | - return new MountPoint($config['class'], '/', $config['arguments'], $loader, null, null, self::class); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - private function getMultiBucketStoreRootMount(IStorageFactory $loader, array $config): MountPoint { |
|
| 89 | - $this->validateObjectStoreConfig($config); |
|
| 90 | - |
|
| 91 | - if (!isset($config['arguments']['bucket'])) { |
|
| 92 | - $config['arguments']['bucket'] = ''; |
|
| 93 | - } |
|
| 94 | - // put the root FS always in first bucket for multibucket configuration |
|
| 95 | - $config['arguments']['bucket'] .= '0'; |
|
| 96 | - |
|
| 97 | - $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
| 98 | - // mount with plain / root object store implementation |
|
| 99 | - $config['class'] = ObjectStoreStorage::class; |
|
| 100 | - |
|
| 101 | - return new MountPoint($config['class'], '/', $config['arguments'], $loader, null, null, self::class); |
|
| 102 | - } |
|
| 36 | + private IConfig $config; |
|
| 37 | + private LoggerInterface $logger; |
|
| 38 | + |
|
| 39 | + public function __construct(IConfig $config, LoggerInterface $logger) { |
|
| 40 | + $this->config = $config; |
|
| 41 | + $this->logger = $logger; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + public function getRootMounts(IStorageFactory $loader): array { |
|
| 45 | + $objectStore = $this->config->getSystemValue('objectstore', null); |
|
| 46 | + $objectStoreMultiBucket = $this->config->getSystemValue('objectstore_multibucket', null); |
|
| 47 | + |
|
| 48 | + if ($objectStoreMultiBucket) { |
|
| 49 | + return [$this->getMultiBucketStoreRootMount($loader, $objectStoreMultiBucket)]; |
|
| 50 | + } elseif ($objectStore) { |
|
| 51 | + return [$this->getObjectStoreRootMount($loader, $objectStore)]; |
|
| 52 | + } else { |
|
| 53 | + return [$this->getLocalRootMount($loader)]; |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + private function validateObjectStoreConfig(array &$config) { |
|
| 58 | + if (empty($config['class'])) { |
|
| 59 | + $this->logger->error('No class given for objectstore', ['app' => 'files']); |
|
| 60 | + } |
|
| 61 | + if (!isset($config['arguments'])) { |
|
| 62 | + $config['arguments'] = []; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + // instantiate object store implementation |
|
| 66 | + $name = $config['class']; |
|
| 67 | + if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
| 68 | + $segments = explode('\\', $name); |
|
| 69 | + OC_App::loadApp(strtolower($segments[1])); |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + private function getLocalRootMount(IStorageFactory $loader): MountPoint { |
|
| 74 | + $configDataDirectory = $this->config->getSystemValue("datadirectory", OC::$SERVERROOT . "/data"); |
|
| 75 | + return new MountPoint(LocalRootStorage::class, '/', ['datadir' => $configDataDirectory], $loader, null, null, self::class); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + private function getObjectStoreRootMount(IStorageFactory $loader, array $config): MountPoint { |
|
| 79 | + $this->validateObjectStoreConfig($config); |
|
| 80 | + |
|
| 81 | + $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
| 82 | + // mount with plain / root object store implementation |
|
| 83 | + $config['class'] = ObjectStoreStorage::class; |
|
| 84 | + |
|
| 85 | + return new MountPoint($config['class'], '/', $config['arguments'], $loader, null, null, self::class); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + private function getMultiBucketStoreRootMount(IStorageFactory $loader, array $config): MountPoint { |
|
| 89 | + $this->validateObjectStoreConfig($config); |
|
| 90 | + |
|
| 91 | + if (!isset($config['arguments']['bucket'])) { |
|
| 92 | + $config['arguments']['bucket'] = ''; |
|
| 93 | + } |
|
| 94 | + // put the root FS always in first bucket for multibucket configuration |
|
| 95 | + $config['arguments']['bucket'] .= '0'; |
|
| 96 | + |
|
| 97 | + $config['arguments']['objectstore'] = new $config['class']($config['arguments']); |
|
| 98 | + // mount with plain / root object store implementation |
|
| 99 | + $config['class'] = ObjectStoreStorage::class; |
|
| 100 | + |
|
| 101 | + return new MountPoint($config['class'], '/', $config['arguments'], $loader, null, null, self::class); |
|
| 102 | + } |
|
| 103 | 103 | } |
@@ -71,7 +71,7 @@ |
||
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | private function getLocalRootMount(IStorageFactory $loader): MountPoint { |
| 74 | - $configDataDirectory = $this->config->getSystemValue("datadirectory", OC::$SERVERROOT . "/data"); |
|
| 74 | + $configDataDirectory = $this->config->getSystemValue("datadirectory", OC::$SERVERROOT."/data"); |
|
| 75 | 75 | return new MountPoint(LocalRootStorage::class, '/', ['datadir' => $configDataDirectory], $loader, null, null, self::class); |
| 76 | 76 | } |
| 77 | 77 | |
@@ -56,139 +56,139 @@ |
||
| 56 | 56 | */ |
| 57 | 57 | class AvatarManager implements IAvatarManager { |
| 58 | 58 | |
| 59 | - /** @var IUserSession */ |
|
| 60 | - private $userSession; |
|
| 61 | - |
|
| 62 | - /** @var Manager */ |
|
| 63 | - private $userManager; |
|
| 64 | - |
|
| 65 | - /** @var IAppData */ |
|
| 66 | - private $appData; |
|
| 67 | - |
|
| 68 | - /** @var IL10N */ |
|
| 69 | - private $l; |
|
| 70 | - |
|
| 71 | - /** @var LoggerInterface */ |
|
| 72 | - private $logger; |
|
| 73 | - |
|
| 74 | - /** @var IConfig */ |
|
| 75 | - private $config; |
|
| 76 | - |
|
| 77 | - /** @var IAccountManager */ |
|
| 78 | - private $accountManager; |
|
| 79 | - |
|
| 80 | - /** @var KnownUserService */ |
|
| 81 | - private $knownUserService; |
|
| 82 | - |
|
| 83 | - public function __construct( |
|
| 84 | - IUserSession $userSession, |
|
| 85 | - Manager $userManager, |
|
| 86 | - IAppData $appData, |
|
| 87 | - IL10N $l, |
|
| 88 | - LoggerInterface $logger, |
|
| 89 | - IConfig $config, |
|
| 90 | - IAccountManager $accountManager, |
|
| 91 | - KnownUserService $knownUserService |
|
| 92 | - ) { |
|
| 93 | - $this->userSession = $userSession; |
|
| 94 | - $this->userManager = $userManager; |
|
| 95 | - $this->appData = $appData; |
|
| 96 | - $this->l = $l; |
|
| 97 | - $this->logger = $logger; |
|
| 98 | - $this->config = $config; |
|
| 99 | - $this->accountManager = $accountManager; |
|
| 100 | - $this->knownUserService = $knownUserService; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * return a user specific instance of \OCP\IAvatar |
|
| 105 | - * @see \OCP\IAvatar |
|
| 106 | - * @param string $userId the ownCloud user id |
|
| 107 | - * @return \OCP\IAvatar |
|
| 108 | - * @throws \Exception In case the username is potentially dangerous |
|
| 109 | - * @throws NotFoundException In case there is no user folder yet |
|
| 110 | - */ |
|
| 111 | - public function getAvatar(string $userId) : IAvatar { |
|
| 112 | - $user = $this->userManager->get($userId); |
|
| 113 | - if ($user === null) { |
|
| 114 | - throw new \Exception('user does not exist'); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - // sanitize userID - fixes casing issue (needed for the filesystem stuff that is done below) |
|
| 118 | - $userId = $user->getUID(); |
|
| 119 | - |
|
| 120 | - $requestingUser = null; |
|
| 121 | - if ($this->userSession !== null) { |
|
| 122 | - $requestingUser = $this->userSession->getUser(); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - try { |
|
| 126 | - $folder = $this->appData->getFolder($userId); |
|
| 127 | - } catch (NotFoundException $e) { |
|
| 128 | - $folder = $this->appData->newFolder($userId); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - try { |
|
| 132 | - $account = $this->accountManager->getAccount($user); |
|
| 133 | - $avatarProperties = $account->getProperty(IAccountManager::PROPERTY_AVATAR); |
|
| 134 | - $avatarScope = $avatarProperties->getScope(); |
|
| 135 | - } catch (PropertyDoesNotExistException $e) { |
|
| 136 | - $avatarScope = ''; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - if ( |
|
| 140 | - // v2-private scope hides the avatar from public access and from unknown users |
|
| 141 | - $avatarScope === IAccountManager::SCOPE_PRIVATE |
|
| 142 | - && ( |
|
| 143 | - // accessing from public link |
|
| 144 | - $requestingUser === null |
|
| 145 | - // logged in, but unknown to user |
|
| 146 | - || !$this->knownUserService->isKnownToUser($requestingUser->getUID(), $userId) |
|
| 147 | - )) { |
|
| 148 | - // use a placeholder avatar which caches the generated images |
|
| 149 | - return new PlaceholderAvatar($folder, $user, $this->logger); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - return new UserAvatar($folder, $this->l, $user, $this->logger, $this->config); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Clear generated avatars |
|
| 157 | - */ |
|
| 158 | - public function clearCachedAvatars() { |
|
| 159 | - $users = $this->config->getUsersForUserValue('avatar', 'generated', 'true'); |
|
| 160 | - foreach ($users as $userId) { |
|
| 161 | - try { |
|
| 162 | - $folder = $this->appData->getFolder($userId); |
|
| 163 | - $folder->delete(); |
|
| 164 | - } catch (NotFoundException $e) { |
|
| 165 | - $this->logger->debug("No cache for the user $userId. Ignoring..."); |
|
| 166 | - } |
|
| 167 | - $this->config->setUserValue($userId, 'avatar', 'generated', 'false'); |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - public function deleteUserAvatar(string $userId): void { |
|
| 172 | - try { |
|
| 173 | - $folder = $this->appData->getFolder($userId); |
|
| 174 | - $folder->delete(); |
|
| 175 | - } catch (NotFoundException $e) { |
|
| 176 | - $this->logger->debug("No cache for the user $userId. Ignoring avatar deletion"); |
|
| 177 | - } catch (NotPermittedException | StorageNotAvailableException $e) { |
|
| 178 | - $this->logger->error("Unable to delete user avatars for $userId. gnoring avatar deletion"); |
|
| 179 | - } catch (NoUserException $e) { |
|
| 180 | - $this->logger->debug("User $userId not found. gnoring avatar deletion"); |
|
| 181 | - } |
|
| 182 | - $this->config->deleteUserValue($userId, 'avatar', 'generated'); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * Returns a GuestAvatar. |
|
| 187 | - * |
|
| 188 | - * @param string $name The guest name, e.g. "Albert". |
|
| 189 | - * @return IAvatar |
|
| 190 | - */ |
|
| 191 | - public function getGuestAvatar(string $name): IAvatar { |
|
| 192 | - return new GuestAvatar($name, $this->logger); |
|
| 193 | - } |
|
| 59 | + /** @var IUserSession */ |
|
| 60 | + private $userSession; |
|
| 61 | + |
|
| 62 | + /** @var Manager */ |
|
| 63 | + private $userManager; |
|
| 64 | + |
|
| 65 | + /** @var IAppData */ |
|
| 66 | + private $appData; |
|
| 67 | + |
|
| 68 | + /** @var IL10N */ |
|
| 69 | + private $l; |
|
| 70 | + |
|
| 71 | + /** @var LoggerInterface */ |
|
| 72 | + private $logger; |
|
| 73 | + |
|
| 74 | + /** @var IConfig */ |
|
| 75 | + private $config; |
|
| 76 | + |
|
| 77 | + /** @var IAccountManager */ |
|
| 78 | + private $accountManager; |
|
| 79 | + |
|
| 80 | + /** @var KnownUserService */ |
|
| 81 | + private $knownUserService; |
|
| 82 | + |
|
| 83 | + public function __construct( |
|
| 84 | + IUserSession $userSession, |
|
| 85 | + Manager $userManager, |
|
| 86 | + IAppData $appData, |
|
| 87 | + IL10N $l, |
|
| 88 | + LoggerInterface $logger, |
|
| 89 | + IConfig $config, |
|
| 90 | + IAccountManager $accountManager, |
|
| 91 | + KnownUserService $knownUserService |
|
| 92 | + ) { |
|
| 93 | + $this->userSession = $userSession; |
|
| 94 | + $this->userManager = $userManager; |
|
| 95 | + $this->appData = $appData; |
|
| 96 | + $this->l = $l; |
|
| 97 | + $this->logger = $logger; |
|
| 98 | + $this->config = $config; |
|
| 99 | + $this->accountManager = $accountManager; |
|
| 100 | + $this->knownUserService = $knownUserService; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * return a user specific instance of \OCP\IAvatar |
|
| 105 | + * @see \OCP\IAvatar |
|
| 106 | + * @param string $userId the ownCloud user id |
|
| 107 | + * @return \OCP\IAvatar |
|
| 108 | + * @throws \Exception In case the username is potentially dangerous |
|
| 109 | + * @throws NotFoundException In case there is no user folder yet |
|
| 110 | + */ |
|
| 111 | + public function getAvatar(string $userId) : IAvatar { |
|
| 112 | + $user = $this->userManager->get($userId); |
|
| 113 | + if ($user === null) { |
|
| 114 | + throw new \Exception('user does not exist'); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + // sanitize userID - fixes casing issue (needed for the filesystem stuff that is done below) |
|
| 118 | + $userId = $user->getUID(); |
|
| 119 | + |
|
| 120 | + $requestingUser = null; |
|
| 121 | + if ($this->userSession !== null) { |
|
| 122 | + $requestingUser = $this->userSession->getUser(); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + try { |
|
| 126 | + $folder = $this->appData->getFolder($userId); |
|
| 127 | + } catch (NotFoundException $e) { |
|
| 128 | + $folder = $this->appData->newFolder($userId); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + try { |
|
| 132 | + $account = $this->accountManager->getAccount($user); |
|
| 133 | + $avatarProperties = $account->getProperty(IAccountManager::PROPERTY_AVATAR); |
|
| 134 | + $avatarScope = $avatarProperties->getScope(); |
|
| 135 | + } catch (PropertyDoesNotExistException $e) { |
|
| 136 | + $avatarScope = ''; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + if ( |
|
| 140 | + // v2-private scope hides the avatar from public access and from unknown users |
|
| 141 | + $avatarScope === IAccountManager::SCOPE_PRIVATE |
|
| 142 | + && ( |
|
| 143 | + // accessing from public link |
|
| 144 | + $requestingUser === null |
|
| 145 | + // logged in, but unknown to user |
|
| 146 | + || !$this->knownUserService->isKnownToUser($requestingUser->getUID(), $userId) |
|
| 147 | + )) { |
|
| 148 | + // use a placeholder avatar which caches the generated images |
|
| 149 | + return new PlaceholderAvatar($folder, $user, $this->logger); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + return new UserAvatar($folder, $this->l, $user, $this->logger, $this->config); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Clear generated avatars |
|
| 157 | + */ |
|
| 158 | + public function clearCachedAvatars() { |
|
| 159 | + $users = $this->config->getUsersForUserValue('avatar', 'generated', 'true'); |
|
| 160 | + foreach ($users as $userId) { |
|
| 161 | + try { |
|
| 162 | + $folder = $this->appData->getFolder($userId); |
|
| 163 | + $folder->delete(); |
|
| 164 | + } catch (NotFoundException $e) { |
|
| 165 | + $this->logger->debug("No cache for the user $userId. Ignoring..."); |
|
| 166 | + } |
|
| 167 | + $this->config->setUserValue($userId, 'avatar', 'generated', 'false'); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + public function deleteUserAvatar(string $userId): void { |
|
| 172 | + try { |
|
| 173 | + $folder = $this->appData->getFolder($userId); |
|
| 174 | + $folder->delete(); |
|
| 175 | + } catch (NotFoundException $e) { |
|
| 176 | + $this->logger->debug("No cache for the user $userId. Ignoring avatar deletion"); |
|
| 177 | + } catch (NotPermittedException | StorageNotAvailableException $e) { |
|
| 178 | + $this->logger->error("Unable to delete user avatars for $userId. gnoring avatar deletion"); |
|
| 179 | + } catch (NoUserException $e) { |
|
| 180 | + $this->logger->debug("User $userId not found. gnoring avatar deletion"); |
|
| 181 | + } |
|
| 182 | + $this->config->deleteUserValue($userId, 'avatar', 'generated'); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * Returns a GuestAvatar. |
|
| 187 | + * |
|
| 188 | + * @param string $name The guest name, e.g. "Albert". |
|
| 189 | + * @return IAvatar |
|
| 190 | + */ |
|
| 191 | + public function getGuestAvatar(string $name): IAvatar { |
|
| 192 | + return new GuestAvatar($name, $this->logger); |
|
| 193 | + } |
|
| 194 | 194 | } |
@@ -76,674 +76,674 @@ |
||
| 76 | 76 | use Sabre\DAV\IFile; |
| 77 | 77 | |
| 78 | 78 | class File extends Node implements IFile { |
| 79 | - protected $request; |
|
| 80 | - |
|
| 81 | - protected IL10N $l10n; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Sets up the node, expects a full path name |
|
| 85 | - * |
|
| 86 | - * @param \OC\Files\View $view |
|
| 87 | - * @param \OCP\Files\FileInfo $info |
|
| 88 | - * @param \OCP\Share\IManager $shareManager |
|
| 89 | - * @param \OC\AppFramework\Http\Request $request |
|
| 90 | - */ |
|
| 91 | - public function __construct(View $view, FileInfo $info, IManager $shareManager = null, Request $request = null) { |
|
| 92 | - parent::__construct($view, $info, $shareManager); |
|
| 93 | - |
|
| 94 | - // Querying IL10N directly results in a dependency loop |
|
| 95 | - /** @var IL10NFactory $l10nFactory */ |
|
| 96 | - $l10nFactory = \OC::$server->get(IL10NFactory::class); |
|
| 97 | - $this->l10n = $l10nFactory->get(Application::APP_ID); |
|
| 98 | - |
|
| 99 | - if (isset($request)) { |
|
| 100 | - $this->request = $request; |
|
| 101 | - } else { |
|
| 102 | - $this->request = \OC::$server->getRequest(); |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Updates the data |
|
| 108 | - * |
|
| 109 | - * The data argument is a readable stream resource. |
|
| 110 | - * |
|
| 111 | - * After a successful put operation, you may choose to return an ETag. The |
|
| 112 | - * etag must always be surrounded by double-quotes. These quotes must |
|
| 113 | - * appear in the actual string you're returning. |
|
| 114 | - * |
|
| 115 | - * Clients may use the ETag from a PUT request to later on make sure that |
|
| 116 | - * when they update the file, the contents haven't changed in the mean |
|
| 117 | - * time. |
|
| 118 | - * |
|
| 119 | - * If you don't plan to store the file byte-by-byte, and you return a |
|
| 120 | - * different object on a subsequent GET you are strongly recommended to not |
|
| 121 | - * return an ETag, and just return null. |
|
| 122 | - * |
|
| 123 | - * @param resource $data |
|
| 124 | - * |
|
| 125 | - * @throws Forbidden |
|
| 126 | - * @throws UnsupportedMediaType |
|
| 127 | - * @throws BadRequest |
|
| 128 | - * @throws Exception |
|
| 129 | - * @throws EntityTooLarge |
|
| 130 | - * @throws ServiceUnavailable |
|
| 131 | - * @throws FileLocked |
|
| 132 | - * @return string|null |
|
| 133 | - */ |
|
| 134 | - public function put($data) { |
|
| 135 | - try { |
|
| 136 | - $exists = $this->fileView->file_exists($this->path); |
|
| 137 | - if ($this->info && $exists && !$this->info->isUpdateable()) { |
|
| 138 | - throw new Forbidden(); |
|
| 139 | - } |
|
| 140 | - } catch (StorageNotAvailableException $e) { |
|
| 141 | - throw new ServiceUnavailable($this->l10n->t('File is not updatable: %1$s', [$e->getMessage()])); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - // verify path of the target |
|
| 145 | - $this->verifyPath(); |
|
| 146 | - |
|
| 147 | - // chunked handling |
|
| 148 | - if (isset($_SERVER['HTTP_OC_CHUNKED'])) { |
|
| 149 | - try { |
|
| 150 | - return $this->createFileChunked($data); |
|
| 151 | - } catch (\Exception $e) { |
|
| 152 | - $this->convertToSabreException($e); |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** @var Storage $partStorage */ |
|
| 157 | - [$partStorage] = $this->fileView->resolvePath($this->path); |
|
| 158 | - $needsPartFile = $partStorage->needsPartFile() && (strlen($this->path) > 1); |
|
| 159 | - |
|
| 160 | - $view = \OC\Files\Filesystem::getView(); |
|
| 161 | - |
|
| 162 | - if ($needsPartFile) { |
|
| 163 | - // mark file as partial while uploading (ignored by the scanner) |
|
| 164 | - $partFilePath = $this->getPartFileBasePath($this->path) . '.ocTransferId' . rand() . '.part'; |
|
| 165 | - |
|
| 166 | - if (!$view->isCreatable($partFilePath) && $view->isUpdatable($this->path)) { |
|
| 167 | - $needsPartFile = false; |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - if (!$needsPartFile) { |
|
| 171 | - // upload file directly as the final path |
|
| 172 | - $partFilePath = $this->path; |
|
| 173 | - |
|
| 174 | - if ($view && !$this->emitPreHooks($exists)) { |
|
| 175 | - throw new Exception($this->l10n->t('Could not write to final file, canceled by hook')); |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - // the part file and target file might be on a different storage in case of a single file storage (e.g. single file share) |
|
| 180 | - /** @var \OC\Files\Storage\Storage $partStorage */ |
|
| 181 | - [$partStorage, $internalPartPath] = $this->fileView->resolvePath($partFilePath); |
|
| 182 | - /** @var \OC\Files\Storage\Storage $storage */ |
|
| 183 | - [$storage, $internalPath] = $this->fileView->resolvePath($this->path); |
|
| 184 | - try { |
|
| 185 | - if (!$needsPartFile) { |
|
| 186 | - try { |
|
| 187 | - $this->changeLock(ILockingProvider::LOCK_EXCLUSIVE); |
|
| 188 | - } catch (LockedException $e) { |
|
| 189 | - // during very large uploads, the shared lock we got at the start might have been expired |
|
| 190 | - // meaning that the above lock can fail not just only because somebody else got a shared lock |
|
| 191 | - // or because there is no existing shared lock to make exclusive |
|
| 192 | - // |
|
| 193 | - // Thus we try to get a new exclusive lock, if the original lock failed because of a different shared |
|
| 194 | - // lock this will still fail, if our original shared lock expired the new lock will be successful and |
|
| 195 | - // the entire operation will be safe |
|
| 196 | - |
|
| 197 | - try { |
|
| 198 | - $this->acquireLock(ILockingProvider::LOCK_EXCLUSIVE); |
|
| 199 | - } catch (LockedException $ex) { |
|
| 200 | - throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - if (!is_resource($data)) { |
|
| 206 | - $tmpData = fopen('php://temp', 'r+'); |
|
| 207 | - if ($data !== null) { |
|
| 208 | - fwrite($tmpData, $data); |
|
| 209 | - rewind($tmpData); |
|
| 210 | - } |
|
| 211 | - $data = $tmpData; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - $data = HashWrapper::wrap($data, 'md5', function ($hash) { |
|
| 215 | - $this->header('X-Hash-MD5: ' . $hash); |
|
| 216 | - }); |
|
| 217 | - $data = HashWrapper::wrap($data, 'sha1', function ($hash) { |
|
| 218 | - $this->header('X-Hash-SHA1: ' . $hash); |
|
| 219 | - }); |
|
| 220 | - $data = HashWrapper::wrap($data, 'sha256', function ($hash) { |
|
| 221 | - $this->header('X-Hash-SHA256: ' . $hash); |
|
| 222 | - }); |
|
| 223 | - |
|
| 224 | - if ($partStorage->instanceOfStorage(Storage\IWriteStreamStorage::class)) { |
|
| 225 | - $isEOF = false; |
|
| 226 | - $wrappedData = CallbackWrapper::wrap($data, null, null, null, null, function ($stream) use (&$isEOF) { |
|
| 227 | - $isEOF = feof($stream); |
|
| 228 | - }); |
|
| 229 | - |
|
| 230 | - $result = true; |
|
| 231 | - $count = -1; |
|
| 232 | - try { |
|
| 233 | - $count = $partStorage->writeStream($internalPartPath, $wrappedData); |
|
| 234 | - } catch (GenericFileException $e) { |
|
| 235 | - $result = false; |
|
| 236 | - } catch (BadGateway $e) { |
|
| 237 | - throw $e; |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - |
|
| 241 | - if ($result === false) { |
|
| 242 | - $result = $isEOF; |
|
| 243 | - if (is_resource($wrappedData)) { |
|
| 244 | - $result = feof($wrappedData); |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - } else { |
|
| 248 | - $target = $partStorage->fopen($internalPartPath, 'wb'); |
|
| 249 | - if ($target === false) { |
|
| 250 | - \OC::$server->getLogger()->error('\OC\Files\Filesystem::fopen() failed', ['app' => 'webdav']); |
|
| 251 | - // because we have no clue about the cause we can only throw back a 500/Internal Server Error |
|
| 252 | - throw new Exception($this->l10n->t('Could not write file contents')); |
|
| 253 | - } |
|
| 254 | - [$count, $result] = \OC_Helper::streamCopy($data, $target); |
|
| 255 | - fclose($target); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - if ($result === false) { |
|
| 259 | - $expected = -1; |
|
| 260 | - if (isset($_SERVER['CONTENT_LENGTH'])) { |
|
| 261 | - $expected = $_SERVER['CONTENT_LENGTH']; |
|
| 262 | - } |
|
| 263 | - if ($expected !== "0") { |
|
| 264 | - throw new Exception( |
|
| 265 | - $this->l10n->t( |
|
| 266 | - 'Error while copying file to target location (copied: %1$s, expected filesize: %2$s)', |
|
| 267 | - [ |
|
| 268 | - $this->l10n->n('%n byte', '%n bytes', $count), |
|
| 269 | - $this->l10n->n('%n byte', '%n bytes', $expected), |
|
| 270 | - ], |
|
| 271 | - ) |
|
| 272 | - ); |
|
| 273 | - } |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - // if content length is sent by client: |
|
| 277 | - // double check if the file was fully received |
|
| 278 | - // compare expected and actual size |
|
| 279 | - if (isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['REQUEST_METHOD'] === 'PUT') { |
|
| 280 | - $expected = (int)$_SERVER['CONTENT_LENGTH']; |
|
| 281 | - if ($count !== $expected) { |
|
| 282 | - throw new BadRequest( |
|
| 283 | - $this->l10n->t( |
|
| 284 | - 'Expected filesize of %1$s but read (from Nextcloud client) and wrote (to Nextcloud storage) %2$s. Could either be a network problem on the sending side or a problem writing to the storage on the server side.', |
|
| 285 | - [ |
|
| 286 | - $this->l10n->n('%n byte', '%n bytes', $expected), |
|
| 287 | - $this->l10n->n('%n byte', '%n bytes', $count), |
|
| 288 | - ], |
|
| 289 | - ) |
|
| 290 | - ); |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - } catch (\Exception $e) { |
|
| 294 | - $context = []; |
|
| 295 | - |
|
| 296 | - if ($e instanceof LockedException) { |
|
| 297 | - $context['level'] = ILogger::DEBUG; |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - \OC::$server->getLogger()->logException($e, $context); |
|
| 301 | - if ($needsPartFile) { |
|
| 302 | - $partStorage->unlink($internalPartPath); |
|
| 303 | - } |
|
| 304 | - $this->convertToSabreException($e); |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - try { |
|
| 308 | - if ($needsPartFile) { |
|
| 309 | - if ($view && !$this->emitPreHooks($exists)) { |
|
| 310 | - $partStorage->unlink($internalPartPath); |
|
| 311 | - throw new Exception($this->l10n->t('Could not rename part file to final file, canceled by hook')); |
|
| 312 | - } |
|
| 313 | - try { |
|
| 314 | - $this->changeLock(ILockingProvider::LOCK_EXCLUSIVE); |
|
| 315 | - } catch (LockedException $e) { |
|
| 316 | - // during very large uploads, the shared lock we got at the start might have been expired |
|
| 317 | - // meaning that the above lock can fail not just only because somebody else got a shared lock |
|
| 318 | - // or because there is no existing shared lock to make exclusive |
|
| 319 | - // |
|
| 320 | - // Thus we try to get a new exclusive lock, if the original lock failed because of a different shared |
|
| 321 | - // lock this will still fail, if our original shared lock expired the new lock will be successful and |
|
| 322 | - // the entire operation will be safe |
|
| 323 | - |
|
| 324 | - try { |
|
| 325 | - $this->acquireLock(ILockingProvider::LOCK_EXCLUSIVE); |
|
| 326 | - } catch (LockedException $ex) { |
|
| 327 | - if ($needsPartFile) { |
|
| 328 | - $partStorage->unlink($internalPartPath); |
|
| 329 | - } |
|
| 330 | - throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
| 331 | - } |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - // rename to correct path |
|
| 335 | - try { |
|
| 336 | - $renameOkay = $storage->moveFromStorage($partStorage, $internalPartPath, $internalPath); |
|
| 337 | - $fileExists = $storage->file_exists($internalPath); |
|
| 338 | - if ($renameOkay === false || $fileExists === false) { |
|
| 339 | - \OC::$server->getLogger()->error('renaming part file to final file failed $renameOkay: ' . ($renameOkay ? 'true' : 'false') . ', $fileExists: ' . ($fileExists ? 'true' : 'false') . ')', ['app' => 'webdav']); |
|
| 340 | - throw new Exception($this->l10n->t('Could not rename part file to final file')); |
|
| 341 | - } |
|
| 342 | - } catch (ForbiddenException $ex) { |
|
| 343 | - if (!$ex->getRetry()) { |
|
| 344 | - $partStorage->unlink($internalPartPath); |
|
| 345 | - } |
|
| 346 | - throw new DAVForbiddenException($ex->getMessage(), $ex->getRetry()); |
|
| 347 | - } catch (\Exception $e) { |
|
| 348 | - $partStorage->unlink($internalPartPath); |
|
| 349 | - $this->convertToSabreException($e); |
|
| 350 | - } |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - // since we skipped the view we need to scan and emit the hooks ourselves |
|
| 354 | - $storage->getUpdater()->update($internalPath); |
|
| 355 | - |
|
| 356 | - try { |
|
| 357 | - $this->changeLock(ILockingProvider::LOCK_SHARED); |
|
| 358 | - } catch (LockedException $e) { |
|
| 359 | - throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - // allow sync clients to send the mtime along in a header |
|
| 363 | - if (isset($this->request->server['HTTP_X_OC_MTIME'])) { |
|
| 364 | - $mtime = $this->sanitizeMtime($this->request->server['HTTP_X_OC_MTIME']); |
|
| 365 | - if ($this->fileView->touch($this->path, $mtime)) { |
|
| 366 | - $this->header('X-OC-MTime: accepted'); |
|
| 367 | - } |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - $fileInfoUpdate = [ |
|
| 371 | - 'upload_time' => time() |
|
| 372 | - ]; |
|
| 373 | - |
|
| 374 | - // allow sync clients to send the creation time along in a header |
|
| 375 | - if (isset($this->request->server['HTTP_X_OC_CTIME'])) { |
|
| 376 | - $ctime = $this->sanitizeMtime($this->request->server['HTTP_X_OC_CTIME']); |
|
| 377 | - $fileInfoUpdate['creation_time'] = $ctime; |
|
| 378 | - $this->header('X-OC-CTime: accepted'); |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - $this->fileView->putFileInfo($this->path, $fileInfoUpdate); |
|
| 382 | - |
|
| 383 | - if ($view) { |
|
| 384 | - $this->emitPostHooks($exists); |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - $this->refreshInfo(); |
|
| 388 | - |
|
| 389 | - if (isset($this->request->server['HTTP_OC_CHECKSUM'])) { |
|
| 390 | - $checksum = trim($this->request->server['HTTP_OC_CHECKSUM']); |
|
| 391 | - $this->fileView->putFileInfo($this->path, ['checksum' => $checksum]); |
|
| 392 | - $this->refreshInfo(); |
|
| 393 | - } elseif ($this->getChecksum() !== null && $this->getChecksum() !== '') { |
|
| 394 | - $this->fileView->putFileInfo($this->path, ['checksum' => '']); |
|
| 395 | - $this->refreshInfo(); |
|
| 396 | - } |
|
| 397 | - } catch (StorageNotAvailableException $e) { |
|
| 398 | - throw new ServiceUnavailable($this->l10n->t('Failed to check file size: %1$s', [$e->getMessage()]), 0, $e); |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - return '"' . $this->info->getEtag() . '"'; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - private function getPartFileBasePath($path) { |
|
| 405 | - $partFileInStorage = \OC::$server->getConfig()->getSystemValue('part_file_in_storage', true); |
|
| 406 | - if ($partFileInStorage) { |
|
| 407 | - return $path; |
|
| 408 | - } else { |
|
| 409 | - return md5($path); // will place it in the root of the view with a unique name |
|
| 410 | - } |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * @param string $path |
|
| 415 | - */ |
|
| 416 | - private function emitPreHooks($exists, $path = null) { |
|
| 417 | - if (is_null($path)) { |
|
| 418 | - $path = $this->path; |
|
| 419 | - } |
|
| 420 | - $hookPath = Filesystem::getView()->getRelativePath($this->fileView->getAbsolutePath($path)); |
|
| 421 | - $run = true; |
|
| 422 | - |
|
| 423 | - if (!$exists) { |
|
| 424 | - \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_create, [ |
|
| 425 | - \OC\Files\Filesystem::signal_param_path => $hookPath, |
|
| 426 | - \OC\Files\Filesystem::signal_param_run => &$run, |
|
| 427 | - ]); |
|
| 428 | - } else { |
|
| 429 | - \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_update, [ |
|
| 430 | - \OC\Files\Filesystem::signal_param_path => $hookPath, |
|
| 431 | - \OC\Files\Filesystem::signal_param_run => &$run, |
|
| 432 | - ]); |
|
| 433 | - } |
|
| 434 | - \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_write, [ |
|
| 435 | - \OC\Files\Filesystem::signal_param_path => $hookPath, |
|
| 436 | - \OC\Files\Filesystem::signal_param_run => &$run, |
|
| 437 | - ]); |
|
| 438 | - return $run; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - /** |
|
| 442 | - * @param string $path |
|
| 443 | - */ |
|
| 444 | - private function emitPostHooks($exists, $path = null) { |
|
| 445 | - if (is_null($path)) { |
|
| 446 | - $path = $this->path; |
|
| 447 | - } |
|
| 448 | - $hookPath = Filesystem::getView()->getRelativePath($this->fileView->getAbsolutePath($path)); |
|
| 449 | - if (!$exists) { |
|
| 450 | - \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_create, [ |
|
| 451 | - \OC\Files\Filesystem::signal_param_path => $hookPath |
|
| 452 | - ]); |
|
| 453 | - } else { |
|
| 454 | - \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_update, [ |
|
| 455 | - \OC\Files\Filesystem::signal_param_path => $hookPath |
|
| 456 | - ]); |
|
| 457 | - } |
|
| 458 | - \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_write, [ |
|
| 459 | - \OC\Files\Filesystem::signal_param_path => $hookPath |
|
| 460 | - ]); |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * Returns the data |
|
| 465 | - * |
|
| 466 | - * @return resource |
|
| 467 | - * @throws Forbidden |
|
| 468 | - * @throws ServiceUnavailable |
|
| 469 | - */ |
|
| 470 | - public function get() { |
|
| 471 | - //throw exception if encryption is disabled but files are still encrypted |
|
| 472 | - try { |
|
| 473 | - if (!$this->info->isReadable()) { |
|
| 474 | - // do a if the file did not exist |
|
| 475 | - throw new NotFound(); |
|
| 476 | - } |
|
| 477 | - try { |
|
| 478 | - $res = $this->fileView->fopen(ltrim($this->path, '/'), 'rb'); |
|
| 479 | - } catch (\Exception $e) { |
|
| 480 | - $this->convertToSabreException($e); |
|
| 481 | - } |
|
| 482 | - if ($res === false) { |
|
| 483 | - throw new ServiceUnavailable($this->l10n->t('Could not open file')); |
|
| 484 | - } |
|
| 485 | - return $res; |
|
| 486 | - } catch (GenericEncryptionException $e) { |
|
| 487 | - // returning 503 will allow retry of the operation at a later point in time |
|
| 488 | - throw new ServiceUnavailable($this->l10n->t('Encryption not ready: %1$s', [$e->getMessage()])); |
|
| 489 | - } catch (StorageNotAvailableException $e) { |
|
| 490 | - throw new ServiceUnavailable($this->l10n->t('Failed to open file: %1$s', [$e->getMessage()])); |
|
| 491 | - } catch (ForbiddenException $ex) { |
|
| 492 | - throw new DAVForbiddenException($ex->getMessage(), $ex->getRetry()); |
|
| 493 | - } catch (LockedException $e) { |
|
| 494 | - throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
| 495 | - } |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - /** |
|
| 499 | - * Delete the current file |
|
| 500 | - * |
|
| 501 | - * @throws Forbidden |
|
| 502 | - * @throws ServiceUnavailable |
|
| 503 | - */ |
|
| 504 | - public function delete() { |
|
| 505 | - if (!$this->info->isDeletable()) { |
|
| 506 | - throw new Forbidden(); |
|
| 507 | - } |
|
| 508 | - |
|
| 509 | - try { |
|
| 510 | - if (!$this->fileView->unlink($this->path)) { |
|
| 511 | - // assume it wasn't possible to delete due to permissions |
|
| 512 | - throw new Forbidden(); |
|
| 513 | - } |
|
| 514 | - } catch (StorageNotAvailableException $e) { |
|
| 515 | - throw new ServiceUnavailable($this->l10n->t('Failed to unlink: %1$s', [$e->getMessage()])); |
|
| 516 | - } catch (ForbiddenException $ex) { |
|
| 517 | - throw new DAVForbiddenException($ex->getMessage(), $ex->getRetry()); |
|
| 518 | - } catch (LockedException $e) { |
|
| 519 | - throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
| 520 | - } |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - /** |
|
| 524 | - * Returns the mime-type for a file |
|
| 525 | - * |
|
| 526 | - * If null is returned, we'll assume application/octet-stream |
|
| 527 | - * |
|
| 528 | - * @return string |
|
| 529 | - */ |
|
| 530 | - public function getContentType() { |
|
| 531 | - $mimeType = $this->info->getMimetype(); |
|
| 532 | - |
|
| 533 | - // PROPFIND needs to return the correct mime type, for consistency with the web UI |
|
| 534 | - if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PROPFIND') { |
|
| 535 | - return $mimeType; |
|
| 536 | - } |
|
| 537 | - return \OC::$server->getMimeTypeDetector()->getSecureMimeType($mimeType); |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - /** |
|
| 541 | - * @return array|bool |
|
| 542 | - */ |
|
| 543 | - public function getDirectDownload() { |
|
| 544 | - if (\OCP\App::isEnabled('encryption')) { |
|
| 545 | - return []; |
|
| 546 | - } |
|
| 547 | - /** @var \OCP\Files\Storage $storage */ |
|
| 548 | - [$storage, $internalPath] = $this->fileView->resolvePath($this->path); |
|
| 549 | - if (is_null($storage)) { |
|
| 550 | - return []; |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - return $storage->getDirectDownload($internalPath); |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - /** |
|
| 557 | - * @param resource $data |
|
| 558 | - * @return null|string |
|
| 559 | - * @throws Exception |
|
| 560 | - * @throws BadRequest |
|
| 561 | - * @throws NotImplemented |
|
| 562 | - * @throws ServiceUnavailable |
|
| 563 | - */ |
|
| 564 | - private function createFileChunked($data) { |
|
| 565 | - [$path, $name] = \Sabre\Uri\split($this->path); |
|
| 566 | - |
|
| 567 | - $info = \OC_FileChunking::decodeName($name); |
|
| 568 | - if (empty($info)) { |
|
| 569 | - throw new NotImplemented($this->l10n->t('Invalid chunk name')); |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - $chunk_handler = new \OC_FileChunking($info); |
|
| 573 | - $bytesWritten = $chunk_handler->store($info['index'], $data); |
|
| 574 | - |
|
| 575 | - //detect aborted upload |
|
| 576 | - if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT') { |
|
| 577 | - if (isset($_SERVER['CONTENT_LENGTH'])) { |
|
| 578 | - $expected = (int)$_SERVER['CONTENT_LENGTH']; |
|
| 579 | - if ($bytesWritten !== $expected) { |
|
| 580 | - $chunk_handler->remove($info['index']); |
|
| 581 | - throw new BadRequest( |
|
| 582 | - $this->l10n->t( |
|
| 583 | - 'Expected filesize of %1$s but read (from Nextcloud client) and wrote (to Nextcloud storage) %2$s. Could either be a network problem on the sending side or a problem writing to the storage on the server side.', |
|
| 584 | - [ |
|
| 585 | - $this->l10n->n('%n byte', '%n bytes', $expected), |
|
| 586 | - $this->l10n->n('%n byte', '%n bytes', $bytesWritten), |
|
| 587 | - ], |
|
| 588 | - ) |
|
| 589 | - ); |
|
| 590 | - } |
|
| 591 | - } |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - if ($chunk_handler->isComplete()) { |
|
| 595 | - /** @var Storage $storage */ |
|
| 596 | - [$storage,] = $this->fileView->resolvePath($path); |
|
| 597 | - $needsPartFile = $storage->needsPartFile(); |
|
| 598 | - $partFile = null; |
|
| 599 | - |
|
| 600 | - $targetPath = $path . '/' . $info['name']; |
|
| 601 | - /** @var \OC\Files\Storage\Storage $targetStorage */ |
|
| 602 | - [$targetStorage, $targetInternalPath] = $this->fileView->resolvePath($targetPath); |
|
| 603 | - |
|
| 604 | - $exists = $this->fileView->file_exists($targetPath); |
|
| 605 | - |
|
| 606 | - try { |
|
| 607 | - $this->fileView->lockFile($targetPath, ILockingProvider::LOCK_SHARED); |
|
| 608 | - |
|
| 609 | - $this->emitPreHooks($exists, $targetPath); |
|
| 610 | - $this->fileView->changeLock($targetPath, ILockingProvider::LOCK_EXCLUSIVE); |
|
| 611 | - /** @var \OC\Files\Storage\Storage $targetStorage */ |
|
| 612 | - [$targetStorage, $targetInternalPath] = $this->fileView->resolvePath($targetPath); |
|
| 613 | - |
|
| 614 | - if ($needsPartFile) { |
|
| 615 | - // we first assembly the target file as a part file |
|
| 616 | - $partFile = $this->getPartFileBasePath($path . '/' . $info['name']) . '.ocTransferId' . $info['transferid'] . '.part'; |
|
| 617 | - /** @var \OC\Files\Storage\Storage $targetStorage */ |
|
| 618 | - [$partStorage, $partInternalPath] = $this->fileView->resolvePath($partFile); |
|
| 619 | - |
|
| 620 | - |
|
| 621 | - $chunk_handler->file_assemble($partStorage, $partInternalPath); |
|
| 622 | - |
|
| 623 | - // here is the final atomic rename |
|
| 624 | - $renameOkay = $targetStorage->moveFromStorage($partStorage, $partInternalPath, $targetInternalPath); |
|
| 625 | - $fileExists = $targetStorage->file_exists($targetInternalPath); |
|
| 626 | - if ($renameOkay === false || $fileExists === false) { |
|
| 627 | - \OC::$server->getLogger()->error('\OC\Files\Filesystem::rename() failed', ['app' => 'webdav']); |
|
| 628 | - // only delete if an error occurred and the target file was already created |
|
| 629 | - if ($fileExists) { |
|
| 630 | - // set to null to avoid double-deletion when handling exception |
|
| 631 | - // stray part file |
|
| 632 | - $partFile = null; |
|
| 633 | - $targetStorage->unlink($targetInternalPath); |
|
| 634 | - } |
|
| 635 | - $this->fileView->changeLock($targetPath, ILockingProvider::LOCK_SHARED); |
|
| 636 | - throw new Exception($this->l10n->t('Could not rename part file assembled from chunks')); |
|
| 637 | - } |
|
| 638 | - } else { |
|
| 639 | - // assemble directly into the final file |
|
| 640 | - $chunk_handler->file_assemble($targetStorage, $targetInternalPath); |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - // allow sync clients to send the mtime along in a header |
|
| 644 | - if (isset($this->request->server['HTTP_X_OC_MTIME'])) { |
|
| 645 | - $mtime = $this->sanitizeMtime($this->request->server['HTTP_X_OC_MTIME']); |
|
| 646 | - if ($targetStorage->touch($targetInternalPath, $mtime)) { |
|
| 647 | - $this->header('X-OC-MTime: accepted'); |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - // since we skipped the view we need to scan and emit the hooks ourselves |
|
| 652 | - $targetStorage->getUpdater()->update($targetInternalPath); |
|
| 653 | - |
|
| 654 | - $this->fileView->changeLock($targetPath, ILockingProvider::LOCK_SHARED); |
|
| 655 | - |
|
| 656 | - $this->emitPostHooks($exists, $targetPath); |
|
| 657 | - |
|
| 658 | - // FIXME: should call refreshInfo but can't because $this->path is not the of the final file |
|
| 659 | - $info = $this->fileView->getFileInfo($targetPath); |
|
| 660 | - |
|
| 661 | - if (isset($this->request->server['HTTP_OC_CHECKSUM'])) { |
|
| 662 | - $checksum = trim($this->request->server['HTTP_OC_CHECKSUM']); |
|
| 663 | - $this->fileView->putFileInfo($targetPath, ['checksum' => $checksum]); |
|
| 664 | - } elseif ($info->getChecksum() !== null && $info->getChecksum() !== '') { |
|
| 665 | - $this->fileView->putFileInfo($this->path, ['checksum' => '']); |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - $this->fileView->unlockFile($targetPath, ILockingProvider::LOCK_SHARED); |
|
| 669 | - |
|
| 670 | - return $info->getEtag(); |
|
| 671 | - } catch (\Exception $e) { |
|
| 672 | - if ($partFile !== null) { |
|
| 673 | - $targetStorage->unlink($targetInternalPath); |
|
| 674 | - } |
|
| 675 | - $this->convertToSabreException($e); |
|
| 676 | - } |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - return null; |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - /** |
|
| 683 | - * Convert the given exception to a SabreException instance |
|
| 684 | - * |
|
| 685 | - * @param \Exception $e |
|
| 686 | - * |
|
| 687 | - * @throws \Sabre\DAV\Exception |
|
| 688 | - */ |
|
| 689 | - private function convertToSabreException(\Exception $e) { |
|
| 690 | - if ($e instanceof \Sabre\DAV\Exception) { |
|
| 691 | - throw $e; |
|
| 692 | - } |
|
| 693 | - if ($e instanceof NotPermittedException) { |
|
| 694 | - // a more general case - due to whatever reason the content could not be written |
|
| 695 | - throw new Forbidden($e->getMessage(), 0, $e); |
|
| 696 | - } |
|
| 697 | - if ($e instanceof ForbiddenException) { |
|
| 698 | - // the path for the file was forbidden |
|
| 699 | - throw new DAVForbiddenException($e->getMessage(), $e->getRetry(), $e); |
|
| 700 | - } |
|
| 701 | - if ($e instanceof EntityTooLargeException) { |
|
| 702 | - // the file is too big to be stored |
|
| 703 | - throw new EntityTooLarge($e->getMessage(), 0, $e); |
|
| 704 | - } |
|
| 705 | - if ($e instanceof InvalidContentException) { |
|
| 706 | - // the file content is not permitted |
|
| 707 | - throw new UnsupportedMediaType($e->getMessage(), 0, $e); |
|
| 708 | - } |
|
| 709 | - if ($e instanceof InvalidPathException) { |
|
| 710 | - // the path for the file was not valid |
|
| 711 | - // TODO: find proper http status code for this case |
|
| 712 | - throw new Forbidden($e->getMessage(), 0, $e); |
|
| 713 | - } |
|
| 714 | - if ($e instanceof LockedException || $e instanceof LockNotAcquiredException) { |
|
| 715 | - // the file is currently being written to by another process |
|
| 716 | - throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
| 717 | - } |
|
| 718 | - if ($e instanceof GenericEncryptionException) { |
|
| 719 | - // returning 503 will allow retry of the operation at a later point in time |
|
| 720 | - throw new ServiceUnavailable($this->l10n->t('Encryption not ready: %1$s', [$e->getMessage()]), 0, $e); |
|
| 721 | - } |
|
| 722 | - if ($e instanceof StorageNotAvailableException) { |
|
| 723 | - throw new ServiceUnavailable($this->l10n->t('Failed to write file contents: %1$s', [$e->getMessage()]), 0, $e); |
|
| 724 | - } |
|
| 725 | - if ($e instanceof NotFoundException) { |
|
| 726 | - throw new NotFound($this->l10n->t('File not found: %1$s', [$e->getMessage()]), 0, $e); |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - throw new \Sabre\DAV\Exception($e->getMessage(), 0, $e); |
|
| 730 | - } |
|
| 731 | - |
|
| 732 | - /** |
|
| 733 | - * Get the checksum for this file |
|
| 734 | - * |
|
| 735 | - * @return string|null |
|
| 736 | - */ |
|
| 737 | - public function getChecksum() { |
|
| 738 | - if (!$this->info) { |
|
| 739 | - return null; |
|
| 740 | - } |
|
| 741 | - return $this->info->getChecksum(); |
|
| 742 | - } |
|
| 743 | - |
|
| 744 | - protected function header($string) { |
|
| 745 | - if (!\OC::$CLI) { |
|
| 746 | - \header($string); |
|
| 747 | - } |
|
| 748 | - } |
|
| 79 | + protected $request; |
|
| 80 | + |
|
| 81 | + protected IL10N $l10n; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Sets up the node, expects a full path name |
|
| 85 | + * |
|
| 86 | + * @param \OC\Files\View $view |
|
| 87 | + * @param \OCP\Files\FileInfo $info |
|
| 88 | + * @param \OCP\Share\IManager $shareManager |
|
| 89 | + * @param \OC\AppFramework\Http\Request $request |
|
| 90 | + */ |
|
| 91 | + public function __construct(View $view, FileInfo $info, IManager $shareManager = null, Request $request = null) { |
|
| 92 | + parent::__construct($view, $info, $shareManager); |
|
| 93 | + |
|
| 94 | + // Querying IL10N directly results in a dependency loop |
|
| 95 | + /** @var IL10NFactory $l10nFactory */ |
|
| 96 | + $l10nFactory = \OC::$server->get(IL10NFactory::class); |
|
| 97 | + $this->l10n = $l10nFactory->get(Application::APP_ID); |
|
| 98 | + |
|
| 99 | + if (isset($request)) { |
|
| 100 | + $this->request = $request; |
|
| 101 | + } else { |
|
| 102 | + $this->request = \OC::$server->getRequest(); |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Updates the data |
|
| 108 | + * |
|
| 109 | + * The data argument is a readable stream resource. |
|
| 110 | + * |
|
| 111 | + * After a successful put operation, you may choose to return an ETag. The |
|
| 112 | + * etag must always be surrounded by double-quotes. These quotes must |
|
| 113 | + * appear in the actual string you're returning. |
|
| 114 | + * |
|
| 115 | + * Clients may use the ETag from a PUT request to later on make sure that |
|
| 116 | + * when they update the file, the contents haven't changed in the mean |
|
| 117 | + * time. |
|
| 118 | + * |
|
| 119 | + * If you don't plan to store the file byte-by-byte, and you return a |
|
| 120 | + * different object on a subsequent GET you are strongly recommended to not |
|
| 121 | + * return an ETag, and just return null. |
|
| 122 | + * |
|
| 123 | + * @param resource $data |
|
| 124 | + * |
|
| 125 | + * @throws Forbidden |
|
| 126 | + * @throws UnsupportedMediaType |
|
| 127 | + * @throws BadRequest |
|
| 128 | + * @throws Exception |
|
| 129 | + * @throws EntityTooLarge |
|
| 130 | + * @throws ServiceUnavailable |
|
| 131 | + * @throws FileLocked |
|
| 132 | + * @return string|null |
|
| 133 | + */ |
|
| 134 | + public function put($data) { |
|
| 135 | + try { |
|
| 136 | + $exists = $this->fileView->file_exists($this->path); |
|
| 137 | + if ($this->info && $exists && !$this->info->isUpdateable()) { |
|
| 138 | + throw new Forbidden(); |
|
| 139 | + } |
|
| 140 | + } catch (StorageNotAvailableException $e) { |
|
| 141 | + throw new ServiceUnavailable($this->l10n->t('File is not updatable: %1$s', [$e->getMessage()])); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + // verify path of the target |
|
| 145 | + $this->verifyPath(); |
|
| 146 | + |
|
| 147 | + // chunked handling |
|
| 148 | + if (isset($_SERVER['HTTP_OC_CHUNKED'])) { |
|
| 149 | + try { |
|
| 150 | + return $this->createFileChunked($data); |
|
| 151 | + } catch (\Exception $e) { |
|
| 152 | + $this->convertToSabreException($e); |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** @var Storage $partStorage */ |
|
| 157 | + [$partStorage] = $this->fileView->resolvePath($this->path); |
|
| 158 | + $needsPartFile = $partStorage->needsPartFile() && (strlen($this->path) > 1); |
|
| 159 | + |
|
| 160 | + $view = \OC\Files\Filesystem::getView(); |
|
| 161 | + |
|
| 162 | + if ($needsPartFile) { |
|
| 163 | + // mark file as partial while uploading (ignored by the scanner) |
|
| 164 | + $partFilePath = $this->getPartFileBasePath($this->path) . '.ocTransferId' . rand() . '.part'; |
|
| 165 | + |
|
| 166 | + if (!$view->isCreatable($partFilePath) && $view->isUpdatable($this->path)) { |
|
| 167 | + $needsPartFile = false; |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + if (!$needsPartFile) { |
|
| 171 | + // upload file directly as the final path |
|
| 172 | + $partFilePath = $this->path; |
|
| 173 | + |
|
| 174 | + if ($view && !$this->emitPreHooks($exists)) { |
|
| 175 | + throw new Exception($this->l10n->t('Could not write to final file, canceled by hook')); |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + // the part file and target file might be on a different storage in case of a single file storage (e.g. single file share) |
|
| 180 | + /** @var \OC\Files\Storage\Storage $partStorage */ |
|
| 181 | + [$partStorage, $internalPartPath] = $this->fileView->resolvePath($partFilePath); |
|
| 182 | + /** @var \OC\Files\Storage\Storage $storage */ |
|
| 183 | + [$storage, $internalPath] = $this->fileView->resolvePath($this->path); |
|
| 184 | + try { |
|
| 185 | + if (!$needsPartFile) { |
|
| 186 | + try { |
|
| 187 | + $this->changeLock(ILockingProvider::LOCK_EXCLUSIVE); |
|
| 188 | + } catch (LockedException $e) { |
|
| 189 | + // during very large uploads, the shared lock we got at the start might have been expired |
|
| 190 | + // meaning that the above lock can fail not just only because somebody else got a shared lock |
|
| 191 | + // or because there is no existing shared lock to make exclusive |
|
| 192 | + // |
|
| 193 | + // Thus we try to get a new exclusive lock, if the original lock failed because of a different shared |
|
| 194 | + // lock this will still fail, if our original shared lock expired the new lock will be successful and |
|
| 195 | + // the entire operation will be safe |
|
| 196 | + |
|
| 197 | + try { |
|
| 198 | + $this->acquireLock(ILockingProvider::LOCK_EXCLUSIVE); |
|
| 199 | + } catch (LockedException $ex) { |
|
| 200 | + throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + if (!is_resource($data)) { |
|
| 206 | + $tmpData = fopen('php://temp', 'r+'); |
|
| 207 | + if ($data !== null) { |
|
| 208 | + fwrite($tmpData, $data); |
|
| 209 | + rewind($tmpData); |
|
| 210 | + } |
|
| 211 | + $data = $tmpData; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + $data = HashWrapper::wrap($data, 'md5', function ($hash) { |
|
| 215 | + $this->header('X-Hash-MD5: ' . $hash); |
|
| 216 | + }); |
|
| 217 | + $data = HashWrapper::wrap($data, 'sha1', function ($hash) { |
|
| 218 | + $this->header('X-Hash-SHA1: ' . $hash); |
|
| 219 | + }); |
|
| 220 | + $data = HashWrapper::wrap($data, 'sha256', function ($hash) { |
|
| 221 | + $this->header('X-Hash-SHA256: ' . $hash); |
|
| 222 | + }); |
|
| 223 | + |
|
| 224 | + if ($partStorage->instanceOfStorage(Storage\IWriteStreamStorage::class)) { |
|
| 225 | + $isEOF = false; |
|
| 226 | + $wrappedData = CallbackWrapper::wrap($data, null, null, null, null, function ($stream) use (&$isEOF) { |
|
| 227 | + $isEOF = feof($stream); |
|
| 228 | + }); |
|
| 229 | + |
|
| 230 | + $result = true; |
|
| 231 | + $count = -1; |
|
| 232 | + try { |
|
| 233 | + $count = $partStorage->writeStream($internalPartPath, $wrappedData); |
|
| 234 | + } catch (GenericFileException $e) { |
|
| 235 | + $result = false; |
|
| 236 | + } catch (BadGateway $e) { |
|
| 237 | + throw $e; |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + |
|
| 241 | + if ($result === false) { |
|
| 242 | + $result = $isEOF; |
|
| 243 | + if (is_resource($wrappedData)) { |
|
| 244 | + $result = feof($wrappedData); |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + } else { |
|
| 248 | + $target = $partStorage->fopen($internalPartPath, 'wb'); |
|
| 249 | + if ($target === false) { |
|
| 250 | + \OC::$server->getLogger()->error('\OC\Files\Filesystem::fopen() failed', ['app' => 'webdav']); |
|
| 251 | + // because we have no clue about the cause we can only throw back a 500/Internal Server Error |
|
| 252 | + throw new Exception($this->l10n->t('Could not write file contents')); |
|
| 253 | + } |
|
| 254 | + [$count, $result] = \OC_Helper::streamCopy($data, $target); |
|
| 255 | + fclose($target); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + if ($result === false) { |
|
| 259 | + $expected = -1; |
|
| 260 | + if (isset($_SERVER['CONTENT_LENGTH'])) { |
|
| 261 | + $expected = $_SERVER['CONTENT_LENGTH']; |
|
| 262 | + } |
|
| 263 | + if ($expected !== "0") { |
|
| 264 | + throw new Exception( |
|
| 265 | + $this->l10n->t( |
|
| 266 | + 'Error while copying file to target location (copied: %1$s, expected filesize: %2$s)', |
|
| 267 | + [ |
|
| 268 | + $this->l10n->n('%n byte', '%n bytes', $count), |
|
| 269 | + $this->l10n->n('%n byte', '%n bytes', $expected), |
|
| 270 | + ], |
|
| 271 | + ) |
|
| 272 | + ); |
|
| 273 | + } |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + // if content length is sent by client: |
|
| 277 | + // double check if the file was fully received |
|
| 278 | + // compare expected and actual size |
|
| 279 | + if (isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['REQUEST_METHOD'] === 'PUT') { |
|
| 280 | + $expected = (int)$_SERVER['CONTENT_LENGTH']; |
|
| 281 | + if ($count !== $expected) { |
|
| 282 | + throw new BadRequest( |
|
| 283 | + $this->l10n->t( |
|
| 284 | + 'Expected filesize of %1$s but read (from Nextcloud client) and wrote (to Nextcloud storage) %2$s. Could either be a network problem on the sending side or a problem writing to the storage on the server side.', |
|
| 285 | + [ |
|
| 286 | + $this->l10n->n('%n byte', '%n bytes', $expected), |
|
| 287 | + $this->l10n->n('%n byte', '%n bytes', $count), |
|
| 288 | + ], |
|
| 289 | + ) |
|
| 290 | + ); |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + } catch (\Exception $e) { |
|
| 294 | + $context = []; |
|
| 295 | + |
|
| 296 | + if ($e instanceof LockedException) { |
|
| 297 | + $context['level'] = ILogger::DEBUG; |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + \OC::$server->getLogger()->logException($e, $context); |
|
| 301 | + if ($needsPartFile) { |
|
| 302 | + $partStorage->unlink($internalPartPath); |
|
| 303 | + } |
|
| 304 | + $this->convertToSabreException($e); |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + try { |
|
| 308 | + if ($needsPartFile) { |
|
| 309 | + if ($view && !$this->emitPreHooks($exists)) { |
|
| 310 | + $partStorage->unlink($internalPartPath); |
|
| 311 | + throw new Exception($this->l10n->t('Could not rename part file to final file, canceled by hook')); |
|
| 312 | + } |
|
| 313 | + try { |
|
| 314 | + $this->changeLock(ILockingProvider::LOCK_EXCLUSIVE); |
|
| 315 | + } catch (LockedException $e) { |
|
| 316 | + // during very large uploads, the shared lock we got at the start might have been expired |
|
| 317 | + // meaning that the above lock can fail not just only because somebody else got a shared lock |
|
| 318 | + // or because there is no existing shared lock to make exclusive |
|
| 319 | + // |
|
| 320 | + // Thus we try to get a new exclusive lock, if the original lock failed because of a different shared |
|
| 321 | + // lock this will still fail, if our original shared lock expired the new lock will be successful and |
|
| 322 | + // the entire operation will be safe |
|
| 323 | + |
|
| 324 | + try { |
|
| 325 | + $this->acquireLock(ILockingProvider::LOCK_EXCLUSIVE); |
|
| 326 | + } catch (LockedException $ex) { |
|
| 327 | + if ($needsPartFile) { |
|
| 328 | + $partStorage->unlink($internalPartPath); |
|
| 329 | + } |
|
| 330 | + throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
| 331 | + } |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + // rename to correct path |
|
| 335 | + try { |
|
| 336 | + $renameOkay = $storage->moveFromStorage($partStorage, $internalPartPath, $internalPath); |
|
| 337 | + $fileExists = $storage->file_exists($internalPath); |
|
| 338 | + if ($renameOkay === false || $fileExists === false) { |
|
| 339 | + \OC::$server->getLogger()->error('renaming part file to final file failed $renameOkay: ' . ($renameOkay ? 'true' : 'false') . ', $fileExists: ' . ($fileExists ? 'true' : 'false') . ')', ['app' => 'webdav']); |
|
| 340 | + throw new Exception($this->l10n->t('Could not rename part file to final file')); |
|
| 341 | + } |
|
| 342 | + } catch (ForbiddenException $ex) { |
|
| 343 | + if (!$ex->getRetry()) { |
|
| 344 | + $partStorage->unlink($internalPartPath); |
|
| 345 | + } |
|
| 346 | + throw new DAVForbiddenException($ex->getMessage(), $ex->getRetry()); |
|
| 347 | + } catch (\Exception $e) { |
|
| 348 | + $partStorage->unlink($internalPartPath); |
|
| 349 | + $this->convertToSabreException($e); |
|
| 350 | + } |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + // since we skipped the view we need to scan and emit the hooks ourselves |
|
| 354 | + $storage->getUpdater()->update($internalPath); |
|
| 355 | + |
|
| 356 | + try { |
|
| 357 | + $this->changeLock(ILockingProvider::LOCK_SHARED); |
|
| 358 | + } catch (LockedException $e) { |
|
| 359 | + throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + // allow sync clients to send the mtime along in a header |
|
| 363 | + if (isset($this->request->server['HTTP_X_OC_MTIME'])) { |
|
| 364 | + $mtime = $this->sanitizeMtime($this->request->server['HTTP_X_OC_MTIME']); |
|
| 365 | + if ($this->fileView->touch($this->path, $mtime)) { |
|
| 366 | + $this->header('X-OC-MTime: accepted'); |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + $fileInfoUpdate = [ |
|
| 371 | + 'upload_time' => time() |
|
| 372 | + ]; |
|
| 373 | + |
|
| 374 | + // allow sync clients to send the creation time along in a header |
|
| 375 | + if (isset($this->request->server['HTTP_X_OC_CTIME'])) { |
|
| 376 | + $ctime = $this->sanitizeMtime($this->request->server['HTTP_X_OC_CTIME']); |
|
| 377 | + $fileInfoUpdate['creation_time'] = $ctime; |
|
| 378 | + $this->header('X-OC-CTime: accepted'); |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + $this->fileView->putFileInfo($this->path, $fileInfoUpdate); |
|
| 382 | + |
|
| 383 | + if ($view) { |
|
| 384 | + $this->emitPostHooks($exists); |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + $this->refreshInfo(); |
|
| 388 | + |
|
| 389 | + if (isset($this->request->server['HTTP_OC_CHECKSUM'])) { |
|
| 390 | + $checksum = trim($this->request->server['HTTP_OC_CHECKSUM']); |
|
| 391 | + $this->fileView->putFileInfo($this->path, ['checksum' => $checksum]); |
|
| 392 | + $this->refreshInfo(); |
|
| 393 | + } elseif ($this->getChecksum() !== null && $this->getChecksum() !== '') { |
|
| 394 | + $this->fileView->putFileInfo($this->path, ['checksum' => '']); |
|
| 395 | + $this->refreshInfo(); |
|
| 396 | + } |
|
| 397 | + } catch (StorageNotAvailableException $e) { |
|
| 398 | + throw new ServiceUnavailable($this->l10n->t('Failed to check file size: %1$s', [$e->getMessage()]), 0, $e); |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + return '"' . $this->info->getEtag() . '"'; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + private function getPartFileBasePath($path) { |
|
| 405 | + $partFileInStorage = \OC::$server->getConfig()->getSystemValue('part_file_in_storage', true); |
|
| 406 | + if ($partFileInStorage) { |
|
| 407 | + return $path; |
|
| 408 | + } else { |
|
| 409 | + return md5($path); // will place it in the root of the view with a unique name |
|
| 410 | + } |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * @param string $path |
|
| 415 | + */ |
|
| 416 | + private function emitPreHooks($exists, $path = null) { |
|
| 417 | + if (is_null($path)) { |
|
| 418 | + $path = $this->path; |
|
| 419 | + } |
|
| 420 | + $hookPath = Filesystem::getView()->getRelativePath($this->fileView->getAbsolutePath($path)); |
|
| 421 | + $run = true; |
|
| 422 | + |
|
| 423 | + if (!$exists) { |
|
| 424 | + \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_create, [ |
|
| 425 | + \OC\Files\Filesystem::signal_param_path => $hookPath, |
|
| 426 | + \OC\Files\Filesystem::signal_param_run => &$run, |
|
| 427 | + ]); |
|
| 428 | + } else { |
|
| 429 | + \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_update, [ |
|
| 430 | + \OC\Files\Filesystem::signal_param_path => $hookPath, |
|
| 431 | + \OC\Files\Filesystem::signal_param_run => &$run, |
|
| 432 | + ]); |
|
| 433 | + } |
|
| 434 | + \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_write, [ |
|
| 435 | + \OC\Files\Filesystem::signal_param_path => $hookPath, |
|
| 436 | + \OC\Files\Filesystem::signal_param_run => &$run, |
|
| 437 | + ]); |
|
| 438 | + return $run; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + /** |
|
| 442 | + * @param string $path |
|
| 443 | + */ |
|
| 444 | + private function emitPostHooks($exists, $path = null) { |
|
| 445 | + if (is_null($path)) { |
|
| 446 | + $path = $this->path; |
|
| 447 | + } |
|
| 448 | + $hookPath = Filesystem::getView()->getRelativePath($this->fileView->getAbsolutePath($path)); |
|
| 449 | + if (!$exists) { |
|
| 450 | + \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_create, [ |
|
| 451 | + \OC\Files\Filesystem::signal_param_path => $hookPath |
|
| 452 | + ]); |
|
| 453 | + } else { |
|
| 454 | + \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_update, [ |
|
| 455 | + \OC\Files\Filesystem::signal_param_path => $hookPath |
|
| 456 | + ]); |
|
| 457 | + } |
|
| 458 | + \OC_Hook::emit(\OC\Files\Filesystem::CLASSNAME, \OC\Files\Filesystem::signal_post_write, [ |
|
| 459 | + \OC\Files\Filesystem::signal_param_path => $hookPath |
|
| 460 | + ]); |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * Returns the data |
|
| 465 | + * |
|
| 466 | + * @return resource |
|
| 467 | + * @throws Forbidden |
|
| 468 | + * @throws ServiceUnavailable |
|
| 469 | + */ |
|
| 470 | + public function get() { |
|
| 471 | + //throw exception if encryption is disabled but files are still encrypted |
|
| 472 | + try { |
|
| 473 | + if (!$this->info->isReadable()) { |
|
| 474 | + // do a if the file did not exist |
|
| 475 | + throw new NotFound(); |
|
| 476 | + } |
|
| 477 | + try { |
|
| 478 | + $res = $this->fileView->fopen(ltrim($this->path, '/'), 'rb'); |
|
| 479 | + } catch (\Exception $e) { |
|
| 480 | + $this->convertToSabreException($e); |
|
| 481 | + } |
|
| 482 | + if ($res === false) { |
|
| 483 | + throw new ServiceUnavailable($this->l10n->t('Could not open file')); |
|
| 484 | + } |
|
| 485 | + return $res; |
|
| 486 | + } catch (GenericEncryptionException $e) { |
|
| 487 | + // returning 503 will allow retry of the operation at a later point in time |
|
| 488 | + throw new ServiceUnavailable($this->l10n->t('Encryption not ready: %1$s', [$e->getMessage()])); |
|
| 489 | + } catch (StorageNotAvailableException $e) { |
|
| 490 | + throw new ServiceUnavailable($this->l10n->t('Failed to open file: %1$s', [$e->getMessage()])); |
|
| 491 | + } catch (ForbiddenException $ex) { |
|
| 492 | + throw new DAVForbiddenException($ex->getMessage(), $ex->getRetry()); |
|
| 493 | + } catch (LockedException $e) { |
|
| 494 | + throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
| 495 | + } |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + /** |
|
| 499 | + * Delete the current file |
|
| 500 | + * |
|
| 501 | + * @throws Forbidden |
|
| 502 | + * @throws ServiceUnavailable |
|
| 503 | + */ |
|
| 504 | + public function delete() { |
|
| 505 | + if (!$this->info->isDeletable()) { |
|
| 506 | + throw new Forbidden(); |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + try { |
|
| 510 | + if (!$this->fileView->unlink($this->path)) { |
|
| 511 | + // assume it wasn't possible to delete due to permissions |
|
| 512 | + throw new Forbidden(); |
|
| 513 | + } |
|
| 514 | + } catch (StorageNotAvailableException $e) { |
|
| 515 | + throw new ServiceUnavailable($this->l10n->t('Failed to unlink: %1$s', [$e->getMessage()])); |
|
| 516 | + } catch (ForbiddenException $ex) { |
|
| 517 | + throw new DAVForbiddenException($ex->getMessage(), $ex->getRetry()); |
|
| 518 | + } catch (LockedException $e) { |
|
| 519 | + throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
| 520 | + } |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + /** |
|
| 524 | + * Returns the mime-type for a file |
|
| 525 | + * |
|
| 526 | + * If null is returned, we'll assume application/octet-stream |
|
| 527 | + * |
|
| 528 | + * @return string |
|
| 529 | + */ |
|
| 530 | + public function getContentType() { |
|
| 531 | + $mimeType = $this->info->getMimetype(); |
|
| 532 | + |
|
| 533 | + // PROPFIND needs to return the correct mime type, for consistency with the web UI |
|
| 534 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PROPFIND') { |
|
| 535 | + return $mimeType; |
|
| 536 | + } |
|
| 537 | + return \OC::$server->getMimeTypeDetector()->getSecureMimeType($mimeType); |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + /** |
|
| 541 | + * @return array|bool |
|
| 542 | + */ |
|
| 543 | + public function getDirectDownload() { |
|
| 544 | + if (\OCP\App::isEnabled('encryption')) { |
|
| 545 | + return []; |
|
| 546 | + } |
|
| 547 | + /** @var \OCP\Files\Storage $storage */ |
|
| 548 | + [$storage, $internalPath] = $this->fileView->resolvePath($this->path); |
|
| 549 | + if (is_null($storage)) { |
|
| 550 | + return []; |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + return $storage->getDirectDownload($internalPath); |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + /** |
|
| 557 | + * @param resource $data |
|
| 558 | + * @return null|string |
|
| 559 | + * @throws Exception |
|
| 560 | + * @throws BadRequest |
|
| 561 | + * @throws NotImplemented |
|
| 562 | + * @throws ServiceUnavailable |
|
| 563 | + */ |
|
| 564 | + private function createFileChunked($data) { |
|
| 565 | + [$path, $name] = \Sabre\Uri\split($this->path); |
|
| 566 | + |
|
| 567 | + $info = \OC_FileChunking::decodeName($name); |
|
| 568 | + if (empty($info)) { |
|
| 569 | + throw new NotImplemented($this->l10n->t('Invalid chunk name')); |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + $chunk_handler = new \OC_FileChunking($info); |
|
| 573 | + $bytesWritten = $chunk_handler->store($info['index'], $data); |
|
| 574 | + |
|
| 575 | + //detect aborted upload |
|
| 576 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT') { |
|
| 577 | + if (isset($_SERVER['CONTENT_LENGTH'])) { |
|
| 578 | + $expected = (int)$_SERVER['CONTENT_LENGTH']; |
|
| 579 | + if ($bytesWritten !== $expected) { |
|
| 580 | + $chunk_handler->remove($info['index']); |
|
| 581 | + throw new BadRequest( |
|
| 582 | + $this->l10n->t( |
|
| 583 | + 'Expected filesize of %1$s but read (from Nextcloud client) and wrote (to Nextcloud storage) %2$s. Could either be a network problem on the sending side or a problem writing to the storage on the server side.', |
|
| 584 | + [ |
|
| 585 | + $this->l10n->n('%n byte', '%n bytes', $expected), |
|
| 586 | + $this->l10n->n('%n byte', '%n bytes', $bytesWritten), |
|
| 587 | + ], |
|
| 588 | + ) |
|
| 589 | + ); |
|
| 590 | + } |
|
| 591 | + } |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + if ($chunk_handler->isComplete()) { |
|
| 595 | + /** @var Storage $storage */ |
|
| 596 | + [$storage,] = $this->fileView->resolvePath($path); |
|
| 597 | + $needsPartFile = $storage->needsPartFile(); |
|
| 598 | + $partFile = null; |
|
| 599 | + |
|
| 600 | + $targetPath = $path . '/' . $info['name']; |
|
| 601 | + /** @var \OC\Files\Storage\Storage $targetStorage */ |
|
| 602 | + [$targetStorage, $targetInternalPath] = $this->fileView->resolvePath($targetPath); |
|
| 603 | + |
|
| 604 | + $exists = $this->fileView->file_exists($targetPath); |
|
| 605 | + |
|
| 606 | + try { |
|
| 607 | + $this->fileView->lockFile($targetPath, ILockingProvider::LOCK_SHARED); |
|
| 608 | + |
|
| 609 | + $this->emitPreHooks($exists, $targetPath); |
|
| 610 | + $this->fileView->changeLock($targetPath, ILockingProvider::LOCK_EXCLUSIVE); |
|
| 611 | + /** @var \OC\Files\Storage\Storage $targetStorage */ |
|
| 612 | + [$targetStorage, $targetInternalPath] = $this->fileView->resolvePath($targetPath); |
|
| 613 | + |
|
| 614 | + if ($needsPartFile) { |
|
| 615 | + // we first assembly the target file as a part file |
|
| 616 | + $partFile = $this->getPartFileBasePath($path . '/' . $info['name']) . '.ocTransferId' . $info['transferid'] . '.part'; |
|
| 617 | + /** @var \OC\Files\Storage\Storage $targetStorage */ |
|
| 618 | + [$partStorage, $partInternalPath] = $this->fileView->resolvePath($partFile); |
|
| 619 | + |
|
| 620 | + |
|
| 621 | + $chunk_handler->file_assemble($partStorage, $partInternalPath); |
|
| 622 | + |
|
| 623 | + // here is the final atomic rename |
|
| 624 | + $renameOkay = $targetStorage->moveFromStorage($partStorage, $partInternalPath, $targetInternalPath); |
|
| 625 | + $fileExists = $targetStorage->file_exists($targetInternalPath); |
|
| 626 | + if ($renameOkay === false || $fileExists === false) { |
|
| 627 | + \OC::$server->getLogger()->error('\OC\Files\Filesystem::rename() failed', ['app' => 'webdav']); |
|
| 628 | + // only delete if an error occurred and the target file was already created |
|
| 629 | + if ($fileExists) { |
|
| 630 | + // set to null to avoid double-deletion when handling exception |
|
| 631 | + // stray part file |
|
| 632 | + $partFile = null; |
|
| 633 | + $targetStorage->unlink($targetInternalPath); |
|
| 634 | + } |
|
| 635 | + $this->fileView->changeLock($targetPath, ILockingProvider::LOCK_SHARED); |
|
| 636 | + throw new Exception($this->l10n->t('Could not rename part file assembled from chunks')); |
|
| 637 | + } |
|
| 638 | + } else { |
|
| 639 | + // assemble directly into the final file |
|
| 640 | + $chunk_handler->file_assemble($targetStorage, $targetInternalPath); |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + // allow sync clients to send the mtime along in a header |
|
| 644 | + if (isset($this->request->server['HTTP_X_OC_MTIME'])) { |
|
| 645 | + $mtime = $this->sanitizeMtime($this->request->server['HTTP_X_OC_MTIME']); |
|
| 646 | + if ($targetStorage->touch($targetInternalPath, $mtime)) { |
|
| 647 | + $this->header('X-OC-MTime: accepted'); |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + // since we skipped the view we need to scan and emit the hooks ourselves |
|
| 652 | + $targetStorage->getUpdater()->update($targetInternalPath); |
|
| 653 | + |
|
| 654 | + $this->fileView->changeLock($targetPath, ILockingProvider::LOCK_SHARED); |
|
| 655 | + |
|
| 656 | + $this->emitPostHooks($exists, $targetPath); |
|
| 657 | + |
|
| 658 | + // FIXME: should call refreshInfo but can't because $this->path is not the of the final file |
|
| 659 | + $info = $this->fileView->getFileInfo($targetPath); |
|
| 660 | + |
|
| 661 | + if (isset($this->request->server['HTTP_OC_CHECKSUM'])) { |
|
| 662 | + $checksum = trim($this->request->server['HTTP_OC_CHECKSUM']); |
|
| 663 | + $this->fileView->putFileInfo($targetPath, ['checksum' => $checksum]); |
|
| 664 | + } elseif ($info->getChecksum() !== null && $info->getChecksum() !== '') { |
|
| 665 | + $this->fileView->putFileInfo($this->path, ['checksum' => '']); |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + $this->fileView->unlockFile($targetPath, ILockingProvider::LOCK_SHARED); |
|
| 669 | + |
|
| 670 | + return $info->getEtag(); |
|
| 671 | + } catch (\Exception $e) { |
|
| 672 | + if ($partFile !== null) { |
|
| 673 | + $targetStorage->unlink($targetInternalPath); |
|
| 674 | + } |
|
| 675 | + $this->convertToSabreException($e); |
|
| 676 | + } |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + return null; |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + /** |
|
| 683 | + * Convert the given exception to a SabreException instance |
|
| 684 | + * |
|
| 685 | + * @param \Exception $e |
|
| 686 | + * |
|
| 687 | + * @throws \Sabre\DAV\Exception |
|
| 688 | + */ |
|
| 689 | + private function convertToSabreException(\Exception $e) { |
|
| 690 | + if ($e instanceof \Sabre\DAV\Exception) { |
|
| 691 | + throw $e; |
|
| 692 | + } |
|
| 693 | + if ($e instanceof NotPermittedException) { |
|
| 694 | + // a more general case - due to whatever reason the content could not be written |
|
| 695 | + throw new Forbidden($e->getMessage(), 0, $e); |
|
| 696 | + } |
|
| 697 | + if ($e instanceof ForbiddenException) { |
|
| 698 | + // the path for the file was forbidden |
|
| 699 | + throw new DAVForbiddenException($e->getMessage(), $e->getRetry(), $e); |
|
| 700 | + } |
|
| 701 | + if ($e instanceof EntityTooLargeException) { |
|
| 702 | + // the file is too big to be stored |
|
| 703 | + throw new EntityTooLarge($e->getMessage(), 0, $e); |
|
| 704 | + } |
|
| 705 | + if ($e instanceof InvalidContentException) { |
|
| 706 | + // the file content is not permitted |
|
| 707 | + throw new UnsupportedMediaType($e->getMessage(), 0, $e); |
|
| 708 | + } |
|
| 709 | + if ($e instanceof InvalidPathException) { |
|
| 710 | + // the path for the file was not valid |
|
| 711 | + // TODO: find proper http status code for this case |
|
| 712 | + throw new Forbidden($e->getMessage(), 0, $e); |
|
| 713 | + } |
|
| 714 | + if ($e instanceof LockedException || $e instanceof LockNotAcquiredException) { |
|
| 715 | + // the file is currently being written to by another process |
|
| 716 | + throw new FileLocked($e->getMessage(), $e->getCode(), $e); |
|
| 717 | + } |
|
| 718 | + if ($e instanceof GenericEncryptionException) { |
|
| 719 | + // returning 503 will allow retry of the operation at a later point in time |
|
| 720 | + throw new ServiceUnavailable($this->l10n->t('Encryption not ready: %1$s', [$e->getMessage()]), 0, $e); |
|
| 721 | + } |
|
| 722 | + if ($e instanceof StorageNotAvailableException) { |
|
| 723 | + throw new ServiceUnavailable($this->l10n->t('Failed to write file contents: %1$s', [$e->getMessage()]), 0, $e); |
|
| 724 | + } |
|
| 725 | + if ($e instanceof NotFoundException) { |
|
| 726 | + throw new NotFound($this->l10n->t('File not found: %1$s', [$e->getMessage()]), 0, $e); |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + throw new \Sabre\DAV\Exception($e->getMessage(), 0, $e); |
|
| 730 | + } |
|
| 731 | + |
|
| 732 | + /** |
|
| 733 | + * Get the checksum for this file |
|
| 734 | + * |
|
| 735 | + * @return string|null |
|
| 736 | + */ |
|
| 737 | + public function getChecksum() { |
|
| 738 | + if (!$this->info) { |
|
| 739 | + return null; |
|
| 740 | + } |
|
| 741 | + return $this->info->getChecksum(); |
|
| 742 | + } |
|
| 743 | + |
|
| 744 | + protected function header($string) { |
|
| 745 | + if (!\OC::$CLI) { |
|
| 746 | + \header($string); |
|
| 747 | + } |
|
| 748 | + } |
|
| 749 | 749 | } |