Skip to content

Adds checking of plugin compatibility#12480

Open
JhonathanLepidus wants to merge 5 commits intopkp:mainfrom
lepidus:pluginCompatibility-i7531
Open

Adds checking of plugin compatibility#12480
JhonathanLepidus wants to merge 5 commits intopkp:mainfrom
lepidus:pluginCompatibility-i7531

Conversation

@JhonathanLepidus
Copy link
Copy Markdown
Contributor

This pull request adds a plugin compatibility check before installation or update.

Thus, each plugin must specify in its version.xml file which applications and their respective versions it is compatible with (from 3.6 and beyond).

This is done through a new node called “compatibility.” It works similarly to the method used in the plugin gallery to indicate plugin compatibility.

Example of version.xml of a plugin compatible with OJS and OPS versions 3.6.0-x:

<version>
	<application>pluginTemplate</application>
	<type>plugins.generic</type>
	<release>1.0.0.0</release>
	<date>2023-05-15</date>
 	<class>PluginTemplatePlugin</class>
 	<compatibility application="ojs2">
		<release>~3.6.0.0</release>
	</compatibility>
 	<compatibility application="ops">
		<release>~3.6.0.0</release>
	</compatibility>
</version>

This pull request addresses a feature requirement described in the issue #7531 and was implemented in the context of the 2026's Plugin Sprint :)

JhonathanLepidus and others added 4 commits March 18, 2026 16:42
Signed-off-by: Jhon <jhon@lepidus.com.br>
Signed-off-by: Thiago <thiago@lepidus.com.br>
Signed-off-by: Jhon <jhon@lepidus.com.br>
Signed-off-by: Thiago <thiago@lepidus.com.br>
Signed-off-by: Jhon <jhon@lepidus.com.br>
Signed-off-by: Thiago <thiago@lepidus.com.br>
Signed-off-by: Jhon <jhon@lepidus.com.br>
Signed-off-by: Thiago <thiago@lepidus.com.br>
Copy link
Copy Markdown
Member

@asmecher asmecher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few minor comments -- these should be applied to the stable-3_5_0 PR too, please! Feel free to take or leave the stylistic suggestions; they are not important.

Comment on lines +162 to +169
/**
* Checks whether the given plugin version is compatible with the current application version.
*
* @param array $versionInfo
*
* @throws Exception if the plugin version is not compatible
*/
public static function checkPluginVersionCompatibility($versionInfo): void
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just stylistic, but unless the self-doc adds something, it's best to just use a typehint.

Suggested change
/**
* Checks whether the given plugin version is compatible with the current application version.
*
* @param array $versionInfo
*
* @throws Exception if the plugin version is not compatible
*/
public static function checkPluginVersionCompatibility($versionInfo): void
/**
* Checks whether the given plugin version is compatible with the current application version.
* @throws Exception if the plugin version is not compatible
*/
public static function checkPluginVersionCompatibility(array $versionInfo): void

throw new Exception(__('manager.plugins.incompatiblePlugin.application'));
}

$compatibleVersions = $compatibility[$application->getName()];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you'll need to prevent a warning here when there are none for this application:

Suggested change
$compatibleVersions = $compatibility[$application->getName()];
$compatibleVersions = $compatibility[$application->getName()] ?? [];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Never mind, I see this is checked above)

Comment on lines +184 to +194
$hasCompatibleVersion = false;
foreach ($compatibleVersions as $compatibleVersion) {
if ($applicationVersion->isCompatible($compatibleVersion)) {
$hasCompatibleVersion = true;
break;
}
}

if (!$hasCompatibleVersion) {
throw new Exception(__('manager.plugins.incompatiblePlugin.version'));
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just stylistic, but you can use an early return:

Suggested change
$hasCompatibleVersion = false;
foreach ($compatibleVersions as $compatibleVersion) {
if ($applicationVersion->isCompatible($compatibleVersion)) {
$hasCompatibleVersion = true;
break;
}
}
if (!$hasCompatibleVersion) {
throw new Exception(__('manager.plugins.incompatiblePlugin.version'));
}
foreach ($compatibleVersions as $compatibleVersion) {
if ($applicationVersion->isCompatible($compatibleVersion)) {
return; // A compatible version was found
}
}
// There was no compatible version found.
throw new Exception(__('manager.plugins.incompatiblePlugin.version'));

Signed-off-by: Jhon <jhon@lepidus.com.br>
Signed-off-by: Thiago <thiago@lepidus.com.br>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants