implement plugin API version compatibility check
This commit is contained in:
parent
726bd48e8c
commit
ddf28801e4
|
@ -3,6 +3,8 @@ class Plugin {
|
||||||
private $dbh;
|
private $dbh;
|
||||||
private $host;
|
private $host;
|
||||||
|
|
||||||
|
const API_VERSION_COMPAT = 1;
|
||||||
|
|
||||||
function init($host) {
|
function init($host) {
|
||||||
$this->dbh = $host->get_dbh();
|
$this->dbh = $host->get_dbh();
|
||||||
$this->host = $host;
|
$this->host = $host;
|
||||||
|
@ -20,5 +22,9 @@ class Plugin {
|
||||||
function get_prefs_js() {
|
function get_prefs_js() {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function api_version() {
|
||||||
|
return Plugin::API_VERSION_COMPAT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -13,6 +13,8 @@ class PluginHost {
|
||||||
private $last_registered;
|
private $last_registered;
|
||||||
private static $instance;
|
private static $instance;
|
||||||
|
|
||||||
|
const API_VERSION = 1;
|
||||||
|
|
||||||
const HOOK_ARTICLE_BUTTON = 1;
|
const HOOK_ARTICLE_BUTTON = 1;
|
||||||
const HOOK_ARTICLE_FILTER = 2;
|
const HOOK_ARTICLE_FILTER = 2;
|
||||||
const HOOK_PREFS_TAB = 3;
|
const HOOK_PREFS_TAB = 3;
|
||||||
|
@ -137,6 +139,13 @@ class PluginHost {
|
||||||
if (class_exists($class) && is_subclass_of($class, "Plugin")) {
|
if (class_exists($class) && is_subclass_of($class, "Plugin")) {
|
||||||
$plugin = new $class($this);
|
$plugin = new $class($this);
|
||||||
|
|
||||||
|
$plugin_api = $plugin->api_version();
|
||||||
|
|
||||||
|
if ($plugin_api < PluginHost::API_VERSION) {
|
||||||
|
user_error("Plugin $class is not compatible with current API version (need: " . PluginHost::API_VERSION . ", got: $plugin_api)", E_USER_WARNING);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$this->last_registered = $class;
|
$this->last_registered = $class;
|
||||||
|
|
||||||
switch ($kind) {
|
switch ($kind) {
|
||||||
|
|
Loading…
Reference in New Issue