@@ -60,585 +60,585 @@ |
||
| 60 | 60 | * This class provides the functionality needed to install, update and remove apps |
| 61 | 61 | */ |
| 62 | 62 | class Installer { |
| 63 | - /** @var AppFetcher */ |
|
| 64 | - private $appFetcher; |
|
| 65 | - /** @var IClientService */ |
|
| 66 | - private $clientService; |
|
| 67 | - /** @var ITempManager */ |
|
| 68 | - private $tempManager; |
|
| 69 | - /** @var LoggerInterface */ |
|
| 70 | - private $logger; |
|
| 71 | - /** @var IConfig */ |
|
| 72 | - private $config; |
|
| 73 | - /** @var array - for caching the result of app fetcher */ |
|
| 74 | - private $apps = null; |
|
| 75 | - /** @var bool|null - for caching the result of the ready status */ |
|
| 76 | - private $isInstanceReadyForUpdates = null; |
|
| 77 | - /** @var bool */ |
|
| 78 | - private $isCLI; |
|
| 79 | - |
|
| 80 | - public function __construct( |
|
| 81 | - AppFetcher $appFetcher, |
|
| 82 | - IClientService $clientService, |
|
| 83 | - ITempManager $tempManager, |
|
| 84 | - LoggerInterface $logger, |
|
| 85 | - IConfig $config, |
|
| 86 | - bool $isCLI |
|
| 87 | - ) { |
|
| 88 | - $this->appFetcher = $appFetcher; |
|
| 89 | - $this->clientService = $clientService; |
|
| 90 | - $this->tempManager = $tempManager; |
|
| 91 | - $this->logger = $logger; |
|
| 92 | - $this->config = $config; |
|
| 93 | - $this->isCLI = $isCLI; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Installs an app that is located in one of the app folders already |
|
| 98 | - * |
|
| 99 | - * @param string $appId App to install |
|
| 100 | - * @param bool $forceEnable |
|
| 101 | - * @throws \Exception |
|
| 102 | - * @return string app ID |
|
| 103 | - */ |
|
| 104 | - public function installApp(string $appId, bool $forceEnable = false): string { |
|
| 105 | - $app = \OC_App::findAppInDirectories($appId); |
|
| 106 | - if ($app === false) { |
|
| 107 | - throw new \Exception('App not found in any app directory'); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - $basedir = $app['path'].'/'.$appId; |
|
| 111 | - |
|
| 112 | - if (is_file($basedir . '/appinfo/database.xml')) { |
|
| 113 | - throw new \Exception('The appinfo/database.xml file is not longer supported. Used in ' . $appId); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - $info = OC_App::getAppInfo($basedir.'/appinfo/info.xml', true); |
|
| 117 | - |
|
| 118 | - $l = \OC::$server->getL10N('core'); |
|
| 119 | - |
|
| 120 | - if (!is_array($info)) { |
|
| 121 | - throw new \Exception( |
|
| 122 | - $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
| 123 | - [$appId] |
|
| 124 | - ) |
|
| 125 | - ); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - $ignoreMaxApps = $this->config->getSystemValue('app_install_overwrite', []); |
|
| 129 | - $ignoreMax = $forceEnable || in_array($appId, $ignoreMaxApps, true); |
|
| 130 | - |
|
| 131 | - $version = implode('.', \OCP\Util::getVersion()); |
|
| 132 | - if (!\OC_App::isAppCompatible($version, $info, $ignoreMax)) { |
|
| 133 | - throw new \Exception( |
|
| 134 | - // TODO $l |
|
| 135 | - $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
| 136 | - [$info['name']] |
|
| 137 | - ) |
|
| 138 | - ); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - // check for required dependencies |
|
| 142 | - \OC_App::checkAppDependencies($this->config, $l, $info, $ignoreMax); |
|
| 143 | - /** @var Coordinator $coordinator */ |
|
| 144 | - $coordinator = \OC::$server->get(Coordinator::class); |
|
| 145 | - $coordinator->runLazyRegistration($appId); |
|
| 146 | - \OC_App::registerAutoloading($appId, $basedir); |
|
| 147 | - |
|
| 148 | - $previousVersion = $this->config->getAppValue($info['id'], 'installed_version', false); |
|
| 149 | - if ($previousVersion) { |
|
| 150 | - OC_App::executeRepairSteps($appId, $info['repair-steps']['pre-migration']); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - //install the database |
|
| 154 | - $ms = new MigrationService($info['id'], \OC::$server->get(Connection::class)); |
|
| 155 | - $ms->migrate('latest', true); |
|
| 156 | - |
|
| 157 | - if ($previousVersion) { |
|
| 158 | - OC_App::executeRepairSteps($appId, $info['repair-steps']['post-migration']); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
| 162 | - |
|
| 163 | - //run appinfo/install.php |
|
| 164 | - self::includeAppScript($basedir . '/appinfo/install.php'); |
|
| 165 | - |
|
| 166 | - $appData = OC_App::getAppInfo($appId); |
|
| 167 | - OC_App::executeRepairSteps($appId, $appData['repair-steps']['install']); |
|
| 168 | - |
|
| 169 | - //set the installed version |
|
| 170 | - \OC::$server->getConfig()->setAppValue($info['id'], 'installed_version', OC_App::getAppVersion($info['id'], false)); |
|
| 171 | - \OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no'); |
|
| 172 | - |
|
| 173 | - //set remote/public handlers |
|
| 174 | - foreach ($info['remote'] as $name => $path) { |
|
| 175 | - \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); |
|
| 176 | - } |
|
| 177 | - foreach ($info['public'] as $name => $path) { |
|
| 178 | - \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - OC_App::setAppTypes($info['id']); |
|
| 182 | - |
|
| 183 | - return $info['id']; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * Updates the specified app from the appstore |
|
| 188 | - * |
|
| 189 | - * @param string $appId |
|
| 190 | - * @param bool [$allowUnstable] Allow unstable releases |
|
| 191 | - * @return bool |
|
| 192 | - */ |
|
| 193 | - public function updateAppstoreApp($appId, $allowUnstable = false) { |
|
| 194 | - if ($this->isUpdateAvailable($appId, $allowUnstable)) { |
|
| 195 | - try { |
|
| 196 | - $this->downloadApp($appId, $allowUnstable); |
|
| 197 | - } catch (\Exception $e) { |
|
| 198 | - $this->logger->error($e->getMessage(), [ |
|
| 199 | - 'exception' => $e, |
|
| 200 | - ]); |
|
| 201 | - return false; |
|
| 202 | - } |
|
| 203 | - return OC_App::updateApp($appId); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - return false; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * Split the certificate file in individual certs |
|
| 211 | - * |
|
| 212 | - * @param string $cert |
|
| 213 | - * @return string[] |
|
| 214 | - */ |
|
| 215 | - private function splitCerts(string $cert): array { |
|
| 216 | - preg_match_all('([\-]{3,}[\S\ ]+?[\-]{3,}[\S\s]+?[\-]{3,}[\S\ ]+?[\-]{3,})', $cert, $matches); |
|
| 217 | - |
|
| 218 | - return $matches[0]; |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * Downloads an app and puts it into the app directory |
|
| 223 | - * |
|
| 224 | - * @param string $appId |
|
| 225 | - * @param bool [$allowUnstable] |
|
| 226 | - * |
|
| 227 | - * @throws \Exception If the installation was not successful |
|
| 228 | - */ |
|
| 229 | - public function downloadApp($appId, $allowUnstable = false) { |
|
| 230 | - $appId = strtolower($appId); |
|
| 231 | - |
|
| 232 | - $apps = $this->appFetcher->get($allowUnstable); |
|
| 233 | - foreach ($apps as $app) { |
|
| 234 | - if ($app['id'] === $appId) { |
|
| 235 | - // Load the certificate |
|
| 236 | - $certificate = new X509(); |
|
| 237 | - $rootCrt = file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt'); |
|
| 238 | - $rootCrts = $this->splitCerts($rootCrt); |
|
| 239 | - foreach ($rootCrts as $rootCrt) { |
|
| 240 | - $certificate->loadCA($rootCrt); |
|
| 241 | - } |
|
| 242 | - $loadedCertificate = $certificate->loadX509($app['certificate']); |
|
| 243 | - |
|
| 244 | - // Verify if the certificate has been revoked |
|
| 245 | - $crl = new X509(); |
|
| 246 | - foreach ($rootCrts as $rootCrt) { |
|
| 247 | - $crl->loadCA($rootCrt); |
|
| 248 | - } |
|
| 249 | - $crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl')); |
|
| 250 | - if ($crl->validateSignature() !== true) { |
|
| 251 | - throw new \Exception('Could not validate CRL signature'); |
|
| 252 | - } |
|
| 253 | - $csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString(); |
|
| 254 | - $revoked = $crl->getRevoked($csn); |
|
| 255 | - if ($revoked !== false) { |
|
| 256 | - throw new \Exception( |
|
| 257 | - sprintf( |
|
| 258 | - 'Certificate "%s" has been revoked', |
|
| 259 | - $csn |
|
| 260 | - ) |
|
| 261 | - ); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - // Verify if the certificate has been issued by the Nextcloud Code Authority CA |
|
| 265 | - if ($certificate->validateSignature() !== true) { |
|
| 266 | - throw new \Exception( |
|
| 267 | - sprintf( |
|
| 268 | - 'App with id %s has a certificate not issued by a trusted Code Signing Authority', |
|
| 269 | - $appId |
|
| 270 | - ) |
|
| 271 | - ); |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - // Verify if the certificate is issued for the requested app id |
|
| 275 | - $certInfo = openssl_x509_parse($app['certificate']); |
|
| 276 | - if (!isset($certInfo['subject']['CN'])) { |
|
| 277 | - throw new \Exception( |
|
| 278 | - sprintf( |
|
| 279 | - 'App with id %s has a cert with no CN', |
|
| 280 | - $appId |
|
| 281 | - ) |
|
| 282 | - ); |
|
| 283 | - } |
|
| 284 | - if ($certInfo['subject']['CN'] !== $appId) { |
|
| 285 | - throw new \Exception( |
|
| 286 | - sprintf( |
|
| 287 | - 'App with id %s has a cert issued to %s', |
|
| 288 | - $appId, |
|
| 289 | - $certInfo['subject']['CN'] |
|
| 290 | - ) |
|
| 291 | - ); |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - // Download the release |
|
| 295 | - $tempFile = $this->tempManager->getTemporaryFile('.tar.gz'); |
|
| 296 | - $timeout = $this->isCLI ? 0 : 120; |
|
| 297 | - $client = $this->clientService->newClient(); |
|
| 298 | - $client->get($app['releases'][0]['download'], ['sink' => $tempFile, 'timeout' => $timeout]); |
|
| 299 | - |
|
| 300 | - // Check if the signature actually matches the downloaded content |
|
| 301 | - $certificate = openssl_get_publickey($app['certificate']); |
|
| 302 | - $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
| 303 | - // PHP 8+ deprecates openssl_free_key and automatically destroys the key instance when it goes out of scope |
|
| 304 | - if ((PHP_VERSION_ID < 80000)) { |
|
| 305 | - openssl_free_key($certificate); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - if ($verified === true) { |
|
| 309 | - // Seems to match, let's proceed |
|
| 310 | - $extractDir = $this->tempManager->getTemporaryFolder(); |
|
| 311 | - $archive = new TAR($tempFile); |
|
| 312 | - |
|
| 313 | - if ($archive) { |
|
| 314 | - if (!$archive->extract($extractDir)) { |
|
| 315 | - $errorMessage = 'Could not extract app ' . $appId; |
|
| 316 | - |
|
| 317 | - $archiveError = $archive->getError(); |
|
| 318 | - if ($archiveError instanceof \PEAR_Error) { |
|
| 319 | - $errorMessage .= ': ' . $archiveError->getMessage(); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - throw new \Exception($errorMessage); |
|
| 323 | - } |
|
| 324 | - $allFiles = scandir($extractDir); |
|
| 325 | - $folders = array_diff($allFiles, ['.', '..']); |
|
| 326 | - $folders = array_values($folders); |
|
| 327 | - |
|
| 328 | - if (count($folders) > 1) { |
|
| 329 | - throw new \Exception( |
|
| 330 | - sprintf( |
|
| 331 | - 'Extracted app %s has more than 1 folder', |
|
| 332 | - $appId |
|
| 333 | - ) |
|
| 334 | - ); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - // Check if appinfo/info.xml has the same app ID as well |
|
| 338 | - if ((PHP_VERSION_ID < 80000)) { |
|
| 339 | - $loadEntities = libxml_disable_entity_loader(false); |
|
| 340 | - $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); |
|
| 341 | - libxml_disable_entity_loader($loadEntities); |
|
| 342 | - } else { |
|
| 343 | - $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); |
|
| 344 | - } |
|
| 345 | - if ((string)$xml->id !== $appId) { |
|
| 346 | - throw new \Exception( |
|
| 347 | - sprintf( |
|
| 348 | - 'App for id %s has a wrong app ID in info.xml: %s', |
|
| 349 | - $appId, |
|
| 350 | - (string)$xml->id |
|
| 351 | - ) |
|
| 352 | - ); |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - // Check if the version is lower than before |
|
| 356 | - $currentVersion = OC_App::getAppVersion($appId); |
|
| 357 | - $newVersion = (string)$xml->version; |
|
| 358 | - if (version_compare($currentVersion, $newVersion) === 1) { |
|
| 359 | - throw new \Exception( |
|
| 360 | - sprintf( |
|
| 361 | - 'App for id %s has version %s and tried to update to lower version %s', |
|
| 362 | - $appId, |
|
| 363 | - $currentVersion, |
|
| 364 | - $newVersion |
|
| 365 | - ) |
|
| 366 | - ); |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - $baseDir = OC_App::getInstallPath() . '/' . $appId; |
|
| 370 | - // Remove old app with the ID if existent |
|
| 371 | - OC_Helper::rmdirr($baseDir); |
|
| 372 | - // Move to app folder |
|
| 373 | - if (@mkdir($baseDir)) { |
|
| 374 | - $extractDir .= '/' . $folders[0]; |
|
| 375 | - OC_Helper::copyr($extractDir, $baseDir); |
|
| 376 | - } |
|
| 377 | - OC_Helper::copyr($extractDir, $baseDir); |
|
| 378 | - OC_Helper::rmdirr($extractDir); |
|
| 379 | - return; |
|
| 380 | - } else { |
|
| 381 | - throw new \Exception( |
|
| 382 | - sprintf( |
|
| 383 | - 'Could not extract app with ID %s to %s', |
|
| 384 | - $appId, |
|
| 385 | - $extractDir |
|
| 386 | - ) |
|
| 387 | - ); |
|
| 388 | - } |
|
| 389 | - } else { |
|
| 390 | - // Signature does not match |
|
| 391 | - throw new \Exception( |
|
| 392 | - sprintf( |
|
| 393 | - 'App with id %s has invalid signature', |
|
| 394 | - $appId |
|
| 395 | - ) |
|
| 396 | - ); |
|
| 397 | - } |
|
| 398 | - } |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - throw new \Exception( |
|
| 402 | - sprintf( |
|
| 403 | - 'Could not download app %s', |
|
| 404 | - $appId |
|
| 405 | - ) |
|
| 406 | - ); |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * Check if an update for the app is available |
|
| 411 | - * |
|
| 412 | - * @param string $appId |
|
| 413 | - * @param bool $allowUnstable |
|
| 414 | - * @return string|false false or the version number of the update |
|
| 415 | - */ |
|
| 416 | - public function isUpdateAvailable($appId, $allowUnstable = false) { |
|
| 417 | - if ($this->isInstanceReadyForUpdates === null) { |
|
| 418 | - $installPath = OC_App::getInstallPath(); |
|
| 419 | - if ($installPath === false || $installPath === null) { |
|
| 420 | - $this->isInstanceReadyForUpdates = false; |
|
| 421 | - } else { |
|
| 422 | - $this->isInstanceReadyForUpdates = true; |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - if ($this->isInstanceReadyForUpdates === false) { |
|
| 427 | - return false; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - if ($this->isInstalledFromGit($appId) === true) { |
|
| 431 | - return false; |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - if ($this->apps === null) { |
|
| 435 | - $this->apps = $this->appFetcher->get($allowUnstable); |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - foreach ($this->apps as $app) { |
|
| 439 | - if ($app['id'] === $appId) { |
|
| 440 | - $currentVersion = OC_App::getAppVersion($appId); |
|
| 441 | - |
|
| 442 | - if (!isset($app['releases'][0]['version'])) { |
|
| 443 | - return false; |
|
| 444 | - } |
|
| 445 | - $newestVersion = $app['releases'][0]['version']; |
|
| 446 | - if ($currentVersion !== '0' && version_compare($newestVersion, $currentVersion, '>')) { |
|
| 447 | - return $newestVersion; |
|
| 448 | - } else { |
|
| 449 | - return false; |
|
| 450 | - } |
|
| 451 | - } |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - return false; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - /** |
|
| 458 | - * Check if app has been installed from git |
|
| 459 | - * @param string $name name of the application to remove |
|
| 460 | - * @return boolean |
|
| 461 | - * |
|
| 462 | - * The function will check if the path contains a .git folder |
|
| 463 | - */ |
|
| 464 | - private function isInstalledFromGit($appId) { |
|
| 465 | - $app = \OC_App::findAppInDirectories($appId); |
|
| 466 | - if ($app === false) { |
|
| 467 | - return false; |
|
| 468 | - } |
|
| 469 | - $basedir = $app['path'].'/'.$appId; |
|
| 470 | - return file_exists($basedir.'/.git/'); |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - /** |
|
| 474 | - * Check if app is already downloaded |
|
| 475 | - * @param string $name name of the application to remove |
|
| 476 | - * @return boolean |
|
| 477 | - * |
|
| 478 | - * The function will check if the app is already downloaded in the apps repository |
|
| 479 | - */ |
|
| 480 | - public function isDownloaded($name) { |
|
| 481 | - foreach (\OC::$APPSROOTS as $dir) { |
|
| 482 | - $dirToTest = $dir['path']; |
|
| 483 | - $dirToTest .= '/'; |
|
| 484 | - $dirToTest .= $name; |
|
| 485 | - $dirToTest .= '/'; |
|
| 486 | - |
|
| 487 | - if (is_dir($dirToTest)) { |
|
| 488 | - return true; |
|
| 489 | - } |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - return false; |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - /** |
|
| 496 | - * Removes an app |
|
| 497 | - * @param string $appId ID of the application to remove |
|
| 498 | - * @return boolean |
|
| 499 | - * |
|
| 500 | - * |
|
| 501 | - * This function works as follows |
|
| 502 | - * -# call uninstall repair steps |
|
| 503 | - * -# removing the files |
|
| 504 | - * |
|
| 505 | - * The function will not delete preferences, tables and the configuration, |
|
| 506 | - * this has to be done by the function oc_app_uninstall(). |
|
| 507 | - */ |
|
| 508 | - public function removeApp($appId) { |
|
| 509 | - if ($this->isDownloaded($appId)) { |
|
| 510 | - if (\OC::$server->getAppManager()->isShipped($appId)) { |
|
| 511 | - return false; |
|
| 512 | - } |
|
| 513 | - $appDir = OC_App::getInstallPath() . '/' . $appId; |
|
| 514 | - OC_Helper::rmdirr($appDir); |
|
| 515 | - return true; |
|
| 516 | - } else { |
|
| 517 | - \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', ILogger::ERROR); |
|
| 518 | - |
|
| 519 | - return false; |
|
| 520 | - } |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - /** |
|
| 524 | - * Installs the app within the bundle and marks the bundle as installed |
|
| 525 | - * |
|
| 526 | - * @param Bundle $bundle |
|
| 527 | - * @throws \Exception If app could not get installed |
|
| 528 | - */ |
|
| 529 | - public function installAppBundle(Bundle $bundle) { |
|
| 530 | - $appIds = $bundle->getAppIdentifiers(); |
|
| 531 | - foreach ($appIds as $appId) { |
|
| 532 | - if (!$this->isDownloaded($appId)) { |
|
| 533 | - $this->downloadApp($appId); |
|
| 534 | - } |
|
| 535 | - $this->installApp($appId); |
|
| 536 | - $app = new OC_App(); |
|
| 537 | - $app->enable($appId); |
|
| 538 | - } |
|
| 539 | - $bundles = json_decode($this->config->getAppValue('core', 'installed.bundles', json_encode([])), true); |
|
| 540 | - $bundles[] = $bundle->getIdentifier(); |
|
| 541 | - $this->config->setAppValue('core', 'installed.bundles', json_encode($bundles)); |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - /** |
|
| 545 | - * Installs shipped apps |
|
| 546 | - * |
|
| 547 | - * This function installs all apps found in the 'apps' directory that should be enabled by default; |
|
| 548 | - * @param bool $softErrors When updating we ignore errors and simply log them, better to have a |
|
| 549 | - * working ownCloud at the end instead of an aborted update. |
|
| 550 | - * @return array Array of error messages (appid => Exception) |
|
| 551 | - */ |
|
| 552 | - public static function installShippedApps($softErrors = false) { |
|
| 553 | - $appManager = \OC::$server->getAppManager(); |
|
| 554 | - $config = \OC::$server->getConfig(); |
|
| 555 | - $errors = []; |
|
| 556 | - foreach (\OC::$APPSROOTS as $app_dir) { |
|
| 557 | - if ($dir = opendir($app_dir['path'])) { |
|
| 558 | - while (false !== ($filename = readdir($dir))) { |
|
| 559 | - if ($filename[0] !== '.' and is_dir($app_dir['path']."/$filename")) { |
|
| 560 | - if (file_exists($app_dir['path']."/$filename/appinfo/info.xml")) { |
|
| 561 | - if ($config->getAppValue($filename, "installed_version", null) === null) { |
|
| 562 | - $info = OC_App::getAppInfo($filename); |
|
| 563 | - $enabled = isset($info['default_enable']); |
|
| 564 | - if (($enabled || in_array($filename, $appManager->getAlwaysEnabledApps())) |
|
| 565 | - && $config->getAppValue($filename, 'enabled') !== 'no') { |
|
| 566 | - if ($softErrors) { |
|
| 567 | - try { |
|
| 568 | - Installer::installShippedApp($filename); |
|
| 569 | - } catch (HintException $e) { |
|
| 570 | - if ($e->getPrevious() instanceof TableExistsException) { |
|
| 571 | - $errors[$filename] = $e; |
|
| 572 | - continue; |
|
| 573 | - } |
|
| 574 | - throw $e; |
|
| 575 | - } |
|
| 576 | - } else { |
|
| 577 | - Installer::installShippedApp($filename); |
|
| 578 | - } |
|
| 579 | - $config->setAppValue($filename, 'enabled', 'yes'); |
|
| 580 | - } |
|
| 581 | - } |
|
| 582 | - } |
|
| 583 | - } |
|
| 584 | - } |
|
| 585 | - closedir($dir); |
|
| 586 | - } |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - return $errors; |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - /** |
|
| 593 | - * install an app already placed in the app folder |
|
| 594 | - * @param string $app id of the app to install |
|
| 595 | - * @return integer |
|
| 596 | - */ |
|
| 597 | - public static function installShippedApp($app) { |
|
| 598 | - //install the database |
|
| 599 | - $appPath = OC_App::getAppPath($app); |
|
| 600 | - \OC_App::registerAutoloading($app, $appPath); |
|
| 601 | - |
|
| 602 | - $ms = new MigrationService($app, \OC::$server->get(Connection::class)); |
|
| 603 | - $ms->migrate('latest', true); |
|
| 604 | - |
|
| 605 | - //run appinfo/install.php |
|
| 606 | - self::includeAppScript("$appPath/appinfo/install.php"); |
|
| 607 | - |
|
| 608 | - $info = OC_App::getAppInfo($app); |
|
| 609 | - if (is_null($info)) { |
|
| 610 | - return false; |
|
| 611 | - } |
|
| 612 | - \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
| 613 | - |
|
| 614 | - OC_App::executeRepairSteps($app, $info['repair-steps']['install']); |
|
| 615 | - |
|
| 616 | - $config = \OC::$server->getConfig(); |
|
| 617 | - |
|
| 618 | - $config->setAppValue($app, 'installed_version', OC_App::getAppVersion($app)); |
|
| 619 | - if (array_key_exists('ocsid', $info)) { |
|
| 620 | - $config->setAppValue($app, 'ocsid', $info['ocsid']); |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - //set remote/public handlers |
|
| 624 | - foreach ($info['remote'] as $name => $path) { |
|
| 625 | - $config->setAppValue('core', 'remote_'.$name, $app.'/'.$path); |
|
| 626 | - } |
|
| 627 | - foreach ($info['public'] as $name => $path) { |
|
| 628 | - $config->setAppValue('core', 'public_'.$name, $app.'/'.$path); |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - OC_App::setAppTypes($info['id']); |
|
| 632 | - |
|
| 633 | - return $info['id']; |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - /** |
|
| 637 | - * @param string $script |
|
| 638 | - */ |
|
| 639 | - private static function includeAppScript($script) { |
|
| 640 | - if (file_exists($script)) { |
|
| 641 | - include $script; |
|
| 642 | - } |
|
| 643 | - } |
|
| 63 | + /** @var AppFetcher */ |
|
| 64 | + private $appFetcher; |
|
| 65 | + /** @var IClientService */ |
|
| 66 | + private $clientService; |
|
| 67 | + /** @var ITempManager */ |
|
| 68 | + private $tempManager; |
|
| 69 | + /** @var LoggerInterface */ |
|
| 70 | + private $logger; |
|
| 71 | + /** @var IConfig */ |
|
| 72 | + private $config; |
|
| 73 | + /** @var array - for caching the result of app fetcher */ |
|
| 74 | + private $apps = null; |
|
| 75 | + /** @var bool|null - for caching the result of the ready status */ |
|
| 76 | + private $isInstanceReadyForUpdates = null; |
|
| 77 | + /** @var bool */ |
|
| 78 | + private $isCLI; |
|
| 79 | + |
|
| 80 | + public function __construct( |
|
| 81 | + AppFetcher $appFetcher, |
|
| 82 | + IClientService $clientService, |
|
| 83 | + ITempManager $tempManager, |
|
| 84 | + LoggerInterface $logger, |
|
| 85 | + IConfig $config, |
|
| 86 | + bool $isCLI |
|
| 87 | + ) { |
|
| 88 | + $this->appFetcher = $appFetcher; |
|
| 89 | + $this->clientService = $clientService; |
|
| 90 | + $this->tempManager = $tempManager; |
|
| 91 | + $this->logger = $logger; |
|
| 92 | + $this->config = $config; |
|
| 93 | + $this->isCLI = $isCLI; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Installs an app that is located in one of the app folders already |
|
| 98 | + * |
|
| 99 | + * @param string $appId App to install |
|
| 100 | + * @param bool $forceEnable |
|
| 101 | + * @throws \Exception |
|
| 102 | + * @return string app ID |
|
| 103 | + */ |
|
| 104 | + public function installApp(string $appId, bool $forceEnable = false): string { |
|
| 105 | + $app = \OC_App::findAppInDirectories($appId); |
|
| 106 | + if ($app === false) { |
|
| 107 | + throw new \Exception('App not found in any app directory'); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + $basedir = $app['path'].'/'.$appId; |
|
| 111 | + |
|
| 112 | + if (is_file($basedir . '/appinfo/database.xml')) { |
|
| 113 | + throw new \Exception('The appinfo/database.xml file is not longer supported. Used in ' . $appId); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + $info = OC_App::getAppInfo($basedir.'/appinfo/info.xml', true); |
|
| 117 | + |
|
| 118 | + $l = \OC::$server->getL10N('core'); |
|
| 119 | + |
|
| 120 | + if (!is_array($info)) { |
|
| 121 | + throw new \Exception( |
|
| 122 | + $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
| 123 | + [$appId] |
|
| 124 | + ) |
|
| 125 | + ); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + $ignoreMaxApps = $this->config->getSystemValue('app_install_overwrite', []); |
|
| 129 | + $ignoreMax = $forceEnable || in_array($appId, $ignoreMaxApps, true); |
|
| 130 | + |
|
| 131 | + $version = implode('.', \OCP\Util::getVersion()); |
|
| 132 | + if (!\OC_App::isAppCompatible($version, $info, $ignoreMax)) { |
|
| 133 | + throw new \Exception( |
|
| 134 | + // TODO $l |
|
| 135 | + $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
| 136 | + [$info['name']] |
|
| 137 | + ) |
|
| 138 | + ); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + // check for required dependencies |
|
| 142 | + \OC_App::checkAppDependencies($this->config, $l, $info, $ignoreMax); |
|
| 143 | + /** @var Coordinator $coordinator */ |
|
| 144 | + $coordinator = \OC::$server->get(Coordinator::class); |
|
| 145 | + $coordinator->runLazyRegistration($appId); |
|
| 146 | + \OC_App::registerAutoloading($appId, $basedir); |
|
| 147 | + |
|
| 148 | + $previousVersion = $this->config->getAppValue($info['id'], 'installed_version', false); |
|
| 149 | + if ($previousVersion) { |
|
| 150 | + OC_App::executeRepairSteps($appId, $info['repair-steps']['pre-migration']); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + //install the database |
|
| 154 | + $ms = new MigrationService($info['id'], \OC::$server->get(Connection::class)); |
|
| 155 | + $ms->migrate('latest', true); |
|
| 156 | + |
|
| 157 | + if ($previousVersion) { |
|
| 158 | + OC_App::executeRepairSteps($appId, $info['repair-steps']['post-migration']); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
| 162 | + |
|
| 163 | + //run appinfo/install.php |
|
| 164 | + self::includeAppScript($basedir . '/appinfo/install.php'); |
|
| 165 | + |
|
| 166 | + $appData = OC_App::getAppInfo($appId); |
|
| 167 | + OC_App::executeRepairSteps($appId, $appData['repair-steps']['install']); |
|
| 168 | + |
|
| 169 | + //set the installed version |
|
| 170 | + \OC::$server->getConfig()->setAppValue($info['id'], 'installed_version', OC_App::getAppVersion($info['id'], false)); |
|
| 171 | + \OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no'); |
|
| 172 | + |
|
| 173 | + //set remote/public handlers |
|
| 174 | + foreach ($info['remote'] as $name => $path) { |
|
| 175 | + \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); |
|
| 176 | + } |
|
| 177 | + foreach ($info['public'] as $name => $path) { |
|
| 178 | + \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + OC_App::setAppTypes($info['id']); |
|
| 182 | + |
|
| 183 | + return $info['id']; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * Updates the specified app from the appstore |
|
| 188 | + * |
|
| 189 | + * @param string $appId |
|
| 190 | + * @param bool [$allowUnstable] Allow unstable releases |
|
| 191 | + * @return bool |
|
| 192 | + */ |
|
| 193 | + public function updateAppstoreApp($appId, $allowUnstable = false) { |
|
| 194 | + if ($this->isUpdateAvailable($appId, $allowUnstable)) { |
|
| 195 | + try { |
|
| 196 | + $this->downloadApp($appId, $allowUnstable); |
|
| 197 | + } catch (\Exception $e) { |
|
| 198 | + $this->logger->error($e->getMessage(), [ |
|
| 199 | + 'exception' => $e, |
|
| 200 | + ]); |
|
| 201 | + return false; |
|
| 202 | + } |
|
| 203 | + return OC_App::updateApp($appId); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + return false; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * Split the certificate file in individual certs |
|
| 211 | + * |
|
| 212 | + * @param string $cert |
|
| 213 | + * @return string[] |
|
| 214 | + */ |
|
| 215 | + private function splitCerts(string $cert): array { |
|
| 216 | + preg_match_all('([\-]{3,}[\S\ ]+?[\-]{3,}[\S\s]+?[\-]{3,}[\S\ ]+?[\-]{3,})', $cert, $matches); |
|
| 217 | + |
|
| 218 | + return $matches[0]; |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * Downloads an app and puts it into the app directory |
|
| 223 | + * |
|
| 224 | + * @param string $appId |
|
| 225 | + * @param bool [$allowUnstable] |
|
| 226 | + * |
|
| 227 | + * @throws \Exception If the installation was not successful |
|
| 228 | + */ |
|
| 229 | + public function downloadApp($appId, $allowUnstable = false) { |
|
| 230 | + $appId = strtolower($appId); |
|
| 231 | + |
|
| 232 | + $apps = $this->appFetcher->get($allowUnstable); |
|
| 233 | + foreach ($apps as $app) { |
|
| 234 | + if ($app['id'] === $appId) { |
|
| 235 | + // Load the certificate |
|
| 236 | + $certificate = new X509(); |
|
| 237 | + $rootCrt = file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt'); |
|
| 238 | + $rootCrts = $this->splitCerts($rootCrt); |
|
| 239 | + foreach ($rootCrts as $rootCrt) { |
|
| 240 | + $certificate->loadCA($rootCrt); |
|
| 241 | + } |
|
| 242 | + $loadedCertificate = $certificate->loadX509($app['certificate']); |
|
| 243 | + |
|
| 244 | + // Verify if the certificate has been revoked |
|
| 245 | + $crl = new X509(); |
|
| 246 | + foreach ($rootCrts as $rootCrt) { |
|
| 247 | + $crl->loadCA($rootCrt); |
|
| 248 | + } |
|
| 249 | + $crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl')); |
|
| 250 | + if ($crl->validateSignature() !== true) { |
|
| 251 | + throw new \Exception('Could not validate CRL signature'); |
|
| 252 | + } |
|
| 253 | + $csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString(); |
|
| 254 | + $revoked = $crl->getRevoked($csn); |
|
| 255 | + if ($revoked !== false) { |
|
| 256 | + throw new \Exception( |
|
| 257 | + sprintf( |
|
| 258 | + 'Certificate "%s" has been revoked', |
|
| 259 | + $csn |
|
| 260 | + ) |
|
| 261 | + ); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + // Verify if the certificate has been issued by the Nextcloud Code Authority CA |
|
| 265 | + if ($certificate->validateSignature() !== true) { |
|
| 266 | + throw new \Exception( |
|
| 267 | + sprintf( |
|
| 268 | + 'App with id %s has a certificate not issued by a trusted Code Signing Authority', |
|
| 269 | + $appId |
|
| 270 | + ) |
|
| 271 | + ); |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + // Verify if the certificate is issued for the requested app id |
|
| 275 | + $certInfo = openssl_x509_parse($app['certificate']); |
|
| 276 | + if (!isset($certInfo['subject']['CN'])) { |
|
| 277 | + throw new \Exception( |
|
| 278 | + sprintf( |
|
| 279 | + 'App with id %s has a cert with no CN', |
|
| 280 | + $appId |
|
| 281 | + ) |
|
| 282 | + ); |
|
| 283 | + } |
|
| 284 | + if ($certInfo['subject']['CN'] !== $appId) { |
|
| 285 | + throw new \Exception( |
|
| 286 | + sprintf( |
|
| 287 | + 'App with id %s has a cert issued to %s', |
|
| 288 | + $appId, |
|
| 289 | + $certInfo['subject']['CN'] |
|
| 290 | + ) |
|
| 291 | + ); |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + // Download the release |
|
| 295 | + $tempFile = $this->tempManager->getTemporaryFile('.tar.gz'); |
|
| 296 | + $timeout = $this->isCLI ? 0 : 120; |
|
| 297 | + $client = $this->clientService->newClient(); |
|
| 298 | + $client->get($app['releases'][0]['download'], ['sink' => $tempFile, 'timeout' => $timeout]); |
|
| 299 | + |
|
| 300 | + // Check if the signature actually matches the downloaded content |
|
| 301 | + $certificate = openssl_get_publickey($app['certificate']); |
|
| 302 | + $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
| 303 | + // PHP 8+ deprecates openssl_free_key and automatically destroys the key instance when it goes out of scope |
|
| 304 | + if ((PHP_VERSION_ID < 80000)) { |
|
| 305 | + openssl_free_key($certificate); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + if ($verified === true) { |
|
| 309 | + // Seems to match, let's proceed |
|
| 310 | + $extractDir = $this->tempManager->getTemporaryFolder(); |
|
| 311 | + $archive = new TAR($tempFile); |
|
| 312 | + |
|
| 313 | + if ($archive) { |
|
| 314 | + if (!$archive->extract($extractDir)) { |
|
| 315 | + $errorMessage = 'Could not extract app ' . $appId; |
|
| 316 | + |
|
| 317 | + $archiveError = $archive->getError(); |
|
| 318 | + if ($archiveError instanceof \PEAR_Error) { |
|
| 319 | + $errorMessage .= ': ' . $archiveError->getMessage(); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + throw new \Exception($errorMessage); |
|
| 323 | + } |
|
| 324 | + $allFiles = scandir($extractDir); |
|
| 325 | + $folders = array_diff($allFiles, ['.', '..']); |
|
| 326 | + $folders = array_values($folders); |
|
| 327 | + |
|
| 328 | + if (count($folders) > 1) { |
|
| 329 | + throw new \Exception( |
|
| 330 | + sprintf( |
|
| 331 | + 'Extracted app %s has more than 1 folder', |
|
| 332 | + $appId |
|
| 333 | + ) |
|
| 334 | + ); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + // Check if appinfo/info.xml has the same app ID as well |
|
| 338 | + if ((PHP_VERSION_ID < 80000)) { |
|
| 339 | + $loadEntities = libxml_disable_entity_loader(false); |
|
| 340 | + $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); |
|
| 341 | + libxml_disable_entity_loader($loadEntities); |
|
| 342 | + } else { |
|
| 343 | + $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); |
|
| 344 | + } |
|
| 345 | + if ((string)$xml->id !== $appId) { |
|
| 346 | + throw new \Exception( |
|
| 347 | + sprintf( |
|
| 348 | + 'App for id %s has a wrong app ID in info.xml: %s', |
|
| 349 | + $appId, |
|
| 350 | + (string)$xml->id |
|
| 351 | + ) |
|
| 352 | + ); |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + // Check if the version is lower than before |
|
| 356 | + $currentVersion = OC_App::getAppVersion($appId); |
|
| 357 | + $newVersion = (string)$xml->version; |
|
| 358 | + if (version_compare($currentVersion, $newVersion) === 1) { |
|
| 359 | + throw new \Exception( |
|
| 360 | + sprintf( |
|
| 361 | + 'App for id %s has version %s and tried to update to lower version %s', |
|
| 362 | + $appId, |
|
| 363 | + $currentVersion, |
|
| 364 | + $newVersion |
|
| 365 | + ) |
|
| 366 | + ); |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + $baseDir = OC_App::getInstallPath() . '/' . $appId; |
|
| 370 | + // Remove old app with the ID if existent |
|
| 371 | + OC_Helper::rmdirr($baseDir); |
|
| 372 | + // Move to app folder |
|
| 373 | + if (@mkdir($baseDir)) { |
|
| 374 | + $extractDir .= '/' . $folders[0]; |
|
| 375 | + OC_Helper::copyr($extractDir, $baseDir); |
|
| 376 | + } |
|
| 377 | + OC_Helper::copyr($extractDir, $baseDir); |
|
| 378 | + OC_Helper::rmdirr($extractDir); |
|
| 379 | + return; |
|
| 380 | + } else { |
|
| 381 | + throw new \Exception( |
|
| 382 | + sprintf( |
|
| 383 | + 'Could not extract app with ID %s to %s', |
|
| 384 | + $appId, |
|
| 385 | + $extractDir |
|
| 386 | + ) |
|
| 387 | + ); |
|
| 388 | + } |
|
| 389 | + } else { |
|
| 390 | + // Signature does not match |
|
| 391 | + throw new \Exception( |
|
| 392 | + sprintf( |
|
| 393 | + 'App with id %s has invalid signature', |
|
| 394 | + $appId |
|
| 395 | + ) |
|
| 396 | + ); |
|
| 397 | + } |
|
| 398 | + } |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + throw new \Exception( |
|
| 402 | + sprintf( |
|
| 403 | + 'Could not download app %s', |
|
| 404 | + $appId |
|
| 405 | + ) |
|
| 406 | + ); |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * Check if an update for the app is available |
|
| 411 | + * |
|
| 412 | + * @param string $appId |
|
| 413 | + * @param bool $allowUnstable |
|
| 414 | + * @return string|false false or the version number of the update |
|
| 415 | + */ |
|
| 416 | + public function isUpdateAvailable($appId, $allowUnstable = false) { |
|
| 417 | + if ($this->isInstanceReadyForUpdates === null) { |
|
| 418 | + $installPath = OC_App::getInstallPath(); |
|
| 419 | + if ($installPath === false || $installPath === null) { |
|
| 420 | + $this->isInstanceReadyForUpdates = false; |
|
| 421 | + } else { |
|
| 422 | + $this->isInstanceReadyForUpdates = true; |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + if ($this->isInstanceReadyForUpdates === false) { |
|
| 427 | + return false; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + if ($this->isInstalledFromGit($appId) === true) { |
|
| 431 | + return false; |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + if ($this->apps === null) { |
|
| 435 | + $this->apps = $this->appFetcher->get($allowUnstable); |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + foreach ($this->apps as $app) { |
|
| 439 | + if ($app['id'] === $appId) { |
|
| 440 | + $currentVersion = OC_App::getAppVersion($appId); |
|
| 441 | + |
|
| 442 | + if (!isset($app['releases'][0]['version'])) { |
|
| 443 | + return false; |
|
| 444 | + } |
|
| 445 | + $newestVersion = $app['releases'][0]['version']; |
|
| 446 | + if ($currentVersion !== '0' && version_compare($newestVersion, $currentVersion, '>')) { |
|
| 447 | + return $newestVersion; |
|
| 448 | + } else { |
|
| 449 | + return false; |
|
| 450 | + } |
|
| 451 | + } |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + return false; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + /** |
|
| 458 | + * Check if app has been installed from git |
|
| 459 | + * @param string $name name of the application to remove |
|
| 460 | + * @return boolean |
|
| 461 | + * |
|
| 462 | + * The function will check if the path contains a .git folder |
|
| 463 | + */ |
|
| 464 | + private function isInstalledFromGit($appId) { |
|
| 465 | + $app = \OC_App::findAppInDirectories($appId); |
|
| 466 | + if ($app === false) { |
|
| 467 | + return false; |
|
| 468 | + } |
|
| 469 | + $basedir = $app['path'].'/'.$appId; |
|
| 470 | + return file_exists($basedir.'/.git/'); |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + /** |
|
| 474 | + * Check if app is already downloaded |
|
| 475 | + * @param string $name name of the application to remove |
|
| 476 | + * @return boolean |
|
| 477 | + * |
|
| 478 | + * The function will check if the app is already downloaded in the apps repository |
|
| 479 | + */ |
|
| 480 | + public function isDownloaded($name) { |
|
| 481 | + foreach (\OC::$APPSROOTS as $dir) { |
|
| 482 | + $dirToTest = $dir['path']; |
|
| 483 | + $dirToTest .= '/'; |
|
| 484 | + $dirToTest .= $name; |
|
| 485 | + $dirToTest .= '/'; |
|
| 486 | + |
|
| 487 | + if (is_dir($dirToTest)) { |
|
| 488 | + return true; |
|
| 489 | + } |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + return false; |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + /** |
|
| 496 | + * Removes an app |
|
| 497 | + * @param string $appId ID of the application to remove |
|
| 498 | + * @return boolean |
|
| 499 | + * |
|
| 500 | + * |
|
| 501 | + * This function works as follows |
|
| 502 | + * -# call uninstall repair steps |
|
| 503 | + * -# removing the files |
|
| 504 | + * |
|
| 505 | + * The function will not delete preferences, tables and the configuration, |
|
| 506 | + * this has to be done by the function oc_app_uninstall(). |
|
| 507 | + */ |
|
| 508 | + public function removeApp($appId) { |
|
| 509 | + if ($this->isDownloaded($appId)) { |
|
| 510 | + if (\OC::$server->getAppManager()->isShipped($appId)) { |
|
| 511 | + return false; |
|
| 512 | + } |
|
| 513 | + $appDir = OC_App::getInstallPath() . '/' . $appId; |
|
| 514 | + OC_Helper::rmdirr($appDir); |
|
| 515 | + return true; |
|
| 516 | + } else { |
|
| 517 | + \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', ILogger::ERROR); |
|
| 518 | + |
|
| 519 | + return false; |
|
| 520 | + } |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + /** |
|
| 524 | + * Installs the app within the bundle and marks the bundle as installed |
|
| 525 | + * |
|
| 526 | + * @param Bundle $bundle |
|
| 527 | + * @throws \Exception If app could not get installed |
|
| 528 | + */ |
|
| 529 | + public function installAppBundle(Bundle $bundle) { |
|
| 530 | + $appIds = $bundle->getAppIdentifiers(); |
|
| 531 | + foreach ($appIds as $appId) { |
|
| 532 | + if (!$this->isDownloaded($appId)) { |
|
| 533 | + $this->downloadApp($appId); |
|
| 534 | + } |
|
| 535 | + $this->installApp($appId); |
|
| 536 | + $app = new OC_App(); |
|
| 537 | + $app->enable($appId); |
|
| 538 | + } |
|
| 539 | + $bundles = json_decode($this->config->getAppValue('core', 'installed.bundles', json_encode([])), true); |
|
| 540 | + $bundles[] = $bundle->getIdentifier(); |
|
| 541 | + $this->config->setAppValue('core', 'installed.bundles', json_encode($bundles)); |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + /** |
|
| 545 | + * Installs shipped apps |
|
| 546 | + * |
|
| 547 | + * This function installs all apps found in the 'apps' directory that should be enabled by default; |
|
| 548 | + * @param bool $softErrors When updating we ignore errors and simply log them, better to have a |
|
| 549 | + * working ownCloud at the end instead of an aborted update. |
|
| 550 | + * @return array Array of error messages (appid => Exception) |
|
| 551 | + */ |
|
| 552 | + public static function installShippedApps($softErrors = false) { |
|
| 553 | + $appManager = \OC::$server->getAppManager(); |
|
| 554 | + $config = \OC::$server->getConfig(); |
|
| 555 | + $errors = []; |
|
| 556 | + foreach (\OC::$APPSROOTS as $app_dir) { |
|
| 557 | + if ($dir = opendir($app_dir['path'])) { |
|
| 558 | + while (false !== ($filename = readdir($dir))) { |
|
| 559 | + if ($filename[0] !== '.' and is_dir($app_dir['path']."/$filename")) { |
|
| 560 | + if (file_exists($app_dir['path']."/$filename/appinfo/info.xml")) { |
|
| 561 | + if ($config->getAppValue($filename, "installed_version", null) === null) { |
|
| 562 | + $info = OC_App::getAppInfo($filename); |
|
| 563 | + $enabled = isset($info['default_enable']); |
|
| 564 | + if (($enabled || in_array($filename, $appManager->getAlwaysEnabledApps())) |
|
| 565 | + && $config->getAppValue($filename, 'enabled') !== 'no') { |
|
| 566 | + if ($softErrors) { |
|
| 567 | + try { |
|
| 568 | + Installer::installShippedApp($filename); |
|
| 569 | + } catch (HintException $e) { |
|
| 570 | + if ($e->getPrevious() instanceof TableExistsException) { |
|
| 571 | + $errors[$filename] = $e; |
|
| 572 | + continue; |
|
| 573 | + } |
|
| 574 | + throw $e; |
|
| 575 | + } |
|
| 576 | + } else { |
|
| 577 | + Installer::installShippedApp($filename); |
|
| 578 | + } |
|
| 579 | + $config->setAppValue($filename, 'enabled', 'yes'); |
|
| 580 | + } |
|
| 581 | + } |
|
| 582 | + } |
|
| 583 | + } |
|
| 584 | + } |
|
| 585 | + closedir($dir); |
|
| 586 | + } |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + return $errors; |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + /** |
|
| 593 | + * install an app already placed in the app folder |
|
| 594 | + * @param string $app id of the app to install |
|
| 595 | + * @return integer |
|
| 596 | + */ |
|
| 597 | + public static function installShippedApp($app) { |
|
| 598 | + //install the database |
|
| 599 | + $appPath = OC_App::getAppPath($app); |
|
| 600 | + \OC_App::registerAutoloading($app, $appPath); |
|
| 601 | + |
|
| 602 | + $ms = new MigrationService($app, \OC::$server->get(Connection::class)); |
|
| 603 | + $ms->migrate('latest', true); |
|
| 604 | + |
|
| 605 | + //run appinfo/install.php |
|
| 606 | + self::includeAppScript("$appPath/appinfo/install.php"); |
|
| 607 | + |
|
| 608 | + $info = OC_App::getAppInfo($app); |
|
| 609 | + if (is_null($info)) { |
|
| 610 | + return false; |
|
| 611 | + } |
|
| 612 | + \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
| 613 | + |
|
| 614 | + OC_App::executeRepairSteps($app, $info['repair-steps']['install']); |
|
| 615 | + |
|
| 616 | + $config = \OC::$server->getConfig(); |
|
| 617 | + |
|
| 618 | + $config->setAppValue($app, 'installed_version', OC_App::getAppVersion($app)); |
|
| 619 | + if (array_key_exists('ocsid', $info)) { |
|
| 620 | + $config->setAppValue($app, 'ocsid', $info['ocsid']); |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + //set remote/public handlers |
|
| 624 | + foreach ($info['remote'] as $name => $path) { |
|
| 625 | + $config->setAppValue('core', 'remote_'.$name, $app.'/'.$path); |
|
| 626 | + } |
|
| 627 | + foreach ($info['public'] as $name => $path) { |
|
| 628 | + $config->setAppValue('core', 'public_'.$name, $app.'/'.$path); |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + OC_App::setAppTypes($info['id']); |
|
| 632 | + |
|
| 633 | + return $info['id']; |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + /** |
|
| 637 | + * @param string $script |
|
| 638 | + */ |
|
| 639 | + private static function includeAppScript($script) { |
|
| 640 | + if (file_exists($script)) { |
|
| 641 | + include $script; |
|
| 642 | + } |
|
| 643 | + } |
|
| 644 | 644 | } |
@@ -47,186 +47,186 @@ |
||
| 47 | 47 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
| 48 | 48 | |
| 49 | 49 | class Application { |
| 50 | - /** @var IConfig */ |
|
| 51 | - private $config; |
|
| 52 | - /** @var EventDispatcherInterface */ |
|
| 53 | - private $dispatcher; |
|
| 54 | - /** @var IRequest */ |
|
| 55 | - private $request; |
|
| 56 | - /** @var LoggerInterface */ |
|
| 57 | - private $logger; |
|
| 58 | - /** @var MemoryInfo */ |
|
| 59 | - private $memoryInfo; |
|
| 50 | + /** @var IConfig */ |
|
| 51 | + private $config; |
|
| 52 | + /** @var EventDispatcherInterface */ |
|
| 53 | + private $dispatcher; |
|
| 54 | + /** @var IRequest */ |
|
| 55 | + private $request; |
|
| 56 | + /** @var LoggerInterface */ |
|
| 57 | + private $logger; |
|
| 58 | + /** @var MemoryInfo */ |
|
| 59 | + private $memoryInfo; |
|
| 60 | 60 | |
| 61 | - public function __construct(IConfig $config, |
|
| 62 | - EventDispatcherInterface $dispatcher, |
|
| 63 | - IRequest $request, |
|
| 64 | - LoggerInterface $logger, |
|
| 65 | - MemoryInfo $memoryInfo) { |
|
| 66 | - $defaults = \OC::$server->getThemingDefaults(); |
|
| 67 | - $this->config = $config; |
|
| 68 | - $this->application = new SymfonyApplication($defaults->getName(), \OC_Util::getVersionString()); |
|
| 69 | - $this->dispatcher = $dispatcher; |
|
| 70 | - $this->request = $request; |
|
| 71 | - $this->logger = $logger; |
|
| 72 | - $this->memoryInfo = $memoryInfo; |
|
| 73 | - } |
|
| 61 | + public function __construct(IConfig $config, |
|
| 62 | + EventDispatcherInterface $dispatcher, |
|
| 63 | + IRequest $request, |
|
| 64 | + LoggerInterface $logger, |
|
| 65 | + MemoryInfo $memoryInfo) { |
|
| 66 | + $defaults = \OC::$server->getThemingDefaults(); |
|
| 67 | + $this->config = $config; |
|
| 68 | + $this->application = new SymfonyApplication($defaults->getName(), \OC_Util::getVersionString()); |
|
| 69 | + $this->dispatcher = $dispatcher; |
|
| 70 | + $this->request = $request; |
|
| 71 | + $this->logger = $logger; |
|
| 72 | + $this->memoryInfo = $memoryInfo; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * @param InputInterface $input |
|
| 77 | - * @param ConsoleOutputInterface $output |
|
| 78 | - * @throws \Exception |
|
| 79 | - */ |
|
| 80 | - public function loadCommands( |
|
| 81 | - InputInterface $input, |
|
| 82 | - ConsoleOutputInterface $output |
|
| 83 | - ) { |
|
| 84 | - // $application is required to be defined in the register_command scripts |
|
| 85 | - $application = $this->application; |
|
| 86 | - $inputDefinition = $application->getDefinition(); |
|
| 87 | - $inputDefinition->addOption( |
|
| 88 | - new InputOption( |
|
| 89 | - 'no-warnings', |
|
| 90 | - null, |
|
| 91 | - InputOption::VALUE_NONE, |
|
| 92 | - 'Skip global warnings, show command output only', |
|
| 93 | - null |
|
| 94 | - ) |
|
| 95 | - ); |
|
| 96 | - try { |
|
| 97 | - $input->bind($inputDefinition); |
|
| 98 | - } catch (\RuntimeException $e) { |
|
| 99 | - //expected if there are extra options |
|
| 100 | - } |
|
| 101 | - if ($input->getOption('no-warnings')) { |
|
| 102 | - $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); |
|
| 103 | - } |
|
| 75 | + /** |
|
| 76 | + * @param InputInterface $input |
|
| 77 | + * @param ConsoleOutputInterface $output |
|
| 78 | + * @throws \Exception |
|
| 79 | + */ |
|
| 80 | + public function loadCommands( |
|
| 81 | + InputInterface $input, |
|
| 82 | + ConsoleOutputInterface $output |
|
| 83 | + ) { |
|
| 84 | + // $application is required to be defined in the register_command scripts |
|
| 85 | + $application = $this->application; |
|
| 86 | + $inputDefinition = $application->getDefinition(); |
|
| 87 | + $inputDefinition->addOption( |
|
| 88 | + new InputOption( |
|
| 89 | + 'no-warnings', |
|
| 90 | + null, |
|
| 91 | + InputOption::VALUE_NONE, |
|
| 92 | + 'Skip global warnings, show command output only', |
|
| 93 | + null |
|
| 94 | + ) |
|
| 95 | + ); |
|
| 96 | + try { |
|
| 97 | + $input->bind($inputDefinition); |
|
| 98 | + } catch (\RuntimeException $e) { |
|
| 99 | + //expected if there are extra options |
|
| 100 | + } |
|
| 101 | + if ($input->getOption('no-warnings')) { |
|
| 102 | + $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - if ($this->memoryInfo->isMemoryLimitSufficient() === false) { |
|
| 106 | - $output->getErrorOutput()->writeln( |
|
| 107 | - '<comment>The current PHP memory limit ' . |
|
| 108 | - 'is below the recommended value of 512MB.</comment>' |
|
| 109 | - ); |
|
| 110 | - } |
|
| 105 | + if ($this->memoryInfo->isMemoryLimitSufficient() === false) { |
|
| 106 | + $output->getErrorOutput()->writeln( |
|
| 107 | + '<comment>The current PHP memory limit ' . |
|
| 108 | + 'is below the recommended value of 512MB.</comment>' |
|
| 109 | + ); |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - try { |
|
| 113 | - require_once __DIR__ . '/../../../core/register_command.php'; |
|
| 114 | - if ($this->config->getSystemValue('installed', false)) { |
|
| 115 | - if (\OCP\Util::needUpgrade()) { |
|
| 116 | - throw new NeedsUpdateException(); |
|
| 117 | - } elseif ($this->config->getSystemValueBool('maintenance')) { |
|
| 118 | - $this->writeMaintenanceModeInfo($input, $output); |
|
| 119 | - } else { |
|
| 120 | - OC_App::loadApps(); |
|
| 121 | - foreach (\OC::$server->getAppManager()->getInstalledApps() as $app) { |
|
| 122 | - $appPath = \OC_App::getAppPath($app); |
|
| 123 | - if ($appPath === false) { |
|
| 124 | - continue; |
|
| 125 | - } |
|
| 126 | - // load commands using info.xml |
|
| 127 | - $info = \OC_App::getAppInfo($app); |
|
| 128 | - if (isset($info['commands'])) { |
|
| 129 | - $this->loadCommandsFromInfoXml($info['commands']); |
|
| 130 | - } |
|
| 131 | - // load from register_command.php |
|
| 132 | - \OC_App::registerAutoloading($app, $appPath); |
|
| 133 | - $file = $appPath . '/appinfo/register_command.php'; |
|
| 134 | - if (file_exists($file)) { |
|
| 135 | - try { |
|
| 136 | - require $file; |
|
| 137 | - } catch (\Exception $e) { |
|
| 138 | - $this->logger->error($e->getMessage(), [ |
|
| 139 | - 'exception' => $e, |
|
| 140 | - ]); |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - } elseif ($input->getArgument('command') !== '_completion' && $input->getArgument('command') !== 'maintenance:install') { |
|
| 146 | - $output->writeln("Nextcloud is not installed - only a limited number of commands are available"); |
|
| 147 | - } |
|
| 148 | - } catch (NeedsUpdateException $e) { |
|
| 149 | - if ($input->getArgument('command') !== '_completion') { |
|
| 150 | - $output->writeln("Nextcloud or one of the apps require upgrade - only a limited number of commands are available"); |
|
| 151 | - $output->writeln("You may use your browser or the occ upgrade command to do the upgrade"); |
|
| 152 | - } |
|
| 153 | - } |
|
| 112 | + try { |
|
| 113 | + require_once __DIR__ . '/../../../core/register_command.php'; |
|
| 114 | + if ($this->config->getSystemValue('installed', false)) { |
|
| 115 | + if (\OCP\Util::needUpgrade()) { |
|
| 116 | + throw new NeedsUpdateException(); |
|
| 117 | + } elseif ($this->config->getSystemValueBool('maintenance')) { |
|
| 118 | + $this->writeMaintenanceModeInfo($input, $output); |
|
| 119 | + } else { |
|
| 120 | + OC_App::loadApps(); |
|
| 121 | + foreach (\OC::$server->getAppManager()->getInstalledApps() as $app) { |
|
| 122 | + $appPath = \OC_App::getAppPath($app); |
|
| 123 | + if ($appPath === false) { |
|
| 124 | + continue; |
|
| 125 | + } |
|
| 126 | + // load commands using info.xml |
|
| 127 | + $info = \OC_App::getAppInfo($app); |
|
| 128 | + if (isset($info['commands'])) { |
|
| 129 | + $this->loadCommandsFromInfoXml($info['commands']); |
|
| 130 | + } |
|
| 131 | + // load from register_command.php |
|
| 132 | + \OC_App::registerAutoloading($app, $appPath); |
|
| 133 | + $file = $appPath . '/appinfo/register_command.php'; |
|
| 134 | + if (file_exists($file)) { |
|
| 135 | + try { |
|
| 136 | + require $file; |
|
| 137 | + } catch (\Exception $e) { |
|
| 138 | + $this->logger->error($e->getMessage(), [ |
|
| 139 | + 'exception' => $e, |
|
| 140 | + ]); |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + } elseif ($input->getArgument('command') !== '_completion' && $input->getArgument('command') !== 'maintenance:install') { |
|
| 146 | + $output->writeln("Nextcloud is not installed - only a limited number of commands are available"); |
|
| 147 | + } |
|
| 148 | + } catch (NeedsUpdateException $e) { |
|
| 149 | + if ($input->getArgument('command') !== '_completion') { |
|
| 150 | + $output->writeln("Nextcloud or one of the apps require upgrade - only a limited number of commands are available"); |
|
| 151 | + $output->writeln("You may use your browser or the occ upgrade command to do the upgrade"); |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - if ($input->getFirstArgument() !== 'check') { |
|
| 156 | - $errors = \OC_Util::checkServer(\OC::$server->getSystemConfig()); |
|
| 157 | - if (!empty($errors)) { |
|
| 158 | - foreach ($errors as $error) { |
|
| 159 | - $output->writeln((string)$error['error']); |
|
| 160 | - $output->writeln((string)$error['hint']); |
|
| 161 | - $output->writeln(''); |
|
| 162 | - } |
|
| 163 | - throw new \Exception("Environment not properly prepared."); |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - } |
|
| 155 | + if ($input->getFirstArgument() !== 'check') { |
|
| 156 | + $errors = \OC_Util::checkServer(\OC::$server->getSystemConfig()); |
|
| 157 | + if (!empty($errors)) { |
|
| 158 | + foreach ($errors as $error) { |
|
| 159 | + $output->writeln((string)$error['error']); |
|
| 160 | + $output->writeln((string)$error['hint']); |
|
| 161 | + $output->writeln(''); |
|
| 162 | + } |
|
| 163 | + throw new \Exception("Environment not properly prepared."); |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - /** |
|
| 169 | - * Write a maintenance mode info. |
|
| 170 | - * The commands "_completion" and "maintenance:mode" are excluded. |
|
| 171 | - * |
|
| 172 | - * @param InputInterface $input The input implementation for reading inputs. |
|
| 173 | - * @param ConsoleOutputInterface $output The output implementation |
|
| 174 | - * for writing outputs. |
|
| 175 | - * @return void |
|
| 176 | - */ |
|
| 177 | - private function writeMaintenanceModeInfo( |
|
| 178 | - InputInterface $input, ConsoleOutputInterface $output |
|
| 179 | - ) { |
|
| 180 | - if ($input->getArgument('command') !== '_completion' |
|
| 181 | - && $input->getArgument('command') !== 'maintenance:mode') { |
|
| 182 | - $errOutput = $output->getErrorOutput(); |
|
| 183 | - $errOutput->writeln( |
|
| 184 | - '<comment>Nextcloud is in maintenance mode - ' . |
|
| 185 | - 'no apps have been loaded</comment>' . PHP_EOL |
|
| 186 | - ); |
|
| 187 | - } |
|
| 188 | - } |
|
| 168 | + /** |
|
| 169 | + * Write a maintenance mode info. |
|
| 170 | + * The commands "_completion" and "maintenance:mode" are excluded. |
|
| 171 | + * |
|
| 172 | + * @param InputInterface $input The input implementation for reading inputs. |
|
| 173 | + * @param ConsoleOutputInterface $output The output implementation |
|
| 174 | + * for writing outputs. |
|
| 175 | + * @return void |
|
| 176 | + */ |
|
| 177 | + private function writeMaintenanceModeInfo( |
|
| 178 | + InputInterface $input, ConsoleOutputInterface $output |
|
| 179 | + ) { |
|
| 180 | + if ($input->getArgument('command') !== '_completion' |
|
| 181 | + && $input->getArgument('command') !== 'maintenance:mode') { |
|
| 182 | + $errOutput = $output->getErrorOutput(); |
|
| 183 | + $errOutput->writeln( |
|
| 184 | + '<comment>Nextcloud is in maintenance mode - ' . |
|
| 185 | + 'no apps have been loaded</comment>' . PHP_EOL |
|
| 186 | + ); |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | 189 | |
| 190 | - /** |
|
| 191 | - * Sets whether to automatically exit after a command execution or not. |
|
| 192 | - * |
|
| 193 | - * @param bool $boolean Whether to automatically exit after a command execution or not |
|
| 194 | - */ |
|
| 195 | - public function setAutoExit($boolean) { |
|
| 196 | - $this->application->setAutoExit($boolean); |
|
| 197 | - } |
|
| 190 | + /** |
|
| 191 | + * Sets whether to automatically exit after a command execution or not. |
|
| 192 | + * |
|
| 193 | + * @param bool $boolean Whether to automatically exit after a command execution or not |
|
| 194 | + */ |
|
| 195 | + public function setAutoExit($boolean) { |
|
| 196 | + $this->application->setAutoExit($boolean); |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - /** |
|
| 200 | - * @param InputInterface $input |
|
| 201 | - * @param OutputInterface $output |
|
| 202 | - * @return int |
|
| 203 | - * @throws \Exception |
|
| 204 | - */ |
|
| 205 | - public function run(InputInterface $input = null, OutputInterface $output = null) { |
|
| 206 | - $this->dispatcher->dispatch(ConsoleEvent::EVENT_RUN, new ConsoleEvent( |
|
| 207 | - ConsoleEvent::EVENT_RUN, |
|
| 208 | - $this->request->server['argv'] |
|
| 209 | - )); |
|
| 210 | - return $this->application->run($input, $output); |
|
| 211 | - } |
|
| 199 | + /** |
|
| 200 | + * @param InputInterface $input |
|
| 201 | + * @param OutputInterface $output |
|
| 202 | + * @return int |
|
| 203 | + * @throws \Exception |
|
| 204 | + */ |
|
| 205 | + public function run(InputInterface $input = null, OutputInterface $output = null) { |
|
| 206 | + $this->dispatcher->dispatch(ConsoleEvent::EVENT_RUN, new ConsoleEvent( |
|
| 207 | + ConsoleEvent::EVENT_RUN, |
|
| 208 | + $this->request->server['argv'] |
|
| 209 | + )); |
|
| 210 | + return $this->application->run($input, $output); |
|
| 211 | + } |
|
| 212 | 212 | |
| 213 | - private function loadCommandsFromInfoXml($commands) { |
|
| 214 | - foreach ($commands as $command) { |
|
| 215 | - try { |
|
| 216 | - $c = \OC::$server->query($command); |
|
| 217 | - } catch (QueryException $e) { |
|
| 218 | - if (class_exists($command)) { |
|
| 219 | - try { |
|
| 220 | - $c = new $command(); |
|
| 221 | - } catch (\ArgumentCountError $e2) { |
|
| 222 | - throw new \Exception("Failed to construct console command '$command': " . $e->getMessage(), 0, $e); |
|
| 223 | - } |
|
| 224 | - } else { |
|
| 225 | - throw new \Exception("Console command '$command' is unknown and could not be loaded"); |
|
| 226 | - } |
|
| 227 | - } |
|
| 213 | + private function loadCommandsFromInfoXml($commands) { |
|
| 214 | + foreach ($commands as $command) { |
|
| 215 | + try { |
|
| 216 | + $c = \OC::$server->query($command); |
|
| 217 | + } catch (QueryException $e) { |
|
| 218 | + if (class_exists($command)) { |
|
| 219 | + try { |
|
| 220 | + $c = new $command(); |
|
| 221 | + } catch (\ArgumentCountError $e2) { |
|
| 222 | + throw new \Exception("Failed to construct console command '$command': " . $e->getMessage(), 0, $e); |
|
| 223 | + } |
|
| 224 | + } else { |
|
| 225 | + throw new \Exception("Console command '$command' is unknown and could not be loaded"); |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - $this->application->add($c); |
|
| 230 | - } |
|
| 231 | - } |
|
| 229 | + $this->application->add($c); |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | 232 | } |
@@ -260,2066 +260,2066 @@ |
||
| 260 | 260 | */ |
| 261 | 261 | class Server extends ServerContainer implements IServerContainer { |
| 262 | 262 | |
| 263 | - /** @var string */ |
|
| 264 | - private $webRoot; |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * @param string $webRoot |
|
| 268 | - * @param \OC\Config $config |
|
| 269 | - */ |
|
| 270 | - public function __construct($webRoot, \OC\Config $config) { |
|
| 271 | - parent::__construct(); |
|
| 272 | - $this->webRoot = $webRoot; |
|
| 273 | - |
|
| 274 | - // To find out if we are running from CLI or not |
|
| 275 | - $this->registerParameter('isCLI', \OC::$CLI); |
|
| 276 | - $this->registerParameter('serverRoot', \OC::$SERVERROOT); |
|
| 277 | - |
|
| 278 | - $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
| 279 | - return $c; |
|
| 280 | - }); |
|
| 281 | - $this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) { |
|
| 282 | - return $c; |
|
| 283 | - }); |
|
| 284 | - |
|
| 285 | - $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
| 286 | - /** @deprecated 19.0.0 */ |
|
| 287 | - $this->registerDeprecatedAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
| 288 | - |
|
| 289 | - $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
| 290 | - /** @deprecated 19.0.0 */ |
|
| 291 | - $this->registerDeprecatedAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class); |
|
| 292 | - |
|
| 293 | - $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
| 294 | - /** @deprecated 19.0.0 */ |
|
| 295 | - $this->registerDeprecatedAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class); |
|
| 296 | - |
|
| 297 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
| 298 | - /** @deprecated 19.0.0 */ |
|
| 299 | - $this->registerDeprecatedAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
| 300 | - |
|
| 301 | - $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class); |
|
| 302 | - $this->registerAlias(ITemplateManager::class, TemplateManager::class); |
|
| 303 | - |
|
| 304 | - $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
| 305 | - |
|
| 306 | - $this->registerService(View::class, function (Server $c) { |
|
| 307 | - return new View(); |
|
| 308 | - }, false); |
|
| 309 | - |
|
| 310 | - $this->registerService(IPreview::class, function (ContainerInterface $c) { |
|
| 311 | - return new PreviewManager( |
|
| 312 | - $c->get(\OCP\IConfig::class), |
|
| 313 | - $c->get(IRootFolder::class), |
|
| 314 | - new \OC\Preview\Storage\Root( |
|
| 315 | - $c->get(IRootFolder::class), |
|
| 316 | - $c->get(SystemConfig::class) |
|
| 317 | - ), |
|
| 318 | - $c->get(SymfonyAdapter::class), |
|
| 319 | - $c->get(GeneratorHelper::class), |
|
| 320 | - $c->get(ISession::class)->get('user_id') |
|
| 321 | - ); |
|
| 322 | - }); |
|
| 323 | - /** @deprecated 19.0.0 */ |
|
| 324 | - $this->registerDeprecatedAlias('PreviewManager', IPreview::class); |
|
| 325 | - |
|
| 326 | - $this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) { |
|
| 327 | - return new \OC\Preview\Watcher( |
|
| 328 | - new \OC\Preview\Storage\Root( |
|
| 329 | - $c->get(IRootFolder::class), |
|
| 330 | - $c->get(SystemConfig::class) |
|
| 331 | - ) |
|
| 332 | - ); |
|
| 333 | - }); |
|
| 334 | - |
|
| 335 | - $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) { |
|
| 336 | - $view = new View(); |
|
| 337 | - $util = new Encryption\Util( |
|
| 338 | - $view, |
|
| 339 | - $c->get(IUserManager::class), |
|
| 340 | - $c->get(IGroupManager::class), |
|
| 341 | - $c->get(\OCP\IConfig::class) |
|
| 342 | - ); |
|
| 343 | - return new Encryption\Manager( |
|
| 344 | - $c->get(\OCP\IConfig::class), |
|
| 345 | - $c->get(ILogger::class), |
|
| 346 | - $c->getL10N('core'), |
|
| 347 | - new View(), |
|
| 348 | - $util, |
|
| 349 | - new ArrayCache() |
|
| 350 | - ); |
|
| 351 | - }); |
|
| 352 | - /** @deprecated 19.0.0 */ |
|
| 353 | - $this->registerDeprecatedAlias('EncryptionManager', \OCP\Encryption\IManager::class); |
|
| 354 | - |
|
| 355 | - /** @deprecated 21.0.0 */ |
|
| 356 | - $this->registerDeprecatedAlias('EncryptionFileHelper', IFile::class); |
|
| 357 | - $this->registerService(IFile::class, function (ContainerInterface $c) { |
|
| 358 | - $util = new Encryption\Util( |
|
| 359 | - new View(), |
|
| 360 | - $c->get(IUserManager::class), |
|
| 361 | - $c->get(IGroupManager::class), |
|
| 362 | - $c->get(\OCP\IConfig::class) |
|
| 363 | - ); |
|
| 364 | - return new Encryption\File( |
|
| 365 | - $util, |
|
| 366 | - $c->get(IRootFolder::class), |
|
| 367 | - $c->get(\OCP\Share\IManager::class) |
|
| 368 | - ); |
|
| 369 | - }); |
|
| 370 | - |
|
| 371 | - /** @deprecated 21.0.0 */ |
|
| 372 | - $this->registerDeprecatedAlias('EncryptionKeyStorage', IStorage::class); |
|
| 373 | - $this->registerService(IStorage::class, function (ContainerInterface $c) { |
|
| 374 | - $view = new View(); |
|
| 375 | - $util = new Encryption\Util( |
|
| 376 | - $view, |
|
| 377 | - $c->get(IUserManager::class), |
|
| 378 | - $c->get(IGroupManager::class), |
|
| 379 | - $c->get(\OCP\IConfig::class) |
|
| 380 | - ); |
|
| 381 | - |
|
| 382 | - return new Encryption\Keys\Storage( |
|
| 383 | - $view, |
|
| 384 | - $util, |
|
| 385 | - $c->get(ICrypto::class), |
|
| 386 | - $c->get(\OCP\IConfig::class) |
|
| 387 | - ); |
|
| 388 | - }); |
|
| 389 | - /** @deprecated 20.0.0 */ |
|
| 390 | - $this->registerDeprecatedAlias('TagMapper', TagMapper::class); |
|
| 391 | - |
|
| 392 | - $this->registerAlias(\OCP\ITagManager::class, TagManager::class); |
|
| 393 | - /** @deprecated 19.0.0 */ |
|
| 394 | - $this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class); |
|
| 395 | - |
|
| 396 | - $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) { |
|
| 397 | - /** @var \OCP\IConfig $config */ |
|
| 398 | - $config = $c->get(\OCP\IConfig::class); |
|
| 399 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
| 400 | - return new $factoryClass($this); |
|
| 401 | - }); |
|
| 402 | - $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) { |
|
| 403 | - return $c->get('SystemTagManagerFactory')->getManager(); |
|
| 404 | - }); |
|
| 405 | - /** @deprecated 19.0.0 */ |
|
| 406 | - $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
|
| 407 | - |
|
| 408 | - $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) { |
|
| 409 | - return $c->get('SystemTagManagerFactory')->getObjectMapper(); |
|
| 410 | - }); |
|
| 411 | - $this->registerService('RootFolder', function (ContainerInterface $c) { |
|
| 412 | - $manager = \OC\Files\Filesystem::getMountManager(null); |
|
| 413 | - $view = new View(); |
|
| 414 | - $root = new Root( |
|
| 415 | - $manager, |
|
| 416 | - $view, |
|
| 417 | - null, |
|
| 418 | - $c->get(IUserMountCache::class), |
|
| 419 | - $this->get(ILogger::class), |
|
| 420 | - $this->get(IUserManager::class) |
|
| 421 | - ); |
|
| 422 | - |
|
| 423 | - $previewConnector = new \OC\Preview\WatcherConnector( |
|
| 424 | - $root, |
|
| 425 | - $c->get(SystemConfig::class) |
|
| 426 | - ); |
|
| 427 | - $previewConnector->connectWatcher(); |
|
| 428 | - |
|
| 429 | - return $root; |
|
| 430 | - }); |
|
| 431 | - $this->registerService(HookConnector::class, function (ContainerInterface $c) { |
|
| 432 | - return new HookConnector( |
|
| 433 | - $c->get(IRootFolder::class), |
|
| 434 | - new View(), |
|
| 435 | - $c->get(\OC\EventDispatcher\SymfonyAdapter::class), |
|
| 436 | - $c->get(IEventDispatcher::class) |
|
| 437 | - ); |
|
| 438 | - }); |
|
| 439 | - |
|
| 440 | - /** @deprecated 19.0.0 */ |
|
| 441 | - $this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class); |
|
| 442 | - |
|
| 443 | - $this->registerService(IRootFolder::class, function (ContainerInterface $c) { |
|
| 444 | - return new LazyRoot(function () use ($c) { |
|
| 445 | - return $c->get('RootFolder'); |
|
| 446 | - }); |
|
| 447 | - }); |
|
| 448 | - /** @deprecated 19.0.0 */ |
|
| 449 | - $this->registerDeprecatedAlias('LazyRootFolder', IRootFolder::class); |
|
| 450 | - |
|
| 451 | - /** @deprecated 19.0.0 */ |
|
| 452 | - $this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class); |
|
| 453 | - $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
| 454 | - |
|
| 455 | - $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) { |
|
| 456 | - $groupManager = new \OC\Group\Manager($this->get(IUserManager::class), $c->get(SymfonyAdapter::class), $this->get(ILogger::class)); |
|
| 457 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
| 458 | - /** @var IEventDispatcher $dispatcher */ |
|
| 459 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 460 | - $dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid)); |
|
| 461 | - }); |
|
| 462 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) { |
|
| 463 | - /** @var IEventDispatcher $dispatcher */ |
|
| 464 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 465 | - $dispatcher->dispatchTyped(new GroupCreatedEvent($group)); |
|
| 466 | - }); |
|
| 467 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
| 468 | - /** @var IEventDispatcher $dispatcher */ |
|
| 469 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 470 | - $dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group)); |
|
| 471 | - }); |
|
| 472 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
| 473 | - /** @var IEventDispatcher $dispatcher */ |
|
| 474 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 475 | - $dispatcher->dispatchTyped(new GroupDeletedEvent($group)); |
|
| 476 | - }); |
|
| 477 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 478 | - /** @var IEventDispatcher $dispatcher */ |
|
| 479 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 480 | - $dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user)); |
|
| 481 | - }); |
|
| 482 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 483 | - /** @var IEventDispatcher $dispatcher */ |
|
| 484 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 485 | - $dispatcher->dispatchTyped(new UserAddedEvent($group, $user)); |
|
| 486 | - }); |
|
| 487 | - $groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 488 | - /** @var IEventDispatcher $dispatcher */ |
|
| 489 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 490 | - $dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user)); |
|
| 491 | - }); |
|
| 492 | - $groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 493 | - /** @var IEventDispatcher $dispatcher */ |
|
| 494 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 495 | - $dispatcher->dispatchTyped(new UserRemovedEvent($group, $user)); |
|
| 496 | - }); |
|
| 497 | - return $groupManager; |
|
| 498 | - }); |
|
| 499 | - /** @deprecated 19.0.0 */ |
|
| 500 | - $this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class); |
|
| 501 | - |
|
| 502 | - $this->registerService(Store::class, function (ContainerInterface $c) { |
|
| 503 | - $session = $c->get(ISession::class); |
|
| 504 | - if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 505 | - $tokenProvider = $c->get(IProvider::class); |
|
| 506 | - } else { |
|
| 507 | - $tokenProvider = null; |
|
| 508 | - } |
|
| 509 | - $logger = $c->get(LoggerInterface::class); |
|
| 510 | - return new Store($session, $logger, $tokenProvider); |
|
| 511 | - }); |
|
| 512 | - $this->registerAlias(IStore::class, Store::class); |
|
| 513 | - $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
| 514 | - |
|
| 515 | - $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
| 516 | - $manager = $c->get(IUserManager::class); |
|
| 517 | - $session = new \OC\Session\Memory(''); |
|
| 518 | - $timeFactory = new TimeFactory(); |
|
| 519 | - // Token providers might require a working database. This code |
|
| 520 | - // might however be called when ownCloud is not yet setup. |
|
| 521 | - if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 522 | - $defaultTokenProvider = $c->get(IProvider::class); |
|
| 523 | - } else { |
|
| 524 | - $defaultTokenProvider = null; |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - $legacyDispatcher = $c->get(SymfonyAdapter::class); |
|
| 528 | - |
|
| 529 | - $userSession = new \OC\User\Session( |
|
| 530 | - $manager, |
|
| 531 | - $session, |
|
| 532 | - $timeFactory, |
|
| 533 | - $defaultTokenProvider, |
|
| 534 | - $c->get(\OCP\IConfig::class), |
|
| 535 | - $c->get(ISecureRandom::class), |
|
| 536 | - $c->getLockdownManager(), |
|
| 537 | - $c->get(ILogger::class), |
|
| 538 | - $c->get(IEventDispatcher::class) |
|
| 539 | - ); |
|
| 540 | - /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */ |
|
| 541 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 542 | - \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 543 | - }); |
|
| 544 | - /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */ |
|
| 545 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 546 | - /** @var \OC\User\User $user */ |
|
| 547 | - \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
|
| 548 | - }); |
|
| 549 | - /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */ |
|
| 550 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) { |
|
| 551 | - /** @var \OC\User\User $user */ |
|
| 552 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
|
| 553 | - $legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
| 554 | - }); |
|
| 555 | - /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ |
|
| 556 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 557 | - /** @var \OC\User\User $user */ |
|
| 558 | - \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
|
| 559 | - }); |
|
| 560 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 561 | - /** @var \OC\User\User $user */ |
|
| 562 | - \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 563 | - |
|
| 564 | - /** @var IEventDispatcher $dispatcher */ |
|
| 565 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 566 | - $dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
| 567 | - }); |
|
| 568 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 569 | - /** @var \OC\User\User $user */ |
|
| 570 | - \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 571 | - |
|
| 572 | - /** @var IEventDispatcher $dispatcher */ |
|
| 573 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 574 | - $dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
| 575 | - }); |
|
| 576 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 577 | - \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 578 | - |
|
| 579 | - /** @var IEventDispatcher $dispatcher */ |
|
| 580 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 581 | - $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
|
| 582 | - }); |
|
| 583 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) { |
|
| 584 | - /** @var \OC\User\User $user */ |
|
| 585 | - \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
|
| 586 | - |
|
| 587 | - /** @var IEventDispatcher $dispatcher */ |
|
| 588 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 589 | - $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin)); |
|
| 590 | - }); |
|
| 591 | - $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
| 592 | - /** @var IEventDispatcher $dispatcher */ |
|
| 593 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 594 | - $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
|
| 595 | - }); |
|
| 596 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
| 597 | - /** @var \OC\User\User $user */ |
|
| 598 | - \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
|
| 599 | - |
|
| 600 | - /** @var IEventDispatcher $dispatcher */ |
|
| 601 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 602 | - $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
|
| 603 | - }); |
|
| 604 | - $userSession->listen('\OC\User', 'logout', function ($user) { |
|
| 605 | - \OC_Hook::emit('OC_User', 'logout', []); |
|
| 606 | - |
|
| 607 | - /** @var IEventDispatcher $dispatcher */ |
|
| 608 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 609 | - $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
|
| 610 | - }); |
|
| 611 | - $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
| 612 | - /** @var IEventDispatcher $dispatcher */ |
|
| 613 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 614 | - $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
|
| 615 | - }); |
|
| 616 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 617 | - /** @var \OC\User\User $user */ |
|
| 618 | - \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
|
| 619 | - |
|
| 620 | - /** @var IEventDispatcher $dispatcher */ |
|
| 621 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
| 622 | - $dispatcher->dispatchTyped(new UserChangedEvent($user, $feature, $value, $oldValue)); |
|
| 623 | - }); |
|
| 624 | - return $userSession; |
|
| 625 | - }); |
|
| 626 | - $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
| 627 | - /** @deprecated 19.0.0 */ |
|
| 628 | - $this->registerDeprecatedAlias('UserSession', \OC\User\Session::class); |
|
| 629 | - |
|
| 630 | - $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
| 631 | - |
|
| 632 | - $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class); |
|
| 633 | - /** @deprecated 19.0.0 */ |
|
| 634 | - $this->registerDeprecatedAlias('NavigationManager', INavigationManager::class); |
|
| 635 | - |
|
| 636 | - /** @deprecated 19.0.0 */ |
|
| 637 | - $this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class); |
|
| 638 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
| 639 | - |
|
| 640 | - $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
| 641 | - return new \OC\SystemConfig($config); |
|
| 642 | - }); |
|
| 643 | - /** @deprecated 19.0.0 */ |
|
| 644 | - $this->registerDeprecatedAlias('SystemConfig', \OC\SystemConfig::class); |
|
| 645 | - |
|
| 646 | - /** @deprecated 19.0.0 */ |
|
| 647 | - $this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class); |
|
| 648 | - $this->registerAlias(IAppConfig::class, \OC\AppConfig::class); |
|
| 649 | - |
|
| 650 | - $this->registerService(IFactory::class, function (Server $c) { |
|
| 651 | - return new \OC\L10N\Factory( |
|
| 652 | - $c->get(\OCP\IConfig::class), |
|
| 653 | - $c->getRequest(), |
|
| 654 | - $c->get(IUserSession::class), |
|
| 655 | - \OC::$SERVERROOT |
|
| 656 | - ); |
|
| 657 | - }); |
|
| 658 | - /** @deprecated 19.0.0 */ |
|
| 659 | - $this->registerDeprecatedAlias('L10NFactory', IFactory::class); |
|
| 660 | - |
|
| 661 | - $this->registerAlias(IURLGenerator::class, URLGenerator::class); |
|
| 662 | - /** @deprecated 19.0.0 */ |
|
| 663 | - $this->registerDeprecatedAlias('URLGenerator', IURLGenerator::class); |
|
| 664 | - |
|
| 665 | - /** @deprecated 19.0.0 */ |
|
| 666 | - $this->registerDeprecatedAlias('AppFetcher', AppFetcher::class); |
|
| 667 | - /** @deprecated 19.0.0 */ |
|
| 668 | - $this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class); |
|
| 669 | - |
|
| 670 | - $this->registerService(ICache::class, function ($c) { |
|
| 671 | - return new Cache\File(); |
|
| 672 | - }); |
|
| 673 | - /** @deprecated 19.0.0 */ |
|
| 674 | - $this->registerDeprecatedAlias('UserCache', ICache::class); |
|
| 675 | - |
|
| 676 | - $this->registerService(Factory::class, function (Server $c) { |
|
| 677 | - $arrayCacheFactory = new \OC\Memcache\Factory('', $c->get(ILogger::class), |
|
| 678 | - ArrayCache::class, |
|
| 679 | - ArrayCache::class, |
|
| 680 | - ArrayCache::class |
|
| 681 | - ); |
|
| 682 | - /** @var \OCP\IConfig $config */ |
|
| 683 | - $config = $c->get(\OCP\IConfig::class); |
|
| 684 | - |
|
| 685 | - if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 686 | - $v = \OC_App::getAppVersions(); |
|
| 687 | - $v['core'] = implode(',', \OC_Util::getVersion()); |
|
| 688 | - $version = implode(',', $v); |
|
| 689 | - $instanceId = \OC_Util::getInstanceId(); |
|
| 690 | - $path = \OC::$SERVERROOT; |
|
| 691 | - $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
| 692 | - return new \OC\Memcache\Factory($prefix, $c->get(ILogger::class), |
|
| 693 | - $config->getSystemValue('memcache.local', null), |
|
| 694 | - $config->getSystemValue('memcache.distributed', null), |
|
| 695 | - $config->getSystemValue('memcache.locking', null) |
|
| 696 | - ); |
|
| 697 | - } |
|
| 698 | - return $arrayCacheFactory; |
|
| 699 | - }); |
|
| 700 | - /** @deprecated 19.0.0 */ |
|
| 701 | - $this->registerDeprecatedAlias('MemCacheFactory', Factory::class); |
|
| 702 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
| 703 | - |
|
| 704 | - $this->registerService('RedisFactory', function (Server $c) { |
|
| 705 | - $systemConfig = $c->get(SystemConfig::class); |
|
| 706 | - return new RedisFactory($systemConfig); |
|
| 707 | - }); |
|
| 708 | - |
|
| 709 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 710 | - $l10n = $this->get(IFactory::class)->get('lib'); |
|
| 711 | - return new \OC\Activity\Manager( |
|
| 712 | - $c->getRequest(), |
|
| 713 | - $c->get(IUserSession::class), |
|
| 714 | - $c->get(\OCP\IConfig::class), |
|
| 715 | - $c->get(IValidator::class), |
|
| 716 | - $l10n |
|
| 717 | - ); |
|
| 718 | - }); |
|
| 719 | - /** @deprecated 19.0.0 */ |
|
| 720 | - $this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
| 721 | - |
|
| 722 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 723 | - return new \OC\Activity\EventMerger( |
|
| 724 | - $c->getL10N('lib') |
|
| 725 | - ); |
|
| 726 | - }); |
|
| 727 | - $this->registerAlias(IValidator::class, Validator::class); |
|
| 728 | - |
|
| 729 | - $this->registerService(AvatarManager::class, function (Server $c) { |
|
| 730 | - return new AvatarManager( |
|
| 731 | - $c->get(IUserSession::class), |
|
| 732 | - $c->get(\OC\User\Manager::class), |
|
| 733 | - $c->getAppDataDir('avatar'), |
|
| 734 | - $c->getL10N('lib'), |
|
| 735 | - $c->get(LoggerInterface::class), |
|
| 736 | - $c->get(\OCP\IConfig::class), |
|
| 737 | - $c->get(IAccountManager::class), |
|
| 738 | - $c->get(KnownUserService::class) |
|
| 739 | - ); |
|
| 740 | - }); |
|
| 741 | - $this->registerAlias(IAvatarManager::class, AvatarManager::class); |
|
| 742 | - /** @deprecated 19.0.0 */ |
|
| 743 | - $this->registerDeprecatedAlias('AvatarManager', AvatarManager::class); |
|
| 744 | - |
|
| 745 | - $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
| 746 | - $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
| 747 | - |
|
| 748 | - $this->registerService(\OC\Log::class, function (Server $c) { |
|
| 749 | - $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file'); |
|
| 750 | - $factory = new LogFactory($c, $this->get(SystemConfig::class)); |
|
| 751 | - $logger = $factory->get($logType); |
|
| 752 | - $registry = $c->get(\OCP\Support\CrashReport\IRegistry::class); |
|
| 753 | - |
|
| 754 | - return new Log($logger, $this->get(SystemConfig::class), null, $registry); |
|
| 755 | - }); |
|
| 756 | - $this->registerAlias(ILogger::class, \OC\Log::class); |
|
| 757 | - /** @deprecated 19.0.0 */ |
|
| 758 | - $this->registerDeprecatedAlias('Logger', \OC\Log::class); |
|
| 759 | - // PSR-3 logger |
|
| 760 | - $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
|
| 761 | - |
|
| 762 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
| 763 | - return new LogFactory($c, $this->get(SystemConfig::class)); |
|
| 764 | - }); |
|
| 765 | - |
|
| 766 | - $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class); |
|
| 767 | - /** @deprecated 19.0.0 */ |
|
| 768 | - $this->registerDeprecatedAlias('JobList', IJobList::class); |
|
| 769 | - |
|
| 770 | - $this->registerService(Router::class, function (Server $c) { |
|
| 771 | - $cacheFactory = $c->get(ICacheFactory::class); |
|
| 772 | - $logger = $c->get(ILogger::class); |
|
| 773 | - if ($cacheFactory->isLocalCacheAvailable()) { |
|
| 774 | - $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
| 775 | - } else { |
|
| 776 | - $router = new \OC\Route\Router($logger); |
|
| 777 | - } |
|
| 778 | - return $router; |
|
| 779 | - }); |
|
| 780 | - $this->registerAlias(IRouter::class, Router::class); |
|
| 781 | - /** @deprecated 19.0.0 */ |
|
| 782 | - $this->registerDeprecatedAlias('Router', IRouter::class); |
|
| 783 | - |
|
| 784 | - $this->registerAlias(ISearch::class, Search::class); |
|
| 785 | - /** @deprecated 19.0.0 */ |
|
| 786 | - $this->registerDeprecatedAlias('Search', ISearch::class); |
|
| 787 | - |
|
| 788 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
| 789 | - return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
| 790 | - $this->get(ICacheFactory::class), |
|
| 791 | - new \OC\AppFramework\Utility\TimeFactory() |
|
| 792 | - ); |
|
| 793 | - }); |
|
| 794 | - |
|
| 795 | - $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class); |
|
| 796 | - /** @deprecated 19.0.0 */ |
|
| 797 | - $this->registerDeprecatedAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
| 798 | - |
|
| 799 | - $this->registerAlias(ICrypto::class, Crypto::class); |
|
| 800 | - /** @deprecated 19.0.0 */ |
|
| 801 | - $this->registerDeprecatedAlias('Crypto', ICrypto::class); |
|
| 802 | - |
|
| 803 | - $this->registerAlias(IHasher::class, Hasher::class); |
|
| 804 | - /** @deprecated 19.0.0 */ |
|
| 805 | - $this->registerDeprecatedAlias('Hasher', IHasher::class); |
|
| 806 | - |
|
| 807 | - $this->registerAlias(ICredentialsManager::class, CredentialsManager::class); |
|
| 808 | - /** @deprecated 19.0.0 */ |
|
| 809 | - $this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class); |
|
| 810 | - |
|
| 811 | - $this->registerAlias(IDBConnection::class, ConnectionAdapter::class); |
|
| 812 | - $this->registerService(Connection::class, function (Server $c) { |
|
| 813 | - $systemConfig = $c->get(SystemConfig::class); |
|
| 814 | - $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
| 815 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
| 816 | - if (!$factory->isValidType($type)) { |
|
| 817 | - throw new \OC\DatabaseException('Invalid database type'); |
|
| 818 | - } |
|
| 819 | - $connectionParams = $factory->createConnectionParams(); |
|
| 820 | - $connection = $factory->getConnection($type, $connectionParams); |
|
| 821 | - $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
| 822 | - return $connection; |
|
| 823 | - }); |
|
| 824 | - /** @deprecated 19.0.0 */ |
|
| 825 | - $this->registerDeprecatedAlias('DatabaseConnection', IDBConnection::class); |
|
| 826 | - |
|
| 827 | - $this->registerAlias(ICertificateManager::class, CertificateManager::class); |
|
| 828 | - $this->registerAlias(IClientService::class, ClientService::class); |
|
| 829 | - $this->registerService(LocalAddressChecker::class, function (ContainerInterface $c) { |
|
| 830 | - return new LocalAddressChecker( |
|
| 831 | - $c->get(ILogger::class), |
|
| 832 | - ); |
|
| 833 | - }); |
|
| 834 | - $this->registerService(NegativeDnsCache::class, function (ContainerInterface $c) { |
|
| 835 | - return new NegativeDnsCache( |
|
| 836 | - $c->get(ICacheFactory::class), |
|
| 837 | - ); |
|
| 838 | - }); |
|
| 839 | - $this->registerService(DnsPinMiddleware::class, function (ContainerInterface $c) { |
|
| 840 | - return new DnsPinMiddleware( |
|
| 841 | - $c->get(NegativeDnsCache::class), |
|
| 842 | - $c->get(LocalAddressChecker::class) |
|
| 843 | - ); |
|
| 844 | - }); |
|
| 845 | - $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
|
| 846 | - $this->registerService(IEventLogger::class, function (ContainerInterface $c) { |
|
| 847 | - $eventLogger = new EventLogger(); |
|
| 848 | - if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
|
| 849 | - // In debug mode, module is being activated by default |
|
| 850 | - $eventLogger->activate(); |
|
| 851 | - } |
|
| 852 | - return $eventLogger; |
|
| 853 | - }); |
|
| 854 | - /** @deprecated 19.0.0 */ |
|
| 855 | - $this->registerDeprecatedAlias('EventLogger', IEventLogger::class); |
|
| 856 | - |
|
| 857 | - $this->registerService(IQueryLogger::class, function (ContainerInterface $c) { |
|
| 858 | - $queryLogger = new QueryLogger(); |
|
| 859 | - if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
|
| 860 | - // In debug mode, module is being activated by default |
|
| 861 | - $queryLogger->activate(); |
|
| 862 | - } |
|
| 863 | - return $queryLogger; |
|
| 864 | - }); |
|
| 865 | - /** @deprecated 19.0.0 */ |
|
| 866 | - $this->registerDeprecatedAlias('QueryLogger', IQueryLogger::class); |
|
| 867 | - |
|
| 868 | - /** @deprecated 19.0.0 */ |
|
| 869 | - $this->registerDeprecatedAlias('TempManager', TempManager::class); |
|
| 870 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
| 871 | - |
|
| 872 | - $this->registerService(AppManager::class, function (ContainerInterface $c) { |
|
| 873 | - // TODO: use auto-wiring |
|
| 874 | - return new \OC\App\AppManager( |
|
| 875 | - $c->get(IUserSession::class), |
|
| 876 | - $c->get(\OCP\IConfig::class), |
|
| 877 | - $c->get(\OC\AppConfig::class), |
|
| 878 | - $c->get(IGroupManager::class), |
|
| 879 | - $c->get(ICacheFactory::class), |
|
| 880 | - $c->get(SymfonyAdapter::class), |
|
| 881 | - $c->get(LoggerInterface::class) |
|
| 882 | - ); |
|
| 883 | - }); |
|
| 884 | - /** @deprecated 19.0.0 */ |
|
| 885 | - $this->registerDeprecatedAlias('AppManager', AppManager::class); |
|
| 886 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
| 887 | - |
|
| 888 | - $this->registerAlias(IDateTimeZone::class, DateTimeZone::class); |
|
| 889 | - /** @deprecated 19.0.0 */ |
|
| 890 | - $this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class); |
|
| 891 | - |
|
| 892 | - $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
| 893 | - $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null); |
|
| 894 | - |
|
| 895 | - return new DateTimeFormatter( |
|
| 896 | - $c->get(IDateTimeZone::class)->getTimeZone(), |
|
| 897 | - $c->getL10N('lib', $language) |
|
| 898 | - ); |
|
| 899 | - }); |
|
| 900 | - /** @deprecated 19.0.0 */ |
|
| 901 | - $this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class); |
|
| 902 | - |
|
| 903 | - $this->registerService(IUserMountCache::class, function (ContainerInterface $c) { |
|
| 904 | - $mountCache = new UserMountCache( |
|
| 905 | - $c->get(IDBConnection::class), |
|
| 906 | - $c->get(IUserManager::class), |
|
| 907 | - $c->get(ILogger::class) |
|
| 908 | - ); |
|
| 909 | - $listener = new UserMountCacheListener($mountCache); |
|
| 910 | - $listener->listen($c->get(IUserManager::class)); |
|
| 911 | - return $mountCache; |
|
| 912 | - }); |
|
| 913 | - /** @deprecated 19.0.0 */ |
|
| 914 | - $this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class); |
|
| 915 | - |
|
| 916 | - $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) { |
|
| 917 | - $loader = \OC\Files\Filesystem::getLoader(); |
|
| 918 | - $mountCache = $c->get(IUserMountCache::class); |
|
| 919 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
| 920 | - |
|
| 921 | - // builtin providers |
|
| 922 | - |
|
| 923 | - $config = $c->get(\OCP\IConfig::class); |
|
| 924 | - $logger = $c->get(ILogger::class); |
|
| 925 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
| 926 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
| 927 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
| 928 | - $manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config)); |
|
| 929 | - |
|
| 930 | - return $manager; |
|
| 931 | - }); |
|
| 932 | - /** @deprecated 19.0.0 */ |
|
| 933 | - $this->registerDeprecatedAlias('MountConfigManager', IMountProviderCollection::class); |
|
| 934 | - |
|
| 935 | - /** @deprecated 20.0.0 */ |
|
| 936 | - $this->registerDeprecatedAlias('IniWrapper', IniGetWrapper::class); |
|
| 937 | - $this->registerService(IBus::class, function (ContainerInterface $c) { |
|
| 938 | - $busClass = $c->get(\OCP\IConfig::class)->getSystemValue('commandbus'); |
|
| 939 | - if ($busClass) { |
|
| 940 | - [$app, $class] = explode('::', $busClass, 2); |
|
| 941 | - if ($c->get(IAppManager::class)->isInstalled($app)) { |
|
| 942 | - \OC_App::loadApp($app); |
|
| 943 | - return $c->get($class); |
|
| 944 | - } else { |
|
| 945 | - throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
| 946 | - } |
|
| 947 | - } else { |
|
| 948 | - $jobList = $c->get(IJobList::class); |
|
| 949 | - return new CronBus($jobList); |
|
| 950 | - } |
|
| 951 | - }); |
|
| 952 | - $this->registerDeprecatedAlias('AsyncCommandBus', IBus::class); |
|
| 953 | - /** @deprecated 20.0.0 */ |
|
| 954 | - $this->registerDeprecatedAlias('TrustedDomainHelper', TrustedDomainHelper::class); |
|
| 955 | - /** @deprecated 19.0.0 */ |
|
| 956 | - $this->registerDeprecatedAlias('Throttler', Throttler::class); |
|
| 957 | - $this->registerService('IntegrityCodeChecker', function (ContainerInterface $c) { |
|
| 958 | - // IConfig and IAppManager requires a working database. This code |
|
| 959 | - // might however be called when ownCloud is not yet setup. |
|
| 960 | - if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 961 | - $config = $c->get(\OCP\IConfig::class); |
|
| 962 | - $appManager = $c->get(IAppManager::class); |
|
| 963 | - } else { |
|
| 964 | - $config = null; |
|
| 965 | - $appManager = null; |
|
| 966 | - } |
|
| 967 | - |
|
| 968 | - return new Checker( |
|
| 969 | - new EnvironmentHelper(), |
|
| 970 | - new FileAccessHelper(), |
|
| 971 | - new AppLocator(), |
|
| 972 | - $config, |
|
| 973 | - $c->get(ICacheFactory::class), |
|
| 974 | - $appManager, |
|
| 975 | - $c->get(IMimeTypeDetector::class) |
|
| 976 | - ); |
|
| 977 | - }); |
|
| 978 | - $this->registerService(\OCP\IRequest::class, function (ContainerInterface $c) { |
|
| 979 | - if (isset($this['urlParams'])) { |
|
| 980 | - $urlParams = $this['urlParams']; |
|
| 981 | - } else { |
|
| 982 | - $urlParams = []; |
|
| 983 | - } |
|
| 984 | - |
|
| 985 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
| 986 | - && in_array('fakeinput', stream_get_wrappers()) |
|
| 987 | - ) { |
|
| 988 | - $stream = 'fakeinput://data'; |
|
| 989 | - } else { |
|
| 990 | - $stream = 'php://input'; |
|
| 991 | - } |
|
| 992 | - |
|
| 993 | - return new Request( |
|
| 994 | - [ |
|
| 995 | - 'get' => $_GET, |
|
| 996 | - 'post' => $_POST, |
|
| 997 | - 'files' => $_FILES, |
|
| 998 | - 'server' => $_SERVER, |
|
| 999 | - 'env' => $_ENV, |
|
| 1000 | - 'cookies' => $_COOKIE, |
|
| 1001 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 1002 | - ? $_SERVER['REQUEST_METHOD'] |
|
| 1003 | - : '', |
|
| 1004 | - 'urlParams' => $urlParams, |
|
| 1005 | - ], |
|
| 1006 | - $this->get(ISecureRandom::class), |
|
| 1007 | - $this->get(\OCP\IConfig::class), |
|
| 1008 | - $this->get(CsrfTokenManager::class), |
|
| 1009 | - $stream |
|
| 1010 | - ); |
|
| 1011 | - }); |
|
| 1012 | - /** @deprecated 19.0.0 */ |
|
| 1013 | - $this->registerDeprecatedAlias('Request', \OCP\IRequest::class); |
|
| 1014 | - |
|
| 1015 | - $this->registerService(IMailer::class, function (Server $c) { |
|
| 1016 | - return new Mailer( |
|
| 1017 | - $c->get(\OCP\IConfig::class), |
|
| 1018 | - $c->get(ILogger::class), |
|
| 1019 | - $c->get(Defaults::class), |
|
| 1020 | - $c->get(IURLGenerator::class), |
|
| 1021 | - $c->getL10N('lib'), |
|
| 1022 | - $c->get(IEventDispatcher::class), |
|
| 1023 | - $c->get(IFactory::class) |
|
| 1024 | - ); |
|
| 1025 | - }); |
|
| 1026 | - /** @deprecated 19.0.0 */ |
|
| 1027 | - $this->registerDeprecatedAlias('Mailer', IMailer::class); |
|
| 1028 | - |
|
| 1029 | - /** @deprecated 21.0.0 */ |
|
| 1030 | - $this->registerDeprecatedAlias('LDAPProvider', ILDAPProvider::class); |
|
| 1031 | - |
|
| 1032 | - $this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) { |
|
| 1033 | - $config = $c->get(\OCP\IConfig::class); |
|
| 1034 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
| 1035 | - if (is_null($factoryClass)) { |
|
| 1036 | - return new NullLDAPProviderFactory($this); |
|
| 1037 | - } |
|
| 1038 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
| 1039 | - return new $factoryClass($this); |
|
| 1040 | - }); |
|
| 1041 | - $this->registerService(ILDAPProvider::class, function (ContainerInterface $c) { |
|
| 1042 | - $factory = $c->get(ILDAPProviderFactory::class); |
|
| 1043 | - return $factory->getLDAPProvider(); |
|
| 1044 | - }); |
|
| 1045 | - $this->registerService(ILockingProvider::class, function (ContainerInterface $c) { |
|
| 1046 | - $ini = $c->get(IniGetWrapper::class); |
|
| 1047 | - $config = $c->get(\OCP\IConfig::class); |
|
| 1048 | - $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
| 1049 | - if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 1050 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
| 1051 | - $memcacheFactory = $c->get(ICacheFactory::class); |
|
| 1052 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
| 1053 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
| 1054 | - return new MemcacheLockingProvider($memcache, $ttl); |
|
| 1055 | - } |
|
| 1056 | - return new DBLockingProvider( |
|
| 1057 | - $c->get(IDBConnection::class), |
|
| 1058 | - $c->get(ILogger::class), |
|
| 1059 | - new TimeFactory(), |
|
| 1060 | - $ttl, |
|
| 1061 | - !\OC::$CLI |
|
| 1062 | - ); |
|
| 1063 | - } |
|
| 1064 | - return new NoopLockingProvider(); |
|
| 1065 | - }); |
|
| 1066 | - /** @deprecated 19.0.0 */ |
|
| 1067 | - $this->registerDeprecatedAlias('LockingProvider', ILockingProvider::class); |
|
| 1068 | - |
|
| 1069 | - $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class); |
|
| 1070 | - /** @deprecated 19.0.0 */ |
|
| 1071 | - $this->registerDeprecatedAlias('MountManager', IMountManager::class); |
|
| 1072 | - |
|
| 1073 | - $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) { |
|
| 1074 | - return new \OC\Files\Type\Detection( |
|
| 1075 | - $c->get(IURLGenerator::class), |
|
| 1076 | - $c->get(ILogger::class), |
|
| 1077 | - \OC::$configDir, |
|
| 1078 | - \OC::$SERVERROOT . '/resources/config/' |
|
| 1079 | - ); |
|
| 1080 | - }); |
|
| 1081 | - /** @deprecated 19.0.0 */ |
|
| 1082 | - $this->registerDeprecatedAlias('MimeTypeDetector', IMimeTypeDetector::class); |
|
| 1083 | - |
|
| 1084 | - $this->registerAlias(IMimeTypeLoader::class, Loader::class); |
|
| 1085 | - /** @deprecated 19.0.0 */ |
|
| 1086 | - $this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class); |
|
| 1087 | - $this->registerService(BundleFetcher::class, function () { |
|
| 1088 | - return new BundleFetcher($this->getL10N('lib')); |
|
| 1089 | - }); |
|
| 1090 | - $this->registerAlias(\OCP\Notification\IManager::class, Manager::class); |
|
| 1091 | - /** @deprecated 19.0.0 */ |
|
| 1092 | - $this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
| 1093 | - |
|
| 1094 | - $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) { |
|
| 1095 | - $manager = new CapabilitiesManager($c->get(LoggerInterface::class)); |
|
| 1096 | - $manager->registerCapability(function () use ($c) { |
|
| 1097 | - return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class)); |
|
| 1098 | - }); |
|
| 1099 | - $manager->registerCapability(function () use ($c) { |
|
| 1100 | - return $c->get(\OC\Security\Bruteforce\Capabilities::class); |
|
| 1101 | - }); |
|
| 1102 | - return $manager; |
|
| 1103 | - }); |
|
| 1104 | - /** @deprecated 19.0.0 */ |
|
| 1105 | - $this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class); |
|
| 1106 | - |
|
| 1107 | - $this->registerService(ICommentsManager::class, function (Server $c) { |
|
| 1108 | - $config = $c->get(\OCP\IConfig::class); |
|
| 1109 | - $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
| 1110 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
| 1111 | - $factory = new $factoryClass($this); |
|
| 1112 | - $manager = $factory->getManager(); |
|
| 1113 | - |
|
| 1114 | - $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
| 1115 | - $manager = $c->get(IUserManager::class); |
|
| 1116 | - $user = $manager->get($id); |
|
| 1117 | - if (is_null($user)) { |
|
| 1118 | - $l = $c->getL10N('core'); |
|
| 1119 | - $displayName = $l->t('Unknown user'); |
|
| 1120 | - } else { |
|
| 1121 | - $displayName = $user->getDisplayName(); |
|
| 1122 | - } |
|
| 1123 | - return $displayName; |
|
| 1124 | - }); |
|
| 1125 | - |
|
| 1126 | - return $manager; |
|
| 1127 | - }); |
|
| 1128 | - /** @deprecated 19.0.0 */ |
|
| 1129 | - $this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class); |
|
| 1130 | - |
|
| 1131 | - $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults'); |
|
| 1132 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
| 1133 | - /* |
|
| 263 | + /** @var string */ |
|
| 264 | + private $webRoot; |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * @param string $webRoot |
|
| 268 | + * @param \OC\Config $config |
|
| 269 | + */ |
|
| 270 | + public function __construct($webRoot, \OC\Config $config) { |
|
| 271 | + parent::__construct(); |
|
| 272 | + $this->webRoot = $webRoot; |
|
| 273 | + |
|
| 274 | + // To find out if we are running from CLI or not |
|
| 275 | + $this->registerParameter('isCLI', \OC::$CLI); |
|
| 276 | + $this->registerParameter('serverRoot', \OC::$SERVERROOT); |
|
| 277 | + |
|
| 278 | + $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
| 279 | + return $c; |
|
| 280 | + }); |
|
| 281 | + $this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) { |
|
| 282 | + return $c; |
|
| 283 | + }); |
|
| 284 | + |
|
| 285 | + $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
| 286 | + /** @deprecated 19.0.0 */ |
|
| 287 | + $this->registerDeprecatedAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
| 288 | + |
|
| 289 | + $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
| 290 | + /** @deprecated 19.0.0 */ |
|
| 291 | + $this->registerDeprecatedAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class); |
|
| 292 | + |
|
| 293 | + $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
| 294 | + /** @deprecated 19.0.0 */ |
|
| 295 | + $this->registerDeprecatedAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class); |
|
| 296 | + |
|
| 297 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
| 298 | + /** @deprecated 19.0.0 */ |
|
| 299 | + $this->registerDeprecatedAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
| 300 | + |
|
| 301 | + $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class); |
|
| 302 | + $this->registerAlias(ITemplateManager::class, TemplateManager::class); |
|
| 303 | + |
|
| 304 | + $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
| 305 | + |
|
| 306 | + $this->registerService(View::class, function (Server $c) { |
|
| 307 | + return new View(); |
|
| 308 | + }, false); |
|
| 309 | + |
|
| 310 | + $this->registerService(IPreview::class, function (ContainerInterface $c) { |
|
| 311 | + return new PreviewManager( |
|
| 312 | + $c->get(\OCP\IConfig::class), |
|
| 313 | + $c->get(IRootFolder::class), |
|
| 314 | + new \OC\Preview\Storage\Root( |
|
| 315 | + $c->get(IRootFolder::class), |
|
| 316 | + $c->get(SystemConfig::class) |
|
| 317 | + ), |
|
| 318 | + $c->get(SymfonyAdapter::class), |
|
| 319 | + $c->get(GeneratorHelper::class), |
|
| 320 | + $c->get(ISession::class)->get('user_id') |
|
| 321 | + ); |
|
| 322 | + }); |
|
| 323 | + /** @deprecated 19.0.0 */ |
|
| 324 | + $this->registerDeprecatedAlias('PreviewManager', IPreview::class); |
|
| 325 | + |
|
| 326 | + $this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) { |
|
| 327 | + return new \OC\Preview\Watcher( |
|
| 328 | + new \OC\Preview\Storage\Root( |
|
| 329 | + $c->get(IRootFolder::class), |
|
| 330 | + $c->get(SystemConfig::class) |
|
| 331 | + ) |
|
| 332 | + ); |
|
| 333 | + }); |
|
| 334 | + |
|
| 335 | + $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) { |
|
| 336 | + $view = new View(); |
|
| 337 | + $util = new Encryption\Util( |
|
| 338 | + $view, |
|
| 339 | + $c->get(IUserManager::class), |
|
| 340 | + $c->get(IGroupManager::class), |
|
| 341 | + $c->get(\OCP\IConfig::class) |
|
| 342 | + ); |
|
| 343 | + return new Encryption\Manager( |
|
| 344 | + $c->get(\OCP\IConfig::class), |
|
| 345 | + $c->get(ILogger::class), |
|
| 346 | + $c->getL10N('core'), |
|
| 347 | + new View(), |
|
| 348 | + $util, |
|
| 349 | + new ArrayCache() |
|
| 350 | + ); |
|
| 351 | + }); |
|
| 352 | + /** @deprecated 19.0.0 */ |
|
| 353 | + $this->registerDeprecatedAlias('EncryptionManager', \OCP\Encryption\IManager::class); |
|
| 354 | + |
|
| 355 | + /** @deprecated 21.0.0 */ |
|
| 356 | + $this->registerDeprecatedAlias('EncryptionFileHelper', IFile::class); |
|
| 357 | + $this->registerService(IFile::class, function (ContainerInterface $c) { |
|
| 358 | + $util = new Encryption\Util( |
|
| 359 | + new View(), |
|
| 360 | + $c->get(IUserManager::class), |
|
| 361 | + $c->get(IGroupManager::class), |
|
| 362 | + $c->get(\OCP\IConfig::class) |
|
| 363 | + ); |
|
| 364 | + return new Encryption\File( |
|
| 365 | + $util, |
|
| 366 | + $c->get(IRootFolder::class), |
|
| 367 | + $c->get(\OCP\Share\IManager::class) |
|
| 368 | + ); |
|
| 369 | + }); |
|
| 370 | + |
|
| 371 | + /** @deprecated 21.0.0 */ |
|
| 372 | + $this->registerDeprecatedAlias('EncryptionKeyStorage', IStorage::class); |
|
| 373 | + $this->registerService(IStorage::class, function (ContainerInterface $c) { |
|
| 374 | + $view = new View(); |
|
| 375 | + $util = new Encryption\Util( |
|
| 376 | + $view, |
|
| 377 | + $c->get(IUserManager::class), |
|
| 378 | + $c->get(IGroupManager::class), |
|
| 379 | + $c->get(\OCP\IConfig::class) |
|
| 380 | + ); |
|
| 381 | + |
|
| 382 | + return new Encryption\Keys\Storage( |
|
| 383 | + $view, |
|
| 384 | + $util, |
|
| 385 | + $c->get(ICrypto::class), |
|
| 386 | + $c->get(\OCP\IConfig::class) |
|
| 387 | + ); |
|
| 388 | + }); |
|
| 389 | + /** @deprecated 20.0.0 */ |
|
| 390 | + $this->registerDeprecatedAlias('TagMapper', TagMapper::class); |
|
| 391 | + |
|
| 392 | + $this->registerAlias(\OCP\ITagManager::class, TagManager::class); |
|
| 393 | + /** @deprecated 19.0.0 */ |
|
| 394 | + $this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class); |
|
| 395 | + |
|
| 396 | + $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) { |
|
| 397 | + /** @var \OCP\IConfig $config */ |
|
| 398 | + $config = $c->get(\OCP\IConfig::class); |
|
| 399 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
| 400 | + return new $factoryClass($this); |
|
| 401 | + }); |
|
| 402 | + $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) { |
|
| 403 | + return $c->get('SystemTagManagerFactory')->getManager(); |
|
| 404 | + }); |
|
| 405 | + /** @deprecated 19.0.0 */ |
|
| 406 | + $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
|
| 407 | + |
|
| 408 | + $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) { |
|
| 409 | + return $c->get('SystemTagManagerFactory')->getObjectMapper(); |
|
| 410 | + }); |
|
| 411 | + $this->registerService('RootFolder', function (ContainerInterface $c) { |
|
| 412 | + $manager = \OC\Files\Filesystem::getMountManager(null); |
|
| 413 | + $view = new View(); |
|
| 414 | + $root = new Root( |
|
| 415 | + $manager, |
|
| 416 | + $view, |
|
| 417 | + null, |
|
| 418 | + $c->get(IUserMountCache::class), |
|
| 419 | + $this->get(ILogger::class), |
|
| 420 | + $this->get(IUserManager::class) |
|
| 421 | + ); |
|
| 422 | + |
|
| 423 | + $previewConnector = new \OC\Preview\WatcherConnector( |
|
| 424 | + $root, |
|
| 425 | + $c->get(SystemConfig::class) |
|
| 426 | + ); |
|
| 427 | + $previewConnector->connectWatcher(); |
|
| 428 | + |
|
| 429 | + return $root; |
|
| 430 | + }); |
|
| 431 | + $this->registerService(HookConnector::class, function (ContainerInterface $c) { |
|
| 432 | + return new HookConnector( |
|
| 433 | + $c->get(IRootFolder::class), |
|
| 434 | + new View(), |
|
| 435 | + $c->get(\OC\EventDispatcher\SymfonyAdapter::class), |
|
| 436 | + $c->get(IEventDispatcher::class) |
|
| 437 | + ); |
|
| 438 | + }); |
|
| 439 | + |
|
| 440 | + /** @deprecated 19.0.0 */ |
|
| 441 | + $this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class); |
|
| 442 | + |
|
| 443 | + $this->registerService(IRootFolder::class, function (ContainerInterface $c) { |
|
| 444 | + return new LazyRoot(function () use ($c) { |
|
| 445 | + return $c->get('RootFolder'); |
|
| 446 | + }); |
|
| 447 | + }); |
|
| 448 | + /** @deprecated 19.0.0 */ |
|
| 449 | + $this->registerDeprecatedAlias('LazyRootFolder', IRootFolder::class); |
|
| 450 | + |
|
| 451 | + /** @deprecated 19.0.0 */ |
|
| 452 | + $this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class); |
|
| 453 | + $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
| 454 | + |
|
| 455 | + $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) { |
|
| 456 | + $groupManager = new \OC\Group\Manager($this->get(IUserManager::class), $c->get(SymfonyAdapter::class), $this->get(ILogger::class)); |
|
| 457 | + $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
| 458 | + /** @var IEventDispatcher $dispatcher */ |
|
| 459 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 460 | + $dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid)); |
|
| 461 | + }); |
|
| 462 | + $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) { |
|
| 463 | + /** @var IEventDispatcher $dispatcher */ |
|
| 464 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 465 | + $dispatcher->dispatchTyped(new GroupCreatedEvent($group)); |
|
| 466 | + }); |
|
| 467 | + $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
| 468 | + /** @var IEventDispatcher $dispatcher */ |
|
| 469 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 470 | + $dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group)); |
|
| 471 | + }); |
|
| 472 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
| 473 | + /** @var IEventDispatcher $dispatcher */ |
|
| 474 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 475 | + $dispatcher->dispatchTyped(new GroupDeletedEvent($group)); |
|
| 476 | + }); |
|
| 477 | + $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 478 | + /** @var IEventDispatcher $dispatcher */ |
|
| 479 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 480 | + $dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user)); |
|
| 481 | + }); |
|
| 482 | + $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 483 | + /** @var IEventDispatcher $dispatcher */ |
|
| 484 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 485 | + $dispatcher->dispatchTyped(new UserAddedEvent($group, $user)); |
|
| 486 | + }); |
|
| 487 | + $groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 488 | + /** @var IEventDispatcher $dispatcher */ |
|
| 489 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 490 | + $dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user)); |
|
| 491 | + }); |
|
| 492 | + $groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 493 | + /** @var IEventDispatcher $dispatcher */ |
|
| 494 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 495 | + $dispatcher->dispatchTyped(new UserRemovedEvent($group, $user)); |
|
| 496 | + }); |
|
| 497 | + return $groupManager; |
|
| 498 | + }); |
|
| 499 | + /** @deprecated 19.0.0 */ |
|
| 500 | + $this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class); |
|
| 501 | + |
|
| 502 | + $this->registerService(Store::class, function (ContainerInterface $c) { |
|
| 503 | + $session = $c->get(ISession::class); |
|
| 504 | + if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 505 | + $tokenProvider = $c->get(IProvider::class); |
|
| 506 | + } else { |
|
| 507 | + $tokenProvider = null; |
|
| 508 | + } |
|
| 509 | + $logger = $c->get(LoggerInterface::class); |
|
| 510 | + return new Store($session, $logger, $tokenProvider); |
|
| 511 | + }); |
|
| 512 | + $this->registerAlias(IStore::class, Store::class); |
|
| 513 | + $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
| 514 | + |
|
| 515 | + $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
| 516 | + $manager = $c->get(IUserManager::class); |
|
| 517 | + $session = new \OC\Session\Memory(''); |
|
| 518 | + $timeFactory = new TimeFactory(); |
|
| 519 | + // Token providers might require a working database. This code |
|
| 520 | + // might however be called when ownCloud is not yet setup. |
|
| 521 | + if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 522 | + $defaultTokenProvider = $c->get(IProvider::class); |
|
| 523 | + } else { |
|
| 524 | + $defaultTokenProvider = null; |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + $legacyDispatcher = $c->get(SymfonyAdapter::class); |
|
| 528 | + |
|
| 529 | + $userSession = new \OC\User\Session( |
|
| 530 | + $manager, |
|
| 531 | + $session, |
|
| 532 | + $timeFactory, |
|
| 533 | + $defaultTokenProvider, |
|
| 534 | + $c->get(\OCP\IConfig::class), |
|
| 535 | + $c->get(ISecureRandom::class), |
|
| 536 | + $c->getLockdownManager(), |
|
| 537 | + $c->get(ILogger::class), |
|
| 538 | + $c->get(IEventDispatcher::class) |
|
| 539 | + ); |
|
| 540 | + /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */ |
|
| 541 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 542 | + \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 543 | + }); |
|
| 544 | + /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */ |
|
| 545 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 546 | + /** @var \OC\User\User $user */ |
|
| 547 | + \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
|
| 548 | + }); |
|
| 549 | + /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */ |
|
| 550 | + $userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) { |
|
| 551 | + /** @var \OC\User\User $user */ |
|
| 552 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
|
| 553 | + $legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
| 554 | + }); |
|
| 555 | + /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ |
|
| 556 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 557 | + /** @var \OC\User\User $user */ |
|
| 558 | + \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
|
| 559 | + }); |
|
| 560 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 561 | + /** @var \OC\User\User $user */ |
|
| 562 | + \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 563 | + |
|
| 564 | + /** @var IEventDispatcher $dispatcher */ |
|
| 565 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 566 | + $dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
| 567 | + }); |
|
| 568 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 569 | + /** @var \OC\User\User $user */ |
|
| 570 | + \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
| 571 | + |
|
| 572 | + /** @var IEventDispatcher $dispatcher */ |
|
| 573 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 574 | + $dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
| 575 | + }); |
|
| 576 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 577 | + \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
| 578 | + |
|
| 579 | + /** @var IEventDispatcher $dispatcher */ |
|
| 580 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 581 | + $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
|
| 582 | + }); |
|
| 583 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) { |
|
| 584 | + /** @var \OC\User\User $user */ |
|
| 585 | + \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
|
| 586 | + |
|
| 587 | + /** @var IEventDispatcher $dispatcher */ |
|
| 588 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 589 | + $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin)); |
|
| 590 | + }); |
|
| 591 | + $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
| 592 | + /** @var IEventDispatcher $dispatcher */ |
|
| 593 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 594 | + $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
|
| 595 | + }); |
|
| 596 | + $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
| 597 | + /** @var \OC\User\User $user */ |
|
| 598 | + \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
|
| 599 | + |
|
| 600 | + /** @var IEventDispatcher $dispatcher */ |
|
| 601 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 602 | + $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
|
| 603 | + }); |
|
| 604 | + $userSession->listen('\OC\User', 'logout', function ($user) { |
|
| 605 | + \OC_Hook::emit('OC_User', 'logout', []); |
|
| 606 | + |
|
| 607 | + /** @var IEventDispatcher $dispatcher */ |
|
| 608 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 609 | + $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
|
| 610 | + }); |
|
| 611 | + $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
| 612 | + /** @var IEventDispatcher $dispatcher */ |
|
| 613 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 614 | + $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
|
| 615 | + }); |
|
| 616 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 617 | + /** @var \OC\User\User $user */ |
|
| 618 | + \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
|
| 619 | + |
|
| 620 | + /** @var IEventDispatcher $dispatcher */ |
|
| 621 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
| 622 | + $dispatcher->dispatchTyped(new UserChangedEvent($user, $feature, $value, $oldValue)); |
|
| 623 | + }); |
|
| 624 | + return $userSession; |
|
| 625 | + }); |
|
| 626 | + $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
| 627 | + /** @deprecated 19.0.0 */ |
|
| 628 | + $this->registerDeprecatedAlias('UserSession', \OC\User\Session::class); |
|
| 629 | + |
|
| 630 | + $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
| 631 | + |
|
| 632 | + $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class); |
|
| 633 | + /** @deprecated 19.0.0 */ |
|
| 634 | + $this->registerDeprecatedAlias('NavigationManager', INavigationManager::class); |
|
| 635 | + |
|
| 636 | + /** @deprecated 19.0.0 */ |
|
| 637 | + $this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class); |
|
| 638 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
| 639 | + |
|
| 640 | + $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
| 641 | + return new \OC\SystemConfig($config); |
|
| 642 | + }); |
|
| 643 | + /** @deprecated 19.0.0 */ |
|
| 644 | + $this->registerDeprecatedAlias('SystemConfig', \OC\SystemConfig::class); |
|
| 645 | + |
|
| 646 | + /** @deprecated 19.0.0 */ |
|
| 647 | + $this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class); |
|
| 648 | + $this->registerAlias(IAppConfig::class, \OC\AppConfig::class); |
|
| 649 | + |
|
| 650 | + $this->registerService(IFactory::class, function (Server $c) { |
|
| 651 | + return new \OC\L10N\Factory( |
|
| 652 | + $c->get(\OCP\IConfig::class), |
|
| 653 | + $c->getRequest(), |
|
| 654 | + $c->get(IUserSession::class), |
|
| 655 | + \OC::$SERVERROOT |
|
| 656 | + ); |
|
| 657 | + }); |
|
| 658 | + /** @deprecated 19.0.0 */ |
|
| 659 | + $this->registerDeprecatedAlias('L10NFactory', IFactory::class); |
|
| 660 | + |
|
| 661 | + $this->registerAlias(IURLGenerator::class, URLGenerator::class); |
|
| 662 | + /** @deprecated 19.0.0 */ |
|
| 663 | + $this->registerDeprecatedAlias('URLGenerator', IURLGenerator::class); |
|
| 664 | + |
|
| 665 | + /** @deprecated 19.0.0 */ |
|
| 666 | + $this->registerDeprecatedAlias('AppFetcher', AppFetcher::class); |
|
| 667 | + /** @deprecated 19.0.0 */ |
|
| 668 | + $this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class); |
|
| 669 | + |
|
| 670 | + $this->registerService(ICache::class, function ($c) { |
|
| 671 | + return new Cache\File(); |
|
| 672 | + }); |
|
| 673 | + /** @deprecated 19.0.0 */ |
|
| 674 | + $this->registerDeprecatedAlias('UserCache', ICache::class); |
|
| 675 | + |
|
| 676 | + $this->registerService(Factory::class, function (Server $c) { |
|
| 677 | + $arrayCacheFactory = new \OC\Memcache\Factory('', $c->get(ILogger::class), |
|
| 678 | + ArrayCache::class, |
|
| 679 | + ArrayCache::class, |
|
| 680 | + ArrayCache::class |
|
| 681 | + ); |
|
| 682 | + /** @var \OCP\IConfig $config */ |
|
| 683 | + $config = $c->get(\OCP\IConfig::class); |
|
| 684 | + |
|
| 685 | + if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 686 | + $v = \OC_App::getAppVersions(); |
|
| 687 | + $v['core'] = implode(',', \OC_Util::getVersion()); |
|
| 688 | + $version = implode(',', $v); |
|
| 689 | + $instanceId = \OC_Util::getInstanceId(); |
|
| 690 | + $path = \OC::$SERVERROOT; |
|
| 691 | + $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
| 692 | + return new \OC\Memcache\Factory($prefix, $c->get(ILogger::class), |
|
| 693 | + $config->getSystemValue('memcache.local', null), |
|
| 694 | + $config->getSystemValue('memcache.distributed', null), |
|
| 695 | + $config->getSystemValue('memcache.locking', null) |
|
| 696 | + ); |
|
| 697 | + } |
|
| 698 | + return $arrayCacheFactory; |
|
| 699 | + }); |
|
| 700 | + /** @deprecated 19.0.0 */ |
|
| 701 | + $this->registerDeprecatedAlias('MemCacheFactory', Factory::class); |
|
| 702 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
| 703 | + |
|
| 704 | + $this->registerService('RedisFactory', function (Server $c) { |
|
| 705 | + $systemConfig = $c->get(SystemConfig::class); |
|
| 706 | + return new RedisFactory($systemConfig); |
|
| 707 | + }); |
|
| 708 | + |
|
| 709 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 710 | + $l10n = $this->get(IFactory::class)->get('lib'); |
|
| 711 | + return new \OC\Activity\Manager( |
|
| 712 | + $c->getRequest(), |
|
| 713 | + $c->get(IUserSession::class), |
|
| 714 | + $c->get(\OCP\IConfig::class), |
|
| 715 | + $c->get(IValidator::class), |
|
| 716 | + $l10n |
|
| 717 | + ); |
|
| 718 | + }); |
|
| 719 | + /** @deprecated 19.0.0 */ |
|
| 720 | + $this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
| 721 | + |
|
| 722 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 723 | + return new \OC\Activity\EventMerger( |
|
| 724 | + $c->getL10N('lib') |
|
| 725 | + ); |
|
| 726 | + }); |
|
| 727 | + $this->registerAlias(IValidator::class, Validator::class); |
|
| 728 | + |
|
| 729 | + $this->registerService(AvatarManager::class, function (Server $c) { |
|
| 730 | + return new AvatarManager( |
|
| 731 | + $c->get(IUserSession::class), |
|
| 732 | + $c->get(\OC\User\Manager::class), |
|
| 733 | + $c->getAppDataDir('avatar'), |
|
| 734 | + $c->getL10N('lib'), |
|
| 735 | + $c->get(LoggerInterface::class), |
|
| 736 | + $c->get(\OCP\IConfig::class), |
|
| 737 | + $c->get(IAccountManager::class), |
|
| 738 | + $c->get(KnownUserService::class) |
|
| 739 | + ); |
|
| 740 | + }); |
|
| 741 | + $this->registerAlias(IAvatarManager::class, AvatarManager::class); |
|
| 742 | + /** @deprecated 19.0.0 */ |
|
| 743 | + $this->registerDeprecatedAlias('AvatarManager', AvatarManager::class); |
|
| 744 | + |
|
| 745 | + $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
| 746 | + $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
| 747 | + |
|
| 748 | + $this->registerService(\OC\Log::class, function (Server $c) { |
|
| 749 | + $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file'); |
|
| 750 | + $factory = new LogFactory($c, $this->get(SystemConfig::class)); |
|
| 751 | + $logger = $factory->get($logType); |
|
| 752 | + $registry = $c->get(\OCP\Support\CrashReport\IRegistry::class); |
|
| 753 | + |
|
| 754 | + return new Log($logger, $this->get(SystemConfig::class), null, $registry); |
|
| 755 | + }); |
|
| 756 | + $this->registerAlias(ILogger::class, \OC\Log::class); |
|
| 757 | + /** @deprecated 19.0.0 */ |
|
| 758 | + $this->registerDeprecatedAlias('Logger', \OC\Log::class); |
|
| 759 | + // PSR-3 logger |
|
| 760 | + $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
|
| 761 | + |
|
| 762 | + $this->registerService(ILogFactory::class, function (Server $c) { |
|
| 763 | + return new LogFactory($c, $this->get(SystemConfig::class)); |
|
| 764 | + }); |
|
| 765 | + |
|
| 766 | + $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class); |
|
| 767 | + /** @deprecated 19.0.0 */ |
|
| 768 | + $this->registerDeprecatedAlias('JobList', IJobList::class); |
|
| 769 | + |
|
| 770 | + $this->registerService(Router::class, function (Server $c) { |
|
| 771 | + $cacheFactory = $c->get(ICacheFactory::class); |
|
| 772 | + $logger = $c->get(ILogger::class); |
|
| 773 | + if ($cacheFactory->isLocalCacheAvailable()) { |
|
| 774 | + $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
| 775 | + } else { |
|
| 776 | + $router = new \OC\Route\Router($logger); |
|
| 777 | + } |
|
| 778 | + return $router; |
|
| 779 | + }); |
|
| 780 | + $this->registerAlias(IRouter::class, Router::class); |
|
| 781 | + /** @deprecated 19.0.0 */ |
|
| 782 | + $this->registerDeprecatedAlias('Router', IRouter::class); |
|
| 783 | + |
|
| 784 | + $this->registerAlias(ISearch::class, Search::class); |
|
| 785 | + /** @deprecated 19.0.0 */ |
|
| 786 | + $this->registerDeprecatedAlias('Search', ISearch::class); |
|
| 787 | + |
|
| 788 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
| 789 | + return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
| 790 | + $this->get(ICacheFactory::class), |
|
| 791 | + new \OC\AppFramework\Utility\TimeFactory() |
|
| 792 | + ); |
|
| 793 | + }); |
|
| 794 | + |
|
| 795 | + $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class); |
|
| 796 | + /** @deprecated 19.0.0 */ |
|
| 797 | + $this->registerDeprecatedAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
| 798 | + |
|
| 799 | + $this->registerAlias(ICrypto::class, Crypto::class); |
|
| 800 | + /** @deprecated 19.0.0 */ |
|
| 801 | + $this->registerDeprecatedAlias('Crypto', ICrypto::class); |
|
| 802 | + |
|
| 803 | + $this->registerAlias(IHasher::class, Hasher::class); |
|
| 804 | + /** @deprecated 19.0.0 */ |
|
| 805 | + $this->registerDeprecatedAlias('Hasher', IHasher::class); |
|
| 806 | + |
|
| 807 | + $this->registerAlias(ICredentialsManager::class, CredentialsManager::class); |
|
| 808 | + /** @deprecated 19.0.0 */ |
|
| 809 | + $this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class); |
|
| 810 | + |
|
| 811 | + $this->registerAlias(IDBConnection::class, ConnectionAdapter::class); |
|
| 812 | + $this->registerService(Connection::class, function (Server $c) { |
|
| 813 | + $systemConfig = $c->get(SystemConfig::class); |
|
| 814 | + $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
| 815 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
| 816 | + if (!$factory->isValidType($type)) { |
|
| 817 | + throw new \OC\DatabaseException('Invalid database type'); |
|
| 818 | + } |
|
| 819 | + $connectionParams = $factory->createConnectionParams(); |
|
| 820 | + $connection = $factory->getConnection($type, $connectionParams); |
|
| 821 | + $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
| 822 | + return $connection; |
|
| 823 | + }); |
|
| 824 | + /** @deprecated 19.0.0 */ |
|
| 825 | + $this->registerDeprecatedAlias('DatabaseConnection', IDBConnection::class); |
|
| 826 | + |
|
| 827 | + $this->registerAlias(ICertificateManager::class, CertificateManager::class); |
|
| 828 | + $this->registerAlias(IClientService::class, ClientService::class); |
|
| 829 | + $this->registerService(LocalAddressChecker::class, function (ContainerInterface $c) { |
|
| 830 | + return new LocalAddressChecker( |
|
| 831 | + $c->get(ILogger::class), |
|
| 832 | + ); |
|
| 833 | + }); |
|
| 834 | + $this->registerService(NegativeDnsCache::class, function (ContainerInterface $c) { |
|
| 835 | + return new NegativeDnsCache( |
|
| 836 | + $c->get(ICacheFactory::class), |
|
| 837 | + ); |
|
| 838 | + }); |
|
| 839 | + $this->registerService(DnsPinMiddleware::class, function (ContainerInterface $c) { |
|
| 840 | + return new DnsPinMiddleware( |
|
| 841 | + $c->get(NegativeDnsCache::class), |
|
| 842 | + $c->get(LocalAddressChecker::class) |
|
| 843 | + ); |
|
| 844 | + }); |
|
| 845 | + $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
|
| 846 | + $this->registerService(IEventLogger::class, function (ContainerInterface $c) { |
|
| 847 | + $eventLogger = new EventLogger(); |
|
| 848 | + if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
|
| 849 | + // In debug mode, module is being activated by default |
|
| 850 | + $eventLogger->activate(); |
|
| 851 | + } |
|
| 852 | + return $eventLogger; |
|
| 853 | + }); |
|
| 854 | + /** @deprecated 19.0.0 */ |
|
| 855 | + $this->registerDeprecatedAlias('EventLogger', IEventLogger::class); |
|
| 856 | + |
|
| 857 | + $this->registerService(IQueryLogger::class, function (ContainerInterface $c) { |
|
| 858 | + $queryLogger = new QueryLogger(); |
|
| 859 | + if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
|
| 860 | + // In debug mode, module is being activated by default |
|
| 861 | + $queryLogger->activate(); |
|
| 862 | + } |
|
| 863 | + return $queryLogger; |
|
| 864 | + }); |
|
| 865 | + /** @deprecated 19.0.0 */ |
|
| 866 | + $this->registerDeprecatedAlias('QueryLogger', IQueryLogger::class); |
|
| 867 | + |
|
| 868 | + /** @deprecated 19.0.0 */ |
|
| 869 | + $this->registerDeprecatedAlias('TempManager', TempManager::class); |
|
| 870 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
| 871 | + |
|
| 872 | + $this->registerService(AppManager::class, function (ContainerInterface $c) { |
|
| 873 | + // TODO: use auto-wiring |
|
| 874 | + return new \OC\App\AppManager( |
|
| 875 | + $c->get(IUserSession::class), |
|
| 876 | + $c->get(\OCP\IConfig::class), |
|
| 877 | + $c->get(\OC\AppConfig::class), |
|
| 878 | + $c->get(IGroupManager::class), |
|
| 879 | + $c->get(ICacheFactory::class), |
|
| 880 | + $c->get(SymfonyAdapter::class), |
|
| 881 | + $c->get(LoggerInterface::class) |
|
| 882 | + ); |
|
| 883 | + }); |
|
| 884 | + /** @deprecated 19.0.0 */ |
|
| 885 | + $this->registerDeprecatedAlias('AppManager', AppManager::class); |
|
| 886 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
| 887 | + |
|
| 888 | + $this->registerAlias(IDateTimeZone::class, DateTimeZone::class); |
|
| 889 | + /** @deprecated 19.0.0 */ |
|
| 890 | + $this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class); |
|
| 891 | + |
|
| 892 | + $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
| 893 | + $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null); |
|
| 894 | + |
|
| 895 | + return new DateTimeFormatter( |
|
| 896 | + $c->get(IDateTimeZone::class)->getTimeZone(), |
|
| 897 | + $c->getL10N('lib', $language) |
|
| 898 | + ); |
|
| 899 | + }); |
|
| 900 | + /** @deprecated 19.0.0 */ |
|
| 901 | + $this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class); |
|
| 902 | + |
|
| 903 | + $this->registerService(IUserMountCache::class, function (ContainerInterface $c) { |
|
| 904 | + $mountCache = new UserMountCache( |
|
| 905 | + $c->get(IDBConnection::class), |
|
| 906 | + $c->get(IUserManager::class), |
|
| 907 | + $c->get(ILogger::class) |
|
| 908 | + ); |
|
| 909 | + $listener = new UserMountCacheListener($mountCache); |
|
| 910 | + $listener->listen($c->get(IUserManager::class)); |
|
| 911 | + return $mountCache; |
|
| 912 | + }); |
|
| 913 | + /** @deprecated 19.0.0 */ |
|
| 914 | + $this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class); |
|
| 915 | + |
|
| 916 | + $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) { |
|
| 917 | + $loader = \OC\Files\Filesystem::getLoader(); |
|
| 918 | + $mountCache = $c->get(IUserMountCache::class); |
|
| 919 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
| 920 | + |
|
| 921 | + // builtin providers |
|
| 922 | + |
|
| 923 | + $config = $c->get(\OCP\IConfig::class); |
|
| 924 | + $logger = $c->get(ILogger::class); |
|
| 925 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
| 926 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
| 927 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
| 928 | + $manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config)); |
|
| 929 | + |
|
| 930 | + return $manager; |
|
| 931 | + }); |
|
| 932 | + /** @deprecated 19.0.0 */ |
|
| 933 | + $this->registerDeprecatedAlias('MountConfigManager', IMountProviderCollection::class); |
|
| 934 | + |
|
| 935 | + /** @deprecated 20.0.0 */ |
|
| 936 | + $this->registerDeprecatedAlias('IniWrapper', IniGetWrapper::class); |
|
| 937 | + $this->registerService(IBus::class, function (ContainerInterface $c) { |
|
| 938 | + $busClass = $c->get(\OCP\IConfig::class)->getSystemValue('commandbus'); |
|
| 939 | + if ($busClass) { |
|
| 940 | + [$app, $class] = explode('::', $busClass, 2); |
|
| 941 | + if ($c->get(IAppManager::class)->isInstalled($app)) { |
|
| 942 | + \OC_App::loadApp($app); |
|
| 943 | + return $c->get($class); |
|
| 944 | + } else { |
|
| 945 | + throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
| 946 | + } |
|
| 947 | + } else { |
|
| 948 | + $jobList = $c->get(IJobList::class); |
|
| 949 | + return new CronBus($jobList); |
|
| 950 | + } |
|
| 951 | + }); |
|
| 952 | + $this->registerDeprecatedAlias('AsyncCommandBus', IBus::class); |
|
| 953 | + /** @deprecated 20.0.0 */ |
|
| 954 | + $this->registerDeprecatedAlias('TrustedDomainHelper', TrustedDomainHelper::class); |
|
| 955 | + /** @deprecated 19.0.0 */ |
|
| 956 | + $this->registerDeprecatedAlias('Throttler', Throttler::class); |
|
| 957 | + $this->registerService('IntegrityCodeChecker', function (ContainerInterface $c) { |
|
| 958 | + // IConfig and IAppManager requires a working database. This code |
|
| 959 | + // might however be called when ownCloud is not yet setup. |
|
| 960 | + if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
| 961 | + $config = $c->get(\OCP\IConfig::class); |
|
| 962 | + $appManager = $c->get(IAppManager::class); |
|
| 963 | + } else { |
|
| 964 | + $config = null; |
|
| 965 | + $appManager = null; |
|
| 966 | + } |
|
| 967 | + |
|
| 968 | + return new Checker( |
|
| 969 | + new EnvironmentHelper(), |
|
| 970 | + new FileAccessHelper(), |
|
| 971 | + new AppLocator(), |
|
| 972 | + $config, |
|
| 973 | + $c->get(ICacheFactory::class), |
|
| 974 | + $appManager, |
|
| 975 | + $c->get(IMimeTypeDetector::class) |
|
| 976 | + ); |
|
| 977 | + }); |
|
| 978 | + $this->registerService(\OCP\IRequest::class, function (ContainerInterface $c) { |
|
| 979 | + if (isset($this['urlParams'])) { |
|
| 980 | + $urlParams = $this['urlParams']; |
|
| 981 | + } else { |
|
| 982 | + $urlParams = []; |
|
| 983 | + } |
|
| 984 | + |
|
| 985 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
| 986 | + && in_array('fakeinput', stream_get_wrappers()) |
|
| 987 | + ) { |
|
| 988 | + $stream = 'fakeinput://data'; |
|
| 989 | + } else { |
|
| 990 | + $stream = 'php://input'; |
|
| 991 | + } |
|
| 992 | + |
|
| 993 | + return new Request( |
|
| 994 | + [ |
|
| 995 | + 'get' => $_GET, |
|
| 996 | + 'post' => $_POST, |
|
| 997 | + 'files' => $_FILES, |
|
| 998 | + 'server' => $_SERVER, |
|
| 999 | + 'env' => $_ENV, |
|
| 1000 | + 'cookies' => $_COOKIE, |
|
| 1001 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 1002 | + ? $_SERVER['REQUEST_METHOD'] |
|
| 1003 | + : '', |
|
| 1004 | + 'urlParams' => $urlParams, |
|
| 1005 | + ], |
|
| 1006 | + $this->get(ISecureRandom::class), |
|
| 1007 | + $this->get(\OCP\IConfig::class), |
|
| 1008 | + $this->get(CsrfTokenManager::class), |
|
| 1009 | + $stream |
|
| 1010 | + ); |
|
| 1011 | + }); |
|
| 1012 | + /** @deprecated 19.0.0 */ |
|
| 1013 | + $this->registerDeprecatedAlias('Request', \OCP\IRequest::class); |
|
| 1014 | + |
|
| 1015 | + $this->registerService(IMailer::class, function (Server $c) { |
|
| 1016 | + return new Mailer( |
|
| 1017 | + $c->get(\OCP\IConfig::class), |
|
| 1018 | + $c->get(ILogger::class), |
|
| 1019 | + $c->get(Defaults::class), |
|
| 1020 | + $c->get(IURLGenerator::class), |
|
| 1021 | + $c->getL10N('lib'), |
|
| 1022 | + $c->get(IEventDispatcher::class), |
|
| 1023 | + $c->get(IFactory::class) |
|
| 1024 | + ); |
|
| 1025 | + }); |
|
| 1026 | + /** @deprecated 19.0.0 */ |
|
| 1027 | + $this->registerDeprecatedAlias('Mailer', IMailer::class); |
|
| 1028 | + |
|
| 1029 | + /** @deprecated 21.0.0 */ |
|
| 1030 | + $this->registerDeprecatedAlias('LDAPProvider', ILDAPProvider::class); |
|
| 1031 | + |
|
| 1032 | + $this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) { |
|
| 1033 | + $config = $c->get(\OCP\IConfig::class); |
|
| 1034 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
| 1035 | + if (is_null($factoryClass)) { |
|
| 1036 | + return new NullLDAPProviderFactory($this); |
|
| 1037 | + } |
|
| 1038 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
| 1039 | + return new $factoryClass($this); |
|
| 1040 | + }); |
|
| 1041 | + $this->registerService(ILDAPProvider::class, function (ContainerInterface $c) { |
|
| 1042 | + $factory = $c->get(ILDAPProviderFactory::class); |
|
| 1043 | + return $factory->getLDAPProvider(); |
|
| 1044 | + }); |
|
| 1045 | + $this->registerService(ILockingProvider::class, function (ContainerInterface $c) { |
|
| 1046 | + $ini = $c->get(IniGetWrapper::class); |
|
| 1047 | + $config = $c->get(\OCP\IConfig::class); |
|
| 1048 | + $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
| 1049 | + if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 1050 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
| 1051 | + $memcacheFactory = $c->get(ICacheFactory::class); |
|
| 1052 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
| 1053 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
| 1054 | + return new MemcacheLockingProvider($memcache, $ttl); |
|
| 1055 | + } |
|
| 1056 | + return new DBLockingProvider( |
|
| 1057 | + $c->get(IDBConnection::class), |
|
| 1058 | + $c->get(ILogger::class), |
|
| 1059 | + new TimeFactory(), |
|
| 1060 | + $ttl, |
|
| 1061 | + !\OC::$CLI |
|
| 1062 | + ); |
|
| 1063 | + } |
|
| 1064 | + return new NoopLockingProvider(); |
|
| 1065 | + }); |
|
| 1066 | + /** @deprecated 19.0.0 */ |
|
| 1067 | + $this->registerDeprecatedAlias('LockingProvider', ILockingProvider::class); |
|
| 1068 | + |
|
| 1069 | + $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class); |
|
| 1070 | + /** @deprecated 19.0.0 */ |
|
| 1071 | + $this->registerDeprecatedAlias('MountManager', IMountManager::class); |
|
| 1072 | + |
|
| 1073 | + $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) { |
|
| 1074 | + return new \OC\Files\Type\Detection( |
|
| 1075 | + $c->get(IURLGenerator::class), |
|
| 1076 | + $c->get(ILogger::class), |
|
| 1077 | + \OC::$configDir, |
|
| 1078 | + \OC::$SERVERROOT . '/resources/config/' |
|
| 1079 | + ); |
|
| 1080 | + }); |
|
| 1081 | + /** @deprecated 19.0.0 */ |
|
| 1082 | + $this->registerDeprecatedAlias('MimeTypeDetector', IMimeTypeDetector::class); |
|
| 1083 | + |
|
| 1084 | + $this->registerAlias(IMimeTypeLoader::class, Loader::class); |
|
| 1085 | + /** @deprecated 19.0.0 */ |
|
| 1086 | + $this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class); |
|
| 1087 | + $this->registerService(BundleFetcher::class, function () { |
|
| 1088 | + return new BundleFetcher($this->getL10N('lib')); |
|
| 1089 | + }); |
|
| 1090 | + $this->registerAlias(\OCP\Notification\IManager::class, Manager::class); |
|
| 1091 | + /** @deprecated 19.0.0 */ |
|
| 1092 | + $this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
| 1093 | + |
|
| 1094 | + $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) { |
|
| 1095 | + $manager = new CapabilitiesManager($c->get(LoggerInterface::class)); |
|
| 1096 | + $manager->registerCapability(function () use ($c) { |
|
| 1097 | + return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class)); |
|
| 1098 | + }); |
|
| 1099 | + $manager->registerCapability(function () use ($c) { |
|
| 1100 | + return $c->get(\OC\Security\Bruteforce\Capabilities::class); |
|
| 1101 | + }); |
|
| 1102 | + return $manager; |
|
| 1103 | + }); |
|
| 1104 | + /** @deprecated 19.0.0 */ |
|
| 1105 | + $this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class); |
|
| 1106 | + |
|
| 1107 | + $this->registerService(ICommentsManager::class, function (Server $c) { |
|
| 1108 | + $config = $c->get(\OCP\IConfig::class); |
|
| 1109 | + $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
| 1110 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
| 1111 | + $factory = new $factoryClass($this); |
|
| 1112 | + $manager = $factory->getManager(); |
|
| 1113 | + |
|
| 1114 | + $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
| 1115 | + $manager = $c->get(IUserManager::class); |
|
| 1116 | + $user = $manager->get($id); |
|
| 1117 | + if (is_null($user)) { |
|
| 1118 | + $l = $c->getL10N('core'); |
|
| 1119 | + $displayName = $l->t('Unknown user'); |
|
| 1120 | + } else { |
|
| 1121 | + $displayName = $user->getDisplayName(); |
|
| 1122 | + } |
|
| 1123 | + return $displayName; |
|
| 1124 | + }); |
|
| 1125 | + |
|
| 1126 | + return $manager; |
|
| 1127 | + }); |
|
| 1128 | + /** @deprecated 19.0.0 */ |
|
| 1129 | + $this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class); |
|
| 1130 | + |
|
| 1131 | + $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults'); |
|
| 1132 | + $this->registerService('ThemingDefaults', function (Server $c) { |
|
| 1133 | + /* |
|
| 1134 | 1134 | * Dark magic for autoloader. |
| 1135 | 1135 | * If we do a class_exists it will try to load the class which will |
| 1136 | 1136 | * make composer cache the result. Resulting in errors when enabling |
| 1137 | 1137 | * the theming app. |
| 1138 | 1138 | */ |
| 1139 | - $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
| 1140 | - if (isset($prefixes['OCA\\Theming\\'])) { |
|
| 1141 | - $classExists = true; |
|
| 1142 | - } else { |
|
| 1143 | - $classExists = false; |
|
| 1144 | - } |
|
| 1145 | - |
|
| 1146 | - if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValue('installed', false) && $c->get(IAppManager::class)->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
| 1147 | - return new ThemingDefaults( |
|
| 1148 | - $c->get(\OCP\IConfig::class), |
|
| 1149 | - $c->getL10N('theming'), |
|
| 1150 | - $c->get(IURLGenerator::class), |
|
| 1151 | - $c->get(ICacheFactory::class), |
|
| 1152 | - new Util($c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming')), |
|
| 1153 | - new ImageManager( |
|
| 1154 | - $c->get(\OCP\IConfig::class), |
|
| 1155 | - $c->getAppDataDir('theming'), |
|
| 1156 | - $c->get(IURLGenerator::class), |
|
| 1157 | - $this->get(ICacheFactory::class), |
|
| 1158 | - $this->get(ILogger::class), |
|
| 1159 | - $this->get(ITempManager::class) |
|
| 1160 | - ), |
|
| 1161 | - $c->get(IAppManager::class), |
|
| 1162 | - $c->get(INavigationManager::class) |
|
| 1163 | - ); |
|
| 1164 | - } |
|
| 1165 | - return new \OC_Defaults(); |
|
| 1166 | - }); |
|
| 1167 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
| 1168 | - return new JSCombiner( |
|
| 1169 | - $c->getAppDataDir('js'), |
|
| 1170 | - $c->get(IURLGenerator::class), |
|
| 1171 | - $this->get(ICacheFactory::class), |
|
| 1172 | - $c->get(SystemConfig::class), |
|
| 1173 | - $c->get(ILogger::class) |
|
| 1174 | - ); |
|
| 1175 | - }); |
|
| 1176 | - $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
| 1177 | - /** @deprecated 19.0.0 */ |
|
| 1178 | - $this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class); |
|
| 1179 | - $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class); |
|
| 1180 | - |
|
| 1181 | - $this->registerService('CryptoWrapper', function (ContainerInterface $c) { |
|
| 1182 | - // FIXME: Instantiiated here due to cyclic dependency |
|
| 1183 | - $request = new Request( |
|
| 1184 | - [ |
|
| 1185 | - 'get' => $_GET, |
|
| 1186 | - 'post' => $_POST, |
|
| 1187 | - 'files' => $_FILES, |
|
| 1188 | - 'server' => $_SERVER, |
|
| 1189 | - 'env' => $_ENV, |
|
| 1190 | - 'cookies' => $_COOKIE, |
|
| 1191 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 1192 | - ? $_SERVER['REQUEST_METHOD'] |
|
| 1193 | - : null, |
|
| 1194 | - ], |
|
| 1195 | - $c->get(ISecureRandom::class), |
|
| 1196 | - $c->get(\OCP\IConfig::class) |
|
| 1197 | - ); |
|
| 1198 | - |
|
| 1199 | - return new CryptoWrapper( |
|
| 1200 | - $c->get(\OCP\IConfig::class), |
|
| 1201 | - $c->get(ICrypto::class), |
|
| 1202 | - $c->get(ISecureRandom::class), |
|
| 1203 | - $request |
|
| 1204 | - ); |
|
| 1205 | - }); |
|
| 1206 | - /** @deprecated 19.0.0 */ |
|
| 1207 | - $this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class); |
|
| 1208 | - $this->registerService(SessionStorage::class, function (ContainerInterface $c) { |
|
| 1209 | - return new SessionStorage($c->get(ISession::class)); |
|
| 1210 | - }); |
|
| 1211 | - $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
|
| 1212 | - /** @deprecated 19.0.0 */ |
|
| 1213 | - $this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class); |
|
| 1214 | - |
|
| 1215 | - $this->registerService(\OCP\Share\IManager::class, function (IServerContainer $c) { |
|
| 1216 | - $config = $c->get(\OCP\IConfig::class); |
|
| 1217 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
| 1218 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
| 1219 | - $factory = new $factoryClass($this); |
|
| 1220 | - |
|
| 1221 | - $manager = new \OC\Share20\Manager( |
|
| 1222 | - $c->get(ILogger::class), |
|
| 1223 | - $c->get(\OCP\IConfig::class), |
|
| 1224 | - $c->get(ISecureRandom::class), |
|
| 1225 | - $c->get(IHasher::class), |
|
| 1226 | - $c->get(IMountManager::class), |
|
| 1227 | - $c->get(IGroupManager::class), |
|
| 1228 | - $c->getL10N('lib'), |
|
| 1229 | - $c->get(IFactory::class), |
|
| 1230 | - $factory, |
|
| 1231 | - $c->get(IUserManager::class), |
|
| 1232 | - $c->get(IRootFolder::class), |
|
| 1233 | - $c->get(SymfonyAdapter::class), |
|
| 1234 | - $c->get(IMailer::class), |
|
| 1235 | - $c->get(IURLGenerator::class), |
|
| 1236 | - $c->get('ThemingDefaults'), |
|
| 1237 | - $c->get(IEventDispatcher::class) |
|
| 1238 | - ); |
|
| 1239 | - |
|
| 1240 | - return $manager; |
|
| 1241 | - }); |
|
| 1242 | - /** @deprecated 19.0.0 */ |
|
| 1243 | - $this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class); |
|
| 1244 | - |
|
| 1245 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
| 1246 | - $instance = new Collaboration\Collaborators\Search($c); |
|
| 1247 | - |
|
| 1248 | - // register default plugins |
|
| 1249 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
| 1250 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
| 1251 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
| 1252 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
| 1253 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
| 1254 | - |
|
| 1255 | - return $instance; |
|
| 1256 | - }); |
|
| 1257 | - /** @deprecated 19.0.0 */ |
|
| 1258 | - $this->registerDeprecatedAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
| 1259 | - $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
| 1260 | - |
|
| 1261 | - $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
| 1262 | - |
|
| 1263 | - $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class); |
|
| 1264 | - $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
| 1265 | - |
|
| 1266 | - $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class); |
|
| 1267 | - $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class); |
|
| 1268 | - $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) { |
|
| 1269 | - return new \OC\Files\AppData\Factory( |
|
| 1270 | - $c->get(IRootFolder::class), |
|
| 1271 | - $c->get(SystemConfig::class) |
|
| 1272 | - ); |
|
| 1273 | - }); |
|
| 1274 | - |
|
| 1275 | - $this->registerService('LockdownManager', function (ContainerInterface $c) { |
|
| 1276 | - return new LockdownManager(function () use ($c) { |
|
| 1277 | - return $c->get(ISession::class); |
|
| 1278 | - }); |
|
| 1279 | - }); |
|
| 1280 | - |
|
| 1281 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) { |
|
| 1282 | - return new DiscoveryService( |
|
| 1283 | - $c->get(ICacheFactory::class), |
|
| 1284 | - $c->get(IClientService::class) |
|
| 1285 | - ); |
|
| 1286 | - }); |
|
| 1287 | - |
|
| 1288 | - $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) { |
|
| 1289 | - return new CloudIdManager($c->get(\OCP\Contacts\IManager::class)); |
|
| 1290 | - }); |
|
| 1291 | - |
|
| 1292 | - $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); |
|
| 1293 | - |
|
| 1294 | - $this->registerService(ICloudFederationProviderManager::class, function (ContainerInterface $c) { |
|
| 1295 | - return new CloudFederationProviderManager( |
|
| 1296 | - $c->get(IAppManager::class), |
|
| 1297 | - $c->get(IClientService::class), |
|
| 1298 | - $c->get(ICloudIdManager::class), |
|
| 1299 | - $c->get(ILogger::class) |
|
| 1300 | - ); |
|
| 1301 | - }); |
|
| 1302 | - |
|
| 1303 | - $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
| 1304 | - return new CloudFederationFactory(); |
|
| 1305 | - }); |
|
| 1306 | - |
|
| 1307 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 1308 | - /** @deprecated 19.0.0 */ |
|
| 1309 | - $this->registerDeprecatedAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
| 1310 | - |
|
| 1311 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 1312 | - /** @deprecated 19.0.0 */ |
|
| 1313 | - $this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 1314 | - |
|
| 1315 | - $this->registerService(Defaults::class, function (Server $c) { |
|
| 1316 | - return new Defaults( |
|
| 1317 | - $c->getThemingDefaults() |
|
| 1318 | - ); |
|
| 1319 | - }); |
|
| 1320 | - /** @deprecated 19.0.0 */ |
|
| 1321 | - $this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class); |
|
| 1322 | - |
|
| 1323 | - $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) { |
|
| 1324 | - return $c->get(\OCP\IUserSession::class)->getSession(); |
|
| 1325 | - }, false); |
|
| 1326 | - |
|
| 1327 | - $this->registerService(IShareHelper::class, function (ContainerInterface $c) { |
|
| 1328 | - return new ShareHelper( |
|
| 1329 | - $c->get(\OCP\Share\IManager::class) |
|
| 1330 | - ); |
|
| 1331 | - }); |
|
| 1332 | - |
|
| 1333 | - $this->registerService(Installer::class, function (ContainerInterface $c) { |
|
| 1334 | - return new Installer( |
|
| 1335 | - $c->get(AppFetcher::class), |
|
| 1336 | - $c->get(IClientService::class), |
|
| 1337 | - $c->get(ITempManager::class), |
|
| 1338 | - $c->get(LoggerInterface::class), |
|
| 1339 | - $c->get(\OCP\IConfig::class), |
|
| 1340 | - \OC::$CLI |
|
| 1341 | - ); |
|
| 1342 | - }); |
|
| 1343 | - |
|
| 1344 | - $this->registerService(IApiFactory::class, function (ContainerInterface $c) { |
|
| 1345 | - return new ApiFactory($c->get(IClientService::class)); |
|
| 1346 | - }); |
|
| 1347 | - |
|
| 1348 | - $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) { |
|
| 1349 | - $memcacheFactory = $c->get(ICacheFactory::class); |
|
| 1350 | - return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class)); |
|
| 1351 | - }); |
|
| 1352 | - |
|
| 1353 | - $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
| 1354 | - $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
| 1355 | - |
|
| 1356 | - $this->registerAlias(IStorageFactory::class, StorageFactory::class); |
|
| 1357 | - |
|
| 1358 | - $this->registerAlias(IDashboardManager::class, DashboardManager::class); |
|
| 1359 | - $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class); |
|
| 1360 | - $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
| 1361 | - |
|
| 1362 | - $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
| 1363 | - |
|
| 1364 | - $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
| 1365 | - |
|
| 1366 | - $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class); |
|
| 1367 | - |
|
| 1368 | - $this->connectDispatcher(); |
|
| 1369 | - } |
|
| 1370 | - |
|
| 1371 | - public function boot() { |
|
| 1372 | - /** @var HookConnector $hookConnector */ |
|
| 1373 | - $hookConnector = $this->get(HookConnector::class); |
|
| 1374 | - $hookConnector->viewToNode(); |
|
| 1375 | - } |
|
| 1376 | - |
|
| 1377 | - /** |
|
| 1378 | - * @return \OCP\Calendar\IManager |
|
| 1379 | - * @deprecated 20.0.0 |
|
| 1380 | - */ |
|
| 1381 | - public function getCalendarManager() { |
|
| 1382 | - return $this->get(\OC\Calendar\Manager::class); |
|
| 1383 | - } |
|
| 1384 | - |
|
| 1385 | - /** |
|
| 1386 | - * @return \OCP\Calendar\Resource\IManager |
|
| 1387 | - * @deprecated 20.0.0 |
|
| 1388 | - */ |
|
| 1389 | - public function getCalendarResourceBackendManager() { |
|
| 1390 | - return $this->get(\OC\Calendar\Resource\Manager::class); |
|
| 1391 | - } |
|
| 1392 | - |
|
| 1393 | - /** |
|
| 1394 | - * @return \OCP\Calendar\Room\IManager |
|
| 1395 | - * @deprecated 20.0.0 |
|
| 1396 | - */ |
|
| 1397 | - public function getCalendarRoomBackendManager() { |
|
| 1398 | - return $this->get(\OC\Calendar\Room\Manager::class); |
|
| 1399 | - } |
|
| 1400 | - |
|
| 1401 | - private function connectDispatcher() { |
|
| 1402 | - $dispatcher = $this->get(SymfonyAdapter::class); |
|
| 1403 | - |
|
| 1404 | - // Delete avatar on user deletion |
|
| 1405 | - $dispatcher->addListener('OCP\IUser::preDelete', function (GenericEvent $e) { |
|
| 1406 | - $logger = $this->get(ILogger::class); |
|
| 1407 | - $manager = $this->getAvatarManager(); |
|
| 1408 | - /** @var IUser $user */ |
|
| 1409 | - $user = $e->getSubject(); |
|
| 1410 | - |
|
| 1411 | - try { |
|
| 1412 | - $avatar = $manager->getAvatar($user->getUID()); |
|
| 1413 | - $avatar->remove(); |
|
| 1414 | - } catch (NotFoundException $e) { |
|
| 1415 | - // no avatar to remove |
|
| 1416 | - } catch (\Exception $e) { |
|
| 1417 | - // Ignore exceptions |
|
| 1418 | - $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
| 1419 | - } |
|
| 1420 | - }); |
|
| 1421 | - |
|
| 1422 | - $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
| 1423 | - $manager = $this->getAvatarManager(); |
|
| 1424 | - /** @var IUser $user */ |
|
| 1425 | - $user = $e->getSubject(); |
|
| 1426 | - $feature = $e->getArgument('feature'); |
|
| 1427 | - $oldValue = $e->getArgument('oldValue'); |
|
| 1428 | - $value = $e->getArgument('value'); |
|
| 1429 | - |
|
| 1430 | - // We only change the avatar on display name changes |
|
| 1431 | - if ($feature !== 'displayName') { |
|
| 1432 | - return; |
|
| 1433 | - } |
|
| 1434 | - |
|
| 1435 | - try { |
|
| 1436 | - $avatar = $manager->getAvatar($user->getUID()); |
|
| 1437 | - $avatar->userChanged($feature, $oldValue, $value); |
|
| 1438 | - } catch (NotFoundException $e) { |
|
| 1439 | - // no avatar to remove |
|
| 1440 | - } |
|
| 1441 | - }); |
|
| 1442 | - |
|
| 1443 | - /** @var IEventDispatcher $eventDispatched */ |
|
| 1444 | - $eventDispatched = $this->get(IEventDispatcher::class); |
|
| 1445 | - $eventDispatched->addServiceListener(LoginFailed::class, LoginFailedListener::class); |
|
| 1446 | - $eventDispatched->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class); |
|
| 1447 | - } |
|
| 1448 | - |
|
| 1449 | - /** |
|
| 1450 | - * @return \OCP\Contacts\IManager |
|
| 1451 | - * @deprecated 20.0.0 |
|
| 1452 | - */ |
|
| 1453 | - public function getContactsManager() { |
|
| 1454 | - return $this->get(\OCP\Contacts\IManager::class); |
|
| 1455 | - } |
|
| 1456 | - |
|
| 1457 | - /** |
|
| 1458 | - * @return \OC\Encryption\Manager |
|
| 1459 | - * @deprecated 20.0.0 |
|
| 1460 | - */ |
|
| 1461 | - public function getEncryptionManager() { |
|
| 1462 | - return $this->get(\OCP\Encryption\IManager::class); |
|
| 1463 | - } |
|
| 1464 | - |
|
| 1465 | - /** |
|
| 1466 | - * @return \OC\Encryption\File |
|
| 1467 | - * @deprecated 20.0.0 |
|
| 1468 | - */ |
|
| 1469 | - public function getEncryptionFilesHelper() { |
|
| 1470 | - return $this->get(IFile::class); |
|
| 1471 | - } |
|
| 1472 | - |
|
| 1473 | - /** |
|
| 1474 | - * @return \OCP\Encryption\Keys\IStorage |
|
| 1475 | - * @deprecated 20.0.0 |
|
| 1476 | - */ |
|
| 1477 | - public function getEncryptionKeyStorage() { |
|
| 1478 | - return $this->get(IStorage::class); |
|
| 1479 | - } |
|
| 1480 | - |
|
| 1481 | - /** |
|
| 1482 | - * The current request object holding all information about the request |
|
| 1483 | - * currently being processed is returned from this method. |
|
| 1484 | - * In case the current execution was not initiated by a web request null is returned |
|
| 1485 | - * |
|
| 1486 | - * @return \OCP\IRequest |
|
| 1487 | - * @deprecated 20.0.0 |
|
| 1488 | - */ |
|
| 1489 | - public function getRequest() { |
|
| 1490 | - return $this->get(IRequest::class); |
|
| 1491 | - } |
|
| 1492 | - |
|
| 1493 | - /** |
|
| 1494 | - * Returns the preview manager which can create preview images for a given file |
|
| 1495 | - * |
|
| 1496 | - * @return IPreview |
|
| 1497 | - * @deprecated 20.0.0 |
|
| 1498 | - */ |
|
| 1499 | - public function getPreviewManager() { |
|
| 1500 | - return $this->get(IPreview::class); |
|
| 1501 | - } |
|
| 1502 | - |
|
| 1503 | - /** |
|
| 1504 | - * Returns the tag manager which can get and set tags for different object types |
|
| 1505 | - * |
|
| 1506 | - * @see \OCP\ITagManager::load() |
|
| 1507 | - * @return ITagManager |
|
| 1508 | - * @deprecated 20.0.0 |
|
| 1509 | - */ |
|
| 1510 | - public function getTagManager() { |
|
| 1511 | - return $this->get(ITagManager::class); |
|
| 1512 | - } |
|
| 1513 | - |
|
| 1514 | - /** |
|
| 1515 | - * Returns the system-tag manager |
|
| 1516 | - * |
|
| 1517 | - * @return ISystemTagManager |
|
| 1518 | - * |
|
| 1519 | - * @since 9.0.0 |
|
| 1520 | - * @deprecated 20.0.0 |
|
| 1521 | - */ |
|
| 1522 | - public function getSystemTagManager() { |
|
| 1523 | - return $this->get(ISystemTagManager::class); |
|
| 1524 | - } |
|
| 1525 | - |
|
| 1526 | - /** |
|
| 1527 | - * Returns the system-tag object mapper |
|
| 1528 | - * |
|
| 1529 | - * @return ISystemTagObjectMapper |
|
| 1530 | - * |
|
| 1531 | - * @since 9.0.0 |
|
| 1532 | - * @deprecated 20.0.0 |
|
| 1533 | - */ |
|
| 1534 | - public function getSystemTagObjectMapper() { |
|
| 1535 | - return $this->get(ISystemTagObjectMapper::class); |
|
| 1536 | - } |
|
| 1537 | - |
|
| 1538 | - /** |
|
| 1539 | - * Returns the avatar manager, used for avatar functionality |
|
| 1540 | - * |
|
| 1541 | - * @return IAvatarManager |
|
| 1542 | - * @deprecated 20.0.0 |
|
| 1543 | - */ |
|
| 1544 | - public function getAvatarManager() { |
|
| 1545 | - return $this->get(IAvatarManager::class); |
|
| 1546 | - } |
|
| 1547 | - |
|
| 1548 | - /** |
|
| 1549 | - * Returns the root folder of ownCloud's data directory |
|
| 1550 | - * |
|
| 1551 | - * @return IRootFolder |
|
| 1552 | - * @deprecated 20.0.0 |
|
| 1553 | - */ |
|
| 1554 | - public function getRootFolder() { |
|
| 1555 | - return $this->get(IRootFolder::class); |
|
| 1556 | - } |
|
| 1557 | - |
|
| 1558 | - /** |
|
| 1559 | - * Returns the root folder of ownCloud's data directory |
|
| 1560 | - * This is the lazy variant so this gets only initialized once it |
|
| 1561 | - * is actually used. |
|
| 1562 | - * |
|
| 1563 | - * @return IRootFolder |
|
| 1564 | - * @deprecated 20.0.0 |
|
| 1565 | - */ |
|
| 1566 | - public function getLazyRootFolder() { |
|
| 1567 | - return $this->get(IRootFolder::class); |
|
| 1568 | - } |
|
| 1569 | - |
|
| 1570 | - /** |
|
| 1571 | - * Returns a view to ownCloud's files folder |
|
| 1572 | - * |
|
| 1573 | - * @param string $userId user ID |
|
| 1574 | - * @return \OCP\Files\Folder|null |
|
| 1575 | - * @deprecated 20.0.0 |
|
| 1576 | - */ |
|
| 1577 | - public function getUserFolder($userId = null) { |
|
| 1578 | - if ($userId === null) { |
|
| 1579 | - $user = $this->get(IUserSession::class)->getUser(); |
|
| 1580 | - if (!$user) { |
|
| 1581 | - return null; |
|
| 1582 | - } |
|
| 1583 | - $userId = $user->getUID(); |
|
| 1584 | - } |
|
| 1585 | - $root = $this->get(IRootFolder::class); |
|
| 1586 | - return $root->getUserFolder($userId); |
|
| 1587 | - } |
|
| 1588 | - |
|
| 1589 | - /** |
|
| 1590 | - * @return \OC\User\Manager |
|
| 1591 | - * @deprecated 20.0.0 |
|
| 1592 | - */ |
|
| 1593 | - public function getUserManager() { |
|
| 1594 | - return $this->get(IUserManager::class); |
|
| 1595 | - } |
|
| 1596 | - |
|
| 1597 | - /** |
|
| 1598 | - * @return \OC\Group\Manager |
|
| 1599 | - * @deprecated 20.0.0 |
|
| 1600 | - */ |
|
| 1601 | - public function getGroupManager() { |
|
| 1602 | - return $this->get(IGroupManager::class); |
|
| 1603 | - } |
|
| 1604 | - |
|
| 1605 | - /** |
|
| 1606 | - * @return \OC\User\Session |
|
| 1607 | - * @deprecated 20.0.0 |
|
| 1608 | - */ |
|
| 1609 | - public function getUserSession() { |
|
| 1610 | - return $this->get(IUserSession::class); |
|
| 1611 | - } |
|
| 1612 | - |
|
| 1613 | - /** |
|
| 1614 | - * @return \OCP\ISession |
|
| 1615 | - * @deprecated 20.0.0 |
|
| 1616 | - */ |
|
| 1617 | - public function getSession() { |
|
| 1618 | - return $this->get(IUserSession::class)->getSession(); |
|
| 1619 | - } |
|
| 1620 | - |
|
| 1621 | - /** |
|
| 1622 | - * @param \OCP\ISession $session |
|
| 1623 | - */ |
|
| 1624 | - public function setSession(\OCP\ISession $session) { |
|
| 1625 | - $this->get(SessionStorage::class)->setSession($session); |
|
| 1626 | - $this->get(IUserSession::class)->setSession($session); |
|
| 1627 | - $this->get(Store::class)->setSession($session); |
|
| 1628 | - } |
|
| 1629 | - |
|
| 1630 | - /** |
|
| 1631 | - * @return \OC\Authentication\TwoFactorAuth\Manager |
|
| 1632 | - * @deprecated 20.0.0 |
|
| 1633 | - */ |
|
| 1634 | - public function getTwoFactorAuthManager() { |
|
| 1635 | - return $this->get(\OC\Authentication\TwoFactorAuth\Manager::class); |
|
| 1636 | - } |
|
| 1637 | - |
|
| 1638 | - /** |
|
| 1639 | - * @return \OC\NavigationManager |
|
| 1640 | - * @deprecated 20.0.0 |
|
| 1641 | - */ |
|
| 1642 | - public function getNavigationManager() { |
|
| 1643 | - return $this->get(INavigationManager::class); |
|
| 1644 | - } |
|
| 1645 | - |
|
| 1646 | - /** |
|
| 1647 | - * @return \OCP\IConfig |
|
| 1648 | - * @deprecated 20.0.0 |
|
| 1649 | - */ |
|
| 1650 | - public function getConfig() { |
|
| 1651 | - return $this->get(AllConfig::class); |
|
| 1652 | - } |
|
| 1653 | - |
|
| 1654 | - /** |
|
| 1655 | - * @return \OC\SystemConfig |
|
| 1656 | - * @deprecated 20.0.0 |
|
| 1657 | - */ |
|
| 1658 | - public function getSystemConfig() { |
|
| 1659 | - return $this->get(SystemConfig::class); |
|
| 1660 | - } |
|
| 1661 | - |
|
| 1662 | - /** |
|
| 1663 | - * Returns the app config manager |
|
| 1664 | - * |
|
| 1665 | - * @return IAppConfig |
|
| 1666 | - * @deprecated 20.0.0 |
|
| 1667 | - */ |
|
| 1668 | - public function getAppConfig() { |
|
| 1669 | - return $this->get(IAppConfig::class); |
|
| 1670 | - } |
|
| 1671 | - |
|
| 1672 | - /** |
|
| 1673 | - * @return IFactory |
|
| 1674 | - * @deprecated 20.0.0 |
|
| 1675 | - */ |
|
| 1676 | - public function getL10NFactory() { |
|
| 1677 | - return $this->get(IFactory::class); |
|
| 1678 | - } |
|
| 1679 | - |
|
| 1680 | - /** |
|
| 1681 | - * get an L10N instance |
|
| 1682 | - * |
|
| 1683 | - * @param string $app appid |
|
| 1684 | - * @param string $lang |
|
| 1685 | - * @return IL10N |
|
| 1686 | - * @deprecated 20.0.0 |
|
| 1687 | - */ |
|
| 1688 | - public function getL10N($app, $lang = null) { |
|
| 1689 | - return $this->get(IFactory::class)->get($app, $lang); |
|
| 1690 | - } |
|
| 1691 | - |
|
| 1692 | - /** |
|
| 1693 | - * @return IURLGenerator |
|
| 1694 | - * @deprecated 20.0.0 |
|
| 1695 | - */ |
|
| 1696 | - public function getURLGenerator() { |
|
| 1697 | - return $this->get(IURLGenerator::class); |
|
| 1698 | - } |
|
| 1699 | - |
|
| 1700 | - /** |
|
| 1701 | - * @return AppFetcher |
|
| 1702 | - * @deprecated 20.0.0 |
|
| 1703 | - */ |
|
| 1704 | - public function getAppFetcher() { |
|
| 1705 | - return $this->get(AppFetcher::class); |
|
| 1706 | - } |
|
| 1707 | - |
|
| 1708 | - /** |
|
| 1709 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
| 1710 | - * getMemCacheFactory() instead. |
|
| 1711 | - * |
|
| 1712 | - * @return ICache |
|
| 1713 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
| 1714 | - */ |
|
| 1715 | - public function getCache() { |
|
| 1716 | - return $this->get(ICache::class); |
|
| 1717 | - } |
|
| 1718 | - |
|
| 1719 | - /** |
|
| 1720 | - * Returns an \OCP\CacheFactory instance |
|
| 1721 | - * |
|
| 1722 | - * @return \OCP\ICacheFactory |
|
| 1723 | - * @deprecated 20.0.0 |
|
| 1724 | - */ |
|
| 1725 | - public function getMemCacheFactory() { |
|
| 1726 | - return $this->get(ICacheFactory::class); |
|
| 1727 | - } |
|
| 1728 | - |
|
| 1729 | - /** |
|
| 1730 | - * Returns an \OC\RedisFactory instance |
|
| 1731 | - * |
|
| 1732 | - * @return \OC\RedisFactory |
|
| 1733 | - * @deprecated 20.0.0 |
|
| 1734 | - */ |
|
| 1735 | - public function getGetRedisFactory() { |
|
| 1736 | - return $this->get('RedisFactory'); |
|
| 1737 | - } |
|
| 1738 | - |
|
| 1739 | - |
|
| 1740 | - /** |
|
| 1741 | - * Returns the current session |
|
| 1742 | - * |
|
| 1743 | - * @return \OCP\IDBConnection |
|
| 1744 | - * @deprecated 20.0.0 |
|
| 1745 | - */ |
|
| 1746 | - public function getDatabaseConnection() { |
|
| 1747 | - return $this->get(IDBConnection::class); |
|
| 1748 | - } |
|
| 1749 | - |
|
| 1750 | - /** |
|
| 1751 | - * Returns the activity manager |
|
| 1752 | - * |
|
| 1753 | - * @return \OCP\Activity\IManager |
|
| 1754 | - * @deprecated 20.0.0 |
|
| 1755 | - */ |
|
| 1756 | - public function getActivityManager() { |
|
| 1757 | - return $this->get(\OCP\Activity\IManager::class); |
|
| 1758 | - } |
|
| 1759 | - |
|
| 1760 | - /** |
|
| 1761 | - * Returns an job list for controlling background jobs |
|
| 1762 | - * |
|
| 1763 | - * @return IJobList |
|
| 1764 | - * @deprecated 20.0.0 |
|
| 1765 | - */ |
|
| 1766 | - public function getJobList() { |
|
| 1767 | - return $this->get(IJobList::class); |
|
| 1768 | - } |
|
| 1769 | - |
|
| 1770 | - /** |
|
| 1771 | - * Returns a logger instance |
|
| 1772 | - * |
|
| 1773 | - * @return ILogger |
|
| 1774 | - * @deprecated 20.0.0 |
|
| 1775 | - */ |
|
| 1776 | - public function getLogger() { |
|
| 1777 | - return $this->get(ILogger::class); |
|
| 1778 | - } |
|
| 1779 | - |
|
| 1780 | - /** |
|
| 1781 | - * @return ILogFactory |
|
| 1782 | - * @throws \OCP\AppFramework\QueryException |
|
| 1783 | - * @deprecated 20.0.0 |
|
| 1784 | - */ |
|
| 1785 | - public function getLogFactory() { |
|
| 1786 | - return $this->get(ILogFactory::class); |
|
| 1787 | - } |
|
| 1788 | - |
|
| 1789 | - /** |
|
| 1790 | - * Returns a router for generating and matching urls |
|
| 1791 | - * |
|
| 1792 | - * @return IRouter |
|
| 1793 | - * @deprecated 20.0.0 |
|
| 1794 | - */ |
|
| 1795 | - public function getRouter() { |
|
| 1796 | - return $this->get(IRouter::class); |
|
| 1797 | - } |
|
| 1798 | - |
|
| 1799 | - /** |
|
| 1800 | - * Returns a search instance |
|
| 1801 | - * |
|
| 1802 | - * @return ISearch |
|
| 1803 | - * @deprecated 20.0.0 |
|
| 1804 | - */ |
|
| 1805 | - public function getSearch() { |
|
| 1806 | - return $this->get(ISearch::class); |
|
| 1807 | - } |
|
| 1808 | - |
|
| 1809 | - /** |
|
| 1810 | - * Returns a SecureRandom instance |
|
| 1811 | - * |
|
| 1812 | - * @return \OCP\Security\ISecureRandom |
|
| 1813 | - * @deprecated 20.0.0 |
|
| 1814 | - */ |
|
| 1815 | - public function getSecureRandom() { |
|
| 1816 | - return $this->get(ISecureRandom::class); |
|
| 1817 | - } |
|
| 1818 | - |
|
| 1819 | - /** |
|
| 1820 | - * Returns a Crypto instance |
|
| 1821 | - * |
|
| 1822 | - * @return ICrypto |
|
| 1823 | - * @deprecated 20.0.0 |
|
| 1824 | - */ |
|
| 1825 | - public function getCrypto() { |
|
| 1826 | - return $this->get(ICrypto::class); |
|
| 1827 | - } |
|
| 1828 | - |
|
| 1829 | - /** |
|
| 1830 | - * Returns a Hasher instance |
|
| 1831 | - * |
|
| 1832 | - * @return IHasher |
|
| 1833 | - * @deprecated 20.0.0 |
|
| 1834 | - */ |
|
| 1835 | - public function getHasher() { |
|
| 1836 | - return $this->get(IHasher::class); |
|
| 1837 | - } |
|
| 1838 | - |
|
| 1839 | - /** |
|
| 1840 | - * Returns a CredentialsManager instance |
|
| 1841 | - * |
|
| 1842 | - * @return ICredentialsManager |
|
| 1843 | - * @deprecated 20.0.0 |
|
| 1844 | - */ |
|
| 1845 | - public function getCredentialsManager() { |
|
| 1846 | - return $this->get(ICredentialsManager::class); |
|
| 1847 | - } |
|
| 1848 | - |
|
| 1849 | - /** |
|
| 1850 | - * Get the certificate manager |
|
| 1851 | - * |
|
| 1852 | - * @return \OCP\ICertificateManager |
|
| 1853 | - */ |
|
| 1854 | - public function getCertificateManager() { |
|
| 1855 | - return $this->get(ICertificateManager::class); |
|
| 1856 | - } |
|
| 1857 | - |
|
| 1858 | - /** |
|
| 1859 | - * Returns an instance of the HTTP client service |
|
| 1860 | - * |
|
| 1861 | - * @return IClientService |
|
| 1862 | - * @deprecated 20.0.0 |
|
| 1863 | - */ |
|
| 1864 | - public function getHTTPClientService() { |
|
| 1865 | - return $this->get(IClientService::class); |
|
| 1866 | - } |
|
| 1867 | - |
|
| 1868 | - /** |
|
| 1869 | - * Create a new event source |
|
| 1870 | - * |
|
| 1871 | - * @return \OCP\IEventSource |
|
| 1872 | - * @deprecated 20.0.0 |
|
| 1873 | - */ |
|
| 1874 | - public function createEventSource() { |
|
| 1875 | - return new \OC_EventSource(); |
|
| 1876 | - } |
|
| 1877 | - |
|
| 1878 | - /** |
|
| 1879 | - * Get the active event logger |
|
| 1880 | - * |
|
| 1881 | - * The returned logger only logs data when debug mode is enabled |
|
| 1882 | - * |
|
| 1883 | - * @return IEventLogger |
|
| 1884 | - * @deprecated 20.0.0 |
|
| 1885 | - */ |
|
| 1886 | - public function getEventLogger() { |
|
| 1887 | - return $this->get(IEventLogger::class); |
|
| 1888 | - } |
|
| 1889 | - |
|
| 1890 | - /** |
|
| 1891 | - * Get the active query logger |
|
| 1892 | - * |
|
| 1893 | - * The returned logger only logs data when debug mode is enabled |
|
| 1894 | - * |
|
| 1895 | - * @return IQueryLogger |
|
| 1896 | - * @deprecated 20.0.0 |
|
| 1897 | - */ |
|
| 1898 | - public function getQueryLogger() { |
|
| 1899 | - return $this->get(IQueryLogger::class); |
|
| 1900 | - } |
|
| 1901 | - |
|
| 1902 | - /** |
|
| 1903 | - * Get the manager for temporary files and folders |
|
| 1904 | - * |
|
| 1905 | - * @return \OCP\ITempManager |
|
| 1906 | - * @deprecated 20.0.0 |
|
| 1907 | - */ |
|
| 1908 | - public function getTempManager() { |
|
| 1909 | - return $this->get(ITempManager::class); |
|
| 1910 | - } |
|
| 1911 | - |
|
| 1912 | - /** |
|
| 1913 | - * Get the app manager |
|
| 1914 | - * |
|
| 1915 | - * @return \OCP\App\IAppManager |
|
| 1916 | - * @deprecated 20.0.0 |
|
| 1917 | - */ |
|
| 1918 | - public function getAppManager() { |
|
| 1919 | - return $this->get(IAppManager::class); |
|
| 1920 | - } |
|
| 1921 | - |
|
| 1922 | - /** |
|
| 1923 | - * Creates a new mailer |
|
| 1924 | - * |
|
| 1925 | - * @return IMailer |
|
| 1926 | - * @deprecated 20.0.0 |
|
| 1927 | - */ |
|
| 1928 | - public function getMailer() { |
|
| 1929 | - return $this->get(IMailer::class); |
|
| 1930 | - } |
|
| 1931 | - |
|
| 1932 | - /** |
|
| 1933 | - * Get the webroot |
|
| 1934 | - * |
|
| 1935 | - * @return string |
|
| 1936 | - * @deprecated 20.0.0 |
|
| 1937 | - */ |
|
| 1938 | - public function getWebRoot() { |
|
| 1939 | - return $this->webRoot; |
|
| 1940 | - } |
|
| 1941 | - |
|
| 1942 | - /** |
|
| 1943 | - * @return \OC\OCSClient |
|
| 1944 | - * @deprecated 20.0.0 |
|
| 1945 | - */ |
|
| 1946 | - public function getOcsClient() { |
|
| 1947 | - return $this->get('OcsClient'); |
|
| 1948 | - } |
|
| 1949 | - |
|
| 1950 | - /** |
|
| 1951 | - * @return IDateTimeZone |
|
| 1952 | - * @deprecated 20.0.0 |
|
| 1953 | - */ |
|
| 1954 | - public function getDateTimeZone() { |
|
| 1955 | - return $this->get(IDateTimeZone::class); |
|
| 1956 | - } |
|
| 1957 | - |
|
| 1958 | - /** |
|
| 1959 | - * @return IDateTimeFormatter |
|
| 1960 | - * @deprecated 20.0.0 |
|
| 1961 | - */ |
|
| 1962 | - public function getDateTimeFormatter() { |
|
| 1963 | - return $this->get(IDateTimeFormatter::class); |
|
| 1964 | - } |
|
| 1965 | - |
|
| 1966 | - /** |
|
| 1967 | - * @return IMountProviderCollection |
|
| 1968 | - * @deprecated 20.0.0 |
|
| 1969 | - */ |
|
| 1970 | - public function getMountProviderCollection() { |
|
| 1971 | - return $this->get(IMountProviderCollection::class); |
|
| 1972 | - } |
|
| 1973 | - |
|
| 1974 | - /** |
|
| 1975 | - * Get the IniWrapper |
|
| 1976 | - * |
|
| 1977 | - * @return IniGetWrapper |
|
| 1978 | - * @deprecated 20.0.0 |
|
| 1979 | - */ |
|
| 1980 | - public function getIniWrapper() { |
|
| 1981 | - return $this->get(IniGetWrapper::class); |
|
| 1982 | - } |
|
| 1983 | - |
|
| 1984 | - /** |
|
| 1985 | - * @return \OCP\Command\IBus |
|
| 1986 | - * @deprecated 20.0.0 |
|
| 1987 | - */ |
|
| 1988 | - public function getCommandBus() { |
|
| 1989 | - return $this->get(IBus::class); |
|
| 1990 | - } |
|
| 1991 | - |
|
| 1992 | - /** |
|
| 1993 | - * Get the trusted domain helper |
|
| 1994 | - * |
|
| 1995 | - * @return TrustedDomainHelper |
|
| 1996 | - * @deprecated 20.0.0 |
|
| 1997 | - */ |
|
| 1998 | - public function getTrustedDomainHelper() { |
|
| 1999 | - return $this->get(TrustedDomainHelper::class); |
|
| 2000 | - } |
|
| 2001 | - |
|
| 2002 | - /** |
|
| 2003 | - * Get the locking provider |
|
| 2004 | - * |
|
| 2005 | - * @return ILockingProvider |
|
| 2006 | - * @since 8.1.0 |
|
| 2007 | - * @deprecated 20.0.0 |
|
| 2008 | - */ |
|
| 2009 | - public function getLockingProvider() { |
|
| 2010 | - return $this->get(ILockingProvider::class); |
|
| 2011 | - } |
|
| 2012 | - |
|
| 2013 | - /** |
|
| 2014 | - * @return IMountManager |
|
| 2015 | - * @deprecated 20.0.0 |
|
| 2016 | - **/ |
|
| 2017 | - public function getMountManager() { |
|
| 2018 | - return $this->get(IMountManager::class); |
|
| 2019 | - } |
|
| 2020 | - |
|
| 2021 | - /** |
|
| 2022 | - * @return IUserMountCache |
|
| 2023 | - * @deprecated 20.0.0 |
|
| 2024 | - */ |
|
| 2025 | - public function getUserMountCache() { |
|
| 2026 | - return $this->get(IUserMountCache::class); |
|
| 2027 | - } |
|
| 2028 | - |
|
| 2029 | - /** |
|
| 2030 | - * Get the MimeTypeDetector |
|
| 2031 | - * |
|
| 2032 | - * @return IMimeTypeDetector |
|
| 2033 | - * @deprecated 20.0.0 |
|
| 2034 | - */ |
|
| 2035 | - public function getMimeTypeDetector() { |
|
| 2036 | - return $this->get(IMimeTypeDetector::class); |
|
| 2037 | - } |
|
| 2038 | - |
|
| 2039 | - /** |
|
| 2040 | - * Get the MimeTypeLoader |
|
| 2041 | - * |
|
| 2042 | - * @return IMimeTypeLoader |
|
| 2043 | - * @deprecated 20.0.0 |
|
| 2044 | - */ |
|
| 2045 | - public function getMimeTypeLoader() { |
|
| 2046 | - return $this->get(IMimeTypeLoader::class); |
|
| 2047 | - } |
|
| 2048 | - |
|
| 2049 | - /** |
|
| 2050 | - * Get the manager of all the capabilities |
|
| 2051 | - * |
|
| 2052 | - * @return CapabilitiesManager |
|
| 2053 | - * @deprecated 20.0.0 |
|
| 2054 | - */ |
|
| 2055 | - public function getCapabilitiesManager() { |
|
| 2056 | - return $this->get(CapabilitiesManager::class); |
|
| 2057 | - } |
|
| 2058 | - |
|
| 2059 | - /** |
|
| 2060 | - * Get the EventDispatcher |
|
| 2061 | - * |
|
| 2062 | - * @return EventDispatcherInterface |
|
| 2063 | - * @since 8.2.0 |
|
| 2064 | - * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher |
|
| 2065 | - */ |
|
| 2066 | - public function getEventDispatcher() { |
|
| 2067 | - return $this->get(\OC\EventDispatcher\SymfonyAdapter::class); |
|
| 2068 | - } |
|
| 2069 | - |
|
| 2070 | - /** |
|
| 2071 | - * Get the Notification Manager |
|
| 2072 | - * |
|
| 2073 | - * @return \OCP\Notification\IManager |
|
| 2074 | - * @since 8.2.0 |
|
| 2075 | - * @deprecated 20.0.0 |
|
| 2076 | - */ |
|
| 2077 | - public function getNotificationManager() { |
|
| 2078 | - return $this->get(\OCP\Notification\IManager::class); |
|
| 2079 | - } |
|
| 2080 | - |
|
| 2081 | - /** |
|
| 2082 | - * @return ICommentsManager |
|
| 2083 | - * @deprecated 20.0.0 |
|
| 2084 | - */ |
|
| 2085 | - public function getCommentsManager() { |
|
| 2086 | - return $this->get(ICommentsManager::class); |
|
| 2087 | - } |
|
| 2088 | - |
|
| 2089 | - /** |
|
| 2090 | - * @return \OCA\Theming\ThemingDefaults |
|
| 2091 | - * @deprecated 20.0.0 |
|
| 2092 | - */ |
|
| 2093 | - public function getThemingDefaults() { |
|
| 2094 | - return $this->get('ThemingDefaults'); |
|
| 2095 | - } |
|
| 2096 | - |
|
| 2097 | - /** |
|
| 2098 | - * @return \OC\IntegrityCheck\Checker |
|
| 2099 | - * @deprecated 20.0.0 |
|
| 2100 | - */ |
|
| 2101 | - public function getIntegrityCodeChecker() { |
|
| 2102 | - return $this->get('IntegrityCodeChecker'); |
|
| 2103 | - } |
|
| 2104 | - |
|
| 2105 | - /** |
|
| 2106 | - * @return \OC\Session\CryptoWrapper |
|
| 2107 | - * @deprecated 20.0.0 |
|
| 2108 | - */ |
|
| 2109 | - public function getSessionCryptoWrapper() { |
|
| 2110 | - return $this->get('CryptoWrapper'); |
|
| 2111 | - } |
|
| 2112 | - |
|
| 2113 | - /** |
|
| 2114 | - * @return CsrfTokenManager |
|
| 2115 | - * @deprecated 20.0.0 |
|
| 2116 | - */ |
|
| 2117 | - public function getCsrfTokenManager() { |
|
| 2118 | - return $this->get(CsrfTokenManager::class); |
|
| 2119 | - } |
|
| 2120 | - |
|
| 2121 | - /** |
|
| 2122 | - * @return Throttler |
|
| 2123 | - * @deprecated 20.0.0 |
|
| 2124 | - */ |
|
| 2125 | - public function getBruteForceThrottler() { |
|
| 2126 | - return $this->get(Throttler::class); |
|
| 2127 | - } |
|
| 2128 | - |
|
| 2129 | - /** |
|
| 2130 | - * @return IContentSecurityPolicyManager |
|
| 2131 | - * @deprecated 20.0.0 |
|
| 2132 | - */ |
|
| 2133 | - public function getContentSecurityPolicyManager() { |
|
| 2134 | - return $this->get(ContentSecurityPolicyManager::class); |
|
| 2135 | - } |
|
| 2136 | - |
|
| 2137 | - /** |
|
| 2138 | - * @return ContentSecurityPolicyNonceManager |
|
| 2139 | - * @deprecated 20.0.0 |
|
| 2140 | - */ |
|
| 2141 | - public function getContentSecurityPolicyNonceManager() { |
|
| 2142 | - return $this->get(ContentSecurityPolicyNonceManager::class); |
|
| 2143 | - } |
|
| 2144 | - |
|
| 2145 | - /** |
|
| 2146 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 2147 | - * |
|
| 2148 | - * @return \OCA\Files_External\Service\BackendService |
|
| 2149 | - * @deprecated 20.0.0 |
|
| 2150 | - */ |
|
| 2151 | - public function getStoragesBackendService() { |
|
| 2152 | - return $this->get(BackendService::class); |
|
| 2153 | - } |
|
| 2154 | - |
|
| 2155 | - /** |
|
| 2156 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 2157 | - * |
|
| 2158 | - * @return \OCA\Files_External\Service\GlobalStoragesService |
|
| 2159 | - * @deprecated 20.0.0 |
|
| 2160 | - */ |
|
| 2161 | - public function getGlobalStoragesService() { |
|
| 2162 | - return $this->get(GlobalStoragesService::class); |
|
| 2163 | - } |
|
| 2164 | - |
|
| 2165 | - /** |
|
| 2166 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 2167 | - * |
|
| 2168 | - * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
| 2169 | - * @deprecated 20.0.0 |
|
| 2170 | - */ |
|
| 2171 | - public function getUserGlobalStoragesService() { |
|
| 2172 | - return $this->get(UserGlobalStoragesService::class); |
|
| 2173 | - } |
|
| 2174 | - |
|
| 2175 | - /** |
|
| 2176 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 2177 | - * |
|
| 2178 | - * @return \OCA\Files_External\Service\UserStoragesService |
|
| 2179 | - * @deprecated 20.0.0 |
|
| 2180 | - */ |
|
| 2181 | - public function getUserStoragesService() { |
|
| 2182 | - return $this->get(UserStoragesService::class); |
|
| 2183 | - } |
|
| 2184 | - |
|
| 2185 | - /** |
|
| 2186 | - * @return \OCP\Share\IManager |
|
| 2187 | - * @deprecated 20.0.0 |
|
| 2188 | - */ |
|
| 2189 | - public function getShareManager() { |
|
| 2190 | - return $this->get(\OCP\Share\IManager::class); |
|
| 2191 | - } |
|
| 2192 | - |
|
| 2193 | - /** |
|
| 2194 | - * @return \OCP\Collaboration\Collaborators\ISearch |
|
| 2195 | - * @deprecated 20.0.0 |
|
| 2196 | - */ |
|
| 2197 | - public function getCollaboratorSearch() { |
|
| 2198 | - return $this->get(\OCP\Collaboration\Collaborators\ISearch::class); |
|
| 2199 | - } |
|
| 2200 | - |
|
| 2201 | - /** |
|
| 2202 | - * @return \OCP\Collaboration\AutoComplete\IManager |
|
| 2203 | - * @deprecated 20.0.0 |
|
| 2204 | - */ |
|
| 2205 | - public function getAutoCompleteManager() { |
|
| 2206 | - return $this->get(IManager::class); |
|
| 2207 | - } |
|
| 2208 | - |
|
| 2209 | - /** |
|
| 2210 | - * Returns the LDAP Provider |
|
| 2211 | - * |
|
| 2212 | - * @return \OCP\LDAP\ILDAPProvider |
|
| 2213 | - * @deprecated 20.0.0 |
|
| 2214 | - */ |
|
| 2215 | - public function getLDAPProvider() { |
|
| 2216 | - return $this->get('LDAPProvider'); |
|
| 2217 | - } |
|
| 2218 | - |
|
| 2219 | - /** |
|
| 2220 | - * @return \OCP\Settings\IManager |
|
| 2221 | - * @deprecated 20.0.0 |
|
| 2222 | - */ |
|
| 2223 | - public function getSettingsManager() { |
|
| 2224 | - return $this->get(\OC\Settings\Manager::class); |
|
| 2225 | - } |
|
| 2226 | - |
|
| 2227 | - /** |
|
| 2228 | - * @return \OCP\Files\IAppData |
|
| 2229 | - * @deprecated 20.0.0 |
|
| 2230 | - */ |
|
| 2231 | - public function getAppDataDir($app) { |
|
| 2232 | - /** @var \OC\Files\AppData\Factory $factory */ |
|
| 2233 | - $factory = $this->get(\OC\Files\AppData\Factory::class); |
|
| 2234 | - return $factory->get($app); |
|
| 2235 | - } |
|
| 2236 | - |
|
| 2237 | - /** |
|
| 2238 | - * @return \OCP\Lockdown\ILockdownManager |
|
| 2239 | - * @deprecated 20.0.0 |
|
| 2240 | - */ |
|
| 2241 | - public function getLockdownManager() { |
|
| 2242 | - return $this->get('LockdownManager'); |
|
| 2243 | - } |
|
| 2244 | - |
|
| 2245 | - /** |
|
| 2246 | - * @return \OCP\Federation\ICloudIdManager |
|
| 2247 | - * @deprecated 20.0.0 |
|
| 2248 | - */ |
|
| 2249 | - public function getCloudIdManager() { |
|
| 2250 | - return $this->get(ICloudIdManager::class); |
|
| 2251 | - } |
|
| 2252 | - |
|
| 2253 | - /** |
|
| 2254 | - * @return \OCP\GlobalScale\IConfig |
|
| 2255 | - * @deprecated 20.0.0 |
|
| 2256 | - */ |
|
| 2257 | - public function getGlobalScaleConfig() { |
|
| 2258 | - return $this->get(IConfig::class); |
|
| 2259 | - } |
|
| 2260 | - |
|
| 2261 | - /** |
|
| 2262 | - * @return \OCP\Federation\ICloudFederationProviderManager |
|
| 2263 | - * @deprecated 20.0.0 |
|
| 2264 | - */ |
|
| 2265 | - public function getCloudFederationProviderManager() { |
|
| 2266 | - return $this->get(ICloudFederationProviderManager::class); |
|
| 2267 | - } |
|
| 2268 | - |
|
| 2269 | - /** |
|
| 2270 | - * @return \OCP\Remote\Api\IApiFactory |
|
| 2271 | - * @deprecated 20.0.0 |
|
| 2272 | - */ |
|
| 2273 | - public function getRemoteApiFactory() { |
|
| 2274 | - return $this->get(IApiFactory::class); |
|
| 2275 | - } |
|
| 2276 | - |
|
| 2277 | - /** |
|
| 2278 | - * @return \OCP\Federation\ICloudFederationFactory |
|
| 2279 | - * @deprecated 20.0.0 |
|
| 2280 | - */ |
|
| 2281 | - public function getCloudFederationFactory() { |
|
| 2282 | - return $this->get(ICloudFederationFactory::class); |
|
| 2283 | - } |
|
| 2284 | - |
|
| 2285 | - /** |
|
| 2286 | - * @return \OCP\Remote\IInstanceFactory |
|
| 2287 | - * @deprecated 20.0.0 |
|
| 2288 | - */ |
|
| 2289 | - public function getRemoteInstanceFactory() { |
|
| 2290 | - return $this->get(IInstanceFactory::class); |
|
| 2291 | - } |
|
| 2292 | - |
|
| 2293 | - /** |
|
| 2294 | - * @return IStorageFactory |
|
| 2295 | - * @deprecated 20.0.0 |
|
| 2296 | - */ |
|
| 2297 | - public function getStorageFactory() { |
|
| 2298 | - return $this->get(IStorageFactory::class); |
|
| 2299 | - } |
|
| 2300 | - |
|
| 2301 | - /** |
|
| 2302 | - * Get the Preview GeneratorHelper |
|
| 2303 | - * |
|
| 2304 | - * @return GeneratorHelper |
|
| 2305 | - * @since 17.0.0 |
|
| 2306 | - * @deprecated 20.0.0 |
|
| 2307 | - */ |
|
| 2308 | - public function getGeneratorHelper() { |
|
| 2309 | - return $this->get(\OC\Preview\GeneratorHelper::class); |
|
| 2310 | - } |
|
| 2311 | - |
|
| 2312 | - private function registerDeprecatedAlias(string $alias, string $target) { |
|
| 2313 | - $this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) { |
|
| 2314 | - try { |
|
| 2315 | - /** @var ILogger $logger */ |
|
| 2316 | - $logger = $container->get(ILogger::class); |
|
| 2317 | - $logger->debug('The requested alias "' . $alias . '" is deprecated. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']); |
|
| 2318 | - } catch (ContainerExceptionInterface $e) { |
|
| 2319 | - // Could not get logger. Continue |
|
| 2320 | - } |
|
| 2321 | - |
|
| 2322 | - return $container->get($target); |
|
| 2323 | - }, false); |
|
| 2324 | - } |
|
| 1139 | + $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
| 1140 | + if (isset($prefixes['OCA\\Theming\\'])) { |
|
| 1141 | + $classExists = true; |
|
| 1142 | + } else { |
|
| 1143 | + $classExists = false; |
|
| 1144 | + } |
|
| 1145 | + |
|
| 1146 | + if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValue('installed', false) && $c->get(IAppManager::class)->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
| 1147 | + return new ThemingDefaults( |
|
| 1148 | + $c->get(\OCP\IConfig::class), |
|
| 1149 | + $c->getL10N('theming'), |
|
| 1150 | + $c->get(IURLGenerator::class), |
|
| 1151 | + $c->get(ICacheFactory::class), |
|
| 1152 | + new Util($c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming')), |
|
| 1153 | + new ImageManager( |
|
| 1154 | + $c->get(\OCP\IConfig::class), |
|
| 1155 | + $c->getAppDataDir('theming'), |
|
| 1156 | + $c->get(IURLGenerator::class), |
|
| 1157 | + $this->get(ICacheFactory::class), |
|
| 1158 | + $this->get(ILogger::class), |
|
| 1159 | + $this->get(ITempManager::class) |
|
| 1160 | + ), |
|
| 1161 | + $c->get(IAppManager::class), |
|
| 1162 | + $c->get(INavigationManager::class) |
|
| 1163 | + ); |
|
| 1164 | + } |
|
| 1165 | + return new \OC_Defaults(); |
|
| 1166 | + }); |
|
| 1167 | + $this->registerService(JSCombiner::class, function (Server $c) { |
|
| 1168 | + return new JSCombiner( |
|
| 1169 | + $c->getAppDataDir('js'), |
|
| 1170 | + $c->get(IURLGenerator::class), |
|
| 1171 | + $this->get(ICacheFactory::class), |
|
| 1172 | + $c->get(SystemConfig::class), |
|
| 1173 | + $c->get(ILogger::class) |
|
| 1174 | + ); |
|
| 1175 | + }); |
|
| 1176 | + $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
| 1177 | + /** @deprecated 19.0.0 */ |
|
| 1178 | + $this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class); |
|
| 1179 | + $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class); |
|
| 1180 | + |
|
| 1181 | + $this->registerService('CryptoWrapper', function (ContainerInterface $c) { |
|
| 1182 | + // FIXME: Instantiiated here due to cyclic dependency |
|
| 1183 | + $request = new Request( |
|
| 1184 | + [ |
|
| 1185 | + 'get' => $_GET, |
|
| 1186 | + 'post' => $_POST, |
|
| 1187 | + 'files' => $_FILES, |
|
| 1188 | + 'server' => $_SERVER, |
|
| 1189 | + 'env' => $_ENV, |
|
| 1190 | + 'cookies' => $_COOKIE, |
|
| 1191 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 1192 | + ? $_SERVER['REQUEST_METHOD'] |
|
| 1193 | + : null, |
|
| 1194 | + ], |
|
| 1195 | + $c->get(ISecureRandom::class), |
|
| 1196 | + $c->get(\OCP\IConfig::class) |
|
| 1197 | + ); |
|
| 1198 | + |
|
| 1199 | + return new CryptoWrapper( |
|
| 1200 | + $c->get(\OCP\IConfig::class), |
|
| 1201 | + $c->get(ICrypto::class), |
|
| 1202 | + $c->get(ISecureRandom::class), |
|
| 1203 | + $request |
|
| 1204 | + ); |
|
| 1205 | + }); |
|
| 1206 | + /** @deprecated 19.0.0 */ |
|
| 1207 | + $this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class); |
|
| 1208 | + $this->registerService(SessionStorage::class, function (ContainerInterface $c) { |
|
| 1209 | + return new SessionStorage($c->get(ISession::class)); |
|
| 1210 | + }); |
|
| 1211 | + $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
|
| 1212 | + /** @deprecated 19.0.0 */ |
|
| 1213 | + $this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class); |
|
| 1214 | + |
|
| 1215 | + $this->registerService(\OCP\Share\IManager::class, function (IServerContainer $c) { |
|
| 1216 | + $config = $c->get(\OCP\IConfig::class); |
|
| 1217 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
| 1218 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
| 1219 | + $factory = new $factoryClass($this); |
|
| 1220 | + |
|
| 1221 | + $manager = new \OC\Share20\Manager( |
|
| 1222 | + $c->get(ILogger::class), |
|
| 1223 | + $c->get(\OCP\IConfig::class), |
|
| 1224 | + $c->get(ISecureRandom::class), |
|
| 1225 | + $c->get(IHasher::class), |
|
| 1226 | + $c->get(IMountManager::class), |
|
| 1227 | + $c->get(IGroupManager::class), |
|
| 1228 | + $c->getL10N('lib'), |
|
| 1229 | + $c->get(IFactory::class), |
|
| 1230 | + $factory, |
|
| 1231 | + $c->get(IUserManager::class), |
|
| 1232 | + $c->get(IRootFolder::class), |
|
| 1233 | + $c->get(SymfonyAdapter::class), |
|
| 1234 | + $c->get(IMailer::class), |
|
| 1235 | + $c->get(IURLGenerator::class), |
|
| 1236 | + $c->get('ThemingDefaults'), |
|
| 1237 | + $c->get(IEventDispatcher::class) |
|
| 1238 | + ); |
|
| 1239 | + |
|
| 1240 | + return $manager; |
|
| 1241 | + }); |
|
| 1242 | + /** @deprecated 19.0.0 */ |
|
| 1243 | + $this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class); |
|
| 1244 | + |
|
| 1245 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
| 1246 | + $instance = new Collaboration\Collaborators\Search($c); |
|
| 1247 | + |
|
| 1248 | + // register default plugins |
|
| 1249 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
| 1250 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
| 1251 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
| 1252 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
| 1253 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
| 1254 | + |
|
| 1255 | + return $instance; |
|
| 1256 | + }); |
|
| 1257 | + /** @deprecated 19.0.0 */ |
|
| 1258 | + $this->registerDeprecatedAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
| 1259 | + $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
| 1260 | + |
|
| 1261 | + $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
| 1262 | + |
|
| 1263 | + $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class); |
|
| 1264 | + $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
| 1265 | + |
|
| 1266 | + $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class); |
|
| 1267 | + $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class); |
|
| 1268 | + $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) { |
|
| 1269 | + return new \OC\Files\AppData\Factory( |
|
| 1270 | + $c->get(IRootFolder::class), |
|
| 1271 | + $c->get(SystemConfig::class) |
|
| 1272 | + ); |
|
| 1273 | + }); |
|
| 1274 | + |
|
| 1275 | + $this->registerService('LockdownManager', function (ContainerInterface $c) { |
|
| 1276 | + return new LockdownManager(function () use ($c) { |
|
| 1277 | + return $c->get(ISession::class); |
|
| 1278 | + }); |
|
| 1279 | + }); |
|
| 1280 | + |
|
| 1281 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) { |
|
| 1282 | + return new DiscoveryService( |
|
| 1283 | + $c->get(ICacheFactory::class), |
|
| 1284 | + $c->get(IClientService::class) |
|
| 1285 | + ); |
|
| 1286 | + }); |
|
| 1287 | + |
|
| 1288 | + $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) { |
|
| 1289 | + return new CloudIdManager($c->get(\OCP\Contacts\IManager::class)); |
|
| 1290 | + }); |
|
| 1291 | + |
|
| 1292 | + $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); |
|
| 1293 | + |
|
| 1294 | + $this->registerService(ICloudFederationProviderManager::class, function (ContainerInterface $c) { |
|
| 1295 | + return new CloudFederationProviderManager( |
|
| 1296 | + $c->get(IAppManager::class), |
|
| 1297 | + $c->get(IClientService::class), |
|
| 1298 | + $c->get(ICloudIdManager::class), |
|
| 1299 | + $c->get(ILogger::class) |
|
| 1300 | + ); |
|
| 1301 | + }); |
|
| 1302 | + |
|
| 1303 | + $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
| 1304 | + return new CloudFederationFactory(); |
|
| 1305 | + }); |
|
| 1306 | + |
|
| 1307 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 1308 | + /** @deprecated 19.0.0 */ |
|
| 1309 | + $this->registerDeprecatedAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
| 1310 | + |
|
| 1311 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 1312 | + /** @deprecated 19.0.0 */ |
|
| 1313 | + $this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 1314 | + |
|
| 1315 | + $this->registerService(Defaults::class, function (Server $c) { |
|
| 1316 | + return new Defaults( |
|
| 1317 | + $c->getThemingDefaults() |
|
| 1318 | + ); |
|
| 1319 | + }); |
|
| 1320 | + /** @deprecated 19.0.0 */ |
|
| 1321 | + $this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class); |
|
| 1322 | + |
|
| 1323 | + $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) { |
|
| 1324 | + return $c->get(\OCP\IUserSession::class)->getSession(); |
|
| 1325 | + }, false); |
|
| 1326 | + |
|
| 1327 | + $this->registerService(IShareHelper::class, function (ContainerInterface $c) { |
|
| 1328 | + return new ShareHelper( |
|
| 1329 | + $c->get(\OCP\Share\IManager::class) |
|
| 1330 | + ); |
|
| 1331 | + }); |
|
| 1332 | + |
|
| 1333 | + $this->registerService(Installer::class, function (ContainerInterface $c) { |
|
| 1334 | + return new Installer( |
|
| 1335 | + $c->get(AppFetcher::class), |
|
| 1336 | + $c->get(IClientService::class), |
|
| 1337 | + $c->get(ITempManager::class), |
|
| 1338 | + $c->get(LoggerInterface::class), |
|
| 1339 | + $c->get(\OCP\IConfig::class), |
|
| 1340 | + \OC::$CLI |
|
| 1341 | + ); |
|
| 1342 | + }); |
|
| 1343 | + |
|
| 1344 | + $this->registerService(IApiFactory::class, function (ContainerInterface $c) { |
|
| 1345 | + return new ApiFactory($c->get(IClientService::class)); |
|
| 1346 | + }); |
|
| 1347 | + |
|
| 1348 | + $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) { |
|
| 1349 | + $memcacheFactory = $c->get(ICacheFactory::class); |
|
| 1350 | + return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class)); |
|
| 1351 | + }); |
|
| 1352 | + |
|
| 1353 | + $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
| 1354 | + $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
| 1355 | + |
|
| 1356 | + $this->registerAlias(IStorageFactory::class, StorageFactory::class); |
|
| 1357 | + |
|
| 1358 | + $this->registerAlias(IDashboardManager::class, DashboardManager::class); |
|
| 1359 | + $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class); |
|
| 1360 | + $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
| 1361 | + |
|
| 1362 | + $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
| 1363 | + |
|
| 1364 | + $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
| 1365 | + |
|
| 1366 | + $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class); |
|
| 1367 | + |
|
| 1368 | + $this->connectDispatcher(); |
|
| 1369 | + } |
|
| 1370 | + |
|
| 1371 | + public function boot() { |
|
| 1372 | + /** @var HookConnector $hookConnector */ |
|
| 1373 | + $hookConnector = $this->get(HookConnector::class); |
|
| 1374 | + $hookConnector->viewToNode(); |
|
| 1375 | + } |
|
| 1376 | + |
|
| 1377 | + /** |
|
| 1378 | + * @return \OCP\Calendar\IManager |
|
| 1379 | + * @deprecated 20.0.0 |
|
| 1380 | + */ |
|
| 1381 | + public function getCalendarManager() { |
|
| 1382 | + return $this->get(\OC\Calendar\Manager::class); |
|
| 1383 | + } |
|
| 1384 | + |
|
| 1385 | + /** |
|
| 1386 | + * @return \OCP\Calendar\Resource\IManager |
|
| 1387 | + * @deprecated 20.0.0 |
|
| 1388 | + */ |
|
| 1389 | + public function getCalendarResourceBackendManager() { |
|
| 1390 | + return $this->get(\OC\Calendar\Resource\Manager::class); |
|
| 1391 | + } |
|
| 1392 | + |
|
| 1393 | + /** |
|
| 1394 | + * @return \OCP\Calendar\Room\IManager |
|
| 1395 | + * @deprecated 20.0.0 |
|
| 1396 | + */ |
|
| 1397 | + public function getCalendarRoomBackendManager() { |
|
| 1398 | + return $this->get(\OC\Calendar\Room\Manager::class); |
|
| 1399 | + } |
|
| 1400 | + |
|
| 1401 | + private function connectDispatcher() { |
|
| 1402 | + $dispatcher = $this->get(SymfonyAdapter::class); |
|
| 1403 | + |
|
| 1404 | + // Delete avatar on user deletion |
|
| 1405 | + $dispatcher->addListener('OCP\IUser::preDelete', function (GenericEvent $e) { |
|
| 1406 | + $logger = $this->get(ILogger::class); |
|
| 1407 | + $manager = $this->getAvatarManager(); |
|
| 1408 | + /** @var IUser $user */ |
|
| 1409 | + $user = $e->getSubject(); |
|
| 1410 | + |
|
| 1411 | + try { |
|
| 1412 | + $avatar = $manager->getAvatar($user->getUID()); |
|
| 1413 | + $avatar->remove(); |
|
| 1414 | + } catch (NotFoundException $e) { |
|
| 1415 | + // no avatar to remove |
|
| 1416 | + } catch (\Exception $e) { |
|
| 1417 | + // Ignore exceptions |
|
| 1418 | + $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
| 1419 | + } |
|
| 1420 | + }); |
|
| 1421 | + |
|
| 1422 | + $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
| 1423 | + $manager = $this->getAvatarManager(); |
|
| 1424 | + /** @var IUser $user */ |
|
| 1425 | + $user = $e->getSubject(); |
|
| 1426 | + $feature = $e->getArgument('feature'); |
|
| 1427 | + $oldValue = $e->getArgument('oldValue'); |
|
| 1428 | + $value = $e->getArgument('value'); |
|
| 1429 | + |
|
| 1430 | + // We only change the avatar on display name changes |
|
| 1431 | + if ($feature !== 'displayName') { |
|
| 1432 | + return; |
|
| 1433 | + } |
|
| 1434 | + |
|
| 1435 | + try { |
|
| 1436 | + $avatar = $manager->getAvatar($user->getUID()); |
|
| 1437 | + $avatar->userChanged($feature, $oldValue, $value); |
|
| 1438 | + } catch (NotFoundException $e) { |
|
| 1439 | + // no avatar to remove |
|
| 1440 | + } |
|
| 1441 | + }); |
|
| 1442 | + |
|
| 1443 | + /** @var IEventDispatcher $eventDispatched */ |
|
| 1444 | + $eventDispatched = $this->get(IEventDispatcher::class); |
|
| 1445 | + $eventDispatched->addServiceListener(LoginFailed::class, LoginFailedListener::class); |
|
| 1446 | + $eventDispatched->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class); |
|
| 1447 | + } |
|
| 1448 | + |
|
| 1449 | + /** |
|
| 1450 | + * @return \OCP\Contacts\IManager |
|
| 1451 | + * @deprecated 20.0.0 |
|
| 1452 | + */ |
|
| 1453 | + public function getContactsManager() { |
|
| 1454 | + return $this->get(\OCP\Contacts\IManager::class); |
|
| 1455 | + } |
|
| 1456 | + |
|
| 1457 | + /** |
|
| 1458 | + * @return \OC\Encryption\Manager |
|
| 1459 | + * @deprecated 20.0.0 |
|
| 1460 | + */ |
|
| 1461 | + public function getEncryptionManager() { |
|
| 1462 | + return $this->get(\OCP\Encryption\IManager::class); |
|
| 1463 | + } |
|
| 1464 | + |
|
| 1465 | + /** |
|
| 1466 | + * @return \OC\Encryption\File |
|
| 1467 | + * @deprecated 20.0.0 |
|
| 1468 | + */ |
|
| 1469 | + public function getEncryptionFilesHelper() { |
|
| 1470 | + return $this->get(IFile::class); |
|
| 1471 | + } |
|
| 1472 | + |
|
| 1473 | + /** |
|
| 1474 | + * @return \OCP\Encryption\Keys\IStorage |
|
| 1475 | + * @deprecated 20.0.0 |
|
| 1476 | + */ |
|
| 1477 | + public function getEncryptionKeyStorage() { |
|
| 1478 | + return $this->get(IStorage::class); |
|
| 1479 | + } |
|
| 1480 | + |
|
| 1481 | + /** |
|
| 1482 | + * The current request object holding all information about the request |
|
| 1483 | + * currently being processed is returned from this method. |
|
| 1484 | + * In case the current execution was not initiated by a web request null is returned |
|
| 1485 | + * |
|
| 1486 | + * @return \OCP\IRequest |
|
| 1487 | + * @deprecated 20.0.0 |
|
| 1488 | + */ |
|
| 1489 | + public function getRequest() { |
|
| 1490 | + return $this->get(IRequest::class); |
|
| 1491 | + } |
|
| 1492 | + |
|
| 1493 | + /** |
|
| 1494 | + * Returns the preview manager which can create preview images for a given file |
|
| 1495 | + * |
|
| 1496 | + * @return IPreview |
|
| 1497 | + * @deprecated 20.0.0 |
|
| 1498 | + */ |
|
| 1499 | + public function getPreviewManager() { |
|
| 1500 | + return $this->get(IPreview::class); |
|
| 1501 | + } |
|
| 1502 | + |
|
| 1503 | + /** |
|
| 1504 | + * Returns the tag manager which can get and set tags for different object types |
|
| 1505 | + * |
|
| 1506 | + * @see \OCP\ITagManager::load() |
|
| 1507 | + * @return ITagManager |
|
| 1508 | + * @deprecated 20.0.0 |
|
| 1509 | + */ |
|
| 1510 | + public function getTagManager() { |
|
| 1511 | + return $this->get(ITagManager::class); |
|
| 1512 | + } |
|
| 1513 | + |
|
| 1514 | + /** |
|
| 1515 | + * Returns the system-tag manager |
|
| 1516 | + * |
|
| 1517 | + * @return ISystemTagManager |
|
| 1518 | + * |
|
| 1519 | + * @since 9.0.0 |
|
| 1520 | + * @deprecated 20.0.0 |
|
| 1521 | + */ |
|
| 1522 | + public function getSystemTagManager() { |
|
| 1523 | + return $this->get(ISystemTagManager::class); |
|
| 1524 | + } |
|
| 1525 | + |
|
| 1526 | + /** |
|
| 1527 | + * Returns the system-tag object mapper |
|
| 1528 | + * |
|
| 1529 | + * @return ISystemTagObjectMapper |
|
| 1530 | + * |
|
| 1531 | + * @since 9.0.0 |
|
| 1532 | + * @deprecated 20.0.0 |
|
| 1533 | + */ |
|
| 1534 | + public function getSystemTagObjectMapper() { |
|
| 1535 | + return $this->get(ISystemTagObjectMapper::class); |
|
| 1536 | + } |
|
| 1537 | + |
|
| 1538 | + /** |
|
| 1539 | + * Returns the avatar manager, used for avatar functionality |
|
| 1540 | + * |
|
| 1541 | + * @return IAvatarManager |
|
| 1542 | + * @deprecated 20.0.0 |
|
| 1543 | + */ |
|
| 1544 | + public function getAvatarManager() { |
|
| 1545 | + return $this->get(IAvatarManager::class); |
|
| 1546 | + } |
|
| 1547 | + |
|
| 1548 | + /** |
|
| 1549 | + * Returns the root folder of ownCloud's data directory |
|
| 1550 | + * |
|
| 1551 | + * @return IRootFolder |
|
| 1552 | + * @deprecated 20.0.0 |
|
| 1553 | + */ |
|
| 1554 | + public function getRootFolder() { |
|
| 1555 | + return $this->get(IRootFolder::class); |
|
| 1556 | + } |
|
| 1557 | + |
|
| 1558 | + /** |
|
| 1559 | + * Returns the root folder of ownCloud's data directory |
|
| 1560 | + * This is the lazy variant so this gets only initialized once it |
|
| 1561 | + * is actually used. |
|
| 1562 | + * |
|
| 1563 | + * @return IRootFolder |
|
| 1564 | + * @deprecated 20.0.0 |
|
| 1565 | + */ |
|
| 1566 | + public function getLazyRootFolder() { |
|
| 1567 | + return $this->get(IRootFolder::class); |
|
| 1568 | + } |
|
| 1569 | + |
|
| 1570 | + /** |
|
| 1571 | + * Returns a view to ownCloud's files folder |
|
| 1572 | + * |
|
| 1573 | + * @param string $userId user ID |
|
| 1574 | + * @return \OCP\Files\Folder|null |
|
| 1575 | + * @deprecated 20.0.0 |
|
| 1576 | + */ |
|
| 1577 | + public function getUserFolder($userId = null) { |
|
| 1578 | + if ($userId === null) { |
|
| 1579 | + $user = $this->get(IUserSession::class)->getUser(); |
|
| 1580 | + if (!$user) { |
|
| 1581 | + return null; |
|
| 1582 | + } |
|
| 1583 | + $userId = $user->getUID(); |
|
| 1584 | + } |
|
| 1585 | + $root = $this->get(IRootFolder::class); |
|
| 1586 | + return $root->getUserFolder($userId); |
|
| 1587 | + } |
|
| 1588 | + |
|
| 1589 | + /** |
|
| 1590 | + * @return \OC\User\Manager |
|
| 1591 | + * @deprecated 20.0.0 |
|
| 1592 | + */ |
|
| 1593 | + public function getUserManager() { |
|
| 1594 | + return $this->get(IUserManager::class); |
|
| 1595 | + } |
|
| 1596 | + |
|
| 1597 | + /** |
|
| 1598 | + * @return \OC\Group\Manager |
|
| 1599 | + * @deprecated 20.0.0 |
|
| 1600 | + */ |
|
| 1601 | + public function getGroupManager() { |
|
| 1602 | + return $this->get(IGroupManager::class); |
|
| 1603 | + } |
|
| 1604 | + |
|
| 1605 | + /** |
|
| 1606 | + * @return \OC\User\Session |
|
| 1607 | + * @deprecated 20.0.0 |
|
| 1608 | + */ |
|
| 1609 | + public function getUserSession() { |
|
| 1610 | + return $this->get(IUserSession::class); |
|
| 1611 | + } |
|
| 1612 | + |
|
| 1613 | + /** |
|
| 1614 | + * @return \OCP\ISession |
|
| 1615 | + * @deprecated 20.0.0 |
|
| 1616 | + */ |
|
| 1617 | + public function getSession() { |
|
| 1618 | + return $this->get(IUserSession::class)->getSession(); |
|
| 1619 | + } |
|
| 1620 | + |
|
| 1621 | + /** |
|
| 1622 | + * @param \OCP\ISession $session |
|
| 1623 | + */ |
|
| 1624 | + public function setSession(\OCP\ISession $session) { |
|
| 1625 | + $this->get(SessionStorage::class)->setSession($session); |
|
| 1626 | + $this->get(IUserSession::class)->setSession($session); |
|
| 1627 | + $this->get(Store::class)->setSession($session); |
|
| 1628 | + } |
|
| 1629 | + |
|
| 1630 | + /** |
|
| 1631 | + * @return \OC\Authentication\TwoFactorAuth\Manager |
|
| 1632 | + * @deprecated 20.0.0 |
|
| 1633 | + */ |
|
| 1634 | + public function getTwoFactorAuthManager() { |
|
| 1635 | + return $this->get(\OC\Authentication\TwoFactorAuth\Manager::class); |
|
| 1636 | + } |
|
| 1637 | + |
|
| 1638 | + /** |
|
| 1639 | + * @return \OC\NavigationManager |
|
| 1640 | + * @deprecated 20.0.0 |
|
| 1641 | + */ |
|
| 1642 | + public function getNavigationManager() { |
|
| 1643 | + return $this->get(INavigationManager::class); |
|
| 1644 | + } |
|
| 1645 | + |
|
| 1646 | + /** |
|
| 1647 | + * @return \OCP\IConfig |
|
| 1648 | + * @deprecated 20.0.0 |
|
| 1649 | + */ |
|
| 1650 | + public function getConfig() { |
|
| 1651 | + return $this->get(AllConfig::class); |
|
| 1652 | + } |
|
| 1653 | + |
|
| 1654 | + /** |
|
| 1655 | + * @return \OC\SystemConfig |
|
| 1656 | + * @deprecated 20.0.0 |
|
| 1657 | + */ |
|
| 1658 | + public function getSystemConfig() { |
|
| 1659 | + return $this->get(SystemConfig::class); |
|
| 1660 | + } |
|
| 1661 | + |
|
| 1662 | + /** |
|
| 1663 | + * Returns the app config manager |
|
| 1664 | + * |
|
| 1665 | + * @return IAppConfig |
|
| 1666 | + * @deprecated 20.0.0 |
|
| 1667 | + */ |
|
| 1668 | + public function getAppConfig() { |
|
| 1669 | + return $this->get(IAppConfig::class); |
|
| 1670 | + } |
|
| 1671 | + |
|
| 1672 | + /** |
|
| 1673 | + * @return IFactory |
|
| 1674 | + * @deprecated 20.0.0 |
|
| 1675 | + */ |
|
| 1676 | + public function getL10NFactory() { |
|
| 1677 | + return $this->get(IFactory::class); |
|
| 1678 | + } |
|
| 1679 | + |
|
| 1680 | + /** |
|
| 1681 | + * get an L10N instance |
|
| 1682 | + * |
|
| 1683 | + * @param string $app appid |
|
| 1684 | + * @param string $lang |
|
| 1685 | + * @return IL10N |
|
| 1686 | + * @deprecated 20.0.0 |
|
| 1687 | + */ |
|
| 1688 | + public function getL10N($app, $lang = null) { |
|
| 1689 | + return $this->get(IFactory::class)->get($app, $lang); |
|
| 1690 | + } |
|
| 1691 | + |
|
| 1692 | + /** |
|
| 1693 | + * @return IURLGenerator |
|
| 1694 | + * @deprecated 20.0.0 |
|
| 1695 | + */ |
|
| 1696 | + public function getURLGenerator() { |
|
| 1697 | + return $this->get(IURLGenerator::class); |
|
| 1698 | + } |
|
| 1699 | + |
|
| 1700 | + /** |
|
| 1701 | + * @return AppFetcher |
|
| 1702 | + * @deprecated 20.0.0 |
|
| 1703 | + */ |
|
| 1704 | + public function getAppFetcher() { |
|
| 1705 | + return $this->get(AppFetcher::class); |
|
| 1706 | + } |
|
| 1707 | + |
|
| 1708 | + /** |
|
| 1709 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
| 1710 | + * getMemCacheFactory() instead. |
|
| 1711 | + * |
|
| 1712 | + * @return ICache |
|
| 1713 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
| 1714 | + */ |
|
| 1715 | + public function getCache() { |
|
| 1716 | + return $this->get(ICache::class); |
|
| 1717 | + } |
|
| 1718 | + |
|
| 1719 | + /** |
|
| 1720 | + * Returns an \OCP\CacheFactory instance |
|
| 1721 | + * |
|
| 1722 | + * @return \OCP\ICacheFactory |
|
| 1723 | + * @deprecated 20.0.0 |
|
| 1724 | + */ |
|
| 1725 | + public function getMemCacheFactory() { |
|
| 1726 | + return $this->get(ICacheFactory::class); |
|
| 1727 | + } |
|
| 1728 | + |
|
| 1729 | + /** |
|
| 1730 | + * Returns an \OC\RedisFactory instance |
|
| 1731 | + * |
|
| 1732 | + * @return \OC\RedisFactory |
|
| 1733 | + * @deprecated 20.0.0 |
|
| 1734 | + */ |
|
| 1735 | + public function getGetRedisFactory() { |
|
| 1736 | + return $this->get('RedisFactory'); |
|
| 1737 | + } |
|
| 1738 | + |
|
| 1739 | + |
|
| 1740 | + /** |
|
| 1741 | + * Returns the current session |
|
| 1742 | + * |
|
| 1743 | + * @return \OCP\IDBConnection |
|
| 1744 | + * @deprecated 20.0.0 |
|
| 1745 | + */ |
|
| 1746 | + public function getDatabaseConnection() { |
|
| 1747 | + return $this->get(IDBConnection::class); |
|
| 1748 | + } |
|
| 1749 | + |
|
| 1750 | + /** |
|
| 1751 | + * Returns the activity manager |
|
| 1752 | + * |
|
| 1753 | + * @return \OCP\Activity\IManager |
|
| 1754 | + * @deprecated 20.0.0 |
|
| 1755 | + */ |
|
| 1756 | + public function getActivityManager() { |
|
| 1757 | + return $this->get(\OCP\Activity\IManager::class); |
|
| 1758 | + } |
|
| 1759 | + |
|
| 1760 | + /** |
|
| 1761 | + * Returns an job list for controlling background jobs |
|
| 1762 | + * |
|
| 1763 | + * @return IJobList |
|
| 1764 | + * @deprecated 20.0.0 |
|
| 1765 | + */ |
|
| 1766 | + public function getJobList() { |
|
| 1767 | + return $this->get(IJobList::class); |
|
| 1768 | + } |
|
| 1769 | + |
|
| 1770 | + /** |
|
| 1771 | + * Returns a logger instance |
|
| 1772 | + * |
|
| 1773 | + * @return ILogger |
|
| 1774 | + * @deprecated 20.0.0 |
|
| 1775 | + */ |
|
| 1776 | + public function getLogger() { |
|
| 1777 | + return $this->get(ILogger::class); |
|
| 1778 | + } |
|
| 1779 | + |
|
| 1780 | + /** |
|
| 1781 | + * @return ILogFactory |
|
| 1782 | + * @throws \OCP\AppFramework\QueryException |
|
| 1783 | + * @deprecated 20.0.0 |
|
| 1784 | + */ |
|
| 1785 | + public function getLogFactory() { |
|
| 1786 | + return $this->get(ILogFactory::class); |
|
| 1787 | + } |
|
| 1788 | + |
|
| 1789 | + /** |
|
| 1790 | + * Returns a router for generating and matching urls |
|
| 1791 | + * |
|
| 1792 | + * @return IRouter |
|
| 1793 | + * @deprecated 20.0.0 |
|
| 1794 | + */ |
|
| 1795 | + public function getRouter() { |
|
| 1796 | + return $this->get(IRouter::class); |
|
| 1797 | + } |
|
| 1798 | + |
|
| 1799 | + /** |
|
| 1800 | + * Returns a search instance |
|
| 1801 | + * |
|
| 1802 | + * @return ISearch |
|
| 1803 | + * @deprecated 20.0.0 |
|
| 1804 | + */ |
|
| 1805 | + public function getSearch() { |
|
| 1806 | + return $this->get(ISearch::class); |
|
| 1807 | + } |
|
| 1808 | + |
|
| 1809 | + /** |
|
| 1810 | + * Returns a SecureRandom instance |
|
| 1811 | + * |
|
| 1812 | + * @return \OCP\Security\ISecureRandom |
|
| 1813 | + * @deprecated 20.0.0 |
|
| 1814 | + */ |
|
| 1815 | + public function getSecureRandom() { |
|
| 1816 | + return $this->get(ISecureRandom::class); |
|
| 1817 | + } |
|
| 1818 | + |
|
| 1819 | + /** |
|
| 1820 | + * Returns a Crypto instance |
|
| 1821 | + * |
|
| 1822 | + * @return ICrypto |
|
| 1823 | + * @deprecated 20.0.0 |
|
| 1824 | + */ |
|
| 1825 | + public function getCrypto() { |
|
| 1826 | + return $this->get(ICrypto::class); |
|
| 1827 | + } |
|
| 1828 | + |
|
| 1829 | + /** |
|
| 1830 | + * Returns a Hasher instance |
|
| 1831 | + * |
|
| 1832 | + * @return IHasher |
|
| 1833 | + * @deprecated 20.0.0 |
|
| 1834 | + */ |
|
| 1835 | + public function getHasher() { |
|
| 1836 | + return $this->get(IHasher::class); |
|
| 1837 | + } |
|
| 1838 | + |
|
| 1839 | + /** |
|
| 1840 | + * Returns a CredentialsManager instance |
|
| 1841 | + * |
|
| 1842 | + * @return ICredentialsManager |
|
| 1843 | + * @deprecated 20.0.0 |
|
| 1844 | + */ |
|
| 1845 | + public function getCredentialsManager() { |
|
| 1846 | + return $this->get(ICredentialsManager::class); |
|
| 1847 | + } |
|
| 1848 | + |
|
| 1849 | + /** |
|
| 1850 | + * Get the certificate manager |
|
| 1851 | + * |
|
| 1852 | + * @return \OCP\ICertificateManager |
|
| 1853 | + */ |
|
| 1854 | + public function getCertificateManager() { |
|
| 1855 | + return $this->get(ICertificateManager::class); |
|
| 1856 | + } |
|
| 1857 | + |
|
| 1858 | + /** |
|
| 1859 | + * Returns an instance of the HTTP client service |
|
| 1860 | + * |
|
| 1861 | + * @return IClientService |
|
| 1862 | + * @deprecated 20.0.0 |
|
| 1863 | + */ |
|
| 1864 | + public function getHTTPClientService() { |
|
| 1865 | + return $this->get(IClientService::class); |
|
| 1866 | + } |
|
| 1867 | + |
|
| 1868 | + /** |
|
| 1869 | + * Create a new event source |
|
| 1870 | + * |
|
| 1871 | + * @return \OCP\IEventSource |
|
| 1872 | + * @deprecated 20.0.0 |
|
| 1873 | + */ |
|
| 1874 | + public function createEventSource() { |
|
| 1875 | + return new \OC_EventSource(); |
|
| 1876 | + } |
|
| 1877 | + |
|
| 1878 | + /** |
|
| 1879 | + * Get the active event logger |
|
| 1880 | + * |
|
| 1881 | + * The returned logger only logs data when debug mode is enabled |
|
| 1882 | + * |
|
| 1883 | + * @return IEventLogger |
|
| 1884 | + * @deprecated 20.0.0 |
|
| 1885 | + */ |
|
| 1886 | + public function getEventLogger() { |
|
| 1887 | + return $this->get(IEventLogger::class); |
|
| 1888 | + } |
|
| 1889 | + |
|
| 1890 | + /** |
|
| 1891 | + * Get the active query logger |
|
| 1892 | + * |
|
| 1893 | + * The returned logger only logs data when debug mode is enabled |
|
| 1894 | + * |
|
| 1895 | + * @return IQueryLogger |
|
| 1896 | + * @deprecated 20.0.0 |
|
| 1897 | + */ |
|
| 1898 | + public function getQueryLogger() { |
|
| 1899 | + return $this->get(IQueryLogger::class); |
|
| 1900 | + } |
|
| 1901 | + |
|
| 1902 | + /** |
|
| 1903 | + * Get the manager for temporary files and folders |
|
| 1904 | + * |
|
| 1905 | + * @return \OCP\ITempManager |
|
| 1906 | + * @deprecated 20.0.0 |
|
| 1907 | + */ |
|
| 1908 | + public function getTempManager() { |
|
| 1909 | + return $this->get(ITempManager::class); |
|
| 1910 | + } |
|
| 1911 | + |
|
| 1912 | + /** |
|
| 1913 | + * Get the app manager |
|
| 1914 | + * |
|
| 1915 | + * @return \OCP\App\IAppManager |
|
| 1916 | + * @deprecated 20.0.0 |
|
| 1917 | + */ |
|
| 1918 | + public function getAppManager() { |
|
| 1919 | + return $this->get(IAppManager::class); |
|
| 1920 | + } |
|
| 1921 | + |
|
| 1922 | + /** |
|
| 1923 | + * Creates a new mailer |
|
| 1924 | + * |
|
| 1925 | + * @return IMailer |
|
| 1926 | + * @deprecated 20.0.0 |
|
| 1927 | + */ |
|
| 1928 | + public function getMailer() { |
|
| 1929 | + return $this->get(IMailer::class); |
|
| 1930 | + } |
|
| 1931 | + |
|
| 1932 | + /** |
|
| 1933 | + * Get the webroot |
|
| 1934 | + * |
|
| 1935 | + * @return string |
|
| 1936 | + * @deprecated 20.0.0 |
|
| 1937 | + */ |
|
| 1938 | + public function getWebRoot() { |
|
| 1939 | + return $this->webRoot; |
|
| 1940 | + } |
|
| 1941 | + |
|
| 1942 | + /** |
|
| 1943 | + * @return \OC\OCSClient |
|
| 1944 | + * @deprecated 20.0.0 |
|
| 1945 | + */ |
|
| 1946 | + public function getOcsClient() { |
|
| 1947 | + return $this->get('OcsClient'); |
|
| 1948 | + } |
|
| 1949 | + |
|
| 1950 | + /** |
|
| 1951 | + * @return IDateTimeZone |
|
| 1952 | + * @deprecated 20.0.0 |
|
| 1953 | + */ |
|
| 1954 | + public function getDateTimeZone() { |
|
| 1955 | + return $this->get(IDateTimeZone::class); |
|
| 1956 | + } |
|
| 1957 | + |
|
| 1958 | + /** |
|
| 1959 | + * @return IDateTimeFormatter |
|
| 1960 | + * @deprecated 20.0.0 |
|
| 1961 | + */ |
|
| 1962 | + public function getDateTimeFormatter() { |
|
| 1963 | + return $this->get(IDateTimeFormatter::class); |
|
| 1964 | + } |
|
| 1965 | + |
|
| 1966 | + /** |
|
| 1967 | + * @return IMountProviderCollection |
|
| 1968 | + * @deprecated 20.0.0 |
|
| 1969 | + */ |
|
| 1970 | + public function getMountProviderCollection() { |
|
| 1971 | + return $this->get(IMountProviderCollection::class); |
|
| 1972 | + } |
|
| 1973 | + |
|
| 1974 | + /** |
|
| 1975 | + * Get the IniWrapper |
|
| 1976 | + * |
|
| 1977 | + * @return IniGetWrapper |
|
| 1978 | + * @deprecated 20.0.0 |
|
| 1979 | + */ |
|
| 1980 | + public function getIniWrapper() { |
|
| 1981 | + return $this->get(IniGetWrapper::class); |
|
| 1982 | + } |
|
| 1983 | + |
|
| 1984 | + /** |
|
| 1985 | + * @return \OCP\Command\IBus |
|
| 1986 | + * @deprecated 20.0.0 |
|
| 1987 | + */ |
|
| 1988 | + public function getCommandBus() { |
|
| 1989 | + return $this->get(IBus::class); |
|
| 1990 | + } |
|
| 1991 | + |
|
| 1992 | + /** |
|
| 1993 | + * Get the trusted domain helper |
|
| 1994 | + * |
|
| 1995 | + * @return TrustedDomainHelper |
|
| 1996 | + * @deprecated 20.0.0 |
|
| 1997 | + */ |
|
| 1998 | + public function getTrustedDomainHelper() { |
|
| 1999 | + return $this->get(TrustedDomainHelper::class); |
|
| 2000 | + } |
|
| 2001 | + |
|
| 2002 | + /** |
|
| 2003 | + * Get the locking provider |
|
| 2004 | + * |
|
| 2005 | + * @return ILockingProvider |
|
| 2006 | + * @since 8.1.0 |
|
| 2007 | + * @deprecated 20.0.0 |
|
| 2008 | + */ |
|
| 2009 | + public function getLockingProvider() { |
|
| 2010 | + return $this->get(ILockingProvider::class); |
|
| 2011 | + } |
|
| 2012 | + |
|
| 2013 | + /** |
|
| 2014 | + * @return IMountManager |
|
| 2015 | + * @deprecated 20.0.0 |
|
| 2016 | + **/ |
|
| 2017 | + public function getMountManager() { |
|
| 2018 | + return $this->get(IMountManager::class); |
|
| 2019 | + } |
|
| 2020 | + |
|
| 2021 | + /** |
|
| 2022 | + * @return IUserMountCache |
|
| 2023 | + * @deprecated 20.0.0 |
|
| 2024 | + */ |
|
| 2025 | + public function getUserMountCache() { |
|
| 2026 | + return $this->get(IUserMountCache::class); |
|
| 2027 | + } |
|
| 2028 | + |
|
| 2029 | + /** |
|
| 2030 | + * Get the MimeTypeDetector |
|
| 2031 | + * |
|
| 2032 | + * @return IMimeTypeDetector |
|
| 2033 | + * @deprecated 20.0.0 |
|
| 2034 | + */ |
|
| 2035 | + public function getMimeTypeDetector() { |
|
| 2036 | + return $this->get(IMimeTypeDetector::class); |
|
| 2037 | + } |
|
| 2038 | + |
|
| 2039 | + /** |
|
| 2040 | + * Get the MimeTypeLoader |
|
| 2041 | + * |
|
| 2042 | + * @return IMimeTypeLoader |
|
| 2043 | + * @deprecated 20.0.0 |
|
| 2044 | + */ |
|
| 2045 | + public function getMimeTypeLoader() { |
|
| 2046 | + return $this->get(IMimeTypeLoader::class); |
|
| 2047 | + } |
|
| 2048 | + |
|
| 2049 | + /** |
|
| 2050 | + * Get the manager of all the capabilities |
|
| 2051 | + * |
|
| 2052 | + * @return CapabilitiesManager |
|
| 2053 | + * @deprecated 20.0.0 |
|
| 2054 | + */ |
|
| 2055 | + public function getCapabilitiesManager() { |
|
| 2056 | + return $this->get(CapabilitiesManager::class); |
|
| 2057 | + } |
|
| 2058 | + |
|
| 2059 | + /** |
|
| 2060 | + * Get the EventDispatcher |
|
| 2061 | + * |
|
| 2062 | + * @return EventDispatcherInterface |
|
| 2063 | + * @since 8.2.0 |
|
| 2064 | + * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher |
|
| 2065 | + */ |
|
| 2066 | + public function getEventDispatcher() { |
|
| 2067 | + return $this->get(\OC\EventDispatcher\SymfonyAdapter::class); |
|
| 2068 | + } |
|
| 2069 | + |
|
| 2070 | + /** |
|
| 2071 | + * Get the Notification Manager |
|
| 2072 | + * |
|
| 2073 | + * @return \OCP\Notification\IManager |
|
| 2074 | + * @since 8.2.0 |
|
| 2075 | + * @deprecated 20.0.0 |
|
| 2076 | + */ |
|
| 2077 | + public function getNotificationManager() { |
|
| 2078 | + return $this->get(\OCP\Notification\IManager::class); |
|
| 2079 | + } |
|
| 2080 | + |
|
| 2081 | + /** |
|
| 2082 | + * @return ICommentsManager |
|
| 2083 | + * @deprecated 20.0.0 |
|
| 2084 | + */ |
|
| 2085 | + public function getCommentsManager() { |
|
| 2086 | + return $this->get(ICommentsManager::class); |
|
| 2087 | + } |
|
| 2088 | + |
|
| 2089 | + /** |
|
| 2090 | + * @return \OCA\Theming\ThemingDefaults |
|
| 2091 | + * @deprecated 20.0.0 |
|
| 2092 | + */ |
|
| 2093 | + public function getThemingDefaults() { |
|
| 2094 | + return $this->get('ThemingDefaults'); |
|
| 2095 | + } |
|
| 2096 | + |
|
| 2097 | + /** |
|
| 2098 | + * @return \OC\IntegrityCheck\Checker |
|
| 2099 | + * @deprecated 20.0.0 |
|
| 2100 | + */ |
|
| 2101 | + public function getIntegrityCodeChecker() { |
|
| 2102 | + return $this->get('IntegrityCodeChecker'); |
|
| 2103 | + } |
|
| 2104 | + |
|
| 2105 | + /** |
|
| 2106 | + * @return \OC\Session\CryptoWrapper |
|
| 2107 | + * @deprecated 20.0.0 |
|
| 2108 | + */ |
|
| 2109 | + public function getSessionCryptoWrapper() { |
|
| 2110 | + return $this->get('CryptoWrapper'); |
|
| 2111 | + } |
|
| 2112 | + |
|
| 2113 | + /** |
|
| 2114 | + * @return CsrfTokenManager |
|
| 2115 | + * @deprecated 20.0.0 |
|
| 2116 | + */ |
|
| 2117 | + public function getCsrfTokenManager() { |
|
| 2118 | + return $this->get(CsrfTokenManager::class); |
|
| 2119 | + } |
|
| 2120 | + |
|
| 2121 | + /** |
|
| 2122 | + * @return Throttler |
|
| 2123 | + * @deprecated 20.0.0 |
|
| 2124 | + */ |
|
| 2125 | + public function getBruteForceThrottler() { |
|
| 2126 | + return $this->get(Throttler::class); |
|
| 2127 | + } |
|
| 2128 | + |
|
| 2129 | + /** |
|
| 2130 | + * @return IContentSecurityPolicyManager |
|
| 2131 | + * @deprecated 20.0.0 |
|
| 2132 | + */ |
|
| 2133 | + public function getContentSecurityPolicyManager() { |
|
| 2134 | + return $this->get(ContentSecurityPolicyManager::class); |
|
| 2135 | + } |
|
| 2136 | + |
|
| 2137 | + /** |
|
| 2138 | + * @return ContentSecurityPolicyNonceManager |
|
| 2139 | + * @deprecated 20.0.0 |
|
| 2140 | + */ |
|
| 2141 | + public function getContentSecurityPolicyNonceManager() { |
|
| 2142 | + return $this->get(ContentSecurityPolicyNonceManager::class); |
|
| 2143 | + } |
|
| 2144 | + |
|
| 2145 | + /** |
|
| 2146 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 2147 | + * |
|
| 2148 | + * @return \OCA\Files_External\Service\BackendService |
|
| 2149 | + * @deprecated 20.0.0 |
|
| 2150 | + */ |
|
| 2151 | + public function getStoragesBackendService() { |
|
| 2152 | + return $this->get(BackendService::class); |
|
| 2153 | + } |
|
| 2154 | + |
|
| 2155 | + /** |
|
| 2156 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 2157 | + * |
|
| 2158 | + * @return \OCA\Files_External\Service\GlobalStoragesService |
|
| 2159 | + * @deprecated 20.0.0 |
|
| 2160 | + */ |
|
| 2161 | + public function getGlobalStoragesService() { |
|
| 2162 | + return $this->get(GlobalStoragesService::class); |
|
| 2163 | + } |
|
| 2164 | + |
|
| 2165 | + /** |
|
| 2166 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 2167 | + * |
|
| 2168 | + * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
| 2169 | + * @deprecated 20.0.0 |
|
| 2170 | + */ |
|
| 2171 | + public function getUserGlobalStoragesService() { |
|
| 2172 | + return $this->get(UserGlobalStoragesService::class); |
|
| 2173 | + } |
|
| 2174 | + |
|
| 2175 | + /** |
|
| 2176 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 2177 | + * |
|
| 2178 | + * @return \OCA\Files_External\Service\UserStoragesService |
|
| 2179 | + * @deprecated 20.0.0 |
|
| 2180 | + */ |
|
| 2181 | + public function getUserStoragesService() { |
|
| 2182 | + return $this->get(UserStoragesService::class); |
|
| 2183 | + } |
|
| 2184 | + |
|
| 2185 | + /** |
|
| 2186 | + * @return \OCP\Share\IManager |
|
| 2187 | + * @deprecated 20.0.0 |
|
| 2188 | + */ |
|
| 2189 | + public function getShareManager() { |
|
| 2190 | + return $this->get(\OCP\Share\IManager::class); |
|
| 2191 | + } |
|
| 2192 | + |
|
| 2193 | + /** |
|
| 2194 | + * @return \OCP\Collaboration\Collaborators\ISearch |
|
| 2195 | + * @deprecated 20.0.0 |
|
| 2196 | + */ |
|
| 2197 | + public function getCollaboratorSearch() { |
|
| 2198 | + return $this->get(\OCP\Collaboration\Collaborators\ISearch::class); |
|
| 2199 | + } |
|
| 2200 | + |
|
| 2201 | + /** |
|
| 2202 | + * @return \OCP\Collaboration\AutoComplete\IManager |
|
| 2203 | + * @deprecated 20.0.0 |
|
| 2204 | + */ |
|
| 2205 | + public function getAutoCompleteManager() { |
|
| 2206 | + return $this->get(IManager::class); |
|
| 2207 | + } |
|
| 2208 | + |
|
| 2209 | + /** |
|
| 2210 | + * Returns the LDAP Provider |
|
| 2211 | + * |
|
| 2212 | + * @return \OCP\LDAP\ILDAPProvider |
|
| 2213 | + * @deprecated 20.0.0 |
|
| 2214 | + */ |
|
| 2215 | + public function getLDAPProvider() { |
|
| 2216 | + return $this->get('LDAPProvider'); |
|
| 2217 | + } |
|
| 2218 | + |
|
| 2219 | + /** |
|
| 2220 | + * @return \OCP\Settings\IManager |
|
| 2221 | + * @deprecated 20.0.0 |
|
| 2222 | + */ |
|
| 2223 | + public function getSettingsManager() { |
|
| 2224 | + return $this->get(\OC\Settings\Manager::class); |
|
| 2225 | + } |
|
| 2226 | + |
|
| 2227 | + /** |
|
| 2228 | + * @return \OCP\Files\IAppData |
|
| 2229 | + * @deprecated 20.0.0 |
|
| 2230 | + */ |
|
| 2231 | + public function getAppDataDir($app) { |
|
| 2232 | + /** @var \OC\Files\AppData\Factory $factory */ |
|
| 2233 | + $factory = $this->get(\OC\Files\AppData\Factory::class); |
|
| 2234 | + return $factory->get($app); |
|
| 2235 | + } |
|
| 2236 | + |
|
| 2237 | + /** |
|
| 2238 | + * @return \OCP\Lockdown\ILockdownManager |
|
| 2239 | + * @deprecated 20.0.0 |
|
| 2240 | + */ |
|
| 2241 | + public function getLockdownManager() { |
|
| 2242 | + return $this->get('LockdownManager'); |
|
| 2243 | + } |
|
| 2244 | + |
|
| 2245 | + /** |
|
| 2246 | + * @return \OCP\Federation\ICloudIdManager |
|
| 2247 | + * @deprecated 20.0.0 |
|
| 2248 | + */ |
|
| 2249 | + public function getCloudIdManager() { |
|
| 2250 | + return $this->get(ICloudIdManager::class); |
|
| 2251 | + } |
|
| 2252 | + |
|
| 2253 | + /** |
|
| 2254 | + * @return \OCP\GlobalScale\IConfig |
|
| 2255 | + * @deprecated 20.0.0 |
|
| 2256 | + */ |
|
| 2257 | + public function getGlobalScaleConfig() { |
|
| 2258 | + return $this->get(IConfig::class); |
|
| 2259 | + } |
|
| 2260 | + |
|
| 2261 | + /** |
|
| 2262 | + * @return \OCP\Federation\ICloudFederationProviderManager |
|
| 2263 | + * @deprecated 20.0.0 |
|
| 2264 | + */ |
|
| 2265 | + public function getCloudFederationProviderManager() { |
|
| 2266 | + return $this->get(ICloudFederationProviderManager::class); |
|
| 2267 | + } |
|
| 2268 | + |
|
| 2269 | + /** |
|
| 2270 | + * @return \OCP\Remote\Api\IApiFactory |
|
| 2271 | + * @deprecated 20.0.0 |
|
| 2272 | + */ |
|
| 2273 | + public function getRemoteApiFactory() { |
|
| 2274 | + return $this->get(IApiFactory::class); |
|
| 2275 | + } |
|
| 2276 | + |
|
| 2277 | + /** |
|
| 2278 | + * @return \OCP\Federation\ICloudFederationFactory |
|
| 2279 | + * @deprecated 20.0.0 |
|
| 2280 | + */ |
|
| 2281 | + public function getCloudFederationFactory() { |
|
| 2282 | + return $this->get(ICloudFederationFactory::class); |
|
| 2283 | + } |
|
| 2284 | + |
|
| 2285 | + /** |
|
| 2286 | + * @return \OCP\Remote\IInstanceFactory |
|
| 2287 | + * @deprecated 20.0.0 |
|
| 2288 | + */ |
|
| 2289 | + public function getRemoteInstanceFactory() { |
|
| 2290 | + return $this->get(IInstanceFactory::class); |
|
| 2291 | + } |
|
| 2292 | + |
|
| 2293 | + /** |
|
| 2294 | + * @return IStorageFactory |
|
| 2295 | + * @deprecated 20.0.0 |
|
| 2296 | + */ |
|
| 2297 | + public function getStorageFactory() { |
|
| 2298 | + return $this->get(IStorageFactory::class); |
|
| 2299 | + } |
|
| 2300 | + |
|
| 2301 | + /** |
|
| 2302 | + * Get the Preview GeneratorHelper |
|
| 2303 | + * |
|
| 2304 | + * @return GeneratorHelper |
|
| 2305 | + * @since 17.0.0 |
|
| 2306 | + * @deprecated 20.0.0 |
|
| 2307 | + */ |
|
| 2308 | + public function getGeneratorHelper() { |
|
| 2309 | + return $this->get(\OC\Preview\GeneratorHelper::class); |
|
| 2310 | + } |
|
| 2311 | + |
|
| 2312 | + private function registerDeprecatedAlias(string $alias, string $target) { |
|
| 2313 | + $this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) { |
|
| 2314 | + try { |
|
| 2315 | + /** @var ILogger $logger */ |
|
| 2316 | + $logger = $container->get(ILogger::class); |
|
| 2317 | + $logger->debug('The requested alias "' . $alias . '" is deprecated. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']); |
|
| 2318 | + } catch (ContainerExceptionInterface $e) { |
|
| 2319 | + // Could not get logger. Continue |
|
| 2320 | + } |
|
| 2321 | + |
|
| 2322 | + return $container->get($target); |
|
| 2323 | + }, false); |
|
| 2324 | + } |
|
| 2325 | 2325 | } |
@@ -275,10 +275,10 @@ discard block |
||
| 275 | 275 | $this->registerParameter('isCLI', \OC::$CLI); |
| 276 | 276 | $this->registerParameter('serverRoot', \OC::$SERVERROOT); |
| 277 | 277 | |
| 278 | - $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
| 278 | + $this->registerService(ContainerInterface::class, function(ContainerInterface $c) { |
|
| 279 | 279 | return $c; |
| 280 | 280 | }); |
| 281 | - $this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) { |
|
| 281 | + $this->registerService(\OCP\IServerContainer::class, function(ContainerInterface $c) { |
|
| 282 | 282 | return $c; |
| 283 | 283 | }); |
| 284 | 284 | |
@@ -303,11 +303,11 @@ discard block |
||
| 303 | 303 | |
| 304 | 304 | $this->registerAlias(IActionFactory::class, ActionFactory::class); |
| 305 | 305 | |
| 306 | - $this->registerService(View::class, function (Server $c) { |
|
| 306 | + $this->registerService(View::class, function(Server $c) { |
|
| 307 | 307 | return new View(); |
| 308 | 308 | }, false); |
| 309 | 309 | |
| 310 | - $this->registerService(IPreview::class, function (ContainerInterface $c) { |
|
| 310 | + $this->registerService(IPreview::class, function(ContainerInterface $c) { |
|
| 311 | 311 | return new PreviewManager( |
| 312 | 312 | $c->get(\OCP\IConfig::class), |
| 313 | 313 | $c->get(IRootFolder::class), |
@@ -323,7 +323,7 @@ discard block |
||
| 323 | 323 | /** @deprecated 19.0.0 */ |
| 324 | 324 | $this->registerDeprecatedAlias('PreviewManager', IPreview::class); |
| 325 | 325 | |
| 326 | - $this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) { |
|
| 326 | + $this->registerService(\OC\Preview\Watcher::class, function(ContainerInterface $c) { |
|
| 327 | 327 | return new \OC\Preview\Watcher( |
| 328 | 328 | new \OC\Preview\Storage\Root( |
| 329 | 329 | $c->get(IRootFolder::class), |
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | ); |
| 333 | 333 | }); |
| 334 | 334 | |
| 335 | - $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) { |
|
| 335 | + $this->registerService(\OCP\Encryption\IManager::class, function(Server $c) { |
|
| 336 | 336 | $view = new View(); |
| 337 | 337 | $util = new Encryption\Util( |
| 338 | 338 | $view, |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | |
| 355 | 355 | /** @deprecated 21.0.0 */ |
| 356 | 356 | $this->registerDeprecatedAlias('EncryptionFileHelper', IFile::class); |
| 357 | - $this->registerService(IFile::class, function (ContainerInterface $c) { |
|
| 357 | + $this->registerService(IFile::class, function(ContainerInterface $c) { |
|
| 358 | 358 | $util = new Encryption\Util( |
| 359 | 359 | new View(), |
| 360 | 360 | $c->get(IUserManager::class), |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | |
| 371 | 371 | /** @deprecated 21.0.0 */ |
| 372 | 372 | $this->registerDeprecatedAlias('EncryptionKeyStorage', IStorage::class); |
| 373 | - $this->registerService(IStorage::class, function (ContainerInterface $c) { |
|
| 373 | + $this->registerService(IStorage::class, function(ContainerInterface $c) { |
|
| 374 | 374 | $view = new View(); |
| 375 | 375 | $util = new Encryption\Util( |
| 376 | 376 | $view, |
@@ -393,22 +393,22 @@ discard block |
||
| 393 | 393 | /** @deprecated 19.0.0 */ |
| 394 | 394 | $this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class); |
| 395 | 395 | |
| 396 | - $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) { |
|
| 396 | + $this->registerService('SystemTagManagerFactory', function(ContainerInterface $c) { |
|
| 397 | 397 | /** @var \OCP\IConfig $config */ |
| 398 | 398 | $config = $c->get(\OCP\IConfig::class); |
| 399 | 399 | $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
| 400 | 400 | return new $factoryClass($this); |
| 401 | 401 | }); |
| 402 | - $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) { |
|
| 402 | + $this->registerService(ISystemTagManager::class, function(ContainerInterface $c) { |
|
| 403 | 403 | return $c->get('SystemTagManagerFactory')->getManager(); |
| 404 | 404 | }); |
| 405 | 405 | /** @deprecated 19.0.0 */ |
| 406 | 406 | $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
| 407 | 407 | |
| 408 | - $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) { |
|
| 408 | + $this->registerService(ISystemTagObjectMapper::class, function(ContainerInterface $c) { |
|
| 409 | 409 | return $c->get('SystemTagManagerFactory')->getObjectMapper(); |
| 410 | 410 | }); |
| 411 | - $this->registerService('RootFolder', function (ContainerInterface $c) { |
|
| 411 | + $this->registerService('RootFolder', function(ContainerInterface $c) { |
|
| 412 | 412 | $manager = \OC\Files\Filesystem::getMountManager(null); |
| 413 | 413 | $view = new View(); |
| 414 | 414 | $root = new Root( |
@@ -428,7 +428,7 @@ discard block |
||
| 428 | 428 | |
| 429 | 429 | return $root; |
| 430 | 430 | }); |
| 431 | - $this->registerService(HookConnector::class, function (ContainerInterface $c) { |
|
| 431 | + $this->registerService(HookConnector::class, function(ContainerInterface $c) { |
|
| 432 | 432 | return new HookConnector( |
| 433 | 433 | $c->get(IRootFolder::class), |
| 434 | 434 | new View(), |
@@ -440,8 +440,8 @@ discard block |
||
| 440 | 440 | /** @deprecated 19.0.0 */ |
| 441 | 441 | $this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class); |
| 442 | 442 | |
| 443 | - $this->registerService(IRootFolder::class, function (ContainerInterface $c) { |
|
| 444 | - return new LazyRoot(function () use ($c) { |
|
| 443 | + $this->registerService(IRootFolder::class, function(ContainerInterface $c) { |
|
| 444 | + return new LazyRoot(function() use ($c) { |
|
| 445 | 445 | return $c->get('RootFolder'); |
| 446 | 446 | }); |
| 447 | 447 | }); |
@@ -452,44 +452,44 @@ discard block |
||
| 452 | 452 | $this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class); |
| 453 | 453 | $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
| 454 | 454 | |
| 455 | - $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) { |
|
| 455 | + $this->registerService(\OCP\IGroupManager::class, function(ContainerInterface $c) { |
|
| 456 | 456 | $groupManager = new \OC\Group\Manager($this->get(IUserManager::class), $c->get(SymfonyAdapter::class), $this->get(ILogger::class)); |
| 457 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
| 457 | + $groupManager->listen('\OC\Group', 'preCreate', function($gid) { |
|
| 458 | 458 | /** @var IEventDispatcher $dispatcher */ |
| 459 | 459 | $dispatcher = $this->get(IEventDispatcher::class); |
| 460 | 460 | $dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid)); |
| 461 | 461 | }); |
| 462 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) { |
|
| 462 | + $groupManager->listen('\OC\Group', 'postCreate', function(\OC\Group\Group $group) { |
|
| 463 | 463 | /** @var IEventDispatcher $dispatcher */ |
| 464 | 464 | $dispatcher = $this->get(IEventDispatcher::class); |
| 465 | 465 | $dispatcher->dispatchTyped(new GroupCreatedEvent($group)); |
| 466 | 466 | }); |
| 467 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
| 467 | + $groupManager->listen('\OC\Group', 'preDelete', function(\OC\Group\Group $group) { |
|
| 468 | 468 | /** @var IEventDispatcher $dispatcher */ |
| 469 | 469 | $dispatcher = $this->get(IEventDispatcher::class); |
| 470 | 470 | $dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group)); |
| 471 | 471 | }); |
| 472 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
| 472 | + $groupManager->listen('\OC\Group', 'postDelete', function(\OC\Group\Group $group) { |
|
| 473 | 473 | /** @var IEventDispatcher $dispatcher */ |
| 474 | 474 | $dispatcher = $this->get(IEventDispatcher::class); |
| 475 | 475 | $dispatcher->dispatchTyped(new GroupDeletedEvent($group)); |
| 476 | 476 | }); |
| 477 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 477 | + $groupManager->listen('\OC\Group', 'preAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
| 478 | 478 | /** @var IEventDispatcher $dispatcher */ |
| 479 | 479 | $dispatcher = $this->get(IEventDispatcher::class); |
| 480 | 480 | $dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user)); |
| 481 | 481 | }); |
| 482 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 482 | + $groupManager->listen('\OC\Group', 'postAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
| 483 | 483 | /** @var IEventDispatcher $dispatcher */ |
| 484 | 484 | $dispatcher = $this->get(IEventDispatcher::class); |
| 485 | 485 | $dispatcher->dispatchTyped(new UserAddedEvent($group, $user)); |
| 486 | 486 | }); |
| 487 | - $groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 487 | + $groupManager->listen('\OC\Group', 'preRemoveUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
| 488 | 488 | /** @var IEventDispatcher $dispatcher */ |
| 489 | 489 | $dispatcher = $this->get(IEventDispatcher::class); |
| 490 | 490 | $dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user)); |
| 491 | 491 | }); |
| 492 | - $groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 492 | + $groupManager->listen('\OC\Group', 'postRemoveUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
| 493 | 493 | /** @var IEventDispatcher $dispatcher */ |
| 494 | 494 | $dispatcher = $this->get(IEventDispatcher::class); |
| 495 | 495 | $dispatcher->dispatchTyped(new UserRemovedEvent($group, $user)); |
@@ -499,7 +499,7 @@ discard block |
||
| 499 | 499 | /** @deprecated 19.0.0 */ |
| 500 | 500 | $this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class); |
| 501 | 501 | |
| 502 | - $this->registerService(Store::class, function (ContainerInterface $c) { |
|
| 502 | + $this->registerService(Store::class, function(ContainerInterface $c) { |
|
| 503 | 503 | $session = $c->get(ISession::class); |
| 504 | 504 | if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
| 505 | 505 | $tokenProvider = $c->get(IProvider::class); |
@@ -512,7 +512,7 @@ discard block |
||
| 512 | 512 | $this->registerAlias(IStore::class, Store::class); |
| 513 | 513 | $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
| 514 | 514 | |
| 515 | - $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
| 515 | + $this->registerService(\OC\User\Session::class, function(Server $c) { |
|
| 516 | 516 | $manager = $c->get(IUserManager::class); |
| 517 | 517 | $session = new \OC\Session\Memory(''); |
| 518 | 518 | $timeFactory = new TimeFactory(); |
@@ -538,26 +538,26 @@ discard block |
||
| 538 | 538 | $c->get(IEventDispatcher::class) |
| 539 | 539 | ); |
| 540 | 540 | /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */ |
| 541 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 541 | + $userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) { |
|
| 542 | 542 | \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
| 543 | 543 | }); |
| 544 | 544 | /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */ |
| 545 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 545 | + $userSession->listen('\OC\User', 'postCreateUser', function($user, $password) { |
|
| 546 | 546 | /** @var \OC\User\User $user */ |
| 547 | 547 | \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
| 548 | 548 | }); |
| 549 | 549 | /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */ |
| 550 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) { |
|
| 550 | + $userSession->listen('\OC\User', 'preDelete', function($user) use ($legacyDispatcher) { |
|
| 551 | 551 | /** @var \OC\User\User $user */ |
| 552 | 552 | \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
| 553 | 553 | $legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
| 554 | 554 | }); |
| 555 | 555 | /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ |
| 556 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 556 | + $userSession->listen('\OC\User', 'postDelete', function($user) { |
|
| 557 | 557 | /** @var \OC\User\User $user */ |
| 558 | 558 | \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
| 559 | 559 | }); |
| 560 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 560 | + $userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) { |
|
| 561 | 561 | /** @var \OC\User\User $user */ |
| 562 | 562 | \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
| 563 | 563 | |
@@ -565,7 +565,7 @@ discard block |
||
| 565 | 565 | $dispatcher = $this->get(IEventDispatcher::class); |
| 566 | 566 | $dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword)); |
| 567 | 567 | }); |
| 568 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 568 | + $userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) { |
|
| 569 | 569 | /** @var \OC\User\User $user */ |
| 570 | 570 | \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
| 571 | 571 | |
@@ -573,14 +573,14 @@ discard block |
||
| 573 | 573 | $dispatcher = $this->get(IEventDispatcher::class); |
| 574 | 574 | $dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword)); |
| 575 | 575 | }); |
| 576 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 576 | + $userSession->listen('\OC\User', 'preLogin', function($uid, $password) { |
|
| 577 | 577 | \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
| 578 | 578 | |
| 579 | 579 | /** @var IEventDispatcher $dispatcher */ |
| 580 | 580 | $dispatcher = $this->get(IEventDispatcher::class); |
| 581 | 581 | $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
| 582 | 582 | }); |
| 583 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) { |
|
| 583 | + $userSession->listen('\OC\User', 'postLogin', function($user, $loginName, $password, $isTokenLogin) { |
|
| 584 | 584 | /** @var \OC\User\User $user */ |
| 585 | 585 | \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
| 586 | 586 | |
@@ -588,12 +588,12 @@ discard block |
||
| 588 | 588 | $dispatcher = $this->get(IEventDispatcher::class); |
| 589 | 589 | $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin)); |
| 590 | 590 | }); |
| 591 | - $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
| 591 | + $userSession->listen('\OC\User', 'preRememberedLogin', function($uid) { |
|
| 592 | 592 | /** @var IEventDispatcher $dispatcher */ |
| 593 | 593 | $dispatcher = $this->get(IEventDispatcher::class); |
| 594 | 594 | $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
| 595 | 595 | }); |
| 596 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
| 596 | + $userSession->listen('\OC\User', 'postRememberedLogin', function($user, $password) { |
|
| 597 | 597 | /** @var \OC\User\User $user */ |
| 598 | 598 | \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
| 599 | 599 | |
@@ -601,19 +601,19 @@ discard block |
||
| 601 | 601 | $dispatcher = $this->get(IEventDispatcher::class); |
| 602 | 602 | $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
| 603 | 603 | }); |
| 604 | - $userSession->listen('\OC\User', 'logout', function ($user) { |
|
| 604 | + $userSession->listen('\OC\User', 'logout', function($user) { |
|
| 605 | 605 | \OC_Hook::emit('OC_User', 'logout', []); |
| 606 | 606 | |
| 607 | 607 | /** @var IEventDispatcher $dispatcher */ |
| 608 | 608 | $dispatcher = $this->get(IEventDispatcher::class); |
| 609 | 609 | $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
| 610 | 610 | }); |
| 611 | - $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
| 611 | + $userSession->listen('\OC\User', 'postLogout', function($user) { |
|
| 612 | 612 | /** @var IEventDispatcher $dispatcher */ |
| 613 | 613 | $dispatcher = $this->get(IEventDispatcher::class); |
| 614 | 614 | $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
| 615 | 615 | }); |
| 616 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 616 | + $userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value, $oldValue) { |
|
| 617 | 617 | /** @var \OC\User\User $user */ |
| 618 | 618 | \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
| 619 | 619 | |
@@ -637,7 +637,7 @@ discard block |
||
| 637 | 637 | $this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class); |
| 638 | 638 | $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
| 639 | 639 | |
| 640 | - $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
| 640 | + $this->registerService(\OC\SystemConfig::class, function($c) use ($config) { |
|
| 641 | 641 | return new \OC\SystemConfig($config); |
| 642 | 642 | }); |
| 643 | 643 | /** @deprecated 19.0.0 */ |
@@ -647,7 +647,7 @@ discard block |
||
| 647 | 647 | $this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class); |
| 648 | 648 | $this->registerAlias(IAppConfig::class, \OC\AppConfig::class); |
| 649 | 649 | |
| 650 | - $this->registerService(IFactory::class, function (Server $c) { |
|
| 650 | + $this->registerService(IFactory::class, function(Server $c) { |
|
| 651 | 651 | return new \OC\L10N\Factory( |
| 652 | 652 | $c->get(\OCP\IConfig::class), |
| 653 | 653 | $c->getRequest(), |
@@ -667,13 +667,13 @@ discard block |
||
| 667 | 667 | /** @deprecated 19.0.0 */ |
| 668 | 668 | $this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class); |
| 669 | 669 | |
| 670 | - $this->registerService(ICache::class, function ($c) { |
|
| 670 | + $this->registerService(ICache::class, function($c) { |
|
| 671 | 671 | return new Cache\File(); |
| 672 | 672 | }); |
| 673 | 673 | /** @deprecated 19.0.0 */ |
| 674 | 674 | $this->registerDeprecatedAlias('UserCache', ICache::class); |
| 675 | 675 | |
| 676 | - $this->registerService(Factory::class, function (Server $c) { |
|
| 676 | + $this->registerService(Factory::class, function(Server $c) { |
|
| 677 | 677 | $arrayCacheFactory = new \OC\Memcache\Factory('', $c->get(ILogger::class), |
| 678 | 678 | ArrayCache::class, |
| 679 | 679 | ArrayCache::class, |
@@ -688,7 +688,7 @@ discard block |
||
| 688 | 688 | $version = implode(',', $v); |
| 689 | 689 | $instanceId = \OC_Util::getInstanceId(); |
| 690 | 690 | $path = \OC::$SERVERROOT; |
| 691 | - $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
| 691 | + $prefix = md5($instanceId.'-'.$version.'-'.$path); |
|
| 692 | 692 | return new \OC\Memcache\Factory($prefix, $c->get(ILogger::class), |
| 693 | 693 | $config->getSystemValue('memcache.local', null), |
| 694 | 694 | $config->getSystemValue('memcache.distributed', null), |
@@ -701,12 +701,12 @@ discard block |
||
| 701 | 701 | $this->registerDeprecatedAlias('MemCacheFactory', Factory::class); |
| 702 | 702 | $this->registerAlias(ICacheFactory::class, Factory::class); |
| 703 | 703 | |
| 704 | - $this->registerService('RedisFactory', function (Server $c) { |
|
| 704 | + $this->registerService('RedisFactory', function(Server $c) { |
|
| 705 | 705 | $systemConfig = $c->get(SystemConfig::class); |
| 706 | 706 | return new RedisFactory($systemConfig); |
| 707 | 707 | }); |
| 708 | 708 | |
| 709 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 709 | + $this->registerService(\OCP\Activity\IManager::class, function(Server $c) { |
|
| 710 | 710 | $l10n = $this->get(IFactory::class)->get('lib'); |
| 711 | 711 | return new \OC\Activity\Manager( |
| 712 | 712 | $c->getRequest(), |
@@ -719,14 +719,14 @@ discard block |
||
| 719 | 719 | /** @deprecated 19.0.0 */ |
| 720 | 720 | $this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class); |
| 721 | 721 | |
| 722 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 722 | + $this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) { |
|
| 723 | 723 | return new \OC\Activity\EventMerger( |
| 724 | 724 | $c->getL10N('lib') |
| 725 | 725 | ); |
| 726 | 726 | }); |
| 727 | 727 | $this->registerAlias(IValidator::class, Validator::class); |
| 728 | 728 | |
| 729 | - $this->registerService(AvatarManager::class, function (Server $c) { |
|
| 729 | + $this->registerService(AvatarManager::class, function(Server $c) { |
|
| 730 | 730 | return new AvatarManager( |
| 731 | 731 | $c->get(IUserSession::class), |
| 732 | 732 | $c->get(\OC\User\Manager::class), |
@@ -745,7 +745,7 @@ discard block |
||
| 745 | 745 | $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
| 746 | 746 | $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
| 747 | 747 | |
| 748 | - $this->registerService(\OC\Log::class, function (Server $c) { |
|
| 748 | + $this->registerService(\OC\Log::class, function(Server $c) { |
|
| 749 | 749 | $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file'); |
| 750 | 750 | $factory = new LogFactory($c, $this->get(SystemConfig::class)); |
| 751 | 751 | $logger = $factory->get($logType); |
@@ -759,7 +759,7 @@ discard block |
||
| 759 | 759 | // PSR-3 logger |
| 760 | 760 | $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
| 761 | 761 | |
| 762 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
| 762 | + $this->registerService(ILogFactory::class, function(Server $c) { |
|
| 763 | 763 | return new LogFactory($c, $this->get(SystemConfig::class)); |
| 764 | 764 | }); |
| 765 | 765 | |
@@ -767,7 +767,7 @@ discard block |
||
| 767 | 767 | /** @deprecated 19.0.0 */ |
| 768 | 768 | $this->registerDeprecatedAlias('JobList', IJobList::class); |
| 769 | 769 | |
| 770 | - $this->registerService(Router::class, function (Server $c) { |
|
| 770 | + $this->registerService(Router::class, function(Server $c) { |
|
| 771 | 771 | $cacheFactory = $c->get(ICacheFactory::class); |
| 772 | 772 | $logger = $c->get(ILogger::class); |
| 773 | 773 | if ($cacheFactory->isLocalCacheAvailable()) { |
@@ -785,7 +785,7 @@ discard block |
||
| 785 | 785 | /** @deprecated 19.0.0 */ |
| 786 | 786 | $this->registerDeprecatedAlias('Search', ISearch::class); |
| 787 | 787 | |
| 788 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
| 788 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) { |
|
| 789 | 789 | return new \OC\Security\RateLimiting\Backend\MemoryCache( |
| 790 | 790 | $this->get(ICacheFactory::class), |
| 791 | 791 | new \OC\AppFramework\Utility\TimeFactory() |
@@ -809,7 +809,7 @@ discard block |
||
| 809 | 809 | $this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class); |
| 810 | 810 | |
| 811 | 811 | $this->registerAlias(IDBConnection::class, ConnectionAdapter::class); |
| 812 | - $this->registerService(Connection::class, function (Server $c) { |
|
| 812 | + $this->registerService(Connection::class, function(Server $c) { |
|
| 813 | 813 | $systemConfig = $c->get(SystemConfig::class); |
| 814 | 814 | $factory = new \OC\DB\ConnectionFactory($systemConfig); |
| 815 | 815 | $type = $systemConfig->getValue('dbtype', 'sqlite'); |
@@ -826,24 +826,24 @@ discard block |
||
| 826 | 826 | |
| 827 | 827 | $this->registerAlias(ICertificateManager::class, CertificateManager::class); |
| 828 | 828 | $this->registerAlias(IClientService::class, ClientService::class); |
| 829 | - $this->registerService(LocalAddressChecker::class, function (ContainerInterface $c) { |
|
| 829 | + $this->registerService(LocalAddressChecker::class, function(ContainerInterface $c) { |
|
| 830 | 830 | return new LocalAddressChecker( |
| 831 | 831 | $c->get(ILogger::class), |
| 832 | 832 | ); |
| 833 | 833 | }); |
| 834 | - $this->registerService(NegativeDnsCache::class, function (ContainerInterface $c) { |
|
| 834 | + $this->registerService(NegativeDnsCache::class, function(ContainerInterface $c) { |
|
| 835 | 835 | return new NegativeDnsCache( |
| 836 | 836 | $c->get(ICacheFactory::class), |
| 837 | 837 | ); |
| 838 | 838 | }); |
| 839 | - $this->registerService(DnsPinMiddleware::class, function (ContainerInterface $c) { |
|
| 839 | + $this->registerService(DnsPinMiddleware::class, function(ContainerInterface $c) { |
|
| 840 | 840 | return new DnsPinMiddleware( |
| 841 | 841 | $c->get(NegativeDnsCache::class), |
| 842 | 842 | $c->get(LocalAddressChecker::class) |
| 843 | 843 | ); |
| 844 | 844 | }); |
| 845 | 845 | $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
| 846 | - $this->registerService(IEventLogger::class, function (ContainerInterface $c) { |
|
| 846 | + $this->registerService(IEventLogger::class, function(ContainerInterface $c) { |
|
| 847 | 847 | $eventLogger = new EventLogger(); |
| 848 | 848 | if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
| 849 | 849 | // In debug mode, module is being activated by default |
@@ -854,7 +854,7 @@ discard block |
||
| 854 | 854 | /** @deprecated 19.0.0 */ |
| 855 | 855 | $this->registerDeprecatedAlias('EventLogger', IEventLogger::class); |
| 856 | 856 | |
| 857 | - $this->registerService(IQueryLogger::class, function (ContainerInterface $c) { |
|
| 857 | + $this->registerService(IQueryLogger::class, function(ContainerInterface $c) { |
|
| 858 | 858 | $queryLogger = new QueryLogger(); |
| 859 | 859 | if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
| 860 | 860 | // In debug mode, module is being activated by default |
@@ -869,7 +869,7 @@ discard block |
||
| 869 | 869 | $this->registerDeprecatedAlias('TempManager', TempManager::class); |
| 870 | 870 | $this->registerAlias(ITempManager::class, TempManager::class); |
| 871 | 871 | |
| 872 | - $this->registerService(AppManager::class, function (ContainerInterface $c) { |
|
| 872 | + $this->registerService(AppManager::class, function(ContainerInterface $c) { |
|
| 873 | 873 | // TODO: use auto-wiring |
| 874 | 874 | return new \OC\App\AppManager( |
| 875 | 875 | $c->get(IUserSession::class), |
@@ -889,7 +889,7 @@ discard block |
||
| 889 | 889 | /** @deprecated 19.0.0 */ |
| 890 | 890 | $this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class); |
| 891 | 891 | |
| 892 | - $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
| 892 | + $this->registerService(IDateTimeFormatter::class, function(Server $c) { |
|
| 893 | 893 | $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null); |
| 894 | 894 | |
| 895 | 895 | return new DateTimeFormatter( |
@@ -900,7 +900,7 @@ discard block |
||
| 900 | 900 | /** @deprecated 19.0.0 */ |
| 901 | 901 | $this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class); |
| 902 | 902 | |
| 903 | - $this->registerService(IUserMountCache::class, function (ContainerInterface $c) { |
|
| 903 | + $this->registerService(IUserMountCache::class, function(ContainerInterface $c) { |
|
| 904 | 904 | $mountCache = new UserMountCache( |
| 905 | 905 | $c->get(IDBConnection::class), |
| 906 | 906 | $c->get(IUserManager::class), |
@@ -913,7 +913,7 @@ discard block |
||
| 913 | 913 | /** @deprecated 19.0.0 */ |
| 914 | 914 | $this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class); |
| 915 | 915 | |
| 916 | - $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) { |
|
| 916 | + $this->registerService(IMountProviderCollection::class, function(ContainerInterface $c) { |
|
| 917 | 917 | $loader = \OC\Files\Filesystem::getLoader(); |
| 918 | 918 | $mountCache = $c->get(IUserMountCache::class); |
| 919 | 919 | $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
@@ -934,7 +934,7 @@ discard block |
||
| 934 | 934 | |
| 935 | 935 | /** @deprecated 20.0.0 */ |
| 936 | 936 | $this->registerDeprecatedAlias('IniWrapper', IniGetWrapper::class); |
| 937 | - $this->registerService(IBus::class, function (ContainerInterface $c) { |
|
| 937 | + $this->registerService(IBus::class, function(ContainerInterface $c) { |
|
| 938 | 938 | $busClass = $c->get(\OCP\IConfig::class)->getSystemValue('commandbus'); |
| 939 | 939 | if ($busClass) { |
| 940 | 940 | [$app, $class] = explode('::', $busClass, 2); |
@@ -954,7 +954,7 @@ discard block |
||
| 954 | 954 | $this->registerDeprecatedAlias('TrustedDomainHelper', TrustedDomainHelper::class); |
| 955 | 955 | /** @deprecated 19.0.0 */ |
| 956 | 956 | $this->registerDeprecatedAlias('Throttler', Throttler::class); |
| 957 | - $this->registerService('IntegrityCodeChecker', function (ContainerInterface $c) { |
|
| 957 | + $this->registerService('IntegrityCodeChecker', function(ContainerInterface $c) { |
|
| 958 | 958 | // IConfig and IAppManager requires a working database. This code |
| 959 | 959 | // might however be called when ownCloud is not yet setup. |
| 960 | 960 | if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
@@ -975,7 +975,7 @@ discard block |
||
| 975 | 975 | $c->get(IMimeTypeDetector::class) |
| 976 | 976 | ); |
| 977 | 977 | }); |
| 978 | - $this->registerService(\OCP\IRequest::class, function (ContainerInterface $c) { |
|
| 978 | + $this->registerService(\OCP\IRequest::class, function(ContainerInterface $c) { |
|
| 979 | 979 | if (isset($this['urlParams'])) { |
| 980 | 980 | $urlParams = $this['urlParams']; |
| 981 | 981 | } else { |
@@ -1012,7 +1012,7 @@ discard block |
||
| 1012 | 1012 | /** @deprecated 19.0.0 */ |
| 1013 | 1013 | $this->registerDeprecatedAlias('Request', \OCP\IRequest::class); |
| 1014 | 1014 | |
| 1015 | - $this->registerService(IMailer::class, function (Server $c) { |
|
| 1015 | + $this->registerService(IMailer::class, function(Server $c) { |
|
| 1016 | 1016 | return new Mailer( |
| 1017 | 1017 | $c->get(\OCP\IConfig::class), |
| 1018 | 1018 | $c->get(ILogger::class), |
@@ -1029,7 +1029,7 @@ discard block |
||
| 1029 | 1029 | /** @deprecated 21.0.0 */ |
| 1030 | 1030 | $this->registerDeprecatedAlias('LDAPProvider', ILDAPProvider::class); |
| 1031 | 1031 | |
| 1032 | - $this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) { |
|
| 1032 | + $this->registerService(ILDAPProviderFactory::class, function(ContainerInterface $c) { |
|
| 1033 | 1033 | $config = $c->get(\OCP\IConfig::class); |
| 1034 | 1034 | $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
| 1035 | 1035 | if (is_null($factoryClass)) { |
@@ -1038,11 +1038,11 @@ discard block |
||
| 1038 | 1038 | /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
| 1039 | 1039 | return new $factoryClass($this); |
| 1040 | 1040 | }); |
| 1041 | - $this->registerService(ILDAPProvider::class, function (ContainerInterface $c) { |
|
| 1041 | + $this->registerService(ILDAPProvider::class, function(ContainerInterface $c) { |
|
| 1042 | 1042 | $factory = $c->get(ILDAPProviderFactory::class); |
| 1043 | 1043 | return $factory->getLDAPProvider(); |
| 1044 | 1044 | }); |
| 1045 | - $this->registerService(ILockingProvider::class, function (ContainerInterface $c) { |
|
| 1045 | + $this->registerService(ILockingProvider::class, function(ContainerInterface $c) { |
|
| 1046 | 1046 | $ini = $c->get(IniGetWrapper::class); |
| 1047 | 1047 | $config = $c->get(\OCP\IConfig::class); |
| 1048 | 1048 | $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
@@ -1070,12 +1070,12 @@ discard block |
||
| 1070 | 1070 | /** @deprecated 19.0.0 */ |
| 1071 | 1071 | $this->registerDeprecatedAlias('MountManager', IMountManager::class); |
| 1072 | 1072 | |
| 1073 | - $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) { |
|
| 1073 | + $this->registerService(IMimeTypeDetector::class, function(ContainerInterface $c) { |
|
| 1074 | 1074 | return new \OC\Files\Type\Detection( |
| 1075 | 1075 | $c->get(IURLGenerator::class), |
| 1076 | 1076 | $c->get(ILogger::class), |
| 1077 | 1077 | \OC::$configDir, |
| 1078 | - \OC::$SERVERROOT . '/resources/config/' |
|
| 1078 | + \OC::$SERVERROOT.'/resources/config/' |
|
| 1079 | 1079 | ); |
| 1080 | 1080 | }); |
| 1081 | 1081 | /** @deprecated 19.0.0 */ |
@@ -1084,19 +1084,19 @@ discard block |
||
| 1084 | 1084 | $this->registerAlias(IMimeTypeLoader::class, Loader::class); |
| 1085 | 1085 | /** @deprecated 19.0.0 */ |
| 1086 | 1086 | $this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class); |
| 1087 | - $this->registerService(BundleFetcher::class, function () { |
|
| 1087 | + $this->registerService(BundleFetcher::class, function() { |
|
| 1088 | 1088 | return new BundleFetcher($this->getL10N('lib')); |
| 1089 | 1089 | }); |
| 1090 | 1090 | $this->registerAlias(\OCP\Notification\IManager::class, Manager::class); |
| 1091 | 1091 | /** @deprecated 19.0.0 */ |
| 1092 | 1092 | $this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class); |
| 1093 | 1093 | |
| 1094 | - $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) { |
|
| 1094 | + $this->registerService(CapabilitiesManager::class, function(ContainerInterface $c) { |
|
| 1095 | 1095 | $manager = new CapabilitiesManager($c->get(LoggerInterface::class)); |
| 1096 | - $manager->registerCapability(function () use ($c) { |
|
| 1096 | + $manager->registerCapability(function() use ($c) { |
|
| 1097 | 1097 | return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class)); |
| 1098 | 1098 | }); |
| 1099 | - $manager->registerCapability(function () use ($c) { |
|
| 1099 | + $manager->registerCapability(function() use ($c) { |
|
| 1100 | 1100 | return $c->get(\OC\Security\Bruteforce\Capabilities::class); |
| 1101 | 1101 | }); |
| 1102 | 1102 | return $manager; |
@@ -1104,14 +1104,14 @@ discard block |
||
| 1104 | 1104 | /** @deprecated 19.0.0 */ |
| 1105 | 1105 | $this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class); |
| 1106 | 1106 | |
| 1107 | - $this->registerService(ICommentsManager::class, function (Server $c) { |
|
| 1107 | + $this->registerService(ICommentsManager::class, function(Server $c) { |
|
| 1108 | 1108 | $config = $c->get(\OCP\IConfig::class); |
| 1109 | 1109 | $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
| 1110 | 1110 | /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
| 1111 | 1111 | $factory = new $factoryClass($this); |
| 1112 | 1112 | $manager = $factory->getManager(); |
| 1113 | 1113 | |
| 1114 | - $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
| 1114 | + $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
|
| 1115 | 1115 | $manager = $c->get(IUserManager::class); |
| 1116 | 1116 | $user = $manager->get($id); |
| 1117 | 1117 | if (is_null($user)) { |
@@ -1129,7 +1129,7 @@ discard block |
||
| 1129 | 1129 | $this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class); |
| 1130 | 1130 | |
| 1131 | 1131 | $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults'); |
| 1132 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
| 1132 | + $this->registerService('ThemingDefaults', function(Server $c) { |
|
| 1133 | 1133 | /* |
| 1134 | 1134 | * Dark magic for autoloader. |
| 1135 | 1135 | * If we do a class_exists it will try to load the class which will |
@@ -1164,7 +1164,7 @@ discard block |
||
| 1164 | 1164 | } |
| 1165 | 1165 | return new \OC_Defaults(); |
| 1166 | 1166 | }); |
| 1167 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
| 1167 | + $this->registerService(JSCombiner::class, function(Server $c) { |
|
| 1168 | 1168 | return new JSCombiner( |
| 1169 | 1169 | $c->getAppDataDir('js'), |
| 1170 | 1170 | $c->get(IURLGenerator::class), |
@@ -1178,7 +1178,7 @@ discard block |
||
| 1178 | 1178 | $this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class); |
| 1179 | 1179 | $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class); |
| 1180 | 1180 | |
| 1181 | - $this->registerService('CryptoWrapper', function (ContainerInterface $c) { |
|
| 1181 | + $this->registerService('CryptoWrapper', function(ContainerInterface $c) { |
|
| 1182 | 1182 | // FIXME: Instantiiated here due to cyclic dependency |
| 1183 | 1183 | $request = new Request( |
| 1184 | 1184 | [ |
@@ -1205,14 +1205,14 @@ discard block |
||
| 1205 | 1205 | }); |
| 1206 | 1206 | /** @deprecated 19.0.0 */ |
| 1207 | 1207 | $this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class); |
| 1208 | - $this->registerService(SessionStorage::class, function (ContainerInterface $c) { |
|
| 1208 | + $this->registerService(SessionStorage::class, function(ContainerInterface $c) { |
|
| 1209 | 1209 | return new SessionStorage($c->get(ISession::class)); |
| 1210 | 1210 | }); |
| 1211 | 1211 | $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
| 1212 | 1212 | /** @deprecated 19.0.0 */ |
| 1213 | 1213 | $this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class); |
| 1214 | 1214 | |
| 1215 | - $this->registerService(\OCP\Share\IManager::class, function (IServerContainer $c) { |
|
| 1215 | + $this->registerService(\OCP\Share\IManager::class, function(IServerContainer $c) { |
|
| 1216 | 1216 | $config = $c->get(\OCP\IConfig::class); |
| 1217 | 1217 | $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
| 1218 | 1218 | /** @var \OCP\Share\IProviderFactory $factory */ |
@@ -1242,7 +1242,7 @@ discard block |
||
| 1242 | 1242 | /** @deprecated 19.0.0 */ |
| 1243 | 1243 | $this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class); |
| 1244 | 1244 | |
| 1245 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
| 1245 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
| 1246 | 1246 | $instance = new Collaboration\Collaborators\Search($c); |
| 1247 | 1247 | |
| 1248 | 1248 | // register default plugins |
@@ -1265,33 +1265,33 @@ discard block |
||
| 1265 | 1265 | |
| 1266 | 1266 | $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class); |
| 1267 | 1267 | $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class); |
| 1268 | - $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) { |
|
| 1268 | + $this->registerService(\OC\Files\AppData\Factory::class, function(ContainerInterface $c) { |
|
| 1269 | 1269 | return new \OC\Files\AppData\Factory( |
| 1270 | 1270 | $c->get(IRootFolder::class), |
| 1271 | 1271 | $c->get(SystemConfig::class) |
| 1272 | 1272 | ); |
| 1273 | 1273 | }); |
| 1274 | 1274 | |
| 1275 | - $this->registerService('LockdownManager', function (ContainerInterface $c) { |
|
| 1276 | - return new LockdownManager(function () use ($c) { |
|
| 1275 | + $this->registerService('LockdownManager', function(ContainerInterface $c) { |
|
| 1276 | + return new LockdownManager(function() use ($c) { |
|
| 1277 | 1277 | return $c->get(ISession::class); |
| 1278 | 1278 | }); |
| 1279 | 1279 | }); |
| 1280 | 1280 | |
| 1281 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) { |
|
| 1281 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function(ContainerInterface $c) { |
|
| 1282 | 1282 | return new DiscoveryService( |
| 1283 | 1283 | $c->get(ICacheFactory::class), |
| 1284 | 1284 | $c->get(IClientService::class) |
| 1285 | 1285 | ); |
| 1286 | 1286 | }); |
| 1287 | 1287 | |
| 1288 | - $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) { |
|
| 1288 | + $this->registerService(ICloudIdManager::class, function(ContainerInterface $c) { |
|
| 1289 | 1289 | return new CloudIdManager($c->get(\OCP\Contacts\IManager::class)); |
| 1290 | 1290 | }); |
| 1291 | 1291 | |
| 1292 | 1292 | $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); |
| 1293 | 1293 | |
| 1294 | - $this->registerService(ICloudFederationProviderManager::class, function (ContainerInterface $c) { |
|
| 1294 | + $this->registerService(ICloudFederationProviderManager::class, function(ContainerInterface $c) { |
|
| 1295 | 1295 | return new CloudFederationProviderManager( |
| 1296 | 1296 | $c->get(IAppManager::class), |
| 1297 | 1297 | $c->get(IClientService::class), |
@@ -1300,7 +1300,7 @@ discard block |
||
| 1300 | 1300 | ); |
| 1301 | 1301 | }); |
| 1302 | 1302 | |
| 1303 | - $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
| 1303 | + $this->registerService(ICloudFederationFactory::class, function(Server $c) { |
|
| 1304 | 1304 | return new CloudFederationFactory(); |
| 1305 | 1305 | }); |
| 1306 | 1306 | |
@@ -1312,7 +1312,7 @@ discard block |
||
| 1312 | 1312 | /** @deprecated 19.0.0 */ |
| 1313 | 1313 | $this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
| 1314 | 1314 | |
| 1315 | - $this->registerService(Defaults::class, function (Server $c) { |
|
| 1315 | + $this->registerService(Defaults::class, function(Server $c) { |
|
| 1316 | 1316 | return new Defaults( |
| 1317 | 1317 | $c->getThemingDefaults() |
| 1318 | 1318 | ); |
@@ -1320,17 +1320,17 @@ discard block |
||
| 1320 | 1320 | /** @deprecated 19.0.0 */ |
| 1321 | 1321 | $this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class); |
| 1322 | 1322 | |
| 1323 | - $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) { |
|
| 1323 | + $this->registerService(\OCP\ISession::class, function(ContainerInterface $c) { |
|
| 1324 | 1324 | return $c->get(\OCP\IUserSession::class)->getSession(); |
| 1325 | 1325 | }, false); |
| 1326 | 1326 | |
| 1327 | - $this->registerService(IShareHelper::class, function (ContainerInterface $c) { |
|
| 1327 | + $this->registerService(IShareHelper::class, function(ContainerInterface $c) { |
|
| 1328 | 1328 | return new ShareHelper( |
| 1329 | 1329 | $c->get(\OCP\Share\IManager::class) |
| 1330 | 1330 | ); |
| 1331 | 1331 | }); |
| 1332 | 1332 | |
| 1333 | - $this->registerService(Installer::class, function (ContainerInterface $c) { |
|
| 1333 | + $this->registerService(Installer::class, function(ContainerInterface $c) { |
|
| 1334 | 1334 | return new Installer( |
| 1335 | 1335 | $c->get(AppFetcher::class), |
| 1336 | 1336 | $c->get(IClientService::class), |
@@ -1341,11 +1341,11 @@ discard block |
||
| 1341 | 1341 | ); |
| 1342 | 1342 | }); |
| 1343 | 1343 | |
| 1344 | - $this->registerService(IApiFactory::class, function (ContainerInterface $c) { |
|
| 1344 | + $this->registerService(IApiFactory::class, function(ContainerInterface $c) { |
|
| 1345 | 1345 | return new ApiFactory($c->get(IClientService::class)); |
| 1346 | 1346 | }); |
| 1347 | 1347 | |
| 1348 | - $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) { |
|
| 1348 | + $this->registerService(IInstanceFactory::class, function(ContainerInterface $c) { |
|
| 1349 | 1349 | $memcacheFactory = $c->get(ICacheFactory::class); |
| 1350 | 1350 | return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class)); |
| 1351 | 1351 | }); |
@@ -1402,7 +1402,7 @@ discard block |
||
| 1402 | 1402 | $dispatcher = $this->get(SymfonyAdapter::class); |
| 1403 | 1403 | |
| 1404 | 1404 | // Delete avatar on user deletion |
| 1405 | - $dispatcher->addListener('OCP\IUser::preDelete', function (GenericEvent $e) { |
|
| 1405 | + $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) { |
|
| 1406 | 1406 | $logger = $this->get(ILogger::class); |
| 1407 | 1407 | $manager = $this->getAvatarManager(); |
| 1408 | 1408 | /** @var IUser $user */ |
@@ -1415,11 +1415,11 @@ discard block |
||
| 1415 | 1415 | // no avatar to remove |
| 1416 | 1416 | } catch (\Exception $e) { |
| 1417 | 1417 | // Ignore exceptions |
| 1418 | - $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
| 1418 | + $logger->info('Could not cleanup avatar of '.$user->getUID()); |
|
| 1419 | 1419 | } |
| 1420 | 1420 | }); |
| 1421 | 1421 | |
| 1422 | - $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
| 1422 | + $dispatcher->addListener('OCP\IUser::changeUser', function(GenericEvent $e) { |
|
| 1423 | 1423 | $manager = $this->getAvatarManager(); |
| 1424 | 1424 | /** @var IUser $user */ |
| 1425 | 1425 | $user = $e->getSubject(); |
@@ -2310,11 +2310,11 @@ discard block |
||
| 2310 | 2310 | } |
| 2311 | 2311 | |
| 2312 | 2312 | private function registerDeprecatedAlias(string $alias, string $target) { |
| 2313 | - $this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) { |
|
| 2313 | + $this->registerService($alias, function(ContainerInterface $container) use ($target, $alias) { |
|
| 2314 | 2314 | try { |
| 2315 | 2315 | /** @var ILogger $logger */ |
| 2316 | 2316 | $logger = $container->get(ILogger::class); |
| 2317 | - $logger->debug('The requested alias "' . $alias . '" is deprecated. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']); |
|
| 2317 | + $logger->debug('The requested alias "'.$alias.'" is deprecated. Please request "'.$target.'" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']); |
|
| 2318 | 2318 | } catch (ContainerExceptionInterface $e) { |
| 2319 | 2319 | // Could not get logger. Continue |
| 2320 | 2320 | } |
@@ -39,88 +39,88 @@ |
||
| 39 | 39 | |
| 40 | 40 | class LookupPlugin implements ISearchPlugin { |
| 41 | 41 | |
| 42 | - /** @var IConfig */ |
|
| 43 | - private $config; |
|
| 44 | - /** @var IClientService */ |
|
| 45 | - private $clientService; |
|
| 46 | - /** @var string remote part of the current user's cloud id */ |
|
| 47 | - private $currentUserRemote; |
|
| 48 | - /** @var ICloudIdManager */ |
|
| 49 | - private $cloudIdManager; |
|
| 50 | - /** @var LoggerInterface */ |
|
| 51 | - private $logger; |
|
| 42 | + /** @var IConfig */ |
|
| 43 | + private $config; |
|
| 44 | + /** @var IClientService */ |
|
| 45 | + private $clientService; |
|
| 46 | + /** @var string remote part of the current user's cloud id */ |
|
| 47 | + private $currentUserRemote; |
|
| 48 | + /** @var ICloudIdManager */ |
|
| 49 | + private $cloudIdManager; |
|
| 50 | + /** @var LoggerInterface */ |
|
| 51 | + private $logger; |
|
| 52 | 52 | |
| 53 | - public function __construct(IConfig $config, |
|
| 54 | - IClientService $clientService, |
|
| 55 | - IUserSession $userSession, |
|
| 56 | - ICloudIdManager $cloudIdManager, |
|
| 57 | - LoggerInterface $logger) { |
|
| 58 | - $this->config = $config; |
|
| 59 | - $this->clientService = $clientService; |
|
| 60 | - $this->cloudIdManager = $cloudIdManager; |
|
| 61 | - $currentUserCloudId = $userSession->getUser()->getCloudId(); |
|
| 62 | - $this->currentUserRemote = $cloudIdManager->resolveCloudId($currentUserCloudId)->getRemote(); |
|
| 63 | - $this->logger = $logger; |
|
| 64 | - } |
|
| 53 | + public function __construct(IConfig $config, |
|
| 54 | + IClientService $clientService, |
|
| 55 | + IUserSession $userSession, |
|
| 56 | + ICloudIdManager $cloudIdManager, |
|
| 57 | + LoggerInterface $logger) { |
|
| 58 | + $this->config = $config; |
|
| 59 | + $this->clientService = $clientService; |
|
| 60 | + $this->cloudIdManager = $cloudIdManager; |
|
| 61 | + $currentUserCloudId = $userSession->getUser()->getCloudId(); |
|
| 62 | + $this->currentUserRemote = $cloudIdManager->resolveCloudId($currentUserCloudId)->getRemote(); |
|
| 63 | + $this->logger = $logger; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
| 67 | - $isGlobalScaleEnabled = $this->config->getSystemValue('gs.enabled', false); |
|
| 68 | - $isLookupServerEnabled = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'yes') === 'yes'; |
|
| 69 | - $hasInternetConnection = $this->config->getSystemValueBool('has_internet_connection', true); |
|
| 66 | + public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
| 67 | + $isGlobalScaleEnabled = $this->config->getSystemValue('gs.enabled', false); |
|
| 68 | + $isLookupServerEnabled = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'yes') === 'yes'; |
|
| 69 | + $hasInternetConnection = $this->config->getSystemValueBool('has_internet_connection', true); |
|
| 70 | 70 | |
| 71 | - // if case of Global Scale we always search the lookup server |
|
| 72 | - if (!$isGlobalScaleEnabled && (!$isLookupServerEnabled || !$hasInternetConnection)) { |
|
| 73 | - return false; |
|
| 74 | - } |
|
| 71 | + // if case of Global Scale we always search the lookup server |
|
| 72 | + if (!$isGlobalScaleEnabled && (!$isLookupServerEnabled || !$hasInternetConnection)) { |
|
| 73 | + return false; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - $lookupServerUrl = $this->config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); |
|
| 77 | - if (empty($lookupServerUrl)) { |
|
| 78 | - return false; |
|
| 79 | - } |
|
| 80 | - $lookupServerUrl = rtrim($lookupServerUrl, '/'); |
|
| 81 | - $result = []; |
|
| 76 | + $lookupServerUrl = $this->config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); |
|
| 77 | + if (empty($lookupServerUrl)) { |
|
| 78 | + return false; |
|
| 79 | + } |
|
| 80 | + $lookupServerUrl = rtrim($lookupServerUrl, '/'); |
|
| 81 | + $result = []; |
|
| 82 | 82 | |
| 83 | - try { |
|
| 84 | - $client = $this->clientService->newClient(); |
|
| 85 | - $response = $client->get( |
|
| 86 | - $lookupServerUrl . '/users?search=' . urlencode($search), |
|
| 87 | - [ |
|
| 88 | - 'timeout' => 10, |
|
| 89 | - 'connect_timeout' => 3, |
|
| 90 | - ] |
|
| 91 | - ); |
|
| 83 | + try { |
|
| 84 | + $client = $this->clientService->newClient(); |
|
| 85 | + $response = $client->get( |
|
| 86 | + $lookupServerUrl . '/users?search=' . urlencode($search), |
|
| 87 | + [ |
|
| 88 | + 'timeout' => 10, |
|
| 89 | + 'connect_timeout' => 3, |
|
| 90 | + ] |
|
| 91 | + ); |
|
| 92 | 92 | |
| 93 | - $body = json_decode($response->getBody(), true); |
|
| 93 | + $body = json_decode($response->getBody(), true); |
|
| 94 | 94 | |
| 95 | - foreach ($body as $lookup) { |
|
| 96 | - try { |
|
| 97 | - $remote = $this->cloudIdManager->resolveCloudId($lookup['federationId'])->getRemote(); |
|
| 98 | - } catch (\Exception $e) { |
|
| 99 | - $this->logger->error('Can not parse federated cloud ID "' . $lookup['federationId'] . '"', [ |
|
| 100 | - 'exception' => $e, |
|
| 101 | - ]); |
|
| 102 | - continue; |
|
| 103 | - } |
|
| 104 | - if ($this->currentUserRemote === $remote) { |
|
| 105 | - continue; |
|
| 106 | - } |
|
| 107 | - $name = isset($lookup['name']['value']) ? $lookup['name']['value'] : ''; |
|
| 108 | - $label = empty($name) ? $lookup['federationId'] : $name . ' (' . $lookup['federationId'] . ')'; |
|
| 109 | - $result[] = [ |
|
| 110 | - 'label' => $label, |
|
| 111 | - 'value' => [ |
|
| 112 | - 'shareType' => IShare::TYPE_REMOTE, |
|
| 113 | - 'shareWith' => $lookup['federationId'], |
|
| 114 | - ], |
|
| 115 | - 'extra' => $lookup, |
|
| 116 | - ]; |
|
| 117 | - } |
|
| 118 | - } catch (\Exception $e) { |
|
| 119 | - } |
|
| 95 | + foreach ($body as $lookup) { |
|
| 96 | + try { |
|
| 97 | + $remote = $this->cloudIdManager->resolveCloudId($lookup['federationId'])->getRemote(); |
|
| 98 | + } catch (\Exception $e) { |
|
| 99 | + $this->logger->error('Can not parse federated cloud ID "' . $lookup['federationId'] . '"', [ |
|
| 100 | + 'exception' => $e, |
|
| 101 | + ]); |
|
| 102 | + continue; |
|
| 103 | + } |
|
| 104 | + if ($this->currentUserRemote === $remote) { |
|
| 105 | + continue; |
|
| 106 | + } |
|
| 107 | + $name = isset($lookup['name']['value']) ? $lookup['name']['value'] : ''; |
|
| 108 | + $label = empty($name) ? $lookup['federationId'] : $name . ' (' . $lookup['federationId'] . ')'; |
|
| 109 | + $result[] = [ |
|
| 110 | + 'label' => $label, |
|
| 111 | + 'value' => [ |
|
| 112 | + 'shareType' => IShare::TYPE_REMOTE, |
|
| 113 | + 'shareWith' => $lookup['federationId'], |
|
| 114 | + ], |
|
| 115 | + 'extra' => $lookup, |
|
| 116 | + ]; |
|
| 117 | + } |
|
| 118 | + } catch (\Exception $e) { |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - $type = new SearchResultType('lookup'); |
|
| 122 | - $searchResult->addResultSet($type, $result, []); |
|
| 121 | + $type = new SearchResultType('lookup'); |
|
| 122 | + $searchResult->addResultSet($type, $result, []); |
|
| 123 | 123 | |
| 124 | - return false; |
|
| 125 | - } |
|
| 124 | + return false; |
|
| 125 | + } |
|
| 126 | 126 | } |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | try { |
| 84 | 84 | $client = $this->clientService->newClient(); |
| 85 | 85 | $response = $client->get( |
| 86 | - $lookupServerUrl . '/users?search=' . urlencode($search), |
|
| 86 | + $lookupServerUrl.'/users?search='.urlencode($search), |
|
| 87 | 87 | [ |
| 88 | 88 | 'timeout' => 10, |
| 89 | 89 | 'connect_timeout' => 3, |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | try { |
| 97 | 97 | $remote = $this->cloudIdManager->resolveCloudId($lookup['federationId'])->getRemote(); |
| 98 | 98 | } catch (\Exception $e) { |
| 99 | - $this->logger->error('Can not parse federated cloud ID "' . $lookup['federationId'] . '"', [ |
|
| 99 | + $this->logger->error('Can not parse federated cloud ID "'.$lookup['federationId'].'"', [ |
|
| 100 | 100 | 'exception' => $e, |
| 101 | 101 | ]); |
| 102 | 102 | continue; |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | continue; |
| 106 | 106 | } |
| 107 | 107 | $name = isset($lookup['name']['value']) ? $lookup['name']['value'] : ''; |
| 108 | - $label = empty($name) ? $lookup['federationId'] : $name . ' (' . $lookup['federationId'] . ')'; |
|
| 108 | + $label = empty($name) ? $lookup['federationId'] : $name.' ('.$lookup['federationId'].')'; |
|
| 109 | 109 | $result[] = [ |
| 110 | 110 | 'label' => $label, |
| 111 | 111 | 'value' => [ |
@@ -42,485 +42,485 @@ |
||
| 42 | 42 | use Psr\Log\LoggerInterface; |
| 43 | 43 | |
| 44 | 44 | class Manager implements IManager { |
| 45 | - public const TABLE_COLLECTIONS = 'collres_collections'; |
|
| 46 | - public const TABLE_RESOURCES = 'collres_resources'; |
|
| 47 | - public const TABLE_ACCESS_CACHE = 'collres_accesscache'; |
|
| 48 | - |
|
| 49 | - /** @var IDBConnection */ |
|
| 50 | - protected $connection; |
|
| 51 | - /** @var IProviderManager */ |
|
| 52 | - protected $providerManager; |
|
| 53 | - /** @var LoggerInterface */ |
|
| 54 | - protected $logger; |
|
| 55 | - |
|
| 56 | - /** @var string[] */ |
|
| 57 | - protected $providers = []; |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - public function __construct(IDBConnection $connection, IProviderManager $providerManager, LoggerInterface $logger) { |
|
| 61 | - $this->connection = $connection; |
|
| 62 | - $this->providerManager = $providerManager; |
|
| 63 | - $this->logger = $logger; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @param int $id |
|
| 68 | - * @return ICollection |
|
| 69 | - * @throws CollectionException when the collection could not be found |
|
| 70 | - * @since 16.0.0 |
|
| 71 | - */ |
|
| 72 | - public function getCollection(int $id): ICollection { |
|
| 73 | - $query = $this->connection->getQueryBuilder(); |
|
| 74 | - $query->select('*') |
|
| 75 | - ->from(self::TABLE_COLLECTIONS) |
|
| 76 | - ->where($query->expr()->eq('id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT))); |
|
| 77 | - $result = $query->execute(); |
|
| 78 | - $row = $result->fetch(); |
|
| 79 | - $result->closeCursor(); |
|
| 80 | - |
|
| 81 | - if (!$row) { |
|
| 82 | - throw new CollectionException('Collection not found'); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - return new Collection($this, $this->connection, (int) $row['id'], (string) $row['name']); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @param int $id |
|
| 90 | - * @param IUser|null $user |
|
| 91 | - * @return ICollection |
|
| 92 | - * @throws CollectionException when the collection could not be found |
|
| 93 | - * @since 16.0.0 |
|
| 94 | - */ |
|
| 95 | - public function getCollectionForUser(int $id, ?IUser $user): ICollection { |
|
| 96 | - $query = $this->connection->getQueryBuilder(); |
|
| 97 | - $userId = $user instanceof IUser ? $user->getUID() : ''; |
|
| 98 | - |
|
| 99 | - $query->select('*') |
|
| 100 | - ->from(self::TABLE_COLLECTIONS, 'c') |
|
| 101 | - ->leftJoin( |
|
| 102 | - 'c', self::TABLE_ACCESS_CACHE, 'a', |
|
| 103 | - $query->expr()->andX( |
|
| 104 | - $query->expr()->eq('c.id', 'a.collection_id'), |
|
| 105 | - $query->expr()->eq('a.user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR)) |
|
| 106 | - ) |
|
| 107 | - ) |
|
| 108 | - ->where($query->expr()->eq('c.id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT))); |
|
| 109 | - $result = $query->execute(); |
|
| 110 | - $row = $result->fetch(); |
|
| 111 | - $result->closeCursor(); |
|
| 112 | - |
|
| 113 | - if (!$row) { |
|
| 114 | - throw new CollectionException('Collection not found'); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - $access = $row['access'] === null ? null : (bool) $row['access']; |
|
| 118 | - if ($user instanceof IUser) { |
|
| 119 | - return new Collection($this, $this->connection, (int) $row['id'], (string) $row['name'], $user, $access); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - return new Collection($this, $this->connection, (int) $row['id'], (string) $row['name'], $user, $access); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * @param IUser $user |
|
| 127 | - * @param string $filter |
|
| 128 | - * @param int $limit |
|
| 129 | - * @param int $start |
|
| 130 | - * @return ICollection[] |
|
| 131 | - * @since 16.0.0 |
|
| 132 | - */ |
|
| 133 | - public function searchCollections(IUser $user, string $filter, int $limit = 50, int $start = 0): array { |
|
| 134 | - $query = $this->connection->getQueryBuilder(); |
|
| 135 | - $userId = $user instanceof IUser ? $user->getUID() : ''; |
|
| 136 | - |
|
| 137 | - $query->select('c.*', 'a.access') |
|
| 138 | - ->from(self::TABLE_COLLECTIONS, 'c') |
|
| 139 | - ->leftJoin( |
|
| 140 | - 'c', self::TABLE_ACCESS_CACHE, 'a', |
|
| 141 | - $query->expr()->andX( |
|
| 142 | - $query->expr()->eq('c.id', 'a.collection_id'), |
|
| 143 | - $query->expr()->eq('a.user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR)) |
|
| 144 | - ) |
|
| 145 | - ) |
|
| 146 | - ->where($query->expr()->eq('a.access', $query->createNamedParameter(1, IQueryBuilder::PARAM_INT))) |
|
| 147 | - ->orderBy('c.id') |
|
| 148 | - ->setMaxResults($limit) |
|
| 149 | - ->setFirstResult($start); |
|
| 150 | - |
|
| 151 | - if ($filter !== '') { |
|
| 152 | - $query->where($query->expr()->iLike('c.name', $query->createNamedParameter('%' . $this->connection->escapeLikeParameter($filter) . '%'))); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - $result = $query->execute(); |
|
| 156 | - $collections = []; |
|
| 157 | - |
|
| 158 | - $foundResults = 0; |
|
| 159 | - while ($row = $result->fetch()) { |
|
| 160 | - $foundResults++; |
|
| 161 | - $access = $row['access'] === null ? null : (bool) $row['access']; |
|
| 162 | - $collection = new Collection($this, $this->connection, (int)$row['id'], (string)$row['name'], $user, $access); |
|
| 163 | - if ($collection->canAccess($user)) { |
|
| 164 | - $collections[] = $collection; |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - $result->closeCursor(); |
|
| 168 | - |
|
| 169 | - if (empty($collections) && $foundResults === $limit) { |
|
| 170 | - return $this->searchCollections($user, $filter, $limit, $start + $limit); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - return $collections; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * @param string $name |
|
| 178 | - * @return ICollection |
|
| 179 | - * @since 16.0.0 |
|
| 180 | - */ |
|
| 181 | - public function newCollection(string $name): ICollection { |
|
| 182 | - $query = $this->connection->getQueryBuilder(); |
|
| 183 | - $query->insert(self::TABLE_COLLECTIONS) |
|
| 184 | - ->values([ |
|
| 185 | - 'name' => $query->createNamedParameter($name), |
|
| 186 | - ]); |
|
| 187 | - $query->execute(); |
|
| 188 | - |
|
| 189 | - return new Collection($this, $this->connection, $query->getLastInsertId(), $name); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * @param string $type |
|
| 194 | - * @param string $id |
|
| 195 | - * @return IResource |
|
| 196 | - * @since 16.0.0 |
|
| 197 | - */ |
|
| 198 | - public function createResource(string $type, string $id): IResource { |
|
| 199 | - return new Resource($this, $this->connection, $type, $id); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * @param string $type |
|
| 204 | - * @param string $id |
|
| 205 | - * @param IUser|null $user |
|
| 206 | - * @return IResource |
|
| 207 | - * @throws ResourceException |
|
| 208 | - * @since 16.0.0 |
|
| 209 | - */ |
|
| 210 | - public function getResourceForUser(string $type, string $id, ?IUser $user): IResource { |
|
| 211 | - $query = $this->connection->getQueryBuilder(); |
|
| 212 | - $userId = $user instanceof IUser ? $user->getUID() : ''; |
|
| 213 | - |
|
| 214 | - $query->select('r.*', 'a.access') |
|
| 215 | - ->from(self::TABLE_RESOURCES, 'r') |
|
| 216 | - ->leftJoin( |
|
| 217 | - 'r', self::TABLE_ACCESS_CACHE, 'a', |
|
| 218 | - $query->expr()->andX( |
|
| 219 | - $query->expr()->eq('r.resource_id', 'a.resource_id'), |
|
| 220 | - $query->expr()->eq('r.resource_type', 'a.resource_type'), |
|
| 221 | - $query->expr()->eq('a.user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR)) |
|
| 222 | - ) |
|
| 223 | - ) |
|
| 224 | - ->where($query->expr()->eq('r.resource_type', $query->createNamedParameter($type, IQueryBuilder::PARAM_STR))) |
|
| 225 | - ->andWhere($query->expr()->eq('r.resource_id', $query->createNamedParameter($id, IQueryBuilder::PARAM_STR))); |
|
| 226 | - $result = $query->execute(); |
|
| 227 | - $row = $result->fetch(); |
|
| 228 | - $result->closeCursor(); |
|
| 229 | - |
|
| 230 | - if (!$row) { |
|
| 231 | - throw new ResourceException('Resource not found'); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - $access = $row['access'] === null ? null : (bool) $row['access']; |
|
| 235 | - if ($user instanceof IUser) { |
|
| 236 | - return new Resource($this, $this->connection, $type, $id, $user, $access); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - return new Resource($this, $this->connection, $type, $id, null, $access); |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * @param ICollection $collection |
|
| 244 | - * @param IUser|null $user |
|
| 245 | - * @return IResource[] |
|
| 246 | - * @since 16.0.0 |
|
| 247 | - */ |
|
| 248 | - public function getResourcesByCollectionForUser(ICollection $collection, ?IUser $user): array { |
|
| 249 | - $query = $this->connection->getQueryBuilder(); |
|
| 250 | - $userId = $user instanceof IUser ? $user->getUID() : ''; |
|
| 251 | - |
|
| 252 | - $query->select('r.*', 'a.access') |
|
| 253 | - ->from(self::TABLE_RESOURCES, 'r') |
|
| 254 | - ->leftJoin( |
|
| 255 | - 'r', self::TABLE_ACCESS_CACHE, 'a', |
|
| 256 | - $query->expr()->andX( |
|
| 257 | - $query->expr()->eq('r.resource_id', 'a.resource_id'), |
|
| 258 | - $query->expr()->eq('r.resource_type', 'a.resource_type'), |
|
| 259 | - $query->expr()->eq('a.user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR)) |
|
| 260 | - ) |
|
| 261 | - ) |
|
| 262 | - ->where($query->expr()->eq('r.collection_id', $query->createNamedParameter($collection->getId(), IQueryBuilder::PARAM_INT))); |
|
| 263 | - |
|
| 264 | - $resources = []; |
|
| 265 | - $result = $query->execute(); |
|
| 266 | - while ($row = $result->fetch()) { |
|
| 267 | - $access = $row['access'] === null ? null : (bool) $row['access']; |
|
| 268 | - $resources[] = new Resource($this, $this->connection, $row['resource_type'], $row['resource_id'], $user, $access); |
|
| 269 | - } |
|
| 270 | - $result->closeCursor(); |
|
| 271 | - |
|
| 272 | - return $resources; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * Get the rich object data of a resource |
|
| 277 | - * |
|
| 278 | - * @param IResource $resource |
|
| 279 | - * @return array |
|
| 280 | - * @since 16.0.0 |
|
| 281 | - */ |
|
| 282 | - public function getResourceRichObject(IResource $resource): array { |
|
| 283 | - foreach ($this->providerManager->getResourceProviders() as $provider) { |
|
| 284 | - if ($provider->getType() === $resource->getType()) { |
|
| 285 | - try { |
|
| 286 | - return $provider->getResourceRichObject($resource); |
|
| 287 | - } catch (ResourceException $e) { |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - return []; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * Can a user/guest access the collection |
|
| 297 | - * |
|
| 298 | - * @param IResource $resource |
|
| 299 | - * @param IUser|null $user |
|
| 300 | - * @return bool |
|
| 301 | - * @since 16.0.0 |
|
| 302 | - */ |
|
| 303 | - public function canAccessResource(IResource $resource, ?IUser $user): bool { |
|
| 304 | - $access = $this->checkAccessCacheForUserByResource($resource, $user); |
|
| 305 | - if (\is_bool($access)) { |
|
| 306 | - return $access; |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - $access = false; |
|
| 310 | - foreach ($this->providerManager->getResourceProviders() as $provider) { |
|
| 311 | - if ($provider->getType() === $resource->getType()) { |
|
| 312 | - try { |
|
| 313 | - if ($provider->canAccessResource($resource, $user)) { |
|
| 314 | - $access = true; |
|
| 315 | - break; |
|
| 316 | - } |
|
| 317 | - } catch (ResourceException $e) { |
|
| 318 | - } |
|
| 319 | - } |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - $this->cacheAccessForResource($resource, $user, $access); |
|
| 323 | - return $access; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * Can a user/guest access the collection |
|
| 328 | - * |
|
| 329 | - * @param ICollection $collection |
|
| 330 | - * @param IUser|null $user |
|
| 331 | - * @return bool |
|
| 332 | - * @since 16.0.0 |
|
| 333 | - */ |
|
| 334 | - public function canAccessCollection(ICollection $collection, ?IUser $user): bool { |
|
| 335 | - $access = $this->checkAccessCacheForUserByCollection($collection, $user); |
|
| 336 | - if (\is_bool($access)) { |
|
| 337 | - return $access; |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - $access = null; |
|
| 341 | - // Access is granted when a user can access all resources |
|
| 342 | - foreach ($collection->getResources() as $resource) { |
|
| 343 | - if (!$resource->canAccess($user)) { |
|
| 344 | - $access = false; |
|
| 345 | - break; |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - $access = true; |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - $this->cacheAccessForCollection($collection, $user, $access); |
|
| 352 | - return $access; |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - protected function checkAccessCacheForUserByResource(IResource $resource, ?IUser $user): ?bool { |
|
| 356 | - $query = $this->connection->getQueryBuilder(); |
|
| 357 | - $userId = $user instanceof IUser ? $user->getUID() : ''; |
|
| 358 | - |
|
| 359 | - $query->select('access') |
|
| 360 | - ->from(self::TABLE_ACCESS_CACHE) |
|
| 361 | - ->where($query->expr()->eq('resource_id', $query->createNamedParameter($resource->getId(), IQueryBuilder::PARAM_STR))) |
|
| 362 | - ->andWhere($query->expr()->eq('resource_type', $query->createNamedParameter($resource->getType(), IQueryBuilder::PARAM_STR))) |
|
| 363 | - ->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR))) |
|
| 364 | - ->setMaxResults(1); |
|
| 365 | - |
|
| 366 | - $hasAccess = null; |
|
| 367 | - $result = $query->execute(); |
|
| 368 | - if ($row = $result->fetch()) { |
|
| 369 | - $hasAccess = (bool) $row['access']; |
|
| 370 | - } |
|
| 371 | - $result->closeCursor(); |
|
| 372 | - |
|
| 373 | - return $hasAccess; |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - protected function checkAccessCacheForUserByCollection(ICollection $collection, ?IUser $user): ?bool { |
|
| 377 | - $query = $this->connection->getQueryBuilder(); |
|
| 378 | - $userId = $user instanceof IUser ? $user->getUID() : ''; |
|
| 379 | - |
|
| 380 | - $query->select('access') |
|
| 381 | - ->from(self::TABLE_ACCESS_CACHE) |
|
| 382 | - ->where($query->expr()->eq('collection_id', $query->createNamedParameter($collection->getId(), IQueryBuilder::PARAM_INT))) |
|
| 383 | - ->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR))) |
|
| 384 | - ->setMaxResults(1); |
|
| 385 | - |
|
| 386 | - $hasAccess = null; |
|
| 387 | - $result = $query->execute(); |
|
| 388 | - if ($row = $result->fetch()) { |
|
| 389 | - $hasAccess = (bool) $row['access']; |
|
| 390 | - } |
|
| 391 | - $result->closeCursor(); |
|
| 392 | - |
|
| 393 | - return $hasAccess; |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - public function cacheAccessForResource(IResource $resource, ?IUser $user, bool $access): void { |
|
| 397 | - $query = $this->connection->getQueryBuilder(); |
|
| 398 | - $userId = $user instanceof IUser ? $user->getUID() : ''; |
|
| 399 | - |
|
| 400 | - $query->insert(self::TABLE_ACCESS_CACHE) |
|
| 401 | - ->values([ |
|
| 402 | - 'user_id' => $query->createNamedParameter($userId), |
|
| 403 | - 'resource_id' => $query->createNamedParameter($resource->getId()), |
|
| 404 | - 'resource_type' => $query->createNamedParameter($resource->getType()), |
|
| 405 | - 'access' => $query->createNamedParameter($access, IQueryBuilder::PARAM_BOOL), |
|
| 406 | - ]); |
|
| 407 | - try { |
|
| 408 | - $query->execute(); |
|
| 409 | - } catch (UniqueConstraintViolationException $e) { |
|
| 410 | - } |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - public function cacheAccessForCollection(ICollection $collection, ?IUser $user, bool $access): void { |
|
| 414 | - $query = $this->connection->getQueryBuilder(); |
|
| 415 | - $userId = $user instanceof IUser ? $user->getUID() : ''; |
|
| 416 | - |
|
| 417 | - $query->insert(self::TABLE_ACCESS_CACHE) |
|
| 418 | - ->values([ |
|
| 419 | - 'user_id' => $query->createNamedParameter($userId), |
|
| 420 | - 'collection_id' => $query->createNamedParameter($collection->getId()), |
|
| 421 | - 'access' => $query->createNamedParameter($access, IQueryBuilder::PARAM_BOOL), |
|
| 422 | - ]); |
|
| 423 | - try { |
|
| 424 | - $query->execute(); |
|
| 425 | - } catch (UniqueConstraintViolationException $e) { |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - public function invalidateAccessCacheForUser(?IUser $user): void { |
|
| 430 | - $query = $this->connection->getQueryBuilder(); |
|
| 431 | - $userId = $user instanceof IUser ? $user->getUID() : ''; |
|
| 432 | - |
|
| 433 | - $query->delete(self::TABLE_ACCESS_CACHE) |
|
| 434 | - ->where($query->expr()->eq('user_id', $query->createNamedParameter($userId))); |
|
| 435 | - $query->execute(); |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - public function invalidateAccessCacheForResource(IResource $resource): void { |
|
| 439 | - $query = $this->connection->getQueryBuilder(); |
|
| 440 | - |
|
| 441 | - $query->delete(self::TABLE_ACCESS_CACHE) |
|
| 442 | - ->where($query->expr()->eq('resource_id', $query->createNamedParameter($resource->getId()))) |
|
| 443 | - ->andWhere($query->expr()->eq('resource_type', $query->createNamedParameter($resource->getType(), IQueryBuilder::PARAM_STR))); |
|
| 444 | - $query->execute(); |
|
| 445 | - |
|
| 446 | - foreach ($resource->getCollections() as $collection) { |
|
| 447 | - $this->invalidateAccessCacheForCollection($collection); |
|
| 448 | - } |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - public function invalidateAccessCacheForAllCollections(): void { |
|
| 452 | - $query = $this->connection->getQueryBuilder(); |
|
| 453 | - |
|
| 454 | - $query->delete(self::TABLE_ACCESS_CACHE) |
|
| 455 | - ->where($query->expr()->neq('collection_id', $query->createNamedParameter(0))); |
|
| 456 | - $query->execute(); |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - public function invalidateAccessCacheForCollection(ICollection $collection): void { |
|
| 460 | - $query = $this->connection->getQueryBuilder(); |
|
| 461 | - |
|
| 462 | - $query->delete(self::TABLE_ACCESS_CACHE) |
|
| 463 | - ->where($query->expr()->eq('collection_id', $query->createNamedParameter($collection->getId()))); |
|
| 464 | - $query->execute(); |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - public function invalidateAccessCacheForProvider(IProvider $provider): void { |
|
| 468 | - $query = $this->connection->getQueryBuilder(); |
|
| 469 | - |
|
| 470 | - $query->delete(self::TABLE_ACCESS_CACHE) |
|
| 471 | - ->where($query->expr()->eq('resource_type', $query->createNamedParameter($provider->getType(), IQueryBuilder::PARAM_STR))); |
|
| 472 | - $query->execute(); |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - public function invalidateAccessCacheForResourceByUser(IResource $resource, ?IUser $user): void { |
|
| 476 | - $query = $this->connection->getQueryBuilder(); |
|
| 477 | - $userId = $user instanceof IUser ? $user->getUID() : ''; |
|
| 478 | - |
|
| 479 | - $query->delete(self::TABLE_ACCESS_CACHE) |
|
| 480 | - ->where($query->expr()->eq('resource_id', $query->createNamedParameter($resource->getId()))) |
|
| 481 | - ->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($userId))); |
|
| 482 | - $query->execute(); |
|
| 483 | - |
|
| 484 | - foreach ($resource->getCollections() as $collection) { |
|
| 485 | - $this->invalidateAccessCacheForCollectionByUser($collection, $user); |
|
| 486 | - } |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - protected function invalidateAccessCacheForCollectionByUser(ICollection $collection, ?IUser $user): void { |
|
| 490 | - $query = $this->connection->getQueryBuilder(); |
|
| 491 | - $userId = $user instanceof IUser ? $user->getUID() : ''; |
|
| 492 | - |
|
| 493 | - $query->delete(self::TABLE_ACCESS_CACHE) |
|
| 494 | - ->where($query->expr()->eq('collection_id', $query->createNamedParameter($collection->getId()))) |
|
| 495 | - ->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($userId))); |
|
| 496 | - $query->execute(); |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - public function invalidateAccessCacheForProviderByUser(IProvider $provider, ?IUser $user): void { |
|
| 500 | - $query = $this->connection->getQueryBuilder(); |
|
| 501 | - $userId = $user instanceof IUser ? $user->getUID() : ''; |
|
| 502 | - |
|
| 503 | - $query->delete(self::TABLE_ACCESS_CACHE) |
|
| 504 | - ->where($query->expr()->eq('resource_type', $query->createNamedParameter($provider->getType(), IQueryBuilder::PARAM_STR))) |
|
| 505 | - ->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($userId))); |
|
| 506 | - $query->execute(); |
|
| 507 | - } |
|
| 508 | - |
|
| 509 | - /** |
|
| 510 | - * @param string $provider |
|
| 511 | - */ |
|
| 512 | - public function registerResourceProvider(string $provider): void { |
|
| 513 | - $this->logger->debug('\OC\Collaboration\Resources\Manager::registerResourceProvider is deprecated', ['provider' => $provider]); |
|
| 514 | - $this->providerManager->registerResourceProvider($provider); |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - /** |
|
| 518 | - * Get the resource type of the provider |
|
| 519 | - * |
|
| 520 | - * @return string |
|
| 521 | - * @since 16.0.0 |
|
| 522 | - */ |
|
| 523 | - public function getType(): string { |
|
| 524 | - return ''; |
|
| 525 | - } |
|
| 45 | + public const TABLE_COLLECTIONS = 'collres_collections'; |
|
| 46 | + public const TABLE_RESOURCES = 'collres_resources'; |
|
| 47 | + public const TABLE_ACCESS_CACHE = 'collres_accesscache'; |
|
| 48 | + |
|
| 49 | + /** @var IDBConnection */ |
|
| 50 | + protected $connection; |
|
| 51 | + /** @var IProviderManager */ |
|
| 52 | + protected $providerManager; |
|
| 53 | + /** @var LoggerInterface */ |
|
| 54 | + protected $logger; |
|
| 55 | + |
|
| 56 | + /** @var string[] */ |
|
| 57 | + protected $providers = []; |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + public function __construct(IDBConnection $connection, IProviderManager $providerManager, LoggerInterface $logger) { |
|
| 61 | + $this->connection = $connection; |
|
| 62 | + $this->providerManager = $providerManager; |
|
| 63 | + $this->logger = $logger; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @param int $id |
|
| 68 | + * @return ICollection |
|
| 69 | + * @throws CollectionException when the collection could not be found |
|
| 70 | + * @since 16.0.0 |
|
| 71 | + */ |
|
| 72 | + public function getCollection(int $id): ICollection { |
|
| 73 | + $query = $this->connection->getQueryBuilder(); |
|
| 74 | + $query->select('*') |
|
| 75 | + ->from(self::TABLE_COLLECTIONS) |
|
| 76 | + ->where($query->expr()->eq('id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT))); |
|
| 77 | + $result = $query->execute(); |
|
| 78 | + $row = $result->fetch(); |
|
| 79 | + $result->closeCursor(); |
|
| 80 | + |
|
| 81 | + if (!$row) { |
|
| 82 | + throw new CollectionException('Collection not found'); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + return new Collection($this, $this->connection, (int) $row['id'], (string) $row['name']); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * @param int $id |
|
| 90 | + * @param IUser|null $user |
|
| 91 | + * @return ICollection |
|
| 92 | + * @throws CollectionException when the collection could not be found |
|
| 93 | + * @since 16.0.0 |
|
| 94 | + */ |
|
| 95 | + public function getCollectionForUser(int $id, ?IUser $user): ICollection { |
|
| 96 | + $query = $this->connection->getQueryBuilder(); |
|
| 97 | + $userId = $user instanceof IUser ? $user->getUID() : ''; |
|
| 98 | + |
|
| 99 | + $query->select('*') |
|
| 100 | + ->from(self::TABLE_COLLECTIONS, 'c') |
|
| 101 | + ->leftJoin( |
|
| 102 | + 'c', self::TABLE_ACCESS_CACHE, 'a', |
|
| 103 | + $query->expr()->andX( |
|
| 104 | + $query->expr()->eq('c.id', 'a.collection_id'), |
|
| 105 | + $query->expr()->eq('a.user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR)) |
|
| 106 | + ) |
|
| 107 | + ) |
|
| 108 | + ->where($query->expr()->eq('c.id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT))); |
|
| 109 | + $result = $query->execute(); |
|
| 110 | + $row = $result->fetch(); |
|
| 111 | + $result->closeCursor(); |
|
| 112 | + |
|
| 113 | + if (!$row) { |
|
| 114 | + throw new CollectionException('Collection not found'); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + $access = $row['access'] === null ? null : (bool) $row['access']; |
|
| 118 | + if ($user instanceof IUser) { |
|
| 119 | + return new Collection($this, $this->connection, (int) $row['id'], (string) $row['name'], $user, $access); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + return new Collection($this, $this->connection, (int) $row['id'], (string) $row['name'], $user, $access); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * @param IUser $user |
|
| 127 | + * @param string $filter |
|
| 128 | + * @param int $limit |
|
| 129 | + * @param int $start |
|
| 130 | + * @return ICollection[] |
|
| 131 | + * @since 16.0.0 |
|
| 132 | + */ |
|
| 133 | + public function searchCollections(IUser $user, string $filter, int $limit = 50, int $start = 0): array { |
|
| 134 | + $query = $this->connection->getQueryBuilder(); |
|
| 135 | + $userId = $user instanceof IUser ? $user->getUID() : ''; |
|
| 136 | + |
|
| 137 | + $query->select('c.*', 'a.access') |
|
| 138 | + ->from(self::TABLE_COLLECTIONS, 'c') |
|
| 139 | + ->leftJoin( |
|
| 140 | + 'c', self::TABLE_ACCESS_CACHE, 'a', |
|
| 141 | + $query->expr()->andX( |
|
| 142 | + $query->expr()->eq('c.id', 'a.collection_id'), |
|
| 143 | + $query->expr()->eq('a.user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR)) |
|
| 144 | + ) |
|
| 145 | + ) |
|
| 146 | + ->where($query->expr()->eq('a.access', $query->createNamedParameter(1, IQueryBuilder::PARAM_INT))) |
|
| 147 | + ->orderBy('c.id') |
|
| 148 | + ->setMaxResults($limit) |
|
| 149 | + ->setFirstResult($start); |
|
| 150 | + |
|
| 151 | + if ($filter !== '') { |
|
| 152 | + $query->where($query->expr()->iLike('c.name', $query->createNamedParameter('%' . $this->connection->escapeLikeParameter($filter) . '%'))); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + $result = $query->execute(); |
|
| 156 | + $collections = []; |
|
| 157 | + |
|
| 158 | + $foundResults = 0; |
|
| 159 | + while ($row = $result->fetch()) { |
|
| 160 | + $foundResults++; |
|
| 161 | + $access = $row['access'] === null ? null : (bool) $row['access']; |
|
| 162 | + $collection = new Collection($this, $this->connection, (int)$row['id'], (string)$row['name'], $user, $access); |
|
| 163 | + if ($collection->canAccess($user)) { |
|
| 164 | + $collections[] = $collection; |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + $result->closeCursor(); |
|
| 168 | + |
|
| 169 | + if (empty($collections) && $foundResults === $limit) { |
|
| 170 | + return $this->searchCollections($user, $filter, $limit, $start + $limit); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + return $collections; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * @param string $name |
|
| 178 | + * @return ICollection |
|
| 179 | + * @since 16.0.0 |
|
| 180 | + */ |
|
| 181 | + public function newCollection(string $name): ICollection { |
|
| 182 | + $query = $this->connection->getQueryBuilder(); |
|
| 183 | + $query->insert(self::TABLE_COLLECTIONS) |
|
| 184 | + ->values([ |
|
| 185 | + 'name' => $query->createNamedParameter($name), |
|
| 186 | + ]); |
|
| 187 | + $query->execute(); |
|
| 188 | + |
|
| 189 | + return new Collection($this, $this->connection, $query->getLastInsertId(), $name); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * @param string $type |
|
| 194 | + * @param string $id |
|
| 195 | + * @return IResource |
|
| 196 | + * @since 16.0.0 |
|
| 197 | + */ |
|
| 198 | + public function createResource(string $type, string $id): IResource { |
|
| 199 | + return new Resource($this, $this->connection, $type, $id); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * @param string $type |
|
| 204 | + * @param string $id |
|
| 205 | + * @param IUser|null $user |
|
| 206 | + * @return IResource |
|
| 207 | + * @throws ResourceException |
|
| 208 | + * @since 16.0.0 |
|
| 209 | + */ |
|
| 210 | + public function getResourceForUser(string $type, string $id, ?IUser $user): IResource { |
|
| 211 | + $query = $this->connection->getQueryBuilder(); |
|
| 212 | + $userId = $user instanceof IUser ? $user->getUID() : ''; |
|
| 213 | + |
|
| 214 | + $query->select('r.*', 'a.access') |
|
| 215 | + ->from(self::TABLE_RESOURCES, 'r') |
|
| 216 | + ->leftJoin( |
|
| 217 | + 'r', self::TABLE_ACCESS_CACHE, 'a', |
|
| 218 | + $query->expr()->andX( |
|
| 219 | + $query->expr()->eq('r.resource_id', 'a.resource_id'), |
|
| 220 | + $query->expr()->eq('r.resource_type', 'a.resource_type'), |
|
| 221 | + $query->expr()->eq('a.user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR)) |
|
| 222 | + ) |
|
| 223 | + ) |
|
| 224 | + ->where($query->expr()->eq('r.resource_type', $query->createNamedParameter($type, IQueryBuilder::PARAM_STR))) |
|
| 225 | + ->andWhere($query->expr()->eq('r.resource_id', $query->createNamedParameter($id, IQueryBuilder::PARAM_STR))); |
|
| 226 | + $result = $query->execute(); |
|
| 227 | + $row = $result->fetch(); |
|
| 228 | + $result->closeCursor(); |
|
| 229 | + |
|
| 230 | + if (!$row) { |
|
| 231 | + throw new ResourceException('Resource not found'); |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + $access = $row['access'] === null ? null : (bool) $row['access']; |
|
| 235 | + if ($user instanceof IUser) { |
|
| 236 | + return new Resource($this, $this->connection, $type, $id, $user, $access); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + return new Resource($this, $this->connection, $type, $id, null, $access); |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * @param ICollection $collection |
|
| 244 | + * @param IUser|null $user |
|
| 245 | + * @return IResource[] |
|
| 246 | + * @since 16.0.0 |
|
| 247 | + */ |
|
| 248 | + public function getResourcesByCollectionForUser(ICollection $collection, ?IUser $user): array { |
|
| 249 | + $query = $this->connection->getQueryBuilder(); |
|
| 250 | + $userId = $user instanceof IUser ? $user->getUID() : ''; |
|
| 251 | + |
|
| 252 | + $query->select('r.*', 'a.access') |
|
| 253 | + ->from(self::TABLE_RESOURCES, 'r') |
|
| 254 | + ->leftJoin( |
|
| 255 | + 'r', self::TABLE_ACCESS_CACHE, 'a', |
|
| 256 | + $query->expr()->andX( |
|
| 257 | + $query->expr()->eq('r.resource_id', 'a.resource_id'), |
|
| 258 | + $query->expr()->eq('r.resource_type', 'a.resource_type'), |
|
| 259 | + $query->expr()->eq('a.user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR)) |
|
| 260 | + ) |
|
| 261 | + ) |
|
| 262 | + ->where($query->expr()->eq('r.collection_id', $query->createNamedParameter($collection->getId(), IQueryBuilder::PARAM_INT))); |
|
| 263 | + |
|
| 264 | + $resources = []; |
|
| 265 | + $result = $query->execute(); |
|
| 266 | + while ($row = $result->fetch()) { |
|
| 267 | + $access = $row['access'] === null ? null : (bool) $row['access']; |
|
| 268 | + $resources[] = new Resource($this, $this->connection, $row['resource_type'], $row['resource_id'], $user, $access); |
|
| 269 | + } |
|
| 270 | + $result->closeCursor(); |
|
| 271 | + |
|
| 272 | + return $resources; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * Get the rich object data of a resource |
|
| 277 | + * |
|
| 278 | + * @param IResource $resource |
|
| 279 | + * @return array |
|
| 280 | + * @since 16.0.0 |
|
| 281 | + */ |
|
| 282 | + public function getResourceRichObject(IResource $resource): array { |
|
| 283 | + foreach ($this->providerManager->getResourceProviders() as $provider) { |
|
| 284 | + if ($provider->getType() === $resource->getType()) { |
|
| 285 | + try { |
|
| 286 | + return $provider->getResourceRichObject($resource); |
|
| 287 | + } catch (ResourceException $e) { |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + return []; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * Can a user/guest access the collection |
|
| 297 | + * |
|
| 298 | + * @param IResource $resource |
|
| 299 | + * @param IUser|null $user |
|
| 300 | + * @return bool |
|
| 301 | + * @since 16.0.0 |
|
| 302 | + */ |
|
| 303 | + public function canAccessResource(IResource $resource, ?IUser $user): bool { |
|
| 304 | + $access = $this->checkAccessCacheForUserByResource($resource, $user); |
|
| 305 | + if (\is_bool($access)) { |
|
| 306 | + return $access; |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + $access = false; |
|
| 310 | + foreach ($this->providerManager->getResourceProviders() as $provider) { |
|
| 311 | + if ($provider->getType() === $resource->getType()) { |
|
| 312 | + try { |
|
| 313 | + if ($provider->canAccessResource($resource, $user)) { |
|
| 314 | + $access = true; |
|
| 315 | + break; |
|
| 316 | + } |
|
| 317 | + } catch (ResourceException $e) { |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + $this->cacheAccessForResource($resource, $user, $access); |
|
| 323 | + return $access; |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * Can a user/guest access the collection |
|
| 328 | + * |
|
| 329 | + * @param ICollection $collection |
|
| 330 | + * @param IUser|null $user |
|
| 331 | + * @return bool |
|
| 332 | + * @since 16.0.0 |
|
| 333 | + */ |
|
| 334 | + public function canAccessCollection(ICollection $collection, ?IUser $user): bool { |
|
| 335 | + $access = $this->checkAccessCacheForUserByCollection($collection, $user); |
|
| 336 | + if (\is_bool($access)) { |
|
| 337 | + return $access; |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + $access = null; |
|
| 341 | + // Access is granted when a user can access all resources |
|
| 342 | + foreach ($collection->getResources() as $resource) { |
|
| 343 | + if (!$resource->canAccess($user)) { |
|
| 344 | + $access = false; |
|
| 345 | + break; |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + $access = true; |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + $this->cacheAccessForCollection($collection, $user, $access); |
|
| 352 | + return $access; |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + protected function checkAccessCacheForUserByResource(IResource $resource, ?IUser $user): ?bool { |
|
| 356 | + $query = $this->connection->getQueryBuilder(); |
|
| 357 | + $userId = $user instanceof IUser ? $user->getUID() : ''; |
|
| 358 | + |
|
| 359 | + $query->select('access') |
|
| 360 | + ->from(self::TABLE_ACCESS_CACHE) |
|
| 361 | + ->where($query->expr()->eq('resource_id', $query->createNamedParameter($resource->getId(), IQueryBuilder::PARAM_STR))) |
|
| 362 | + ->andWhere($query->expr()->eq('resource_type', $query->createNamedParameter($resource->getType(), IQueryBuilder::PARAM_STR))) |
|
| 363 | + ->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR))) |
|
| 364 | + ->setMaxResults(1); |
|
| 365 | + |
|
| 366 | + $hasAccess = null; |
|
| 367 | + $result = $query->execute(); |
|
| 368 | + if ($row = $result->fetch()) { |
|
| 369 | + $hasAccess = (bool) $row['access']; |
|
| 370 | + } |
|
| 371 | + $result->closeCursor(); |
|
| 372 | + |
|
| 373 | + return $hasAccess; |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + protected function checkAccessCacheForUserByCollection(ICollection $collection, ?IUser $user): ?bool { |
|
| 377 | + $query = $this->connection->getQueryBuilder(); |
|
| 378 | + $userId = $user instanceof IUser ? $user->getUID() : ''; |
|
| 379 | + |
|
| 380 | + $query->select('access') |
|
| 381 | + ->from(self::TABLE_ACCESS_CACHE) |
|
| 382 | + ->where($query->expr()->eq('collection_id', $query->createNamedParameter($collection->getId(), IQueryBuilder::PARAM_INT))) |
|
| 383 | + ->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR))) |
|
| 384 | + ->setMaxResults(1); |
|
| 385 | + |
|
| 386 | + $hasAccess = null; |
|
| 387 | + $result = $query->execute(); |
|
| 388 | + if ($row = $result->fetch()) { |
|
| 389 | + $hasAccess = (bool) $row['access']; |
|
| 390 | + } |
|
| 391 | + $result->closeCursor(); |
|
| 392 | + |
|
| 393 | + return $hasAccess; |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + public function cacheAccessForResource(IResource $resource, ?IUser $user, bool $access): void { |
|
| 397 | + $query = $this->connection->getQueryBuilder(); |
|
| 398 | + $userId = $user instanceof IUser ? $user->getUID() : ''; |
|
| 399 | + |
|
| 400 | + $query->insert(self::TABLE_ACCESS_CACHE) |
|
| 401 | + ->values([ |
|
| 402 | + 'user_id' => $query->createNamedParameter($userId), |
|
| 403 | + 'resource_id' => $query->createNamedParameter($resource->getId()), |
|
| 404 | + 'resource_type' => $query->createNamedParameter($resource->getType()), |
|
| 405 | + 'access' => $query->createNamedParameter($access, IQueryBuilder::PARAM_BOOL), |
|
| 406 | + ]); |
|
| 407 | + try { |
|
| 408 | + $query->execute(); |
|
| 409 | + } catch (UniqueConstraintViolationException $e) { |
|
| 410 | + } |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + public function cacheAccessForCollection(ICollection $collection, ?IUser $user, bool $access): void { |
|
| 414 | + $query = $this->connection->getQueryBuilder(); |
|
| 415 | + $userId = $user instanceof IUser ? $user->getUID() : ''; |
|
| 416 | + |
|
| 417 | + $query->insert(self::TABLE_ACCESS_CACHE) |
|
| 418 | + ->values([ |
|
| 419 | + 'user_id' => $query->createNamedParameter($userId), |
|
| 420 | + 'collection_id' => $query->createNamedParameter($collection->getId()), |
|
| 421 | + 'access' => $query->createNamedParameter($access, IQueryBuilder::PARAM_BOOL), |
|
| 422 | + ]); |
|
| 423 | + try { |
|
| 424 | + $query->execute(); |
|
| 425 | + } catch (UniqueConstraintViolationException $e) { |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + public function invalidateAccessCacheForUser(?IUser $user): void { |
|
| 430 | + $query = $this->connection->getQueryBuilder(); |
|
| 431 | + $userId = $user instanceof IUser ? $user->getUID() : ''; |
|
| 432 | + |
|
| 433 | + $query->delete(self::TABLE_ACCESS_CACHE) |
|
| 434 | + ->where($query->expr()->eq('user_id', $query->createNamedParameter($userId))); |
|
| 435 | + $query->execute(); |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + public function invalidateAccessCacheForResource(IResource $resource): void { |
|
| 439 | + $query = $this->connection->getQueryBuilder(); |
|
| 440 | + |
|
| 441 | + $query->delete(self::TABLE_ACCESS_CACHE) |
|
| 442 | + ->where($query->expr()->eq('resource_id', $query->createNamedParameter($resource->getId()))) |
|
| 443 | + ->andWhere($query->expr()->eq('resource_type', $query->createNamedParameter($resource->getType(), IQueryBuilder::PARAM_STR))); |
|
| 444 | + $query->execute(); |
|
| 445 | + |
|
| 446 | + foreach ($resource->getCollections() as $collection) { |
|
| 447 | + $this->invalidateAccessCacheForCollection($collection); |
|
| 448 | + } |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + public function invalidateAccessCacheForAllCollections(): void { |
|
| 452 | + $query = $this->connection->getQueryBuilder(); |
|
| 453 | + |
|
| 454 | + $query->delete(self::TABLE_ACCESS_CACHE) |
|
| 455 | + ->where($query->expr()->neq('collection_id', $query->createNamedParameter(0))); |
|
| 456 | + $query->execute(); |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + public function invalidateAccessCacheForCollection(ICollection $collection): void { |
|
| 460 | + $query = $this->connection->getQueryBuilder(); |
|
| 461 | + |
|
| 462 | + $query->delete(self::TABLE_ACCESS_CACHE) |
|
| 463 | + ->where($query->expr()->eq('collection_id', $query->createNamedParameter($collection->getId()))); |
|
| 464 | + $query->execute(); |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + public function invalidateAccessCacheForProvider(IProvider $provider): void { |
|
| 468 | + $query = $this->connection->getQueryBuilder(); |
|
| 469 | + |
|
| 470 | + $query->delete(self::TABLE_ACCESS_CACHE) |
|
| 471 | + ->where($query->expr()->eq('resource_type', $query->createNamedParameter($provider->getType(), IQueryBuilder::PARAM_STR))); |
|
| 472 | + $query->execute(); |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + public function invalidateAccessCacheForResourceByUser(IResource $resource, ?IUser $user): void { |
|
| 476 | + $query = $this->connection->getQueryBuilder(); |
|
| 477 | + $userId = $user instanceof IUser ? $user->getUID() : ''; |
|
| 478 | + |
|
| 479 | + $query->delete(self::TABLE_ACCESS_CACHE) |
|
| 480 | + ->where($query->expr()->eq('resource_id', $query->createNamedParameter($resource->getId()))) |
|
| 481 | + ->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($userId))); |
|
| 482 | + $query->execute(); |
|
| 483 | + |
|
| 484 | + foreach ($resource->getCollections() as $collection) { |
|
| 485 | + $this->invalidateAccessCacheForCollectionByUser($collection, $user); |
|
| 486 | + } |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + protected function invalidateAccessCacheForCollectionByUser(ICollection $collection, ?IUser $user): void { |
|
| 490 | + $query = $this->connection->getQueryBuilder(); |
|
| 491 | + $userId = $user instanceof IUser ? $user->getUID() : ''; |
|
| 492 | + |
|
| 493 | + $query->delete(self::TABLE_ACCESS_CACHE) |
|
| 494 | + ->where($query->expr()->eq('collection_id', $query->createNamedParameter($collection->getId()))) |
|
| 495 | + ->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($userId))); |
|
| 496 | + $query->execute(); |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + public function invalidateAccessCacheForProviderByUser(IProvider $provider, ?IUser $user): void { |
|
| 500 | + $query = $this->connection->getQueryBuilder(); |
|
| 501 | + $userId = $user instanceof IUser ? $user->getUID() : ''; |
|
| 502 | + |
|
| 503 | + $query->delete(self::TABLE_ACCESS_CACHE) |
|
| 504 | + ->where($query->expr()->eq('resource_type', $query->createNamedParameter($provider->getType(), IQueryBuilder::PARAM_STR))) |
|
| 505 | + ->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($userId))); |
|
| 506 | + $query->execute(); |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + /** |
|
| 510 | + * @param string $provider |
|
| 511 | + */ |
|
| 512 | + public function registerResourceProvider(string $provider): void { |
|
| 513 | + $this->logger->debug('\OC\Collaboration\Resources\Manager::registerResourceProvider is deprecated', ['provider' => $provider]); |
|
| 514 | + $this->providerManager->registerResourceProvider($provider); |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + /** |
|
| 518 | + * Get the resource type of the provider |
|
| 519 | + * |
|
| 520 | + * @return string |
|
| 521 | + * @since 16.0.0 |
|
| 522 | + */ |
|
| 523 | + public function getType(): string { |
|
| 524 | + return ''; |
|
| 525 | + } |
|
| 526 | 526 | } |
@@ -34,41 +34,41 @@ |
||
| 34 | 34 | |
| 35 | 35 | class ProviderManager implements IProviderManager { |
| 36 | 36 | |
| 37 | - /** @var string[] */ |
|
| 38 | - protected $providers = []; |
|
| 37 | + /** @var string[] */ |
|
| 38 | + protected $providers = []; |
|
| 39 | 39 | |
| 40 | - /** @var IProvider[] */ |
|
| 41 | - protected $providerInstances = []; |
|
| 40 | + /** @var IProvider[] */ |
|
| 41 | + protected $providerInstances = []; |
|
| 42 | 42 | |
| 43 | - /** @var IServerContainer */ |
|
| 44 | - protected $serverContainer; |
|
| 43 | + /** @var IServerContainer */ |
|
| 44 | + protected $serverContainer; |
|
| 45 | 45 | |
| 46 | - /** @var LoggerInterface */ |
|
| 47 | - protected $logger; |
|
| 46 | + /** @var LoggerInterface */ |
|
| 47 | + protected $logger; |
|
| 48 | 48 | |
| 49 | - public function __construct(IServerContainer $serverContainer, LoggerInterface $logger) { |
|
| 50 | - $this->serverContainer = $serverContainer; |
|
| 51 | - $this->logger = $logger; |
|
| 52 | - } |
|
| 49 | + public function __construct(IServerContainer $serverContainer, LoggerInterface $logger) { |
|
| 50 | + $this->serverContainer = $serverContainer; |
|
| 51 | + $this->logger = $logger; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - public function getResourceProviders(): array { |
|
| 55 | - if ($this->providers !== []) { |
|
| 56 | - foreach ($this->providers as $provider) { |
|
| 57 | - try { |
|
| 58 | - $this->providerInstances[] = $this->serverContainer->query($provider); |
|
| 59 | - } catch (QueryException $e) { |
|
| 60 | - $this->logger->error("Could not query resource provider $provider: " . $e->getMessage(), [ |
|
| 61 | - 'exception' => $e, |
|
| 62 | - ]); |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - $this->providers = []; |
|
| 66 | - } |
|
| 54 | + public function getResourceProviders(): array { |
|
| 55 | + if ($this->providers !== []) { |
|
| 56 | + foreach ($this->providers as $provider) { |
|
| 57 | + try { |
|
| 58 | + $this->providerInstances[] = $this->serverContainer->query($provider); |
|
| 59 | + } catch (QueryException $e) { |
|
| 60 | + $this->logger->error("Could not query resource provider $provider: " . $e->getMessage(), [ |
|
| 61 | + 'exception' => $e, |
|
| 62 | + ]); |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + $this->providers = []; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - return $this->providerInstances; |
|
| 69 | - } |
|
| 68 | + return $this->providerInstances; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - public function registerResourceProvider(string $provider): void { |
|
| 72 | - $this->providers[] = $provider; |
|
| 73 | - } |
|
| 71 | + public function registerResourceProvider(string $provider): void { |
|
| 72 | + $this->providers[] = $provider; |
|
| 73 | + } |
|
| 74 | 74 | } |
@@ -57,7 +57,7 @@ |
||
| 57 | 57 | try { |
| 58 | 58 | $this->providerInstances[] = $this->serverContainer->query($provider); |
| 59 | 59 | } catch (QueryException $e) { |
| 60 | - $this->logger->error("Could not query resource provider $provider: " . $e->getMessage(), [ |
|
| 60 | + $this->logger->error("Could not query resource provider $provider: ".$e->getMessage(), [ |
|
| 61 | 61 | 'exception' => $e, |
| 62 | 62 | ]); |
| 63 | 63 | } |
@@ -64,545 +64,545 @@ |
||
| 64 | 64 | use Psr\Log\LoggerInterface; |
| 65 | 65 | |
| 66 | 66 | class Setup { |
| 67 | - /** @var SystemConfig */ |
|
| 68 | - protected $config; |
|
| 69 | - /** @var IniGetWrapper */ |
|
| 70 | - protected $iniWrapper; |
|
| 71 | - /** @var IL10N */ |
|
| 72 | - protected $l10n; |
|
| 73 | - /** @var Defaults */ |
|
| 74 | - protected $defaults; |
|
| 75 | - /** @var LoggerInterface */ |
|
| 76 | - protected $logger; |
|
| 77 | - /** @var ISecureRandom */ |
|
| 78 | - protected $random; |
|
| 79 | - /** @var Installer */ |
|
| 80 | - protected $installer; |
|
| 81 | - |
|
| 82 | - public function __construct( |
|
| 83 | - SystemConfig $config, |
|
| 84 | - IniGetWrapper $iniWrapper, |
|
| 85 | - IL10N $l10n, |
|
| 86 | - Defaults $defaults, |
|
| 87 | - LoggerInterface $logger, |
|
| 88 | - ISecureRandom $random, |
|
| 89 | - Installer $installer |
|
| 90 | - ) { |
|
| 91 | - $this->config = $config; |
|
| 92 | - $this->iniWrapper = $iniWrapper; |
|
| 93 | - $this->l10n = $l10n; |
|
| 94 | - $this->defaults = $defaults; |
|
| 95 | - $this->logger = $logger; |
|
| 96 | - $this->random = $random; |
|
| 97 | - $this->installer = $installer; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - protected static $dbSetupClasses = [ |
|
| 101 | - 'mysql' => \OC\Setup\MySQL::class, |
|
| 102 | - 'pgsql' => \OC\Setup\PostgreSQL::class, |
|
| 103 | - 'oci' => \OC\Setup\OCI::class, |
|
| 104 | - 'sqlite' => \OC\Setup\Sqlite::class, |
|
| 105 | - 'sqlite3' => \OC\Setup\Sqlite::class, |
|
| 106 | - ]; |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Wrapper around the "class_exists" PHP function to be able to mock it |
|
| 110 | - * |
|
| 111 | - * @param string $name |
|
| 112 | - * @return bool |
|
| 113 | - */ |
|
| 114 | - protected function class_exists($name) { |
|
| 115 | - return class_exists($name); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Wrapper around the "is_callable" PHP function to be able to mock it |
|
| 120 | - * |
|
| 121 | - * @param string $name |
|
| 122 | - * @return bool |
|
| 123 | - */ |
|
| 124 | - protected function is_callable($name) { |
|
| 125 | - return is_callable($name); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Wrapper around \PDO::getAvailableDrivers |
|
| 130 | - * |
|
| 131 | - * @return array |
|
| 132 | - */ |
|
| 133 | - protected function getAvailableDbDriversForPdo() { |
|
| 134 | - return \PDO::getAvailableDrivers(); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Get the available and supported databases of this instance |
|
| 139 | - * |
|
| 140 | - * @param bool $allowAllDatabases |
|
| 141 | - * @return array |
|
| 142 | - * @throws Exception |
|
| 143 | - */ |
|
| 144 | - public function getSupportedDatabases($allowAllDatabases = false) { |
|
| 145 | - $availableDatabases = [ |
|
| 146 | - 'sqlite' => [ |
|
| 147 | - 'type' => 'pdo', |
|
| 148 | - 'call' => 'sqlite', |
|
| 149 | - 'name' => 'SQLite', |
|
| 150 | - ], |
|
| 151 | - 'mysql' => [ |
|
| 152 | - 'type' => 'pdo', |
|
| 153 | - 'call' => 'mysql', |
|
| 154 | - 'name' => 'MySQL/MariaDB', |
|
| 155 | - ], |
|
| 156 | - 'pgsql' => [ |
|
| 157 | - 'type' => 'pdo', |
|
| 158 | - 'call' => 'pgsql', |
|
| 159 | - 'name' => 'PostgreSQL', |
|
| 160 | - ], |
|
| 161 | - 'oci' => [ |
|
| 162 | - 'type' => 'function', |
|
| 163 | - 'call' => 'oci_connect', |
|
| 164 | - 'name' => 'Oracle', |
|
| 165 | - ], |
|
| 166 | - ]; |
|
| 167 | - if ($allowAllDatabases) { |
|
| 168 | - $configuredDatabases = array_keys($availableDatabases); |
|
| 169 | - } else { |
|
| 170 | - $configuredDatabases = $this->config->getValue('supportedDatabases', |
|
| 171 | - ['sqlite', 'mysql', 'pgsql']); |
|
| 172 | - } |
|
| 173 | - if (!is_array($configuredDatabases)) { |
|
| 174 | - throw new Exception('Supported databases are not properly configured.'); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - $supportedDatabases = []; |
|
| 178 | - |
|
| 179 | - foreach ($configuredDatabases as $database) { |
|
| 180 | - if (array_key_exists($database, $availableDatabases)) { |
|
| 181 | - $working = false; |
|
| 182 | - $type = $availableDatabases[$database]['type']; |
|
| 183 | - $call = $availableDatabases[$database]['call']; |
|
| 184 | - |
|
| 185 | - if ($type === 'function') { |
|
| 186 | - $working = $this->is_callable($call); |
|
| 187 | - } elseif ($type === 'pdo') { |
|
| 188 | - $working = in_array($call, $this->getAvailableDbDriversForPdo(), true); |
|
| 189 | - } |
|
| 190 | - if ($working) { |
|
| 191 | - $supportedDatabases[$database] = $availableDatabases[$database]['name']; |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - return $supportedDatabases; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Gathers system information like database type and does |
|
| 201 | - * a few system checks. |
|
| 202 | - * |
|
| 203 | - * @return array of system info, including an "errors" value |
|
| 204 | - * in case of errors/warnings |
|
| 205 | - */ |
|
| 206 | - public function getSystemInfo($allowAllDatabases = false) { |
|
| 207 | - $databases = $this->getSupportedDatabases($allowAllDatabases); |
|
| 208 | - |
|
| 209 | - $dataDir = $this->config->getValue('datadirectory', \OC::$SERVERROOT . '/data'); |
|
| 210 | - |
|
| 211 | - $errors = []; |
|
| 212 | - |
|
| 213 | - // Create data directory to test whether the .htaccess works |
|
| 214 | - // Notice that this is not necessarily the same data directory as the one |
|
| 215 | - // that will effectively be used. |
|
| 216 | - if (!file_exists($dataDir)) { |
|
| 217 | - @mkdir($dataDir); |
|
| 218 | - } |
|
| 219 | - $htAccessWorking = true; |
|
| 220 | - if (is_dir($dataDir) && is_writable($dataDir)) { |
|
| 221 | - // Protect data directory here, so we can test if the protection is working |
|
| 222 | - self::protectDataDirectory(); |
|
| 223 | - |
|
| 224 | - try { |
|
| 225 | - $util = new \OC_Util(); |
|
| 226 | - $htAccessWorking = $util->isHtaccessWorking(\OC::$server->getConfig()); |
|
| 227 | - } catch (\OC\HintException $e) { |
|
| 228 | - $errors[] = [ |
|
| 229 | - 'error' => $e->getMessage(), |
|
| 230 | - 'exception' => $e, |
|
| 231 | - 'hint' => $e->getHint(), |
|
| 232 | - ]; |
|
| 233 | - $htAccessWorking = false; |
|
| 234 | - } |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - if (\OC_Util::runningOnMac()) { |
|
| 238 | - $errors[] = [ |
|
| 239 | - 'error' => $this->l10n->t( |
|
| 240 | - 'Mac OS X is not supported and %s will not work properly on this platform. ' . |
|
| 241 | - 'Use it at your own risk! ', |
|
| 242 | - [$this->defaults->getName()] |
|
| 243 | - ), |
|
| 244 | - 'hint' => $this->l10n->t('For the best results, please consider using a GNU/Linux server instead.'), |
|
| 245 | - ]; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - if ($this->iniWrapper->getString('open_basedir') !== '' && PHP_INT_SIZE === 4) { |
|
| 249 | - $errors[] = [ |
|
| 250 | - 'error' => $this->l10n->t( |
|
| 251 | - 'It seems that this %s instance is running on a 32-bit PHP environment and the open_basedir has been configured in php.ini. ' . |
|
| 252 | - 'This will lead to problems with files over 4 GB and is highly discouraged.', |
|
| 253 | - [$this->defaults->getName()] |
|
| 254 | - ), |
|
| 255 | - 'hint' => $this->l10n->t('Please remove the open_basedir setting within your php.ini or switch to 64-bit PHP.'), |
|
| 256 | - ]; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - return [ |
|
| 260 | - 'hasSQLite' => isset($databases['sqlite']), |
|
| 261 | - 'hasMySQL' => isset($databases['mysql']), |
|
| 262 | - 'hasPostgreSQL' => isset($databases['pgsql']), |
|
| 263 | - 'hasOracle' => isset($databases['oci']), |
|
| 264 | - 'databases' => $databases, |
|
| 265 | - 'directory' => $dataDir, |
|
| 266 | - 'htaccessWorking' => $htAccessWorking, |
|
| 267 | - 'errors' => $errors, |
|
| 268 | - ]; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * @param $options |
|
| 273 | - * @return array |
|
| 274 | - */ |
|
| 275 | - public function install($options) { |
|
| 276 | - $l = $this->l10n; |
|
| 277 | - |
|
| 278 | - $error = []; |
|
| 279 | - $dbType = $options['dbtype']; |
|
| 280 | - |
|
| 281 | - if (empty($options['adminlogin'])) { |
|
| 282 | - $error[] = $l->t('Set an admin username.'); |
|
| 283 | - } |
|
| 284 | - if (empty($options['adminpass'])) { |
|
| 285 | - $error[] = $l->t('Set an admin password.'); |
|
| 286 | - } |
|
| 287 | - if (empty($options['directory'])) { |
|
| 288 | - $options['directory'] = \OC::$SERVERROOT . "/data"; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - if (!isset(self::$dbSetupClasses[$dbType])) { |
|
| 292 | - $dbType = 'sqlite'; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - $username = htmlspecialchars_decode($options['adminlogin']); |
|
| 296 | - $password = htmlspecialchars_decode($options['adminpass']); |
|
| 297 | - $dataDir = htmlspecialchars_decode($options['directory']); |
|
| 298 | - |
|
| 299 | - $class = self::$dbSetupClasses[$dbType]; |
|
| 300 | - /** @var \OC\Setup\AbstractDatabase $dbSetup */ |
|
| 301 | - $dbSetup = new $class($l, $this->config, $this->logger, $this->random); |
|
| 302 | - $error = array_merge($error, $dbSetup->validate($options)); |
|
| 303 | - |
|
| 304 | - // validate the data directory |
|
| 305 | - if ((!is_dir($dataDir) && !mkdir($dataDir)) || !is_writable($dataDir)) { |
|
| 306 | - $error[] = $l->t("Can't create or write into the data directory %s", [$dataDir]); |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - if (!empty($error)) { |
|
| 310 | - return $error; |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - $request = \OC::$server->getRequest(); |
|
| 314 | - |
|
| 315 | - //no errors, good |
|
| 316 | - if (isset($options['trusted_domains']) |
|
| 317 | - && is_array($options['trusted_domains'])) { |
|
| 318 | - $trustedDomains = $options['trusted_domains']; |
|
| 319 | - } else { |
|
| 320 | - $trustedDomains = [$request->getInsecureServerHost()]; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - //use sqlite3 when available, otherwise sqlite2 will be used. |
|
| 324 | - if ($dbType === 'sqlite' && class_exists('SQLite3')) { |
|
| 325 | - $dbType = 'sqlite3'; |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - //generate a random salt that is used to salt the local user passwords |
|
| 329 | - $salt = $this->random->generate(30); |
|
| 330 | - // generate a secret |
|
| 331 | - $secret = $this->random->generate(48); |
|
| 332 | - |
|
| 333 | - //write the config file |
|
| 334 | - $newConfigValues = [ |
|
| 335 | - 'passwordsalt' => $salt, |
|
| 336 | - 'secret' => $secret, |
|
| 337 | - 'trusted_domains' => $trustedDomains, |
|
| 338 | - 'datadirectory' => $dataDir, |
|
| 339 | - 'dbtype' => $dbType, |
|
| 340 | - 'version' => implode('.', \OCP\Util::getVersion()), |
|
| 341 | - ]; |
|
| 342 | - |
|
| 343 | - if ($this->config->getValue('overwrite.cli.url', null) === null) { |
|
| 344 | - $newConfigValues['overwrite.cli.url'] = $request->getServerProtocol() . '://' . $request->getInsecureServerHost() . \OC::$WEBROOT; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - $this->config->setValues($newConfigValues); |
|
| 348 | - |
|
| 349 | - $dbSetup->initialize($options); |
|
| 350 | - try { |
|
| 351 | - $dbSetup->setupDatabase($username); |
|
| 352 | - } catch (\OC\DatabaseSetupException $e) { |
|
| 353 | - $error[] = [ |
|
| 354 | - 'error' => $e->getMessage(), |
|
| 355 | - 'exception' => $e, |
|
| 356 | - 'hint' => $e->getHint(), |
|
| 357 | - ]; |
|
| 358 | - return $error; |
|
| 359 | - } catch (Exception $e) { |
|
| 360 | - $error[] = [ |
|
| 361 | - 'error' => 'Error while trying to create admin user: ' . $e->getMessage(), |
|
| 362 | - 'exception' => $e, |
|
| 363 | - 'hint' => '', |
|
| 364 | - ]; |
|
| 365 | - return $error; |
|
| 366 | - } |
|
| 367 | - try { |
|
| 368 | - // apply necessary migrations |
|
| 369 | - $dbSetup->runMigrations(); |
|
| 370 | - } catch (Exception $e) { |
|
| 371 | - $error[] = [ |
|
| 372 | - 'error' => 'Error while trying to initialise the database: ' . $e->getMessage(), |
|
| 373 | - 'exception' => $e, |
|
| 374 | - 'hint' => '', |
|
| 375 | - ]; |
|
| 376 | - return $error; |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - //create the user and group |
|
| 380 | - $user = null; |
|
| 381 | - try { |
|
| 382 | - $user = \OC::$server->getUserManager()->createUser($username, $password); |
|
| 383 | - if (!$user) { |
|
| 384 | - $error[] = "User <$username> could not be created."; |
|
| 385 | - } |
|
| 386 | - } catch (Exception $exception) { |
|
| 387 | - $error[] = $exception->getMessage(); |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - if (empty($error)) { |
|
| 391 | - $config = \OC::$server->getConfig(); |
|
| 392 | - $config->setAppValue('core', 'installedat', microtime(true)); |
|
| 393 | - $config->setAppValue('core', 'lastupdatedat', microtime(true)); |
|
| 394 | - $config->setAppValue('core', 'vendor', $this->getVendor()); |
|
| 395 | - |
|
| 396 | - $group = \OC::$server->getGroupManager()->createGroup('admin'); |
|
| 397 | - if ($group instanceof IGroup) { |
|
| 398 | - $group->addUser($user); |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - // Install shipped apps and specified app bundles |
|
| 402 | - Installer::installShippedApps(); |
|
| 403 | - $bundleFetcher = new BundleFetcher(\OC::$server->getL10N('lib')); |
|
| 404 | - $defaultInstallationBundles = $bundleFetcher->getDefaultInstallationBundle(); |
|
| 405 | - foreach ($defaultInstallationBundles as $bundle) { |
|
| 406 | - try { |
|
| 407 | - $this->installer->installAppBundle($bundle); |
|
| 408 | - } catch (Exception $e) { |
|
| 409 | - } |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - // create empty file in data dir, so we can later find |
|
| 413 | - // out that this is indeed an ownCloud data directory |
|
| 414 | - file_put_contents($config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', ''); |
|
| 415 | - |
|
| 416 | - // Update .htaccess files |
|
| 417 | - self::updateHtaccess(); |
|
| 418 | - self::protectDataDirectory(); |
|
| 419 | - |
|
| 420 | - self::installBackgroundJobs(); |
|
| 421 | - |
|
| 422 | - //and we are done |
|
| 423 | - $config->setSystemValue('installed', true); |
|
| 424 | - |
|
| 425 | - // Create a session token for the newly created user |
|
| 426 | - // The token provider requires a working db, so it's not injected on setup |
|
| 427 | - /* @var $userSession User\Session */ |
|
| 428 | - $userSession = \OC::$server->getUserSession(); |
|
| 429 | - $defaultTokenProvider = \OC::$server->query(DefaultTokenProvider::class); |
|
| 430 | - $userSession->setTokenProvider($defaultTokenProvider); |
|
| 431 | - $userSession->login($username, $password); |
|
| 432 | - $userSession->createSessionToken($request, $userSession->getUser()->getUID(), $username, $password); |
|
| 433 | - |
|
| 434 | - $session = $userSession->getSession(); |
|
| 435 | - $session->set('last-password-confirm', \OC::$server->query(ITimeFactory::class)->getTime()); |
|
| 436 | - |
|
| 437 | - // Set email for admin |
|
| 438 | - if (!empty($options['adminemail'])) { |
|
| 439 | - $config->setUserValue($user->getUID(), 'settings', 'email', $options['adminemail']); |
|
| 440 | - } |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - return $error; |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - public static function installBackgroundJobs() { |
|
| 447 | - $jobList = \OC::$server->getJobList(); |
|
| 448 | - $jobList->add(DefaultTokenCleanupJob::class); |
|
| 449 | - $jobList->add(Rotate::class); |
|
| 450 | - $jobList->add(BackgroundCleanupJob::class); |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - /** |
|
| 454 | - * @return string Absolute path to htaccess |
|
| 455 | - */ |
|
| 456 | - private function pathToHtaccess() { |
|
| 457 | - return \OC::$SERVERROOT . '/.htaccess'; |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - /** |
|
| 461 | - * Find webroot from config |
|
| 462 | - * |
|
| 463 | - * @param SystemConfig $config |
|
| 464 | - * @return string |
|
| 465 | - * @throws InvalidArgumentException when invalid value for overwrite.cli.url |
|
| 466 | - */ |
|
| 467 | - private static function findWebRoot(SystemConfig $config): string { |
|
| 468 | - // For CLI read the value from overwrite.cli.url |
|
| 469 | - if (\OC::$CLI) { |
|
| 470 | - $webRoot = $config->getValue('overwrite.cli.url', ''); |
|
| 471 | - if ($webRoot === '') { |
|
| 472 | - throw new InvalidArgumentException('overwrite.cli.url is empty'); |
|
| 473 | - } |
|
| 474 | - if (!filter_var($webRoot, FILTER_VALIDATE_URL)) { |
|
| 475 | - throw new InvalidArgumentException('invalid value for overwrite.cli.url'); |
|
| 476 | - } |
|
| 477 | - $webRoot = rtrim(parse_url($webRoot, PHP_URL_PATH), '/'); |
|
| 478 | - } else { |
|
| 479 | - $webRoot = !empty(\OC::$WEBROOT) ? \OC::$WEBROOT : '/'; |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - return $webRoot; |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - /** |
|
| 486 | - * Append the correct ErrorDocument path for Apache hosts |
|
| 487 | - * |
|
| 488 | - * @return bool True when success, False otherwise |
|
| 489 | - * @throws \OCP\AppFramework\QueryException |
|
| 490 | - */ |
|
| 491 | - public static function updateHtaccess() { |
|
| 492 | - $config = \OC::$server->getSystemConfig(); |
|
| 493 | - |
|
| 494 | - try { |
|
| 495 | - $webRoot = self::findWebRoot($config); |
|
| 496 | - } catch (InvalidArgumentException $e) { |
|
| 497 | - return false; |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - $setupHelper = new \OC\Setup( |
|
| 501 | - $config, |
|
| 502 | - \OC::$server->get(IniGetWrapper::class), |
|
| 503 | - \OC::$server->getL10N('lib'), |
|
| 504 | - \OC::$server->query(Defaults::class), |
|
| 505 | - \OC::$server->get(LoggerInterface::class), |
|
| 506 | - \OC::$server->getSecureRandom(), |
|
| 507 | - \OC::$server->query(Installer::class) |
|
| 508 | - ); |
|
| 509 | - |
|
| 510 | - $htaccessContent = file_get_contents($setupHelper->pathToHtaccess()); |
|
| 511 | - $content = "#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####\n"; |
|
| 512 | - $htaccessContent = explode($content, $htaccessContent, 2)[0]; |
|
| 513 | - |
|
| 514 | - //custom 403 error page |
|
| 515 | - $content .= "\nErrorDocument 403 " . $webRoot . '/'; |
|
| 516 | - |
|
| 517 | - //custom 404 error page |
|
| 518 | - $content .= "\nErrorDocument 404 " . $webRoot . '/'; |
|
| 519 | - |
|
| 520 | - // Add rewrite rules if the RewriteBase is configured |
|
| 521 | - $rewriteBase = $config->getValue('htaccess.RewriteBase', ''); |
|
| 522 | - if ($rewriteBase !== '') { |
|
| 523 | - $content .= "\n<IfModule mod_rewrite.c>"; |
|
| 524 | - $content .= "\n Options -MultiViews"; |
|
| 525 | - $content .= "\n RewriteRule ^core/js/oc.js$ index.php [PT,E=PATH_INFO:$1]"; |
|
| 526 | - $content .= "\n RewriteRule ^core/preview.png$ index.php [PT,E=PATH_INFO:$1]"; |
|
| 527 | - $content .= "\n RewriteCond %{REQUEST_FILENAME} !\\.(css|js|svg|gif|png|html|ttf|woff2?|ico|jpg|jpeg|map|webm|mp4|mp3|ogg|wav)$"; |
|
| 528 | - $content .= "\n RewriteCond %{REQUEST_FILENAME} !core/img/favicon.ico$"; |
|
| 529 | - $content .= "\n RewriteCond %{REQUEST_FILENAME} !core/img/manifest.json$"; |
|
| 530 | - $content .= "\n RewriteCond %{REQUEST_FILENAME} !/remote.php"; |
|
| 531 | - $content .= "\n RewriteCond %{REQUEST_FILENAME} !/public.php"; |
|
| 532 | - $content .= "\n RewriteCond %{REQUEST_FILENAME} !/cron.php"; |
|
| 533 | - $content .= "\n RewriteCond %{REQUEST_FILENAME} !/core/ajax/update.php"; |
|
| 534 | - $content .= "\n RewriteCond %{REQUEST_FILENAME} !/status.php"; |
|
| 535 | - $content .= "\n RewriteCond %{REQUEST_FILENAME} !/ocs/v1.php"; |
|
| 536 | - $content .= "\n RewriteCond %{REQUEST_FILENAME} !/ocs/v2.php"; |
|
| 537 | - $content .= "\n RewriteCond %{REQUEST_FILENAME} !/robots.txt"; |
|
| 538 | - $content .= "\n RewriteCond %{REQUEST_FILENAME} !/updater/"; |
|
| 539 | - $content .= "\n RewriteCond %{REQUEST_FILENAME} !/ocs-provider/"; |
|
| 540 | - $content .= "\n RewriteCond %{REQUEST_FILENAME} !/ocm-provider/"; |
|
| 541 | - $content .= "\n RewriteCond %{REQUEST_URI} !^/\\.well-known/(acme-challenge|pki-validation)/.*"; |
|
| 542 | - $content .= "\n RewriteCond %{REQUEST_FILENAME} !/richdocumentscode(_arm64)?/proxy.php$"; |
|
| 543 | - $content .= "\n RewriteRule . index.php [PT,E=PATH_INFO:$1]"; |
|
| 544 | - $content .= "\n RewriteBase " . $rewriteBase; |
|
| 545 | - $content .= "\n <IfModule mod_env.c>"; |
|
| 546 | - $content .= "\n SetEnv front_controller_active true"; |
|
| 547 | - $content .= "\n <IfModule mod_dir.c>"; |
|
| 548 | - $content .= "\n DirectorySlash off"; |
|
| 549 | - $content .= "\n </IfModule>"; |
|
| 550 | - $content .= "\n </IfModule>"; |
|
| 551 | - $content .= "\n</IfModule>"; |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - if ($content !== '') { |
|
| 555 | - //suppress errors in case we don't have permissions for it |
|
| 556 | - return (bool)@file_put_contents($setupHelper->pathToHtaccess(), $htaccessContent . $content . "\n"); |
|
| 557 | - } |
|
| 558 | - |
|
| 559 | - return false; |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - public static function protectDataDirectory() { |
|
| 563 | - //Require all denied |
|
| 564 | - $now = date('Y-m-d H:i:s'); |
|
| 565 | - $content = "# Generated by Nextcloud on $now\n"; |
|
| 566 | - $content .= "# Section for Apache 2.4 to 2.6\n"; |
|
| 567 | - $content .= "<IfModule mod_authz_core.c>\n"; |
|
| 568 | - $content .= " Require all denied\n"; |
|
| 569 | - $content .= "</IfModule>\n"; |
|
| 570 | - $content .= "<IfModule mod_access_compat.c>\n"; |
|
| 571 | - $content .= " Order Allow,Deny\n"; |
|
| 572 | - $content .= " Deny from all\n"; |
|
| 573 | - $content .= " Satisfy All\n"; |
|
| 574 | - $content .= "</IfModule>\n\n"; |
|
| 575 | - $content .= "# Section for Apache 2.2\n"; |
|
| 576 | - $content .= "<IfModule !mod_authz_core.c>\n"; |
|
| 577 | - $content .= " <IfModule !mod_access_compat.c>\n"; |
|
| 578 | - $content .= " <IfModule mod_authz_host.c>\n"; |
|
| 579 | - $content .= " Order Allow,Deny\n"; |
|
| 580 | - $content .= " Deny from all\n"; |
|
| 581 | - $content .= " </IfModule>\n"; |
|
| 582 | - $content .= " Satisfy All\n"; |
|
| 583 | - $content .= " </IfModule>\n"; |
|
| 584 | - $content .= "</IfModule>\n\n"; |
|
| 585 | - $content .= "# Section for Apache 2.2 to 2.6\n"; |
|
| 586 | - $content .= "<IfModule mod_autoindex.c>\n"; |
|
| 587 | - $content .= " IndexIgnore *\n"; |
|
| 588 | - $content .= "</IfModule>"; |
|
| 589 | - |
|
| 590 | - $baseDir = \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data'); |
|
| 591 | - file_put_contents($baseDir . '/.htaccess', $content); |
|
| 592 | - file_put_contents($baseDir . '/index.html', ''); |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - /** |
|
| 596 | - * Return vendor from which this version was published |
|
| 597 | - * |
|
| 598 | - * @return string Get the vendor |
|
| 599 | - * |
|
| 600 | - * Copy of \OC\Updater::getVendor() |
|
| 601 | - */ |
|
| 602 | - private function getVendor() { |
|
| 603 | - // this should really be a JSON file |
|
| 604 | - require \OC::$SERVERROOT . '/version.php'; |
|
| 605 | - /** @var string $vendor */ |
|
| 606 | - return (string)$vendor; |
|
| 607 | - } |
|
| 67 | + /** @var SystemConfig */ |
|
| 68 | + protected $config; |
|
| 69 | + /** @var IniGetWrapper */ |
|
| 70 | + protected $iniWrapper; |
|
| 71 | + /** @var IL10N */ |
|
| 72 | + protected $l10n; |
|
| 73 | + /** @var Defaults */ |
|
| 74 | + protected $defaults; |
|
| 75 | + /** @var LoggerInterface */ |
|
| 76 | + protected $logger; |
|
| 77 | + /** @var ISecureRandom */ |
|
| 78 | + protected $random; |
|
| 79 | + /** @var Installer */ |
|
| 80 | + protected $installer; |
|
| 81 | + |
|
| 82 | + public function __construct( |
|
| 83 | + SystemConfig $config, |
|
| 84 | + IniGetWrapper $iniWrapper, |
|
| 85 | + IL10N $l10n, |
|
| 86 | + Defaults $defaults, |
|
| 87 | + LoggerInterface $logger, |
|
| 88 | + ISecureRandom $random, |
|
| 89 | + Installer $installer |
|
| 90 | + ) { |
|
| 91 | + $this->config = $config; |
|
| 92 | + $this->iniWrapper = $iniWrapper; |
|
| 93 | + $this->l10n = $l10n; |
|
| 94 | + $this->defaults = $defaults; |
|
| 95 | + $this->logger = $logger; |
|
| 96 | + $this->random = $random; |
|
| 97 | + $this->installer = $installer; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + protected static $dbSetupClasses = [ |
|
| 101 | + 'mysql' => \OC\Setup\MySQL::class, |
|
| 102 | + 'pgsql' => \OC\Setup\PostgreSQL::class, |
|
| 103 | + 'oci' => \OC\Setup\OCI::class, |
|
| 104 | + 'sqlite' => \OC\Setup\Sqlite::class, |
|
| 105 | + 'sqlite3' => \OC\Setup\Sqlite::class, |
|
| 106 | + ]; |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Wrapper around the "class_exists" PHP function to be able to mock it |
|
| 110 | + * |
|
| 111 | + * @param string $name |
|
| 112 | + * @return bool |
|
| 113 | + */ |
|
| 114 | + protected function class_exists($name) { |
|
| 115 | + return class_exists($name); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Wrapper around the "is_callable" PHP function to be able to mock it |
|
| 120 | + * |
|
| 121 | + * @param string $name |
|
| 122 | + * @return bool |
|
| 123 | + */ |
|
| 124 | + protected function is_callable($name) { |
|
| 125 | + return is_callable($name); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Wrapper around \PDO::getAvailableDrivers |
|
| 130 | + * |
|
| 131 | + * @return array |
|
| 132 | + */ |
|
| 133 | + protected function getAvailableDbDriversForPdo() { |
|
| 134 | + return \PDO::getAvailableDrivers(); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Get the available and supported databases of this instance |
|
| 139 | + * |
|
| 140 | + * @param bool $allowAllDatabases |
|
| 141 | + * @return array |
|
| 142 | + * @throws Exception |
|
| 143 | + */ |
|
| 144 | + public function getSupportedDatabases($allowAllDatabases = false) { |
|
| 145 | + $availableDatabases = [ |
|
| 146 | + 'sqlite' => [ |
|
| 147 | + 'type' => 'pdo', |
|
| 148 | + 'call' => 'sqlite', |
|
| 149 | + 'name' => 'SQLite', |
|
| 150 | + ], |
|
| 151 | + 'mysql' => [ |
|
| 152 | + 'type' => 'pdo', |
|
| 153 | + 'call' => 'mysql', |
|
| 154 | + 'name' => 'MySQL/MariaDB', |
|
| 155 | + ], |
|
| 156 | + 'pgsql' => [ |
|
| 157 | + 'type' => 'pdo', |
|
| 158 | + 'call' => 'pgsql', |
|
| 159 | + 'name' => 'PostgreSQL', |
|
| 160 | + ], |
|
| 161 | + 'oci' => [ |
|
| 162 | + 'type' => 'function', |
|
| 163 | + 'call' => 'oci_connect', |
|
| 164 | + 'name' => 'Oracle', |
|
| 165 | + ], |
|
| 166 | + ]; |
|
| 167 | + if ($allowAllDatabases) { |
|
| 168 | + $configuredDatabases = array_keys($availableDatabases); |
|
| 169 | + } else { |
|
| 170 | + $configuredDatabases = $this->config->getValue('supportedDatabases', |
|
| 171 | + ['sqlite', 'mysql', 'pgsql']); |
|
| 172 | + } |
|
| 173 | + if (!is_array($configuredDatabases)) { |
|
| 174 | + throw new Exception('Supported databases are not properly configured.'); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + $supportedDatabases = []; |
|
| 178 | + |
|
| 179 | + foreach ($configuredDatabases as $database) { |
|
| 180 | + if (array_key_exists($database, $availableDatabases)) { |
|
| 181 | + $working = false; |
|
| 182 | + $type = $availableDatabases[$database]['type']; |
|
| 183 | + $call = $availableDatabases[$database]['call']; |
|
| 184 | + |
|
| 185 | + if ($type === 'function') { |
|
| 186 | + $working = $this->is_callable($call); |
|
| 187 | + } elseif ($type === 'pdo') { |
|
| 188 | + $working = in_array($call, $this->getAvailableDbDriversForPdo(), true); |
|
| 189 | + } |
|
| 190 | + if ($working) { |
|
| 191 | + $supportedDatabases[$database] = $availableDatabases[$database]['name']; |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + return $supportedDatabases; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * Gathers system information like database type and does |
|
| 201 | + * a few system checks. |
|
| 202 | + * |
|
| 203 | + * @return array of system info, including an "errors" value |
|
| 204 | + * in case of errors/warnings |
|
| 205 | + */ |
|
| 206 | + public function getSystemInfo($allowAllDatabases = false) { |
|
| 207 | + $databases = $this->getSupportedDatabases($allowAllDatabases); |
|
| 208 | + |
|
| 209 | + $dataDir = $this->config->getValue('datadirectory', \OC::$SERVERROOT . '/data'); |
|
| 210 | + |
|
| 211 | + $errors = []; |
|
| 212 | + |
|
| 213 | + // Create data directory to test whether the .htaccess works |
|
| 214 | + // Notice that this is not necessarily the same data directory as the one |
|
| 215 | + // that will effectively be used. |
|
| 216 | + if (!file_exists($dataDir)) { |
|
| 217 | + @mkdir($dataDir); |
|
| 218 | + } |
|
| 219 | + $htAccessWorking = true; |
|
| 220 | + if (is_dir($dataDir) && is_writable($dataDir)) { |
|
| 221 | + // Protect data directory here, so we can test if the protection is working |
|
| 222 | + self::protectDataDirectory(); |
|
| 223 | + |
|
| 224 | + try { |
|
| 225 | + $util = new \OC_Util(); |
|
| 226 | + $htAccessWorking = $util->isHtaccessWorking(\OC::$server->getConfig()); |
|
| 227 | + } catch (\OC\HintException $e) { |
|
| 228 | + $errors[] = [ |
|
| 229 | + 'error' => $e->getMessage(), |
|
| 230 | + 'exception' => $e, |
|
| 231 | + 'hint' => $e->getHint(), |
|
| 232 | + ]; |
|
| 233 | + $htAccessWorking = false; |
|
| 234 | + } |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + if (\OC_Util::runningOnMac()) { |
|
| 238 | + $errors[] = [ |
|
| 239 | + 'error' => $this->l10n->t( |
|
| 240 | + 'Mac OS X is not supported and %s will not work properly on this platform. ' . |
|
| 241 | + 'Use it at your own risk! ', |
|
| 242 | + [$this->defaults->getName()] |
|
| 243 | + ), |
|
| 244 | + 'hint' => $this->l10n->t('For the best results, please consider using a GNU/Linux server instead.'), |
|
| 245 | + ]; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + if ($this->iniWrapper->getString('open_basedir') !== '' && PHP_INT_SIZE === 4) { |
|
| 249 | + $errors[] = [ |
|
| 250 | + 'error' => $this->l10n->t( |
|
| 251 | + 'It seems that this %s instance is running on a 32-bit PHP environment and the open_basedir has been configured in php.ini. ' . |
|
| 252 | + 'This will lead to problems with files over 4 GB and is highly discouraged.', |
|
| 253 | + [$this->defaults->getName()] |
|
| 254 | + ), |
|
| 255 | + 'hint' => $this->l10n->t('Please remove the open_basedir setting within your php.ini or switch to 64-bit PHP.'), |
|
| 256 | + ]; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + return [ |
|
| 260 | + 'hasSQLite' => isset($databases['sqlite']), |
|
| 261 | + 'hasMySQL' => isset($databases['mysql']), |
|
| 262 | + 'hasPostgreSQL' => isset($databases['pgsql']), |
|
| 263 | + 'hasOracle' => isset($databases['oci']), |
|
| 264 | + 'databases' => $databases, |
|
| 265 | + 'directory' => $dataDir, |
|
| 266 | + 'htaccessWorking' => $htAccessWorking, |
|
| 267 | + 'errors' => $errors, |
|
| 268 | + ]; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * @param $options |
|
| 273 | + * @return array |
|
| 274 | + */ |
|
| 275 | + public function install($options) { |
|
| 276 | + $l = $this->l10n; |
|
| 277 | + |
|
| 278 | + $error = []; |
|
| 279 | + $dbType = $options['dbtype']; |
|
| 280 | + |
|
| 281 | + if (empty($options['adminlogin'])) { |
|
| 282 | + $error[] = $l->t('Set an admin username.'); |
|
| 283 | + } |
|
| 284 | + if (empty($options['adminpass'])) { |
|
| 285 | + $error[] = $l->t('Set an admin password.'); |
|
| 286 | + } |
|
| 287 | + if (empty($options['directory'])) { |
|
| 288 | + $options['directory'] = \OC::$SERVERROOT . "/data"; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + if (!isset(self::$dbSetupClasses[$dbType])) { |
|
| 292 | + $dbType = 'sqlite'; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + $username = htmlspecialchars_decode($options['adminlogin']); |
|
| 296 | + $password = htmlspecialchars_decode($options['adminpass']); |
|
| 297 | + $dataDir = htmlspecialchars_decode($options['directory']); |
|
| 298 | + |
|
| 299 | + $class = self::$dbSetupClasses[$dbType]; |
|
| 300 | + /** @var \OC\Setup\AbstractDatabase $dbSetup */ |
|
| 301 | + $dbSetup = new $class($l, $this->config, $this->logger, $this->random); |
|
| 302 | + $error = array_merge($error, $dbSetup->validate($options)); |
|
| 303 | + |
|
| 304 | + // validate the data directory |
|
| 305 | + if ((!is_dir($dataDir) && !mkdir($dataDir)) || !is_writable($dataDir)) { |
|
| 306 | + $error[] = $l->t("Can't create or write into the data directory %s", [$dataDir]); |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + if (!empty($error)) { |
|
| 310 | + return $error; |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + $request = \OC::$server->getRequest(); |
|
| 314 | + |
|
| 315 | + //no errors, good |
|
| 316 | + if (isset($options['trusted_domains']) |
|
| 317 | + && is_array($options['trusted_domains'])) { |
|
| 318 | + $trustedDomains = $options['trusted_domains']; |
|
| 319 | + } else { |
|
| 320 | + $trustedDomains = [$request->getInsecureServerHost()]; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + //use sqlite3 when available, otherwise sqlite2 will be used. |
|
| 324 | + if ($dbType === 'sqlite' && class_exists('SQLite3')) { |
|
| 325 | + $dbType = 'sqlite3'; |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + //generate a random salt that is used to salt the local user passwords |
|
| 329 | + $salt = $this->random->generate(30); |
|
| 330 | + // generate a secret |
|
| 331 | + $secret = $this->random->generate(48); |
|
| 332 | + |
|
| 333 | + //write the config file |
|
| 334 | + $newConfigValues = [ |
|
| 335 | + 'passwordsalt' => $salt, |
|
| 336 | + 'secret' => $secret, |
|
| 337 | + 'trusted_domains' => $trustedDomains, |
|
| 338 | + 'datadirectory' => $dataDir, |
|
| 339 | + 'dbtype' => $dbType, |
|
| 340 | + 'version' => implode('.', \OCP\Util::getVersion()), |
|
| 341 | + ]; |
|
| 342 | + |
|
| 343 | + if ($this->config->getValue('overwrite.cli.url', null) === null) { |
|
| 344 | + $newConfigValues['overwrite.cli.url'] = $request->getServerProtocol() . '://' . $request->getInsecureServerHost() . \OC::$WEBROOT; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + $this->config->setValues($newConfigValues); |
|
| 348 | + |
|
| 349 | + $dbSetup->initialize($options); |
|
| 350 | + try { |
|
| 351 | + $dbSetup->setupDatabase($username); |
|
| 352 | + } catch (\OC\DatabaseSetupException $e) { |
|
| 353 | + $error[] = [ |
|
| 354 | + 'error' => $e->getMessage(), |
|
| 355 | + 'exception' => $e, |
|
| 356 | + 'hint' => $e->getHint(), |
|
| 357 | + ]; |
|
| 358 | + return $error; |
|
| 359 | + } catch (Exception $e) { |
|
| 360 | + $error[] = [ |
|
| 361 | + 'error' => 'Error while trying to create admin user: ' . $e->getMessage(), |
|
| 362 | + 'exception' => $e, |
|
| 363 | + 'hint' => '', |
|
| 364 | + ]; |
|
| 365 | + return $error; |
|
| 366 | + } |
|
| 367 | + try { |
|
| 368 | + // apply necessary migrations |
|
| 369 | + $dbSetup->runMigrations(); |
|
| 370 | + } catch (Exception $e) { |
|
| 371 | + $error[] = [ |
|
| 372 | + 'error' => 'Error while trying to initialise the database: ' . $e->getMessage(), |
|
| 373 | + 'exception' => $e, |
|
| 374 | + 'hint' => '', |
|
| 375 | + ]; |
|
| 376 | + return $error; |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + //create the user and group |
|
| 380 | + $user = null; |
|
| 381 | + try { |
|
| 382 | + $user = \OC::$server->getUserManager()->createUser($username, $password); |
|
| 383 | + if (!$user) { |
|
| 384 | + $error[] = "User <$username> could not be created."; |
|
| 385 | + } |
|
| 386 | + } catch (Exception $exception) { |
|
| 387 | + $error[] = $exception->getMessage(); |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + if (empty($error)) { |
|
| 391 | + $config = \OC::$server->getConfig(); |
|
| 392 | + $config->setAppValue('core', 'installedat', microtime(true)); |
|
| 393 | + $config->setAppValue('core', 'lastupdatedat', microtime(true)); |
|
| 394 | + $config->setAppValue('core', 'vendor', $this->getVendor()); |
|
| 395 | + |
|
| 396 | + $group = \OC::$server->getGroupManager()->createGroup('admin'); |
|
| 397 | + if ($group instanceof IGroup) { |
|
| 398 | + $group->addUser($user); |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + // Install shipped apps and specified app bundles |
|
| 402 | + Installer::installShippedApps(); |
|
| 403 | + $bundleFetcher = new BundleFetcher(\OC::$server->getL10N('lib')); |
|
| 404 | + $defaultInstallationBundles = $bundleFetcher->getDefaultInstallationBundle(); |
|
| 405 | + foreach ($defaultInstallationBundles as $bundle) { |
|
| 406 | + try { |
|
| 407 | + $this->installer->installAppBundle($bundle); |
|
| 408 | + } catch (Exception $e) { |
|
| 409 | + } |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + // create empty file in data dir, so we can later find |
|
| 413 | + // out that this is indeed an ownCloud data directory |
|
| 414 | + file_put_contents($config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', ''); |
|
| 415 | + |
|
| 416 | + // Update .htaccess files |
|
| 417 | + self::updateHtaccess(); |
|
| 418 | + self::protectDataDirectory(); |
|
| 419 | + |
|
| 420 | + self::installBackgroundJobs(); |
|
| 421 | + |
|
| 422 | + //and we are done |
|
| 423 | + $config->setSystemValue('installed', true); |
|
| 424 | + |
|
| 425 | + // Create a session token for the newly created user |
|
| 426 | + // The token provider requires a working db, so it's not injected on setup |
|
| 427 | + /* @var $userSession User\Session */ |
|
| 428 | + $userSession = \OC::$server->getUserSession(); |
|
| 429 | + $defaultTokenProvider = \OC::$server->query(DefaultTokenProvider::class); |
|
| 430 | + $userSession->setTokenProvider($defaultTokenProvider); |
|
| 431 | + $userSession->login($username, $password); |
|
| 432 | + $userSession->createSessionToken($request, $userSession->getUser()->getUID(), $username, $password); |
|
| 433 | + |
|
| 434 | + $session = $userSession->getSession(); |
|
| 435 | + $session->set('last-password-confirm', \OC::$server->query(ITimeFactory::class)->getTime()); |
|
| 436 | + |
|
| 437 | + // Set email for admin |
|
| 438 | + if (!empty($options['adminemail'])) { |
|
| 439 | + $config->setUserValue($user->getUID(), 'settings', 'email', $options['adminemail']); |
|
| 440 | + } |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + return $error; |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + public static function installBackgroundJobs() { |
|
| 447 | + $jobList = \OC::$server->getJobList(); |
|
| 448 | + $jobList->add(DefaultTokenCleanupJob::class); |
|
| 449 | + $jobList->add(Rotate::class); |
|
| 450 | + $jobList->add(BackgroundCleanupJob::class); |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + /** |
|
| 454 | + * @return string Absolute path to htaccess |
|
| 455 | + */ |
|
| 456 | + private function pathToHtaccess() { |
|
| 457 | + return \OC::$SERVERROOT . '/.htaccess'; |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + /** |
|
| 461 | + * Find webroot from config |
|
| 462 | + * |
|
| 463 | + * @param SystemConfig $config |
|
| 464 | + * @return string |
|
| 465 | + * @throws InvalidArgumentException when invalid value for overwrite.cli.url |
|
| 466 | + */ |
|
| 467 | + private static function findWebRoot(SystemConfig $config): string { |
|
| 468 | + // For CLI read the value from overwrite.cli.url |
|
| 469 | + if (\OC::$CLI) { |
|
| 470 | + $webRoot = $config->getValue('overwrite.cli.url', ''); |
|
| 471 | + if ($webRoot === '') { |
|
| 472 | + throw new InvalidArgumentException('overwrite.cli.url is empty'); |
|
| 473 | + } |
|
| 474 | + if (!filter_var($webRoot, FILTER_VALIDATE_URL)) { |
|
| 475 | + throw new InvalidArgumentException('invalid value for overwrite.cli.url'); |
|
| 476 | + } |
|
| 477 | + $webRoot = rtrim(parse_url($webRoot, PHP_URL_PATH), '/'); |
|
| 478 | + } else { |
|
| 479 | + $webRoot = !empty(\OC::$WEBROOT) ? \OC::$WEBROOT : '/'; |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + return $webRoot; |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + /** |
|
| 486 | + * Append the correct ErrorDocument path for Apache hosts |
|
| 487 | + * |
|
| 488 | + * @return bool True when success, False otherwise |
|
| 489 | + * @throws \OCP\AppFramework\QueryException |
|
| 490 | + */ |
|
| 491 | + public static function updateHtaccess() { |
|
| 492 | + $config = \OC::$server->getSystemConfig(); |
|
| 493 | + |
|
| 494 | + try { |
|
| 495 | + $webRoot = self::findWebRoot($config); |
|
| 496 | + } catch (InvalidArgumentException $e) { |
|
| 497 | + return false; |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + $setupHelper = new \OC\Setup( |
|
| 501 | + $config, |
|
| 502 | + \OC::$server->get(IniGetWrapper::class), |
|
| 503 | + \OC::$server->getL10N('lib'), |
|
| 504 | + \OC::$server->query(Defaults::class), |
|
| 505 | + \OC::$server->get(LoggerInterface::class), |
|
| 506 | + \OC::$server->getSecureRandom(), |
|
| 507 | + \OC::$server->query(Installer::class) |
|
| 508 | + ); |
|
| 509 | + |
|
| 510 | + $htaccessContent = file_get_contents($setupHelper->pathToHtaccess()); |
|
| 511 | + $content = "#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####\n"; |
|
| 512 | + $htaccessContent = explode($content, $htaccessContent, 2)[0]; |
|
| 513 | + |
|
| 514 | + //custom 403 error page |
|
| 515 | + $content .= "\nErrorDocument 403 " . $webRoot . '/'; |
|
| 516 | + |
|
| 517 | + //custom 404 error page |
|
| 518 | + $content .= "\nErrorDocument 404 " . $webRoot . '/'; |
|
| 519 | + |
|
| 520 | + // Add rewrite rules if the RewriteBase is configured |
|
| 521 | + $rewriteBase = $config->getValue('htaccess.RewriteBase', ''); |
|
| 522 | + if ($rewriteBase !== '') { |
|
| 523 | + $content .= "\n<IfModule mod_rewrite.c>"; |
|
| 524 | + $content .= "\n Options -MultiViews"; |
|
| 525 | + $content .= "\n RewriteRule ^core/js/oc.js$ index.php [PT,E=PATH_INFO:$1]"; |
|
| 526 | + $content .= "\n RewriteRule ^core/preview.png$ index.php [PT,E=PATH_INFO:$1]"; |
|
| 527 | + $content .= "\n RewriteCond %{REQUEST_FILENAME} !\\.(css|js|svg|gif|png|html|ttf|woff2?|ico|jpg|jpeg|map|webm|mp4|mp3|ogg|wav)$"; |
|
| 528 | + $content .= "\n RewriteCond %{REQUEST_FILENAME} !core/img/favicon.ico$"; |
|
| 529 | + $content .= "\n RewriteCond %{REQUEST_FILENAME} !core/img/manifest.json$"; |
|
| 530 | + $content .= "\n RewriteCond %{REQUEST_FILENAME} !/remote.php"; |
|
| 531 | + $content .= "\n RewriteCond %{REQUEST_FILENAME} !/public.php"; |
|
| 532 | + $content .= "\n RewriteCond %{REQUEST_FILENAME} !/cron.php"; |
|
| 533 | + $content .= "\n RewriteCond %{REQUEST_FILENAME} !/core/ajax/update.php"; |
|
| 534 | + $content .= "\n RewriteCond %{REQUEST_FILENAME} !/status.php"; |
|
| 535 | + $content .= "\n RewriteCond %{REQUEST_FILENAME} !/ocs/v1.php"; |
|
| 536 | + $content .= "\n RewriteCond %{REQUEST_FILENAME} !/ocs/v2.php"; |
|
| 537 | + $content .= "\n RewriteCond %{REQUEST_FILENAME} !/robots.txt"; |
|
| 538 | + $content .= "\n RewriteCond %{REQUEST_FILENAME} !/updater/"; |
|
| 539 | + $content .= "\n RewriteCond %{REQUEST_FILENAME} !/ocs-provider/"; |
|
| 540 | + $content .= "\n RewriteCond %{REQUEST_FILENAME} !/ocm-provider/"; |
|
| 541 | + $content .= "\n RewriteCond %{REQUEST_URI} !^/\\.well-known/(acme-challenge|pki-validation)/.*"; |
|
| 542 | + $content .= "\n RewriteCond %{REQUEST_FILENAME} !/richdocumentscode(_arm64)?/proxy.php$"; |
|
| 543 | + $content .= "\n RewriteRule . index.php [PT,E=PATH_INFO:$1]"; |
|
| 544 | + $content .= "\n RewriteBase " . $rewriteBase; |
|
| 545 | + $content .= "\n <IfModule mod_env.c>"; |
|
| 546 | + $content .= "\n SetEnv front_controller_active true"; |
|
| 547 | + $content .= "\n <IfModule mod_dir.c>"; |
|
| 548 | + $content .= "\n DirectorySlash off"; |
|
| 549 | + $content .= "\n </IfModule>"; |
|
| 550 | + $content .= "\n </IfModule>"; |
|
| 551 | + $content .= "\n</IfModule>"; |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + if ($content !== '') { |
|
| 555 | + //suppress errors in case we don't have permissions for it |
|
| 556 | + return (bool)@file_put_contents($setupHelper->pathToHtaccess(), $htaccessContent . $content . "\n"); |
|
| 557 | + } |
|
| 558 | + |
|
| 559 | + return false; |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + public static function protectDataDirectory() { |
|
| 563 | + //Require all denied |
|
| 564 | + $now = date('Y-m-d H:i:s'); |
|
| 565 | + $content = "# Generated by Nextcloud on $now\n"; |
|
| 566 | + $content .= "# Section for Apache 2.4 to 2.6\n"; |
|
| 567 | + $content .= "<IfModule mod_authz_core.c>\n"; |
|
| 568 | + $content .= " Require all denied\n"; |
|
| 569 | + $content .= "</IfModule>\n"; |
|
| 570 | + $content .= "<IfModule mod_access_compat.c>\n"; |
|
| 571 | + $content .= " Order Allow,Deny\n"; |
|
| 572 | + $content .= " Deny from all\n"; |
|
| 573 | + $content .= " Satisfy All\n"; |
|
| 574 | + $content .= "</IfModule>\n\n"; |
|
| 575 | + $content .= "# Section for Apache 2.2\n"; |
|
| 576 | + $content .= "<IfModule !mod_authz_core.c>\n"; |
|
| 577 | + $content .= " <IfModule !mod_access_compat.c>\n"; |
|
| 578 | + $content .= " <IfModule mod_authz_host.c>\n"; |
|
| 579 | + $content .= " Order Allow,Deny\n"; |
|
| 580 | + $content .= " Deny from all\n"; |
|
| 581 | + $content .= " </IfModule>\n"; |
|
| 582 | + $content .= " Satisfy All\n"; |
|
| 583 | + $content .= " </IfModule>\n"; |
|
| 584 | + $content .= "</IfModule>\n\n"; |
|
| 585 | + $content .= "# Section for Apache 2.2 to 2.6\n"; |
|
| 586 | + $content .= "<IfModule mod_autoindex.c>\n"; |
|
| 587 | + $content .= " IndexIgnore *\n"; |
|
| 588 | + $content .= "</IfModule>"; |
|
| 589 | + |
|
| 590 | + $baseDir = \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data'); |
|
| 591 | + file_put_contents($baseDir . '/.htaccess', $content); |
|
| 592 | + file_put_contents($baseDir . '/index.html', ''); |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + /** |
|
| 596 | + * Return vendor from which this version was published |
|
| 597 | + * |
|
| 598 | + * @return string Get the vendor |
|
| 599 | + * |
|
| 600 | + * Copy of \OC\Updater::getVendor() |
|
| 601 | + */ |
|
| 602 | + private function getVendor() { |
|
| 603 | + // this should really be a JSON file |
|
| 604 | + require \OC::$SERVERROOT . '/version.php'; |
|
| 605 | + /** @var string $vendor */ |
|
| 606 | + return (string)$vendor; |
|
| 607 | + } |
|
| 608 | 608 | } |
@@ -39,118 +39,118 @@ |
||
| 39 | 39 | |
| 40 | 40 | abstract class AbstractDatabase { |
| 41 | 41 | |
| 42 | - /** @var IL10N */ |
|
| 43 | - protected $trans; |
|
| 44 | - /** @var string */ |
|
| 45 | - protected $dbUser; |
|
| 46 | - /** @var string */ |
|
| 47 | - protected $dbPassword; |
|
| 48 | - /** @var string */ |
|
| 49 | - protected $dbName; |
|
| 50 | - /** @var string */ |
|
| 51 | - protected $dbHost; |
|
| 52 | - /** @var string */ |
|
| 53 | - protected $dbPort; |
|
| 54 | - /** @var string */ |
|
| 55 | - protected $tablePrefix; |
|
| 56 | - /** @var SystemConfig */ |
|
| 57 | - protected $config; |
|
| 58 | - /** @var LoggerInterface */ |
|
| 59 | - protected $logger; |
|
| 60 | - /** @var ISecureRandom */ |
|
| 61 | - protected $random; |
|
| 42 | + /** @var IL10N */ |
|
| 43 | + protected $trans; |
|
| 44 | + /** @var string */ |
|
| 45 | + protected $dbUser; |
|
| 46 | + /** @var string */ |
|
| 47 | + protected $dbPassword; |
|
| 48 | + /** @var string */ |
|
| 49 | + protected $dbName; |
|
| 50 | + /** @var string */ |
|
| 51 | + protected $dbHost; |
|
| 52 | + /** @var string */ |
|
| 53 | + protected $dbPort; |
|
| 54 | + /** @var string */ |
|
| 55 | + protected $tablePrefix; |
|
| 56 | + /** @var SystemConfig */ |
|
| 57 | + protected $config; |
|
| 58 | + /** @var LoggerInterface */ |
|
| 59 | + protected $logger; |
|
| 60 | + /** @var ISecureRandom */ |
|
| 61 | + protected $random; |
|
| 62 | 62 | |
| 63 | - public function __construct(IL10N $trans, SystemConfig $config, LoggerInterface $logger, ISecureRandom $random) { |
|
| 64 | - $this->trans = $trans; |
|
| 65 | - $this->config = $config; |
|
| 66 | - $this->logger = $logger; |
|
| 67 | - $this->random = $random; |
|
| 68 | - } |
|
| 63 | + public function __construct(IL10N $trans, SystemConfig $config, LoggerInterface $logger, ISecureRandom $random) { |
|
| 64 | + $this->trans = $trans; |
|
| 65 | + $this->config = $config; |
|
| 66 | + $this->logger = $logger; |
|
| 67 | + $this->random = $random; |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - public function validate($config) { |
|
| 71 | - $errors = []; |
|
| 72 | - if (empty($config['dbuser']) && empty($config['dbname'])) { |
|
| 73 | - $errors[] = $this->trans->t("%s enter the database username and name.", [$this->dbprettyname]); |
|
| 74 | - } elseif (empty($config['dbuser'])) { |
|
| 75 | - $errors[] = $this->trans->t("%s enter the database username.", [$this->dbprettyname]); |
|
| 76 | - } elseif (empty($config['dbname'])) { |
|
| 77 | - $errors[] = $this->trans->t("%s enter the database name.", [$this->dbprettyname]); |
|
| 78 | - } |
|
| 79 | - if (substr_count($config['dbname'], '.') >= 1) { |
|
| 80 | - $errors[] = $this->trans->t("%s you may not use dots in the database name", [$this->dbprettyname]); |
|
| 81 | - } |
|
| 82 | - return $errors; |
|
| 83 | - } |
|
| 70 | + public function validate($config) { |
|
| 71 | + $errors = []; |
|
| 72 | + if (empty($config['dbuser']) && empty($config['dbname'])) { |
|
| 73 | + $errors[] = $this->trans->t("%s enter the database username and name.", [$this->dbprettyname]); |
|
| 74 | + } elseif (empty($config['dbuser'])) { |
|
| 75 | + $errors[] = $this->trans->t("%s enter the database username.", [$this->dbprettyname]); |
|
| 76 | + } elseif (empty($config['dbname'])) { |
|
| 77 | + $errors[] = $this->trans->t("%s enter the database name.", [$this->dbprettyname]); |
|
| 78 | + } |
|
| 79 | + if (substr_count($config['dbname'], '.') >= 1) { |
|
| 80 | + $errors[] = $this->trans->t("%s you may not use dots in the database name", [$this->dbprettyname]); |
|
| 81 | + } |
|
| 82 | + return $errors; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - public function initialize($config) { |
|
| 86 | - $dbUser = $config['dbuser']; |
|
| 87 | - $dbPass = $config['dbpass']; |
|
| 88 | - $dbName = $config['dbname']; |
|
| 89 | - $dbHost = !empty($config['dbhost']) ? $config['dbhost'] : 'localhost'; |
|
| 90 | - $dbPort = !empty($config['dbport']) ? $config['dbport'] : ''; |
|
| 91 | - $dbTablePrefix = isset($config['dbtableprefix']) ? $config['dbtableprefix'] : 'oc_'; |
|
| 85 | + public function initialize($config) { |
|
| 86 | + $dbUser = $config['dbuser']; |
|
| 87 | + $dbPass = $config['dbpass']; |
|
| 88 | + $dbName = $config['dbname']; |
|
| 89 | + $dbHost = !empty($config['dbhost']) ? $config['dbhost'] : 'localhost'; |
|
| 90 | + $dbPort = !empty($config['dbport']) ? $config['dbport'] : ''; |
|
| 91 | + $dbTablePrefix = isset($config['dbtableprefix']) ? $config['dbtableprefix'] : 'oc_'; |
|
| 92 | 92 | |
| 93 | - $this->config->setValues([ |
|
| 94 | - 'dbname' => $dbName, |
|
| 95 | - 'dbhost' => $dbHost, |
|
| 96 | - 'dbport' => $dbPort, |
|
| 97 | - 'dbtableprefix' => $dbTablePrefix, |
|
| 98 | - ]); |
|
| 93 | + $this->config->setValues([ |
|
| 94 | + 'dbname' => $dbName, |
|
| 95 | + 'dbhost' => $dbHost, |
|
| 96 | + 'dbport' => $dbPort, |
|
| 97 | + 'dbtableprefix' => $dbTablePrefix, |
|
| 98 | + ]); |
|
| 99 | 99 | |
| 100 | - $this->dbUser = $dbUser; |
|
| 101 | - $this->dbPassword = $dbPass; |
|
| 102 | - $this->dbName = $dbName; |
|
| 103 | - $this->dbHost = $dbHost; |
|
| 104 | - $this->dbPort = $dbPort; |
|
| 105 | - $this->tablePrefix = $dbTablePrefix; |
|
| 106 | - } |
|
| 100 | + $this->dbUser = $dbUser; |
|
| 101 | + $this->dbPassword = $dbPass; |
|
| 102 | + $this->dbName = $dbName; |
|
| 103 | + $this->dbHost = $dbHost; |
|
| 104 | + $this->dbPort = $dbPort; |
|
| 105 | + $this->tablePrefix = $dbTablePrefix; |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * @param array $configOverwrite |
|
| 110 | - * @return \OC\DB\Connection |
|
| 111 | - */ |
|
| 112 | - protected function connect(array $configOverwrite = []): Connection { |
|
| 113 | - $connectionParams = [ |
|
| 114 | - 'host' => $this->dbHost, |
|
| 115 | - 'user' => $this->dbUser, |
|
| 116 | - 'password' => $this->dbPassword, |
|
| 117 | - 'tablePrefix' => $this->tablePrefix, |
|
| 118 | - 'dbname' => $this->dbName |
|
| 119 | - ]; |
|
| 108 | + /** |
|
| 109 | + * @param array $configOverwrite |
|
| 110 | + * @return \OC\DB\Connection |
|
| 111 | + */ |
|
| 112 | + protected function connect(array $configOverwrite = []): Connection { |
|
| 113 | + $connectionParams = [ |
|
| 114 | + 'host' => $this->dbHost, |
|
| 115 | + 'user' => $this->dbUser, |
|
| 116 | + 'password' => $this->dbPassword, |
|
| 117 | + 'tablePrefix' => $this->tablePrefix, |
|
| 118 | + 'dbname' => $this->dbName |
|
| 119 | + ]; |
|
| 120 | 120 | |
| 121 | - // adding port support through installer |
|
| 122 | - if (!empty($this->dbPort)) { |
|
| 123 | - if (ctype_digit($this->dbPort)) { |
|
| 124 | - $connectionParams['port'] = $this->dbPort; |
|
| 125 | - } else { |
|
| 126 | - $connectionParams['unix_socket'] = $this->dbPort; |
|
| 127 | - } |
|
| 128 | - } elseif (strpos($this->dbHost, ':')) { |
|
| 129 | - // Host variable may carry a port or socket. |
|
| 130 | - [$host, $portOrSocket] = explode(':', $this->dbHost, 2); |
|
| 131 | - if (ctype_digit($portOrSocket)) { |
|
| 132 | - $connectionParams['port'] = $portOrSocket; |
|
| 133 | - } else { |
|
| 134 | - $connectionParams['unix_socket'] = $portOrSocket; |
|
| 135 | - } |
|
| 136 | - $connectionParams['host'] = $host; |
|
| 137 | - } |
|
| 121 | + // adding port support through installer |
|
| 122 | + if (!empty($this->dbPort)) { |
|
| 123 | + if (ctype_digit($this->dbPort)) { |
|
| 124 | + $connectionParams['port'] = $this->dbPort; |
|
| 125 | + } else { |
|
| 126 | + $connectionParams['unix_socket'] = $this->dbPort; |
|
| 127 | + } |
|
| 128 | + } elseif (strpos($this->dbHost, ':')) { |
|
| 129 | + // Host variable may carry a port or socket. |
|
| 130 | + [$host, $portOrSocket] = explode(':', $this->dbHost, 2); |
|
| 131 | + if (ctype_digit($portOrSocket)) { |
|
| 132 | + $connectionParams['port'] = $portOrSocket; |
|
| 133 | + } else { |
|
| 134 | + $connectionParams['unix_socket'] = $portOrSocket; |
|
| 135 | + } |
|
| 136 | + $connectionParams['host'] = $host; |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - $connectionParams = array_merge($connectionParams, $configOverwrite); |
|
| 140 | - $cf = new ConnectionFactory($this->config); |
|
| 141 | - return $cf->getConnection($this->config->getValue('dbtype', 'sqlite'), $connectionParams); |
|
| 142 | - } |
|
| 139 | + $connectionParams = array_merge($connectionParams, $configOverwrite); |
|
| 140 | + $cf = new ConnectionFactory($this->config); |
|
| 141 | + return $cf->getConnection($this->config->getValue('dbtype', 'sqlite'), $connectionParams); |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * @param string $userName |
|
| 146 | - */ |
|
| 147 | - abstract public function setupDatabase($userName); |
|
| 144 | + /** |
|
| 145 | + * @param string $userName |
|
| 146 | + */ |
|
| 147 | + abstract public function setupDatabase($userName); |
|
| 148 | 148 | |
| 149 | - public function runMigrations() { |
|
| 150 | - if (!is_dir(\OC::$SERVERROOT."/core/Migrations")) { |
|
| 151 | - return; |
|
| 152 | - } |
|
| 153 | - $ms = new MigrationService('core', \OC::$server->get(Connection::class)); |
|
| 154 | - $ms->migrate('latest', true); |
|
| 155 | - } |
|
| 149 | + public function runMigrations() { |
|
| 150 | + if (!is_dir(\OC::$SERVERROOT."/core/Migrations")) { |
|
| 151 | + return; |
|
| 152 | + } |
|
| 153 | + $ms = new MigrationService('core', \OC::$server->get(Connection::class)); |
|
| 154 | + $ms->migrate('latest', true); |
|
| 155 | + } |
|
| 156 | 156 | } |
@@ -34,141 +34,141 @@ |
||
| 34 | 34 | use OC\DB\QueryBuilder\Literal; |
| 35 | 35 | |
| 36 | 36 | class PostgreSQL extends AbstractDatabase { |
| 37 | - public $dbprettyname = 'PostgreSQL'; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @param string $username |
|
| 41 | - * @throws \OC\DatabaseSetupException |
|
| 42 | - */ |
|
| 43 | - public function setupDatabase($username) { |
|
| 44 | - try { |
|
| 45 | - $connection = $this->connect([ |
|
| 46 | - 'dbname' => 'postgres' |
|
| 47 | - ]); |
|
| 48 | - //check for roles creation rights in postgresql |
|
| 49 | - $builder = $connection->getQueryBuilder(); |
|
| 50 | - $builder->automaticTablePrefix(false); |
|
| 51 | - $query = $builder |
|
| 52 | - ->select('rolname') |
|
| 53 | - ->from('pg_roles') |
|
| 54 | - ->where($builder->expr()->eq('rolcreaterole', new Literal('TRUE'))) |
|
| 55 | - ->andWhere($builder->expr()->eq('rolname', $builder->createNamedParameter($this->dbUser))); |
|
| 56 | - |
|
| 57 | - try { |
|
| 58 | - $result = $query->execute(); |
|
| 59 | - $canCreateRoles = $result->rowCount() > 0; |
|
| 60 | - } catch (DatabaseException $e) { |
|
| 61 | - $canCreateRoles = false; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - if ($canCreateRoles) { |
|
| 65 | - //use the admin login data for the new database user |
|
| 66 | - |
|
| 67 | - //add prefix to the postgresql user name to prevent collisions |
|
| 68 | - $this->dbUser = 'oc_' . strtolower($username); |
|
| 69 | - //create a new password so we don't need to store the admin config in the config file |
|
| 70 | - $this->dbPassword = \OC::$server->getSecureRandom()->generate(30, \OCP\Security\ISecureRandom::CHAR_LOWER . \OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
| 71 | - |
|
| 72 | - $this->createDBUser($connection); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - $this->config->setValues([ |
|
| 76 | - 'dbuser' => $this->dbUser, |
|
| 77 | - 'dbpassword' => $this->dbPassword, |
|
| 78 | - ]); |
|
| 79 | - |
|
| 80 | - //create the database |
|
| 81 | - $this->createDatabase($connection); |
|
| 82 | - // the connection to dbname=postgres is not needed anymore |
|
| 83 | - $connection->close(); |
|
| 84 | - } catch (\Exception $e) { |
|
| 85 | - $this->logger->warning('Error trying to connect as "postgres", assuming database is setup and tables need to be created', [ |
|
| 86 | - 'exception' => $e, |
|
| 87 | - ]); |
|
| 88 | - $this->config->setValues([ |
|
| 89 | - 'dbuser' => $this->dbUser, |
|
| 90 | - 'dbpassword' => $this->dbPassword, |
|
| 91 | - ]); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - // connect to the database (dbname=$this->dbname) and check if it needs to be filled |
|
| 95 | - $this->dbUser = $this->config->getValue('dbuser'); |
|
| 96 | - $this->dbPassword = $this->config->getValue('dbpassword'); |
|
| 97 | - $connection = $this->connect(); |
|
| 98 | - try { |
|
| 99 | - $connection->connect(); |
|
| 100 | - } catch (\Exception $e) { |
|
| 101 | - $this->logger->error($e->getMessage(), [ |
|
| 102 | - 'exception' => $e, |
|
| 103 | - ]); |
|
| 104 | - throw new \OC\DatabaseSetupException($this->trans->t('PostgreSQL username and/or password not valid'), |
|
| 105 | - $this->trans->t('You need to enter details of an existing account.'), 0, $e); |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - private function createDatabase(Connection $connection) { |
|
| 110 | - if (!$this->databaseExists($connection)) { |
|
| 111 | - //The database does not exists... let's create it |
|
| 112 | - $query = $connection->prepare("CREATE DATABASE " . addslashes($this->dbName) . " OWNER " . addslashes($this->dbUser)); |
|
| 113 | - try { |
|
| 114 | - $query->execute(); |
|
| 115 | - } catch (DatabaseException $e) { |
|
| 116 | - $this->logger->error('Error while trying to create database', [ |
|
| 117 | - 'exception' => $e, |
|
| 118 | - ]); |
|
| 119 | - } |
|
| 120 | - } else { |
|
| 121 | - $query = $connection->prepare("REVOKE ALL PRIVILEGES ON DATABASE " . addslashes($this->dbName) . " FROM PUBLIC"); |
|
| 122 | - try { |
|
| 123 | - $query->execute(); |
|
| 124 | - } catch (DatabaseException $e) { |
|
| 125 | - $this->logger->error('Error while trying to restrict database permissions', [ |
|
| 126 | - 'exception' => $e, |
|
| 127 | - ]); |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - private function userExists(Connection $connection) { |
|
| 133 | - $builder = $connection->getQueryBuilder(); |
|
| 134 | - $builder->automaticTablePrefix(false); |
|
| 135 | - $query = $builder->select('*') |
|
| 136 | - ->from('pg_roles') |
|
| 137 | - ->where($builder->expr()->eq('rolname', $builder->createNamedParameter($this->dbUser))); |
|
| 138 | - $result = $query->execute(); |
|
| 139 | - return $result->rowCount() > 0; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - private function databaseExists(Connection $connection) { |
|
| 143 | - $builder = $connection->getQueryBuilder(); |
|
| 144 | - $builder->automaticTablePrefix(false); |
|
| 145 | - $query = $builder->select('datname') |
|
| 146 | - ->from('pg_database') |
|
| 147 | - ->where($builder->expr()->eq('datname', $builder->createNamedParameter($this->dbName))); |
|
| 148 | - $result = $query->execute(); |
|
| 149 | - return $result->rowCount() > 0; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - private function createDBUser(Connection $connection) { |
|
| 153 | - $dbUser = $this->dbUser; |
|
| 154 | - try { |
|
| 155 | - $i = 1; |
|
| 156 | - while ($this->userExists($connection)) { |
|
| 157 | - $i++; |
|
| 158 | - $this->dbUser = $dbUser . $i; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - // create the user |
|
| 162 | - $query = $connection->prepare("CREATE USER " . addslashes($this->dbUser) . " CREATEDB PASSWORD '" . addslashes($this->dbPassword) . "'"); |
|
| 163 | - $query->execute(); |
|
| 164 | - if ($this->databaseExists($connection)) { |
|
| 165 | - $query = $connection->prepare('GRANT CONNECT ON DATABASE ' . addslashes($this->dbName) . ' TO '.addslashes($this->dbUser)); |
|
| 166 | - $query->execute(); |
|
| 167 | - } |
|
| 168 | - } catch (DatabaseException $e) { |
|
| 169 | - $this->logger->error('Error while trying to create database user', [ |
|
| 170 | - 'exception' => $e, |
|
| 171 | - ]); |
|
| 172 | - } |
|
| 173 | - } |
|
| 37 | + public $dbprettyname = 'PostgreSQL'; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @param string $username |
|
| 41 | + * @throws \OC\DatabaseSetupException |
|
| 42 | + */ |
|
| 43 | + public function setupDatabase($username) { |
|
| 44 | + try { |
|
| 45 | + $connection = $this->connect([ |
|
| 46 | + 'dbname' => 'postgres' |
|
| 47 | + ]); |
|
| 48 | + //check for roles creation rights in postgresql |
|
| 49 | + $builder = $connection->getQueryBuilder(); |
|
| 50 | + $builder->automaticTablePrefix(false); |
|
| 51 | + $query = $builder |
|
| 52 | + ->select('rolname') |
|
| 53 | + ->from('pg_roles') |
|
| 54 | + ->where($builder->expr()->eq('rolcreaterole', new Literal('TRUE'))) |
|
| 55 | + ->andWhere($builder->expr()->eq('rolname', $builder->createNamedParameter($this->dbUser))); |
|
| 56 | + |
|
| 57 | + try { |
|
| 58 | + $result = $query->execute(); |
|
| 59 | + $canCreateRoles = $result->rowCount() > 0; |
|
| 60 | + } catch (DatabaseException $e) { |
|
| 61 | + $canCreateRoles = false; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + if ($canCreateRoles) { |
|
| 65 | + //use the admin login data for the new database user |
|
| 66 | + |
|
| 67 | + //add prefix to the postgresql user name to prevent collisions |
|
| 68 | + $this->dbUser = 'oc_' . strtolower($username); |
|
| 69 | + //create a new password so we don't need to store the admin config in the config file |
|
| 70 | + $this->dbPassword = \OC::$server->getSecureRandom()->generate(30, \OCP\Security\ISecureRandom::CHAR_LOWER . \OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
| 71 | + |
|
| 72 | + $this->createDBUser($connection); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + $this->config->setValues([ |
|
| 76 | + 'dbuser' => $this->dbUser, |
|
| 77 | + 'dbpassword' => $this->dbPassword, |
|
| 78 | + ]); |
|
| 79 | + |
|
| 80 | + //create the database |
|
| 81 | + $this->createDatabase($connection); |
|
| 82 | + // the connection to dbname=postgres is not needed anymore |
|
| 83 | + $connection->close(); |
|
| 84 | + } catch (\Exception $e) { |
|
| 85 | + $this->logger->warning('Error trying to connect as "postgres", assuming database is setup and tables need to be created', [ |
|
| 86 | + 'exception' => $e, |
|
| 87 | + ]); |
|
| 88 | + $this->config->setValues([ |
|
| 89 | + 'dbuser' => $this->dbUser, |
|
| 90 | + 'dbpassword' => $this->dbPassword, |
|
| 91 | + ]); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + // connect to the database (dbname=$this->dbname) and check if it needs to be filled |
|
| 95 | + $this->dbUser = $this->config->getValue('dbuser'); |
|
| 96 | + $this->dbPassword = $this->config->getValue('dbpassword'); |
|
| 97 | + $connection = $this->connect(); |
|
| 98 | + try { |
|
| 99 | + $connection->connect(); |
|
| 100 | + } catch (\Exception $e) { |
|
| 101 | + $this->logger->error($e->getMessage(), [ |
|
| 102 | + 'exception' => $e, |
|
| 103 | + ]); |
|
| 104 | + throw new \OC\DatabaseSetupException($this->trans->t('PostgreSQL username and/or password not valid'), |
|
| 105 | + $this->trans->t('You need to enter details of an existing account.'), 0, $e); |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + private function createDatabase(Connection $connection) { |
|
| 110 | + if (!$this->databaseExists($connection)) { |
|
| 111 | + //The database does not exists... let's create it |
|
| 112 | + $query = $connection->prepare("CREATE DATABASE " . addslashes($this->dbName) . " OWNER " . addslashes($this->dbUser)); |
|
| 113 | + try { |
|
| 114 | + $query->execute(); |
|
| 115 | + } catch (DatabaseException $e) { |
|
| 116 | + $this->logger->error('Error while trying to create database', [ |
|
| 117 | + 'exception' => $e, |
|
| 118 | + ]); |
|
| 119 | + } |
|
| 120 | + } else { |
|
| 121 | + $query = $connection->prepare("REVOKE ALL PRIVILEGES ON DATABASE " . addslashes($this->dbName) . " FROM PUBLIC"); |
|
| 122 | + try { |
|
| 123 | + $query->execute(); |
|
| 124 | + } catch (DatabaseException $e) { |
|
| 125 | + $this->logger->error('Error while trying to restrict database permissions', [ |
|
| 126 | + 'exception' => $e, |
|
| 127 | + ]); |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + private function userExists(Connection $connection) { |
|
| 133 | + $builder = $connection->getQueryBuilder(); |
|
| 134 | + $builder->automaticTablePrefix(false); |
|
| 135 | + $query = $builder->select('*') |
|
| 136 | + ->from('pg_roles') |
|
| 137 | + ->where($builder->expr()->eq('rolname', $builder->createNamedParameter($this->dbUser))); |
|
| 138 | + $result = $query->execute(); |
|
| 139 | + return $result->rowCount() > 0; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + private function databaseExists(Connection $connection) { |
|
| 143 | + $builder = $connection->getQueryBuilder(); |
|
| 144 | + $builder->automaticTablePrefix(false); |
|
| 145 | + $query = $builder->select('datname') |
|
| 146 | + ->from('pg_database') |
|
| 147 | + ->where($builder->expr()->eq('datname', $builder->createNamedParameter($this->dbName))); |
|
| 148 | + $result = $query->execute(); |
|
| 149 | + return $result->rowCount() > 0; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + private function createDBUser(Connection $connection) { |
|
| 153 | + $dbUser = $this->dbUser; |
|
| 154 | + try { |
|
| 155 | + $i = 1; |
|
| 156 | + while ($this->userExists($connection)) { |
|
| 157 | + $i++; |
|
| 158 | + $this->dbUser = $dbUser . $i; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + // create the user |
|
| 162 | + $query = $connection->prepare("CREATE USER " . addslashes($this->dbUser) . " CREATEDB PASSWORD '" . addslashes($this->dbPassword) . "'"); |
|
| 163 | + $query->execute(); |
|
| 164 | + if ($this->databaseExists($connection)) { |
|
| 165 | + $query = $connection->prepare('GRANT CONNECT ON DATABASE ' . addslashes($this->dbName) . ' TO '.addslashes($this->dbUser)); |
|
| 166 | + $query->execute(); |
|
| 167 | + } |
|
| 168 | + } catch (DatabaseException $e) { |
|
| 169 | + $this->logger->error('Error while trying to create database user', [ |
|
| 170 | + 'exception' => $e, |
|
| 171 | + ]); |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | 174 | } |
@@ -65,9 +65,9 @@ discard block |
||
| 65 | 65 | //use the admin login data for the new database user |
| 66 | 66 | |
| 67 | 67 | //add prefix to the postgresql user name to prevent collisions |
| 68 | - $this->dbUser = 'oc_' . strtolower($username); |
|
| 68 | + $this->dbUser = 'oc_'.strtolower($username); |
|
| 69 | 69 | //create a new password so we don't need to store the admin config in the config file |
| 70 | - $this->dbPassword = \OC::$server->getSecureRandom()->generate(30, \OCP\Security\ISecureRandom::CHAR_LOWER . \OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
| 70 | + $this->dbPassword = \OC::$server->getSecureRandom()->generate(30, \OCP\Security\ISecureRandom::CHAR_LOWER.\OCP\Security\ISecureRandom::CHAR_DIGITS); |
|
| 71 | 71 | |
| 72 | 72 | $this->createDBUser($connection); |
| 73 | 73 | } |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | private function createDatabase(Connection $connection) { |
| 110 | 110 | if (!$this->databaseExists($connection)) { |
| 111 | 111 | //The database does not exists... let's create it |
| 112 | - $query = $connection->prepare("CREATE DATABASE " . addslashes($this->dbName) . " OWNER " . addslashes($this->dbUser)); |
|
| 112 | + $query = $connection->prepare("CREATE DATABASE ".addslashes($this->dbName)." OWNER ".addslashes($this->dbUser)); |
|
| 113 | 113 | try { |
| 114 | 114 | $query->execute(); |
| 115 | 115 | } catch (DatabaseException $e) { |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | ]); |
| 119 | 119 | } |
| 120 | 120 | } else { |
| 121 | - $query = $connection->prepare("REVOKE ALL PRIVILEGES ON DATABASE " . addslashes($this->dbName) . " FROM PUBLIC"); |
|
| 121 | + $query = $connection->prepare("REVOKE ALL PRIVILEGES ON DATABASE ".addslashes($this->dbName)." FROM PUBLIC"); |
|
| 122 | 122 | try { |
| 123 | 123 | $query->execute(); |
| 124 | 124 | } catch (DatabaseException $e) { |
@@ -155,14 +155,14 @@ discard block |
||
| 155 | 155 | $i = 1; |
| 156 | 156 | while ($this->userExists($connection)) { |
| 157 | 157 | $i++; |
| 158 | - $this->dbUser = $dbUser . $i; |
|
| 158 | + $this->dbUser = $dbUser.$i; |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | // create the user |
| 162 | - $query = $connection->prepare("CREATE USER " . addslashes($this->dbUser) . " CREATEDB PASSWORD '" . addslashes($this->dbPassword) . "'"); |
|
| 162 | + $query = $connection->prepare("CREATE USER ".addslashes($this->dbUser)." CREATEDB PASSWORD '".addslashes($this->dbPassword)."'"); |
|
| 163 | 163 | $query->execute(); |
| 164 | 164 | if ($this->databaseExists($connection)) { |
| 165 | - $query = $connection->prepare('GRANT CONNECT ON DATABASE ' . addslashes($this->dbName) . ' TO '.addslashes($this->dbUser)); |
|
| 165 | + $query = $connection->prepare('GRANT CONNECT ON DATABASE '.addslashes($this->dbName).' TO '.addslashes($this->dbUser)); |
|
| 166 | 166 | $query->execute(); |
| 167 | 167 | } |
| 168 | 168 | } catch (DatabaseException $e) { |