|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors |
| 7 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 8 | + */ |
| 9 | + |
| 10 | +namespace OCA\Settings\SetupChecks; |
| 11 | + |
| 12 | +use OC\MemoryInfo; |
| 13 | +use OCP\AppFramework\Services\IAppConfig; |
| 14 | +use OCP\IL10N; |
| 15 | +use OCP\IURLGenerator; |
| 16 | +use OCP\SetupCheck\ISetupCheck; |
| 17 | +use OCP\SetupCheck\SetupResult; |
| 18 | +use OCP\Util; |
| 19 | + |
| 20 | +class PhpMaxFileSize implements ISetupCheck { |
| 21 | + public function __construct( |
| 22 | + private IL10N $l10n, |
| 23 | + private IAppConfig $appConfig, |
| 24 | + private IURLGenerator $urlGenerator, |
| 25 | + ) { |
| 26 | + } |
| 27 | + |
| 28 | + public function getCategory(): string { |
| 29 | + return 'php'; |
| 30 | + } |
| 31 | + |
| 32 | + public function getName(): string { |
| 33 | + return $this->l10n->t('PHP file size upload limit'); |
| 34 | + } |
| 35 | + |
| 36 | + public function run(): SetupResult { |
| 37 | + $upload_max_filesize = Util::computerFileSize(trim(ini_get('upload_max_filesize'))); |
| 38 | + $post_max_size = Util::computerFileSize(trim(ini_get('post_max_size'))); |
| 39 | + $max_input_time = trim(ini_get('max_input_time')); |
| 40 | + $max_execution_time = trim(ini_get('max_execution_time')); |
| 41 | + |
| 42 | + $warnings = []; |
| 43 | + $recommendedSize = 16 * 1024 * 1024 * 1024; |
| 44 | + $recommendedTime = 3600; |
| 45 | + |
| 46 | + // Check if the PHP upload limit is too low |
| 47 | + if ($upload_max_filesize < $recommendedSize || $post_max_size < $recommendedSize) { |
| 48 | + $warnings[] = $this->l10n->t('The PHP upload_max_filesize and/or post_max_size is too low. A file size of at least %1$s is recommended. Current value: %2$s', [ |
| 49 | + Util::humanFileSize($recommendedSize), |
| 50 | + Util::humanFileSize(min($upload_max_filesize, $post_max_size)), |
| 51 | + ]); |
| 52 | + } |
| 53 | + |
| 54 | + // Check if the PHP execution time is too low |
| 55 | + if ($max_input_time < $recommendedTime || $max_execution_time < $recommendedTime) { |
| 56 | + $warnings[] = $this->l10n->t('The PHP max_input_time and/or max_execution_time is too low. A time of at least %1$s is recommended. Current value: %2$s', [ |
| 57 | + $recommendedTime . 's', |
| 58 | + min($max_input_time, $max_execution_time) . 's', |
| 59 | + ]); |
| 60 | + } |
| 61 | + |
| 62 | + if (!empty($warnings)) { |
| 63 | + return SetupResult::warning(join(' ', $warnings), $this->urlGenerator->linkToDocs('admin-big-file-upload')); |
| 64 | + } |
| 65 | + |
| 66 | + return SetupResult::success(); |
| 67 | + } |
| 68 | +} |
0 commit comments