Skip to content

Commit

Permalink
Migrate PHP imagick module check to new SetupCheck API
Browse files Browse the repository at this point in the history
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
  • Loading branch information
come-nc committed Jan 11, 2024
1 parent 744720b commit d1f2add
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 98 deletions.
15 changes: 0 additions & 15 deletions apps/settings/lib/Controller/CheckSetupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,15 +342,6 @@ private function isTemporaryDirectoryWritable(): bool {
return false;
}

protected function isImagickEnabled(): bool {
if ($this->config->getAppValue('theming', 'enabled', 'no') === 'yes') {
if (!extension_loaded('imagick')) {
return false;
}
}
return true;
}

protected function areWebauthnExtensionsEnabled(): bool {
if (!extension_loaded('bcmath')) {
return false;
Expand Down Expand Up @@ -401,10 +392,6 @@ protected function isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed(): bool {
return false;
}

protected function imageMagickLacksSVGSupport(): bool {
return extension_loaded('imagick') && count(\Imagick::queryFormats('SVG')) === 0;
}

/**
* @return DataResponse
* @AuthorizedAdminSetting(settings=OCA\Settings\Settings\Admin\Overview)
Expand All @@ -422,12 +409,10 @@ public function check() {
'hasPassedCodeIntegrityCheck' => $this->checker->hasPassedCheck(),
'codeIntegrityCheckerDocumentation' => $this->urlGenerator->linkToDocs('admin-code-integrity'),
'isSettimelimitAvailable' => $this->isSettimelimitAvailable(),
'isImagickEnabled' => $this->isImagickEnabled(),
'areWebauthnExtensionsEnabled' => $this->areWebauthnExtensionsEnabled(),
'isMysqlUsedWithoutUTF8MB4' => $this->isMysqlUsedWithoutUTF8MB4(),
'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed' => $this->isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed(),
'reverseProxyGeneratedURL' => $this->urlGenerator->getAbsoluteURL('index.php'),
'imageMagickLacksSVGSupport' => $this->imageMagickLacksSVGSupport(),
'temporaryDirectoryWritable' => $this->isTemporaryDirectoryWritable(),
'generic' => $this->setupCheckManager->runAll(),
]
Expand Down
8 changes: 0 additions & 8 deletions apps/settings/tests/Controller/CheckSetupControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ protected function setUp(): void {
'getCurlVersion',
'isPhpOutdated',
'isPHPMailerUsed',
'isImagickEnabled',
'areWebauthnExtensionsEnabled',
'isMysqlUsedWithoutUTF8MB4',
'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed',
Expand Down Expand Up @@ -197,11 +196,6 @@ public function testCheck() {
->method('hasPassedCheck')
->willReturn(true);

$this->checkSetupController
->expects($this->once())
->method('isImagickEnabled')
->willReturn(false);

$this->checkSetupController
->expects($this->once())
->method('areWebauthnExtensionsEnabled')
Expand Down Expand Up @@ -263,12 +257,10 @@ public function testCheck() {
'hasPassedCodeIntegrityCheck' => true,
'codeIntegrityCheckerDocumentation' => 'http://docs.example.org/server/go.php?to=admin-code-integrity',
'isSettimelimitAvailable' => true,
'isImagickEnabled' => false,
'areWebauthnExtensionsEnabled' => false,
'isMysqlUsedWithoutUTF8MB4' => false,
'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed' => true,
'reverseProxyGeneratedURL' => 'https://server/index.php',
'imageMagickLacksSVGSupport' => false,
'isFairUseOfFreePushService' => false,
'temporaryDirectoryWritable' => false,
'generic' => [],
Expand Down
1 change: 1 addition & 0 deletions apps/theming/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
'OCA\\Theming\\Settings\\AdminSection' => $baseDir . '/../lib/Settings/AdminSection.php',
'OCA\\Theming\\Settings\\Personal' => $baseDir . '/../lib/Settings/Personal.php',
'OCA\\Theming\\Settings\\PersonalSection' => $baseDir . '/../lib/Settings/PersonalSection.php',
'OCA\\Theming\\SetupChecks\\PhpImagickModule' => $baseDir . '/../lib/SetupChecks/PhpImagickModule.php',
'OCA\\Theming\\Themes\\CommonThemeTrait' => $baseDir . '/../lib/Themes/CommonThemeTrait.php',
'OCA\\Theming\\Themes\\DarkHighContrastTheme' => $baseDir . '/../lib/Themes/DarkHighContrastTheme.php',
'OCA\\Theming\\Themes\\DarkTheme' => $baseDir . '/../lib/Themes/DarkTheme.php',
Expand Down
1 change: 1 addition & 0 deletions apps/theming/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class ComposerStaticInitTheming
'OCA\\Theming\\Settings\\AdminSection' => __DIR__ . '/..' . '/../lib/Settings/AdminSection.php',
'OCA\\Theming\\Settings\\Personal' => __DIR__ . '/..' . '/../lib/Settings/Personal.php',
'OCA\\Theming\\Settings\\PersonalSection' => __DIR__ . '/..' . '/../lib/Settings/PersonalSection.php',
'OCA\\Theming\\SetupChecks\\PhpImagickModule' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpImagickModule.php',
'OCA\\Theming\\Themes\\CommonThemeTrait' => __DIR__ . '/..' . '/../lib/Themes/CommonThemeTrait.php',
'OCA\\Theming\\Themes\\DarkHighContrastTheme' => __DIR__ . '/..' . '/../lib/Themes/DarkHighContrastTheme.php',
'OCA\\Theming\\Themes\\DarkTheme' => __DIR__ . '/..' . '/../lib/Themes/DarkTheme.php',
Expand Down
2 changes: 2 additions & 0 deletions apps/theming/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use OCA\Theming\Capabilities;
use OCA\Theming\Listener\BeforePreferenceListener;
use OCA\Theming\Listener\BeforeTemplateRenderedListener;
use OCA\Theming\SetupChecks\PhpImagickModule;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
Expand All @@ -49,6 +50,7 @@ public function register(IRegistrationContext $context): void {
$context->registerEventListener(BeforeLoginTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
$context->registerEventListener(BeforePreferenceSetEvent::class, BeforePreferenceListener::class);
$context->registerEventListener(BeforePreferenceDeletedEvent::class, BeforePreferenceListener::class);
$context->registerSetupCheck(PhpImagickModule::class);
}

public function boot(IBootContext $context): void {
Expand Down
63 changes: 63 additions & 0 deletions apps/theming/lib/SetupChecks/PhpImagickModule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?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\Theming\SetupChecks;

use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\SetupCheck\ISetupCheck;
use OCP\SetupCheck\SetupResult;

class PhpImagickModule implements ISetupCheck {
public function __construct(
private IL10N $l10n,
private IURLGenerator $urlGenerator,
) {
}

public function getName(): string {
return $this->l10n->t('PHP Imagick module');
}

public function getCategory(): string {
return 'php';
}

public function run(): SetupResult {
if (!extension_loaded('imagick')) {
return SetupResult::info(
$this->l10n->t('The PHP module "imagick" is not enabled although the theming app is. For favicon generation to work correctly, you need to install and enable this module.'),
$this->urlGenerator->linkToDocs('admin-php-modules')
);
} elseif (count(\Imagick::queryFormats('SVG')) === 0) {
return SetupResult::info(
$this->l10n->t('The PHP module "imagick" in this instance has no SVG support. For better compatibility it is recommended to install it.'),
$this->urlGenerator->linkToDocs('admin-php-modules')
);
} else {
return SetupResult::success();
}
}
}
15 changes: 0 additions & 15 deletions core/js/setupchecks.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,6 @@
type: OC.SetupChecks.MESSAGE_TYPE_WARNING
});
}
if (!data.isImagickEnabled) {
messages.push({
msg: t(
'core',
'The PHP module "imagick" is not enabled although the theming app is. For favicon generation to work correctly, you need to install and enable this module.'
),
type: OC.SetupChecks.MESSAGE_TYPE_INFO
})
}
if (!data.areWebauthnExtensionsEnabled) {
messages.push({
msg: t(
Expand All @@ -264,12 +255,6 @@
type: OC.SetupChecks.MESSAGE_TYPE_INFO
})
}
if (data.imageMagickLacksSVGSupport) {
messages.push({
msg: t('core', 'Module php-imagick in this instance has no SVG support. For better compatibility it is recommended to install it.'),
type: OC.SetupChecks.MESSAGE_TYPE_INFO
})
}

if (data.isMysqlUsedWithoutUTF8MB4) {
messages.push({
Expand Down
60 changes: 0 additions & 60 deletions core/js/tests/specs/setupchecksSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ describe('OC.SetupChecks tests', function() {
cronInfo: {
diffInSeconds: 0
},
isImagickEnabled: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
Expand Down Expand Up @@ -279,7 +278,6 @@ describe('OC.SetupChecks tests', function() {
cronInfo: {
diffInSeconds: 0
},
isImagickEnabled: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
Expand Down Expand Up @@ -326,7 +324,6 @@ describe('OC.SetupChecks tests', function() {
cronInfo: {
diffInSeconds: 0
},
isImagickEnabled: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
Expand Down Expand Up @@ -373,7 +370,6 @@ describe('OC.SetupChecks tests', function() {
cronInfo: {
diffInSeconds: 0
},
isImagickEnabled: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
Expand Down Expand Up @@ -419,7 +415,6 @@ describe('OC.SetupChecks tests', function() {
cronInfo: {
diffInSeconds: 0
},
isImagickEnabled: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
Expand Down Expand Up @@ -465,7 +460,6 @@ describe('OC.SetupChecks tests', function() {
cronInfo: {
diffInSeconds: 0
},
isImagickEnabled: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
Expand Down Expand Up @@ -542,7 +536,6 @@ describe('OC.SetupChecks tests', function() {
cronInfo: {
diffInSeconds: 0
},
isImagickEnabled: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
Expand Down Expand Up @@ -594,7 +587,6 @@ describe('OC.SetupChecks tests', function() {
cronInfo: {
diffInSeconds: 0
},
isImagickEnabled: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: true,
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
Expand Down Expand Up @@ -643,7 +635,6 @@ describe('OC.SetupChecks tests', function() {
cronInfo: {
diffInSeconds: 0
},
isImagickEnabled: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
Expand Down Expand Up @@ -689,7 +680,6 @@ describe('OC.SetupChecks tests', function() {
cronInfo: {
diffInSeconds: 0
},
isImagickEnabled: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
Expand Down Expand Up @@ -732,7 +722,6 @@ describe('OC.SetupChecks tests', function() {
cronInfo: {
diffInSeconds: 0
},
isImagickEnabled: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: false,
Expand Down Expand Up @@ -760,52 +749,6 @@ describe('OC.SetupChecks tests', function() {
});


it('should return an error if imagick is not enabled', function(done) {
var async = OC.SetupChecks.checkSetup();

suite.server.requests[0].respond(
200,
{
'Content-Type': 'application/json',
},
JSON.stringify({
suggestedOverwriteCliURL: '',
isFairUseOfFreePushService: true,
isCorrectMemcachedPHPModuleInstalled: true,
hasPassedCodeIntegrityCheck: true,
isSettimelimitAvailable: true,
cronErrors: [],
cronInfo: {
diffInSeconds: 0
},
isImagickEnabled: false,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
reverseProxyGeneratedURL: 'https://server',
temporaryDirectoryWritable: true,
generic: {
network: {
"Internet connectivity": {
severity: "success",
description: null,
linkToDoc: null
}
},
},
})
);

async.done(function( data, s, x ){
expect(data).toEqual([{
msg: 'The PHP module "imagick" is not enabled although the theming app is. For favicon generation to work correctly, you need to install and enable this module.',
type: OC.SetupChecks.MESSAGE_TYPE_INFO
}]);
done();
});
});


it('should return an error if gmp or bcmath are not enabled', function(done) {
var async = OC.SetupChecks.checkSetup();

Expand All @@ -824,7 +767,6 @@ describe('OC.SetupChecks tests', function() {
cronInfo: {
diffInSeconds: 0
},
isImagickEnabled: true,
areWebauthnExtensionsEnabled: false,
isMysqlUsedWithoutUTF8MB4: false,
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
Expand Down Expand Up @@ -869,7 +811,6 @@ describe('OC.SetupChecks tests', function() {
cronInfo: {
diffInSeconds: 0
},
isImagickEnabled: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
Expand Down Expand Up @@ -921,7 +862,6 @@ describe('OC.SetupChecks tests', function() {
cronInfo: {
diffInSeconds: 0
},
isImagickEnabled: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
Expand Down

0 comments on commit d1f2add

Please sign in to comment.