Migrate overwrite.cli.url setup check to new API

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
pull/42796/head
Côme Chilliet 5 months ago committed by Côme Chilliet
parent 80d58f0162
commit 0483064f07

@ -93,6 +93,7 @@ return array(
'OCA\\Settings\\SetupChecks\\LegacySSEKeyFormat' => $baseDir . '/../lib/SetupChecks/LegacySSEKeyFormat.php',
'OCA\\Settings\\SetupChecks\\MaintenanceWindowStart' => $baseDir . '/../lib/SetupChecks/MaintenanceWindowStart.php',
'OCA\\Settings\\SetupChecks\\MemcacheConfigured' => $baseDir . '/../lib/SetupChecks/MemcacheConfigured.php',
'OCA\\Settings\\SetupChecks\\OverwriteCliUrl' => $baseDir . '/../lib/SetupChecks/OverwriteCliUrl.php',
'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => $baseDir . '/../lib/SetupChecks/PhpDefaultCharset.php',
'OCA\\Settings\\SetupChecks\\PhpFreetypeSupport' => $baseDir . '/../lib/SetupChecks/PhpFreetypeSupport.php',
'OCA\\Settings\\SetupChecks\\PhpGetEnv' => $baseDir . '/../lib/SetupChecks/PhpGetEnv.php',

@ -108,6 +108,7 @@ class ComposerStaticInitSettings
'OCA\\Settings\\SetupChecks\\LegacySSEKeyFormat' => __DIR__ . '/..' . '/../lib/SetupChecks/LegacySSEKeyFormat.php',
'OCA\\Settings\\SetupChecks\\MaintenanceWindowStart' => __DIR__ . '/..' . '/../lib/SetupChecks/MaintenanceWindowStart.php',
'OCA\\Settings\\SetupChecks\\MemcacheConfigured' => __DIR__ . '/..' . '/../lib/SetupChecks/MemcacheConfigured.php',
'OCA\\Settings\\SetupChecks\\OverwriteCliUrl' => __DIR__ . '/..' . '/../lib/SetupChecks/OverwriteCliUrl.php',
'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpDefaultCharset.php',
'OCA\\Settings\\SetupChecks\\PhpFreetypeSupport' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpFreetypeSupport.php',
'OCA\\Settings\\SetupChecks\\PhpGetEnv' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpGetEnv.php',

@ -65,6 +65,7 @@ use OCA\Settings\SetupChecks\JavaScriptModules;
use OCA\Settings\SetupChecks\LegacySSEKeyFormat;
use OCA\Settings\SetupChecks\MaintenanceWindowStart;
use OCA\Settings\SetupChecks\MemcacheConfigured;
use OCA\Settings\SetupChecks\OverwriteCliUrl;
use OCA\Settings\SetupChecks\PhpDefaultCharset;
use OCA\Settings\SetupChecks\PhpFreetypeSupport;
use OCA\Settings\SetupChecks\PhpGetEnv;
@ -184,6 +185,7 @@ class Application extends App implements IBootstrap {
$context->registerSetupCheck(LegacySSEKeyFormat::class);
$context->registerSetupCheck(MaintenanceWindowStart::class);
$context->registerSetupCheck(MemcacheConfigured::class);
$context->registerSetupCheck(OverwriteCliUrl::class);
$context->registerSetupCheck(PhpDefaultCharset::class);
$context->registerSetupCheck(PhpFreetypeSupport::class);
$context->registerSetupCheck(PhpGetEnv::class);

@ -302,18 +302,6 @@ Raw output
);
}
protected function getSuggestedOverwriteCliURL(): string {
$currentOverwriteCliUrl = $this->config->getSystemValue('overwrite.cli.url', '');
$suggestedOverwriteCliUrl = $this->request->getServerProtocol() . '://' . $this->request->getInsecureServerHost() . \OC::$WEBROOT;
// Check correctness by checking if it is a valid URL
if (filter_var($currentOverwriteCliUrl, FILTER_VALIDATE_URL)) {
$suggestedOverwriteCliUrl = '';
}
return $suggestedOverwriteCliUrl;
}
protected function getLastCronInfo(): array {
$lastCronRun = (int)$this->config->getAppValue('core', 'lastcron', '0');
return [
@ -400,7 +388,6 @@ Raw output
public function check() {
return new DataResponse(
[
'suggestedOverwriteCliURL' => $this->getSuggestedOverwriteCliURL(),
'cronInfo' => $this->getLastCronInfo(),
'cronErrors' => $this->getCronErrors(),
'isFairUseOfFreePushService' => $this->isFairUseOfFreePushService(),

@ -0,0 +1,81 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2023 Côme Chilliet <come.chilliet@nextcloud.com>
*
* @author Côme Chilliet <come.chilliet@nextcloud.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Settings\SetupChecks;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
use OCP\SetupCheck\ISetupCheck;
use OCP\SetupCheck\SetupResult;
class OverwriteCliUrl implements ISetupCheck {
public function __construct(
private IL10N $l10n,
private IConfig $config,
private IRequest $request,
) {
}
public function getCategory(): string {
return 'config';
}
public function getName(): string {
return $this->l10n->t('Overwrite cli URL');
}
public function run(): SetupResult {
$currentOverwriteCliUrl = $this->config->getSystemValue('overwrite.cli.url', '');
$suggestedOverwriteCliUrl = $this->request->getServerProtocol() . '://' . $this->request->getInsecureServerHost() . \OC::$WEBROOT;
// Check correctness by checking if it is a valid URL
if (filter_var($currentOverwriteCliUrl, FILTER_VALIDATE_URL)) {
if ($currentOverwriteCliUrl == $suggestedOverwriteCliUrl) {
return SetupResult::success(
$this->l10n->t(
'The "overwrite.cli.url" option in your config.php is correctly set to "%s".',
[$currentOverwriteCliUrl]
)
);
} else {
return SetupResult::success(
$this->l10n->t(
'The "overwrite.cli.url" option in your config.php is set to "%s" which is a correct URL. Suggested URL is "%s".',
[$currentOverwriteCliUrl, $suggestedOverwriteCliUrl]
)
);
}
} else {
return SetupResult::warning(
$this->l10n->t(
'Please make sure to set the "overwrite.cli.url" option in your config.php file to the URL that your users mainly use to access this Nextcloud. Suggestion: "%s". Otherwise there might be problems with the URL generation via cron. (It is possible though that the suggested URL is not the URL that your users mainly use to access this Nextcloud. Best is to double check this in any case.)',
[$suggestedOverwriteCliUrl]
)
);
}
}
}

@ -220,7 +220,6 @@ class CheckSetupControllerTest extends TestCase {
$expected = new DataResponse(
[
'suggestedOverwriteCliURL' => '',
'cronInfo' => [
'diffInSeconds' => 123,
'relativeTime' => '2 hours ago',

@ -180,12 +180,6 @@
var afterCall = function(data, statusText, xhr) {
var messages = [];
if (xhr.status === 200 && data) {
if (data.suggestedOverwriteCliURL !== '') {
messages.push({
msg: t('core', 'Please make sure to set the "overwrite.cli.url" option in your config.php file to the URL that your users mainly use to access this Nextcloud. Suggestion: "{suggestedOverwriteCliURL}". Otherwise there might be problems with the URL generation via cron. (It is possible though that the suggested URL is not the URL that your users mainly use to access this Nextcloud. Best is to double check this in any case.)', {suggestedOverwriteCliURL: data.suggestedOverwriteCliURL}),
type: OC.SetupChecks.MESSAGE_TYPE_WARNING
});
}
if (data.cronErrors.length > 0) {
var listOfCronErrors = "";
data.cronErrors.forEach(function(element){

@ -223,7 +223,6 @@ describe('OC.SetupChecks tests', function() {
'Content-Type': 'application/json'
},
JSON.stringify({
suggestedOverwriteCliURL: '',
isFairUseOfFreePushService: true,
isCorrectMemcachedPHPModuleInstalled: true,
isSettimelimitAvailable: true,
@ -268,7 +267,6 @@ describe('OC.SetupChecks tests', function() {
'Content-Type': 'application/json'
},
JSON.stringify({
suggestedOverwriteCliURL: '',
isFairUseOfFreePushService: true,
isCorrectMemcachedPHPModuleInstalled: true,
isSettimelimitAvailable: true,
@ -313,7 +311,6 @@ describe('OC.SetupChecks tests', function() {
'Content-Type': 'application/json',
},
JSON.stringify({
suggestedOverwriteCliURL: '',
isFairUseOfFreePushService: true,
isCorrectMemcachedPHPModuleInstalled: true,
isSettimelimitAvailable: true,
@ -358,7 +355,6 @@ describe('OC.SetupChecks tests', function() {
'Content-Type': 'application/json',
},
JSON.stringify({
suggestedOverwriteCliURL: '',
isFairUseOfFreePushService: true,
isCorrectMemcachedPHPModuleInstalled: false,
isSettimelimitAvailable: true,
@ -401,7 +397,6 @@ describe('OC.SetupChecks tests', function() {
'Content-Type': 'application/json',
},
JSON.stringify({
suggestedOverwriteCliURL: '',
isFairUseOfFreePushService: true,
reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
isCorrectMemcachedPHPModuleInstalled: true,
@ -445,7 +440,6 @@ describe('OC.SetupChecks tests', function() {
'Content-Type': 'application/json',
},
JSON.stringify({
suggestedOverwriteCliURL: '',
isFairUseOfFreePushService: true,
reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
isCorrectMemcachedPHPModuleInstalled: true,
@ -521,7 +515,6 @@ describe('OC.SetupChecks tests', function() {
'Content-Type': 'application/json',
},
JSON.stringify({
suggestedOverwriteCliURL: '',
isFairUseOfFreePushService: true,
isCorrectMemcachedPHPModuleInstalled: true,
isSettimelimitAvailable: true,
@ -571,7 +564,6 @@ describe('OC.SetupChecks tests', function() {
'Content-Type': 'application/json',
},
JSON.stringify({
suggestedOverwriteCliURL: '',
isFairUseOfFreePushService: true,
isCorrectMemcachedPHPModuleInstalled: true,
isSettimelimitAvailable: true,
@ -618,7 +610,6 @@ describe('OC.SetupChecks tests', function() {
'Content-Type': 'application/json',
},
JSON.stringify({
suggestedOverwriteCliURL: '',
isFairUseOfFreePushService: true,
isCorrectMemcachedPHPModuleInstalled: true,
isSettimelimitAvailable: true,
@ -662,7 +653,6 @@ describe('OC.SetupChecks tests', function() {
'Content-Type': 'application/json',
},
JSON.stringify({
suggestedOverwriteCliURL: '',
isFairUseOfFreePushService: true,
isCorrectMemcachedPHPModuleInstalled: true,
isSettimelimitAvailable: true,
@ -703,7 +693,6 @@ describe('OC.SetupChecks tests', function() {
'Content-Type': 'application/json',
},
JSON.stringify({
suggestedOverwriteCliURL: '',
isFairUseOfFreePushService: true,
isCorrectMemcachedPHPModuleInstalled: true,
isSettimelimitAvailable: true,
@ -746,7 +735,6 @@ describe('OC.SetupChecks tests', function() {
'Content-Type': 'application/json',
},
JSON.stringify({
suggestedOverwriteCliURL: '',
isFairUseOfFreePushService: true,
isCorrectMemcachedPHPModuleInstalled: true,
isSettimelimitAvailable: true,
@ -789,7 +777,6 @@ describe('OC.SetupChecks tests', function() {
'Content-Type': 'application/json',
},
JSON.stringify({
suggestedOverwriteCliURL: '',
isFairUseOfFreePushService: true,
isCorrectMemcachedPHPModuleInstalled: true,
isSettimelimitAvailable: true,
@ -839,7 +826,6 @@ describe('OC.SetupChecks tests', function() {
'Content-Type': 'application/json',
},
JSON.stringify({
suggestedOverwriteCliURL: '',
isFairUseOfFreePushService: true,
isCorrectMemcachedPHPModuleInstalled: true,
isSettimelimitAvailable: true,

Loading…
Cancel
Save