| Total Complexity | 137 |
| Total Lines | 803 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like CheckSetupController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use CheckSetupController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 91 | class CheckSetupController extends Controller { |
||
| 92 | /** @var IConfig */ |
||
| 93 | private $config; |
||
| 94 | /** @var IClientService */ |
||
| 95 | private $clientService; |
||
| 96 | /** @var IURLGenerator */ |
||
| 97 | private $urlGenerator; |
||
| 98 | /** @var IL10N */ |
||
| 99 | private $l10n; |
||
| 100 | /** @var Checker */ |
||
| 101 | private $checker; |
||
| 102 | /** @var LoggerInterface */ |
||
| 103 | private $logger; |
||
| 104 | /** @var EventDispatcherInterface */ |
||
| 105 | private $dispatcher; |
||
| 106 | /** @var Connection */ |
||
| 107 | private $db; |
||
| 108 | /** @var ILockingProvider */ |
||
| 109 | private $lockingProvider; |
||
| 110 | /** @var IDateTimeFormatter */ |
||
| 111 | private $dateTimeFormatter; |
||
| 112 | /** @var MemoryInfo */ |
||
| 113 | private $memoryInfo; |
||
| 114 | /** @var ISecureRandom */ |
||
| 115 | private $secureRandom; |
||
| 116 | /** @var IniGetWrapper */ |
||
| 117 | private $iniGetWrapper; |
||
| 118 | /** @var IDBConnection */ |
||
| 119 | private $connection; |
||
| 120 | /** @var ITempManager */ |
||
| 121 | private $tempManager; |
||
| 122 | /** @var IManager */ |
||
| 123 | private $manager; |
||
| 124 | /** @var IAppManager */ |
||
| 125 | private $appManager; |
||
| 126 | /** @var IServerContainer */ |
||
| 127 | private $serverContainer; |
||
| 128 | |||
| 129 | public function __construct($AppName, |
||
| 130 | IRequest $request, |
||
| 131 | IConfig $config, |
||
| 132 | IClientService $clientService, |
||
| 133 | IURLGenerator $urlGenerator, |
||
| 134 | IL10N $l10n, |
||
| 135 | Checker $checker, |
||
| 136 | LoggerInterface $logger, |
||
| 137 | EventDispatcherInterface $dispatcher, |
||
| 138 | Connection $db, |
||
| 139 | ILockingProvider $lockingProvider, |
||
| 140 | IDateTimeFormatter $dateTimeFormatter, |
||
| 141 | MemoryInfo $memoryInfo, |
||
| 142 | ISecureRandom $secureRandom, |
||
| 143 | IniGetWrapper $iniGetWrapper, |
||
| 144 | IDBConnection $connection, |
||
| 145 | ITempManager $tempManager, |
||
| 146 | IManager $manager, |
||
| 147 | IAppManager $appManager, |
||
| 148 | IServerContainer $serverContainer |
||
| 149 | ) { |
||
| 150 | parent::__construct($AppName, $request); |
||
| 151 | $this->config = $config; |
||
| 152 | $this->clientService = $clientService; |
||
| 153 | $this->urlGenerator = $urlGenerator; |
||
| 154 | $this->l10n = $l10n; |
||
| 155 | $this->checker = $checker; |
||
| 156 | $this->logger = $logger; |
||
| 157 | $this->dispatcher = $dispatcher; |
||
| 158 | $this->db = $db; |
||
| 159 | $this->lockingProvider = $lockingProvider; |
||
| 160 | $this->dateTimeFormatter = $dateTimeFormatter; |
||
| 161 | $this->memoryInfo = $memoryInfo; |
||
| 162 | $this->secureRandom = $secureRandom; |
||
| 163 | $this->iniGetWrapper = $iniGetWrapper; |
||
| 164 | $this->connection = $connection; |
||
| 165 | $this->tempManager = $tempManager; |
||
| 166 | $this->manager = $manager; |
||
| 167 | $this->appManager = $appManager; |
||
| 168 | $this->serverContainer = $serverContainer; |
||
| 169 | } |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Check if is fair use of free push service |
||
| 173 | * @return bool |
||
| 174 | */ |
||
| 175 | private function isFairUseOfFreePushService(): bool { |
||
| 177 | } |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Checks if the server can connect to the internet using HTTPS and HTTP |
||
| 181 | * @return bool |
||
| 182 | */ |
||
| 183 | private function hasInternetConnectivityProblems(): bool { |
||
| 198 | } |
||
| 199 | |||
| 200 | /** |
||
| 201 | * Checks if the Nextcloud server can connect to a specific URL |
||
| 202 | * @param string $site site domain or full URL with http/https protocol |
||
| 203 | * @return bool |
||
| 204 | */ |
||
| 205 | private function isSiteReachable(string $site): bool { |
||
| 206 | try { |
||
| 207 | $client = $this->clientService->newClient(); |
||
| 208 | // if there is no protocol, test http:// AND https:// |
||
| 209 | if (preg_match('/^https?:\/\//', $site) !== 1) { |
||
| 210 | $httpSite = 'http://' . $site . '/'; |
||
| 211 | $client->get($httpSite); |
||
| 212 | $httpsSite = 'https://' . $site . '/'; |
||
| 213 | $client->get($httpsSite); |
||
| 214 | } else { |
||
| 215 | $client->get($site); |
||
| 216 | } |
||
| 217 | } catch (\Exception $e) { |
||
| 218 | $this->logger->error('Cannot connect to: ' . $site, [ |
||
| 219 | 'app' => 'internet_connection_check', |
||
| 220 | 'exception' => $e, |
||
| 221 | ]); |
||
| 222 | return false; |
||
| 223 | } |
||
| 224 | return true; |
||
| 225 | } |
||
| 226 | |||
| 227 | /** |
||
| 228 | * Checks whether a local memcache is installed or not |
||
| 229 | * @return bool |
||
| 230 | */ |
||
| 231 | private function isMemcacheConfigured() { |
||
| 232 | return $this->config->getSystemValue('memcache.local', null) !== null; |
||
| 233 | } |
||
| 234 | |||
| 235 | /** |
||
| 236 | * Whether PHP can generate "secure" pseudorandom integers |
||
| 237 | * |
||
| 238 | * @return bool |
||
| 239 | */ |
||
| 240 | private function isRandomnessSecure() { |
||
| 241 | try { |
||
| 242 | $this->secureRandom->generate(1); |
||
| 243 | } catch (\Exception $ex) { |
||
| 244 | return false; |
||
| 245 | } |
||
| 246 | return true; |
||
| 247 | } |
||
| 248 | |||
| 249 | /** |
||
| 250 | * Public for the sake of unit-testing |
||
| 251 | * |
||
| 252 | * @return array |
||
| 253 | */ |
||
| 254 | protected function getCurlVersion() { |
||
| 255 | return curl_version(); |
||
| 256 | } |
||
| 257 | |||
| 258 | /** |
||
| 259 | * Check if the used SSL lib is outdated. Older OpenSSL and NSS versions do |
||
| 260 | * have multiple bugs which likely lead to problems in combination with |
||
| 261 | * functionality required by ownCloud such as SNI. |
||
| 262 | * |
||
| 263 | * @link https://github.com/owncloud/core/issues/17446#issuecomment-122877546 |
||
| 264 | * @link https://bugzilla.redhat.com/show_bug.cgi?id=1241172 |
||
| 265 | * @return string |
||
| 266 | */ |
||
| 267 | private function isUsedTlsLibOutdated() { |
||
| 268 | // Don't run check when: |
||
| 269 | // 1. Server has `has_internet_connection` set to false |
||
| 270 | // 2. AppStore AND S2S is disabled |
||
| 271 | if (!$this->config->getSystemValue('has_internet_connection', true)) { |
||
| 272 | return ''; |
||
| 273 | } |
||
| 274 | if (!$this->config->getSystemValue('appstoreenabled', true) |
||
| 275 | && $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes') === 'no' |
||
| 276 | && $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes') === 'no') { |
||
| 277 | return ''; |
||
| 278 | } |
||
| 279 | |||
| 280 | $versionString = $this->getCurlVersion(); |
||
| 281 | if (isset($versionString['ssl_version'])) { |
||
| 282 | $versionString = $versionString['ssl_version']; |
||
| 283 | } else { |
||
| 284 | return ''; |
||
| 285 | } |
||
| 286 | |||
| 287 | $features = $this->l10n->t('installing and updating apps via the App Store or Federated Cloud Sharing'); |
||
| 288 | if (!$this->config->getSystemValue('appstoreenabled', true)) { |
||
| 289 | $features = $this->l10n->t('Federated Cloud Sharing'); |
||
| 290 | } |
||
| 291 | |||
| 292 | // Check if at least OpenSSL after 1.01d or 1.0.2b |
||
| 293 | if (strpos($versionString, 'OpenSSL/') === 0) { |
||
| 294 | $majorVersion = substr($versionString, 8, 5); |
||
| 295 | $patchRelease = substr($versionString, 13, 6); |
||
| 296 | |||
| 297 | if (($majorVersion === '1.0.1' && ord($patchRelease) < ord('d')) || |
||
| 298 | ($majorVersion === '1.0.2' && ord($patchRelease) < ord('b'))) { |
||
| 299 | return $this->l10n->t('cURL is using an outdated %1$s version (%2$s). Please update your operating system or features such as %3$s will not work reliably.', ['OpenSSL', $versionString, $features]); |
||
| 300 | } |
||
| 301 | } |
||
| 302 | |||
| 303 | // Check if NSS and perform heuristic check |
||
| 304 | if (strpos($versionString, 'NSS/') === 0) { |
||
| 305 | try { |
||
| 306 | $firstClient = $this->clientService->newClient(); |
||
| 307 | $firstClient->get('https://nextcloud.com/'); |
||
| 308 | |||
| 309 | $secondClient = $this->clientService->newClient(); |
||
| 310 | $secondClient->get('https://nextcloud.com/'); |
||
| 311 | } catch (ClientException $e) { |
||
| 312 | if ($e->getResponse()->getStatusCode() === 400) { |
||
| 313 | return $this->l10n->t('cURL is using an outdated %1$s version (%2$s). Please update your operating system or features such as %3$s will not work reliably.', ['NSS', $versionString, $features]); |
||
| 314 | } |
||
| 315 | } catch (\Exception $e) { |
||
| 316 | $this->logger->warning('error checking curl', [ |
||
| 317 | 'app' => 'settings', |
||
| 318 | 'exception' => $e, |
||
| 319 | ]); |
||
| 320 | return $this->l10n->t('Could not determine if TLS version of cURL is outdated or not because an error happened during the HTTPS request against https://nextcloud.com. Please check the nextcloud log file for more details.'); |
||
| 321 | } |
||
| 322 | } |
||
| 323 | |||
| 324 | return ''; |
||
| 325 | } |
||
| 326 | |||
| 327 | /** |
||
| 328 | * Whether the version is outdated |
||
| 329 | * |
||
| 330 | * @return bool |
||
| 331 | */ |
||
| 332 | protected function isPhpOutdated(): bool { |
||
| 333 | return PHP_VERSION_ID < 70400; |
||
| 334 | } |
||
| 335 | |||
| 336 | /** |
||
| 337 | * Whether the php version is still supported (at time of release) |
||
| 338 | * according to: https://www.php.net/supported-versions.php |
||
| 339 | * |
||
| 340 | * @return array |
||
| 341 | */ |
||
| 342 | private function isPhpSupported(): array { |
||
| 343 | return ['eol' => $this->isPhpOutdated(), 'version' => PHP_VERSION]; |
||
| 344 | } |
||
| 345 | |||
| 346 | /** |
||
| 347 | * Check if the reverse proxy configuration is working as expected |
||
| 348 | * |
||
| 349 | * @return bool |
||
| 350 | */ |
||
| 351 | private function forwardedForHeadersWorking(): bool { |
||
| 352 | $trustedProxies = $this->config->getSystemValue('trusted_proxies', []); |
||
| 353 | $remoteAddress = $this->request->getHeader('REMOTE_ADDR'); |
||
| 354 | |||
| 355 | if (empty($trustedProxies) && $this->request->getHeader('X-Forwarded-Host') !== '') { |
||
| 356 | return false; |
||
| 357 | } |
||
| 358 | |||
| 359 | if (\is_array($trustedProxies)) { |
||
| 360 | if (\in_array($remoteAddress, $trustedProxies, true) && $remoteAddress !== '127.0.0.1') { |
||
| 361 | return $remoteAddress !== $this->request->getRemoteAddress(); |
||
| 362 | } |
||
| 363 | } else { |
||
| 364 | return false; |
||
| 365 | } |
||
| 366 | |||
| 367 | // either not enabled or working correctly |
||
| 368 | return true; |
||
| 369 | } |
||
| 370 | |||
| 371 | /** |
||
| 372 | * Checks if the correct memcache module for PHP is installed. Only |
||
| 373 | * fails if memcached is configured and the working module is not installed. |
||
| 374 | * |
||
| 375 | * @return bool |
||
| 376 | */ |
||
| 377 | private function isCorrectMemcachedPHPModuleInstalled() { |
||
| 378 | if ($this->config->getSystemValue('memcache.distributed', null) !== '\OC\Memcache\Memcached') { |
||
| 379 | return true; |
||
| 380 | } |
||
| 381 | |||
| 382 | // there are two different memcached modules for PHP |
||
| 383 | // we only support memcached and not memcache |
||
| 384 | // https://code.google.com/p/memcached/wiki/PHPClientComparison |
||
| 385 | return !(!extension_loaded('memcached') && extension_loaded('memcache')); |
||
| 386 | } |
||
| 387 | |||
| 388 | /** |
||
| 389 | * Checks if set_time_limit is not disabled. |
||
| 390 | * |
||
| 391 | * @return bool |
||
| 392 | */ |
||
| 393 | private function isSettimelimitAvailable() { |
||
| 394 | if (function_exists('set_time_limit') |
||
| 395 | && strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
||
| 396 | return true; |
||
| 397 | } |
||
| 398 | |||
| 399 | return false; |
||
| 400 | } |
||
| 401 | |||
| 402 | /** |
||
| 403 | * @return RedirectResponse |
||
| 404 | * @AuthorizedAdminSetting(settings=OCA\Settings\Settings\Admin\Overview) |
||
| 405 | */ |
||
| 406 | public function rescanFailedIntegrityCheck(): RedirectResponse { |
||
| 407 | $this->checker->runInstanceVerification(); |
||
| 408 | return new RedirectResponse( |
||
| 409 | $this->urlGenerator->linkToRoute('settings.AdminSettings.index', ['section' => 'overview']) |
||
| 410 | ); |
||
| 411 | } |
||
| 412 | |||
| 413 | /** |
||
| 414 | * @NoCSRFRequired |
||
| 415 | * @AuthorizedAdminSetting(settings=OCA\Settings\Settings\Admin\Overview) |
||
| 416 | */ |
||
| 417 | public function getFailedIntegrityCheckFiles(): DataDisplayResponse { |
||
| 418 | if (!$this->checker->isCodeCheckEnforced()) { |
||
| 419 | return new DataDisplayResponse('Integrity checker has been disabled. Integrity cannot be verified.'); |
||
| 420 | } |
||
| 421 | |||
| 422 | $completeResults = $this->checker->getResults(); |
||
| 423 | |||
| 424 | if (!empty($completeResults)) { |
||
| 425 | $formattedTextResponse = 'Technical information |
||
| 426 | ===================== |
||
| 427 | The following list covers which files have failed the integrity check. Please read |
||
| 428 | the previous linked documentation to learn more about the errors and how to fix |
||
| 429 | them. |
||
| 430 | |||
| 431 | Results |
||
| 432 | ======= |
||
| 433 | '; |
||
| 434 | foreach ($completeResults as $context => $contextResult) { |
||
| 435 | $formattedTextResponse .= "- $context\n"; |
||
| 436 | |||
| 437 | foreach ($contextResult as $category => $result) { |
||
| 438 | $formattedTextResponse .= "\t- $category\n"; |
||
| 439 | if ($category !== 'EXCEPTION') { |
||
| 440 | foreach ($result as $key => $results) { |
||
| 441 | $formattedTextResponse .= "\t\t- $key\n"; |
||
| 442 | } |
||
| 443 | } else { |
||
| 444 | foreach ($result as $key => $results) { |
||
| 445 | $formattedTextResponse .= "\t\t- $results\n"; |
||
| 446 | } |
||
| 447 | } |
||
| 448 | } |
||
| 449 | } |
||
| 450 | |||
| 451 | $formattedTextResponse .= ' |
||
| 452 | Raw output |
||
| 453 | ========== |
||
| 454 | '; |
||
| 455 | $formattedTextResponse .= print_r($completeResults, true); |
||
| 456 | } else { |
||
| 457 | $formattedTextResponse = 'No errors have been found.'; |
||
| 458 | } |
||
| 459 | |||
| 460 | |||
| 461 | return new DataDisplayResponse( |
||
| 462 | $formattedTextResponse, |
||
| 463 | Http::STATUS_OK, |
||
| 464 | [ |
||
| 465 | 'Content-Type' => 'text/plain', |
||
| 466 | ] |
||
| 467 | ); |
||
| 468 | } |
||
| 469 | |||
| 470 | /** |
||
| 471 | * Checks whether a PHP OPcache is properly set up |
||
| 472 | * @return string[] The list of OPcache setup recommendations |
||
| 473 | */ |
||
| 474 | protected function getOpcacheSetupRecommendations(): array { |
||
| 475 | // If the module is not loaded, return directly to skip inapplicable checks |
||
| 476 | if (!extension_loaded('Zend OPcache')) { |
||
| 477 | return ['The PHP OPcache module is not loaded. For better performance it is recommended to load it into your PHP installation.']; |
||
| 478 | } |
||
| 479 | |||
| 480 | $recommendations = []; |
||
| 481 | |||
| 482 | // Check whether Nextcloud is allowed to use the OPcache API |
||
| 483 | $isPermitted = true; |
||
| 484 | $permittedPath = $this->iniGetWrapper->getString('opcache.restrict_api'); |
||
| 485 | if (isset($permittedPath) && $permittedPath !== '' && !str_starts_with(\OC::$SERVERROOT, rtrim($permittedPath, '/'))) { |
||
| 486 | $isPermitted = false; |
||
| 487 | } |
||
| 488 | |||
| 489 | if (!$this->iniGetWrapper->getBool('opcache.enable')) { |
||
|
|
|||
| 490 | $recommendations[] = 'OPcache is disabled. For better performance, it is recommended to apply <code>opcache.enable=1</code> to your PHP configuration.'; |
||
| 491 | |||
| 492 | // Check for saved comments only when OPcache is currently disabled. If it was enabled, opcache.save_comments=0 would break Nextcloud in the first place. |
||
| 493 | if (!$this->iniGetWrapper->getBool('opcache.save_comments')) { |
||
| 494 | $recommendations[] = 'OPcache is configured to remove code comments. With OPcache enabled, <code>opcache.save_comments=1</code> must be set for Nextcloud to function.'; |
||
| 495 | } |
||
| 496 | |||
| 497 | if (!$isPermitted) { |
||
| 498 | $recommendations[] = 'Nextcloud is not allowed to use the OPcache API. With OPcache enabled, it is highly recommended to include all Nextcloud directories with <code>opcache.restrict_api</code> or unset this setting to disable OPcache API restrictions, to prevent errors during Nextcloud core or app upgrades.'; |
||
| 499 | } |
||
| 500 | } elseif (!$isPermitted) { |
||
| 501 | $recommendations[] = 'Nextcloud is not allowed to use the OPcache API. It is highly recommended to include all Nextcloud directories with <code>opcache.restrict_api</code> or unset this setting to disable OPcache API restrictions, to prevent errors during Nextcloud core or app upgrades.'; |
||
| 502 | } else { |
||
| 503 | // Check whether opcache_get_status has been explicitly disabled an in case skip usage based checks |
||
| 504 | $disabledFunctions = $this->iniGetWrapper->getString('disable_functions'); |
||
| 505 | if (isset($disabledFunctions) && str_contains($disabledFunctions, 'opcache_get_status')) { |
||
| 506 | return []; |
||
| 507 | } |
||
| 508 | |||
| 509 | $status = opcache_get_status(false); |
||
| 510 | |||
| 511 | // Recommend to raise value, if more than 90% of max value is reached |
||
| 512 | if ( |
||
| 513 | empty($status['opcache_statistics']['max_cached_keys']) || |
||
| 514 | ($status['opcache_statistics']['num_cached_keys'] / $status['opcache_statistics']['max_cached_keys'] > 0.9) |
||
| 515 | ) { |
||
| 516 | $recommendations[] = 'The maximum number of OPcache keys is nearly exceeded. To assure that all scripts can be hold in cache, it is recommended to apply <code>opcache.max_accelerated_files</code> to your PHP configuration with a value higher than <code>' . ($this->iniGetWrapper->getNumeric('opcache.max_accelerated_files') ?: 'currently') . '</code>.'; |
||
| 517 | } |
||
| 518 | |||
| 519 | if ( |
||
| 520 | empty($status['memory_usage']['free_memory']) || |
||
| 521 | ($status['memory_usage']['used_memory'] / $status['memory_usage']['free_memory'] > 9) |
||
| 522 | ) { |
||
| 523 | $recommendations[] = 'The OPcache buffer is nearly full. To assure that all scripts can be hold in cache, it is recommended to apply <code>opcache.memory_consumption</code> to your PHP configuration with a value higher than <code>' . ($this->iniGetWrapper->getNumeric('opcache.memory_consumption') ?: 'currently') . '</code>.'; |
||
| 524 | } |
||
| 525 | |||
| 526 | if ( |
||
| 527 | empty($status['interned_strings_usage']['free_memory']) || |
||
| 528 | ($status['interned_strings_usage']['used_memory'] / $status['interned_strings_usage']['free_memory'] > 9) |
||
| 529 | ) { |
||
| 530 | $recommendations[] = 'The OPcache interned strings buffer is nearly full. To assure that repeating strings can be effectively cached, it is recommended to apply <code>opcache.interned_strings_buffer</code> to your PHP configuration with a value higher than <code>' . ($this->iniGetWrapper->getNumeric('opcache.interned_strings_buffer') ?: 'currently') . '</code>.'; |
||
| 531 | } |
||
| 532 | } |
||
| 533 | |||
| 534 | return $recommendations; |
||
| 535 | } |
||
| 536 | |||
| 537 | /** |
||
| 538 | * Check if the required FreeType functions are present |
||
| 539 | * @return bool |
||
| 540 | */ |
||
| 541 | protected function hasFreeTypeSupport() { |
||
| 542 | return function_exists('imagettfbbox') && function_exists('imagettftext'); |
||
| 543 | } |
||
| 544 | |||
| 545 | protected function hasMissingIndexes(): array { |
||
| 546 | $indexInfo = new MissingIndexInformation(); |
||
| 547 | // Dispatch event so apps can also hint for pending index updates if needed |
||
| 548 | $event = new GenericEvent($indexInfo); |
||
| 549 | $this->dispatcher->dispatch(IDBConnection::CHECK_MISSING_INDEXES_EVENT, $event); |
||
| 550 | |||
| 551 | return $indexInfo->getListOfMissingIndexes(); |
||
| 552 | } |
||
| 553 | |||
| 554 | protected function hasMissingPrimaryKeys(): array { |
||
| 555 | $info = new MissingPrimaryKeyInformation(); |
||
| 556 | // Dispatch event so apps can also hint for pending index updates if needed |
||
| 557 | $event = new GenericEvent($info); |
||
| 558 | $this->dispatcher->dispatch(IDBConnection::CHECK_MISSING_PRIMARY_KEYS_EVENT, $event); |
||
| 559 | |||
| 560 | return $info->getListOfMissingPrimaryKeys(); |
||
| 561 | } |
||
| 562 | |||
| 563 | protected function hasMissingColumns(): array { |
||
| 564 | $indexInfo = new MissingColumnInformation(); |
||
| 565 | // Dispatch event so apps can also hint for pending index updates if needed |
||
| 566 | $event = new GenericEvent($indexInfo); |
||
| 567 | $this->dispatcher->dispatch(IDBConnection::CHECK_MISSING_COLUMNS_EVENT, $event); |
||
| 568 | |||
| 569 | return $indexInfo->getListOfMissingColumns(); |
||
| 570 | } |
||
| 571 | |||
| 572 | protected function isSqliteUsed() { |
||
| 574 | } |
||
| 575 | |||
| 576 | protected function isReadOnlyConfig(): bool { |
||
| 577 | return \OC_Helper::isReadOnlyConfigEnabled(); |
||
| 578 | } |
||
| 579 | |||
| 580 | protected function wasEmailTestSuccessful(): bool { |
||
| 581 | // Handle the case that the configuration was set before the check was introduced or it was only set via command line and not from the UI |
||
| 582 | if ($this->config->getAppValue('core', 'emailTestSuccessful', '') === '' && $this->config->getSystemValue('mail_domain', '') === '') { |
||
| 583 | return false; |
||
| 584 | } |
||
| 585 | |||
| 586 | // The mail test was unsuccessful or the config was changed using the UI without verifying with a testmail, hence return false |
||
| 587 | if ($this->config->getAppValue('core', 'emailTestSuccessful', '') === '0') { |
||
| 588 | return false; |
||
| 589 | } |
||
| 590 | |||
| 591 | return true; |
||
| 592 | } |
||
| 593 | |||
| 594 | protected function hasValidTransactionIsolationLevel(): bool { |
||
| 606 | } |
||
| 607 | |||
| 608 | protected function hasFileinfoInstalled(): bool { |
||
| 609 | return \OC_Util::fileInfoLoaded(); |
||
| 610 | } |
||
| 611 | |||
| 612 | protected function hasWorkingFileLocking(): bool { |
||
| 613 | return !($this->lockingProvider instanceof NoopLockingProvider); |
||
| 614 | } |
||
| 615 | |||
| 616 | protected function getSuggestedOverwriteCliURL(): string { |
||
| 617 | $suggestedOverwriteCliUrl = ''; |
||
| 618 | if ($this->config->getSystemValue('overwrite.cli.url', '') === '') { |
||
| 619 | $suggestedOverwriteCliUrl = $this->request->getServerProtocol() . '://' . $this->request->getInsecureServerHost() . \OC::$WEBROOT; |
||
| 620 | if (!$this->config->getSystemValue('config_is_read_only', false)) { |
||
| 621 | // Set the overwrite URL when it was not set yet. |
||
| 622 | $this->config->setSystemValue('overwrite.cli.url', $suggestedOverwriteCliUrl); |
||
| 623 | $suggestedOverwriteCliUrl = ''; |
||
| 624 | } |
||
| 625 | } |
||
| 626 | return $suggestedOverwriteCliUrl; |
||
| 627 | } |
||
| 628 | |||
| 629 | protected function getLastCronInfo(): array { |
||
| 630 | $lastCronRun = $this->config->getAppValue('core', 'lastcron', 0); |
||
| 631 | return [ |
||
| 632 | 'diffInSeconds' => time() - $lastCronRun, |
||
| 633 | 'relativeTime' => $this->dateTimeFormatter->formatTimeSpan($lastCronRun), |
||
| 634 | 'backgroundJobsUrl' => $this->urlGenerator->linkToRoute('settings.AdminSettings.index', ['section' => 'server']) . '#backgroundjobs', |
||
| 635 | ]; |
||
| 636 | } |
||
| 637 | |||
| 638 | protected function getCronErrors() { |
||
| 639 | $errors = json_decode($this->config->getAppValue('core', 'cronErrors', ''), true); |
||
| 640 | |||
| 641 | if (is_array($errors)) { |
||
| 642 | return $errors; |
||
| 643 | } |
||
| 644 | |||
| 645 | return []; |
||
| 646 | } |
||
| 647 | |||
| 648 | private function isTemporaryDirectoryWritable(): bool { |
||
| 649 | try { |
||
| 650 | if (!empty($this->tempManager->getTempBaseDir())) { |
||
| 651 | return true; |
||
| 652 | } |
||
| 653 | } catch (\Exception $e) { |
||
| 654 | } |
||
| 655 | return false; |
||
| 656 | } |
||
| 657 | |||
| 658 | /** |
||
| 659 | * Iterates through the configured app roots and |
||
| 660 | * tests if the subdirectories are owned by the same user than the current user. |
||
| 661 | * |
||
| 662 | * @return array |
||
| 663 | */ |
||
| 664 | protected function getAppDirsWithDifferentOwner(): array { |
||
| 665 | $currentUser = posix_getuid(); |
||
| 666 | $appDirsWithDifferentOwner = [[]]; |
||
| 667 | |||
| 668 | foreach (OC::$APPSROOTS as $appRoot) { |
||
| 669 | if ($appRoot['writable'] === true) { |
||
| 670 | $appDirsWithDifferentOwner[] = $this->getAppDirsWithDifferentOwnerForAppRoot($currentUser, $appRoot); |
||
| 671 | } |
||
| 672 | } |
||
| 673 | |||
| 674 | $appDirsWithDifferentOwner = array_merge(...$appDirsWithDifferentOwner); |
||
| 675 | sort($appDirsWithDifferentOwner); |
||
| 676 | |||
| 677 | return $appDirsWithDifferentOwner; |
||
| 678 | } |
||
| 679 | |||
| 680 | /** |
||
| 681 | * Tests if the directories for one apps directory are writable by the current user. |
||
| 682 | * |
||
| 683 | * @param int $currentUser The current user |
||
| 684 | * @param array $appRoot The app root config |
||
| 685 | * @return string[] The none writable directory paths inside the app root |
||
| 686 | */ |
||
| 687 | private function getAppDirsWithDifferentOwnerForAppRoot(int $currentUser, array $appRoot): array { |
||
| 703 | } |
||
| 704 | |||
| 705 | /** |
||
| 706 | * Checks for potential PHP modules that would improve the instance |
||
| 707 | * |
||
| 708 | * @return string[] A list of PHP modules that is recommended |
||
| 709 | */ |
||
| 710 | protected function hasRecommendedPHPModules(): array { |
||
| 711 | $recommendedPHPModules = []; |
||
| 712 | |||
| 713 | if (!extension_loaded('intl')) { |
||
| 714 | $recommendedPHPModules[] = 'intl'; |
||
| 715 | } |
||
| 716 | |||
| 717 | if (!defined('PASSWORD_ARGON2I') && PHP_VERSION_ID >= 70400) { |
||
| 718 | // Installing php-sodium on >=php7.4 will provide PASSWORD_ARGON2I |
||
| 719 | // on previous version argon2 wasn't part of the "standard" extension |
||
| 720 | // and RedHat disabled it so even installing php-sodium won't provide argon2i |
||
| 721 | // support in password_hash/password_verify. |
||
| 722 | $recommendedPHPModules[] = 'sodium'; |
||
| 723 | } |
||
| 724 | |||
| 725 | return $recommendedPHPModules; |
||
| 726 | } |
||
| 727 | |||
| 728 | protected function isImagickEnabled(): bool { |
||
| 729 | if ($this->config->getAppValue('theming', 'enabled', 'no') === 'yes') { |
||
| 730 | if (!extension_loaded('imagick')) { |
||
| 731 | return false; |
||
| 732 | } |
||
| 733 | } |
||
| 734 | return true; |
||
| 735 | } |
||
| 736 | |||
| 737 | protected function areWebauthnExtensionsEnabled(): bool { |
||
| 745 | } |
||
| 746 | |||
| 747 | protected function isMysqlUsedWithoutUTF8MB4(): bool { |
||
| 748 | return ($this->config->getSystemValue('dbtype', 'sqlite') === 'mysql') && ($this->config->getSystemValue('mysql.utf8mb4', false) === false); |
||
| 749 | } |
||
| 750 | |||
| 751 | protected function hasBigIntConversionPendingColumns(): array { |
||
| 752 | // copy of ConvertFilecacheBigInt::getColumnsByTable() |
||
| 753 | $tables = [ |
||
| 754 | 'activity' => ['activity_id', 'object_id'], |
||
| 755 | 'activity_mq' => ['mail_id'], |
||
| 756 | 'authtoken' => ['id'], |
||
| 757 | 'bruteforce_attempts' => ['id'], |
||
| 758 | 'federated_reshares' => ['share_id'], |
||
| 759 | 'filecache' => ['fileid', 'storage', 'parent', 'mimetype', 'mimepart', 'mtime', 'storage_mtime'], |
||
| 760 | 'filecache_extended' => ['fileid'], |
||
| 761 | 'file_locks' => ['id'], |
||
| 762 | 'jobs' => ['id'], |
||
| 763 | 'mimetypes' => ['id'], |
||
| 764 | 'mounts' => ['id', 'storage_id', 'root_id', 'mount_id'], |
||
| 765 | 'share_external' => ['id', 'parent'], |
||
| 766 | 'storages' => ['numeric_id'], |
||
| 767 | ]; |
||
| 768 | |||
| 769 | $schema = new SchemaWrapper($this->db); |
||
| 770 | $isSqlite = $this->db->getDatabasePlatform() instanceof SqlitePlatform; |
||
| 771 | $pendingColumns = []; |
||
| 772 | |||
| 773 | foreach ($tables as $tableName => $columns) { |
||
| 774 | if (!$schema->hasTable($tableName)) { |
||
| 775 | continue; |
||
| 776 | } |
||
| 777 | |||
| 778 | $table = $schema->getTable($tableName); |
||
| 779 | foreach ($columns as $columnName) { |
||
| 780 | $column = $table->getColumn($columnName); |
||
| 781 | $isAutoIncrement = $column->getAutoincrement(); |
||
| 782 | $isAutoIncrementOnSqlite = $isSqlite && $isAutoIncrement; |
||
| 783 | if ($column->getType()->getName() !== Types::BIGINT && !$isAutoIncrementOnSqlite) { |
||
| 784 | $pendingColumns[] = $tableName . '.' . $columnName; |
||
| 785 | } |
||
| 786 | } |
||
| 787 | } |
||
| 788 | |||
| 789 | return $pendingColumns; |
||
| 790 | } |
||
| 791 | |||
| 792 | protected function isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed(): bool { |
||
| 826 | } |
||
| 827 | |||
| 828 | protected function imageMagickLacksSVGSupport(): bool { |
||
| 829 | return extension_loaded('imagick') && count(\Imagick::queryFormats('SVG')) === 0; |
||
| 830 | } |
||
| 831 | |||
| 832 | /** |
||
| 833 | * @return DataResponse |
||
| 834 | * @AuthorizedAdminSetting(settings=OCA\Settings\Settings\Admin\Overview) |
||
| 835 | */ |
||
| 836 | public function check() { |
||
| 894 | ] |
||
| 895 | ); |
||
| 896 | } |
||
| 898 |
If an expression can have both
false, andnullas possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.