PhpModules.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2023 Côme Chilliet <come.chilliet@nextcloud.com>
  5. *
  6. * @author Côme Chilliet <come.chilliet@nextcloud.com>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\Settings\SetupChecks;
  25. use OCP\IL10N;
  26. use OCP\IURLGenerator;
  27. use OCP\SetupCheck\ISetupCheck;
  28. use OCP\SetupCheck\SetupResult;
  29. class PhpModules implements ISetupCheck {
  30. protected const REQUIRED_MODULES = [
  31. 'ctype',
  32. 'curl',
  33. 'dom',
  34. 'fileinfo',
  35. 'gd',
  36. 'json',
  37. 'mbstring',
  38. 'openssl',
  39. 'posix',
  40. 'session',
  41. 'xml',
  42. 'xmlreader',
  43. 'xmlwriter',
  44. 'zip',
  45. 'zlib',
  46. ];
  47. protected const RECOMMENDED_MODULES = [
  48. 'exif',
  49. 'intl',
  50. 'sodium',
  51. 'sysvsem',
  52. ];
  53. public function __construct(
  54. private IL10N $l10n,
  55. private IURLGenerator $urlGenerator,
  56. ) {
  57. }
  58. public function getName(): string {
  59. return $this->l10n->t('PHP modules');
  60. }
  61. public function getCategory(): string {
  62. return 'system';
  63. }
  64. public function run(): SetupResult {
  65. $missingRecommendedModules = $this->getMissingModules(self::RECOMMENDED_MODULES);
  66. $missingRequiredModules = $this->getMissingModules(self::REQUIRED_MODULES);
  67. if (!empty($missingRequiredModules)) {
  68. return SetupResult::error(
  69. $this->l10n->t('This instance is missing some required PHP modules. It is required to install them: %s.', implode(', ', $missingRequiredModules)),
  70. $this->urlGenerator->linkToDocs('admin-php-modules')
  71. );
  72. } elseif (!empty($missingRecommendedModules)) {
  73. return SetupResult::info(
  74. $this->l10n->t('This instance is missing some recommended PHP modules. For improved performance and better compatibility it is highly recommended to install them: %s.', implode(', ', $missingRecommendedModules)),
  75. $this->urlGenerator->linkToDocs('admin-php-modules')
  76. );
  77. } else {
  78. return SetupResult::success();
  79. }
  80. }
  81. /**
  82. * Checks for potential PHP modules that would improve the instance
  83. *
  84. * @param string[] $modules modules to test
  85. * @return string[] A list of PHP modules which are missing
  86. */
  87. protected function getMissingModules(array $modules): array {
  88. return array_values(array_filter(
  89. $modules,
  90. fn (string $module) => !extension_loaded($module),
  91. ));
  92. }
  93. }