aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/lib/plugins/extension
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2024-04-17 16:00:12 +0200
committerAndreas Gohr <andi@splitbrain.org>2024-12-04 10:51:13 +0100
commitb2a05b76de6c1d1e38212dff43776aaa41a22894 (patch)
treee02617211b34b0e38cf570d6789f5423afab1867 /lib/plugins/extension
parent160d3688fe2b70ebe88d464cba3417440127a155 (diff)
downloaddokuwiki-b2a05b76de6c1d1e38212dff43776aaa41a22894.tar.gz
dokuwiki-b2a05b76de6c1d1e38212dff43776aaa41a22894.zip
Extension Manager: ensure php requirements before installing
This makes use of the new minphp and maxphp fields in the info.txt
Diffstat (limited to 'lib/plugins/extension')
-rw-r--r--lib/plugins/extension/Extension.php22
-rw-r--r--lib/plugins/extension/Installer.php26
-rw-r--r--lib/plugins/extension/lang/en/lang.php3
3 files changed, 49 insertions, 2 deletions
diff --git a/lib/plugins/extension/Extension.php b/lib/plugins/extension/Extension.php
index b2dd9abbd..e15c6c302 100644
--- a/lib/plugins/extension/Extension.php
+++ b/lib/plugins/extension/Extension.php
@@ -299,6 +299,28 @@ class Extension
}
/**
+ * Return the minimum PHP version required by the extension
+ *
+ * Empty if not set
+ *
+ * @return string
+ */
+ public function getMinimumPHPVersion()
+ {
+ return $this->getTag('phpmin', '');
+ }
+
+ /**
+ * Return the minimum PHP version supported by the extension
+ *
+ * @return string
+ */
+ public function getMaximumPHPVersion()
+ {
+ return $this->getTag('phpmax', '');
+ }
+
+ /**
* Is this extension a template?
*
* @return bool false if it is a plugin
diff --git a/lib/plugins/extension/Installer.php b/lib/plugins/extension/Installer.php
index 75e836367..1de59cd53 100644
--- a/lib/plugins/extension/Installer.php
+++ b/lib/plugins/extension/Installer.php
@@ -164,7 +164,8 @@ class Installer
$status = self::STATUS_INSTALLED;
}
- // FIXME check PHP requirements
+ // check PHP requirements
+ $this->ensurePhpCompatibility($extension);
// install dependencies first
foreach ($extension->getDependencyList() as $id) {
@@ -310,6 +311,29 @@ class Installer
return $this->processed;
}
+
+ /**
+ * Ensure that the given extension is compatible with the current PHP version
+ *
+ * Throws an exception if the extension is not compatible
+ *
+ * @param Extension $extension
+ * @throws Exception
+ */
+ protected function ensurePhpCompatibility(Extension $extension)
+ {
+ $min = $extension->getMinimumPHPVersion();
+ if ($min && version_compare(PHP_VERSION, $min, '<')) {
+ throw new Exception('error_minphp', [$extension->getId(), $min, PHP_VERSION]);
+ }
+
+ $max = $extension->getMaximumPHPVersion();
+ if ($max && version_compare(PHP_VERSION, $max, '>')) {
+ throw new Exception('error_maxphp', [$extension->getId(), $max, PHP_VERSION]);
+ }
+ }
+
+
/**
* Get a base name from an archive name (we don't trust)
*
diff --git a/lib/plugins/extension/lang/en/lang.php b/lib/plugins/extension/lang/en/lang.php
index 75e391e22..22593865e 100644
--- a/lib/plugins/extension/lang/en/lang.php
+++ b/lib/plugins/extension/lang/en/lang.php
@@ -98,7 +98,8 @@ $lang['error_nourl'] = 'No download URL could be found for exte
$lang['error_notinstalled'] = 'Extension %s is not installed';
$lang['error_alreadyenabled'] = 'Extension %s has already been enabled';
$lang['error_alreadydisabled'] = 'Extension %s has already been disabled';
-
+$lang['error_minphp'] = 'Extension %s requires at least PHP %s but this wiki is running PHP %s';
+$lang['error_maxphp'] = 'Extension %s only supports PHP up to %s but this wiki is running PHP %s';
$lang['noperms'] = 'Extension directory is not writable';
$lang['notplperms'] = 'Template directory is not writable';