mirror of
https://github.com/Mibew/mibew.git
synced 2025-01-30 21:10:29 +03:00
Store plugin initialization status in the database
This commit is contained in:
parent
57afba72e8
commit
cf76dd744d
@ -81,6 +81,7 @@ class PluginInfo
|
||||
$state->version = false;
|
||||
$state->installed = false;
|
||||
$state->enabled = false;
|
||||
$state->initialized = false;
|
||||
}
|
||||
$this->pluginState = $state;
|
||||
}
|
||||
@ -209,6 +210,16 @@ class PluginInfo
|
||||
return new $plugin_class($configs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the plugin is initialized.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isInitialized()
|
||||
{
|
||||
return $this->getState()->initialized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the plugin is enabled.
|
||||
*
|
||||
|
@ -181,12 +181,22 @@ class PluginManager
|
||||
$this->loadedPlugins[$name] = $instance;
|
||||
$running_queue[$instance->getWeight() . "_" . $offset] = $instance;
|
||||
$offset++;
|
||||
if (!$plugin_info->isInitialized()) {
|
||||
$plugin_info->getState()->initialized = true;
|
||||
$plugin_info->getState()->save();
|
||||
# TODO: clear cache
|
||||
}
|
||||
} else {
|
||||
// The plugin cannot be loaded. Just skip it.
|
||||
trigger_error(
|
||||
"Plugin '{$name}' was not initialized correctly!",
|
||||
E_USER_WARNING
|
||||
);
|
||||
if ($plugin_info->isInitialized()) {
|
||||
$plugin_info->getState()->initialized = false;
|
||||
$plugin_info->getState()->save();
|
||||
# TODO: clear cache
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -256,6 +266,7 @@ class PluginManager
|
||||
}
|
||||
|
||||
$plugin->getState()->enabled = false;
|
||||
$plugin->getState()->initialized = false;
|
||||
$plugin->getState()->save();
|
||||
|
||||
return true;
|
||||
|
@ -193,6 +193,7 @@ class State
|
||||
$this->version = null;
|
||||
$this->installed = false;
|
||||
$this->enabled = false;
|
||||
$this->initialized = false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -205,13 +206,14 @@ class State
|
||||
if (!$this->id) {
|
||||
// This state is new.
|
||||
$db->query(
|
||||
("INSERT INTO {plugin} (name, version, installed, enabled) "
|
||||
. "VALUES (:name, :version, :installed, :enabled)"),
|
||||
("INSERT INTO {plugin} (name, version, installed, enabled, initialized) "
|
||||
. "VALUES (:name, :version, :installed, :enabled, :initialized)"),
|
||||
array(
|
||||
':name' => $this->pluginName,
|
||||
':version' => $this->version,
|
||||
':installed' => (int)$this->installed,
|
||||
':enabled' => (int)$this->enabled,
|
||||
':initialized' => (int)$this->initialized,
|
||||
)
|
||||
);
|
||||
$this->id = $db->insertedId();
|
||||
@ -219,13 +221,14 @@ class State
|
||||
// Update existing state
|
||||
$db->query(
|
||||
("UPDATE {plugin} SET name = :name, version = :version, "
|
||||
. "installed = :installed, enabled = :enabled WHERE id = :id"),
|
||||
. "installed = :installed, enabled = :enabled, initialized = :initialized WHERE id = :id"),
|
||||
array(
|
||||
':id' => $this->id,
|
||||
':name' => $this->pluginName,
|
||||
':version' => $this->version,
|
||||
':installed' => (int)$this->installed,
|
||||
':enabled' => (int)$this->enabled,
|
||||
':initialized' => (int)$this->initialized,
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -261,5 +264,6 @@ class State
|
||||
$this->version = $db_fields['version'];
|
||||
$this->enabled = (bool)$db_fields['enabled'];
|
||||
$this->installed = (bool)$db_fields['installed'];
|
||||
$this->initialized = (bool)$db_fields['initialized'];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user