pluginhost: load plugin data automatically (also marks load_data method as private)

This commit is contained in:
Andrew Dolgov 2021-01-15 08:32:06 +03:00
parent f67f0f864b
commit 40f38fc87f
7 changed files with 18 additions and 11 deletions

View File

@ -29,7 +29,7 @@ class Article extends Handler_Protected {
if (!$content) {
$pluginhost = new PluginHost();
$pluginhost->load_all(PluginHost::KIND_ALL, $owner_uid);
$pluginhost->load_data();
//$pluginhost->load_data();
foreach ($pluginhost->get_hooks(PluginHost::HOOK_GET_FULL_TEXT) as $p) {
$extracted_content = $p->hook_get_full_text($url);

View File

@ -395,7 +395,7 @@ class DiskCache {
$tmppluginhost = new PluginHost();
$tmppluginhost->load(PLUGINS, PluginHost::KIND_SYSTEM);
$tmppluginhost->load_data();
//$tmppluginhost->load_data();
foreach ($tmppluginhost->get_hooks(PluginHost::HOOK_SEND_LOCAL_FILE) as $plugin) {
if ($plugin->hook_send_local_file($filename)) return true;

View File

@ -45,7 +45,7 @@ class Handler_Public extends Handler {
$tmppluginhost = new PluginHost();
$tmppluginhost->load(PLUGINS, PluginHost::KIND_ALL);
$tmppluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid);
$tmppluginhost->load_data();
//$tmppluginhost->load_data();
$handler = $tmppluginhost->get_feed_handler(
PluginHost::feed_to_pfeed_id($feed));
@ -1246,7 +1246,7 @@ class Handler_Public extends Handler {
$method = clean($_REQUEST["pmethod"]);
$host->load($plugin_name, PluginHost::KIND_USER, 0);
$host->load_data();
//$host->load_data();
$plugin = $host->get_plugin($plugin_name);

View File

@ -14,6 +14,7 @@ class PluginHost {
private $plugin_actions = array();
private $owner_uid;
private $last_registered;
private $data_loaded;
private static $instance;
const API_VERSION = 2;
@ -268,6 +269,8 @@ class PluginHost {
}
}
}
$this->load_data();
}
function is_system($plugin) {
@ -352,8 +355,8 @@ class PluginHost {
}
}
function load_data() {
if ($this->owner_uid) {
private function load_data() {
if (get_schema_version() > 100 && $this->owner_uid && !$this->data_loaded) {
$sth = $this->pdo->prepare("SELECT name, content FROM ttrss_plugin_storage
WHERE owner_uid = ?");
$sth->execute([$this->owner_uid]);
@ -361,6 +364,8 @@ class PluginHost {
while ($line = $sth->fetch()) {
$this->storage[$line["name"]] = unserialize($line["content"]);
}
$this->data_loaded = true;
}
}
@ -411,6 +416,8 @@ class PluginHost {
function get($sender, $name, $default_value = false) {
$idx = get_class($sender);
$this->load_data();
if (isset($this->storage[$idx][$name])) {
return $this->storage[$idx][$name];
} else {

View File

@ -911,7 +911,7 @@ class Pref_Prefs extends Handler_Protected {
$tmppluginhost = new PluginHost();
$tmppluginhost->load_all($tmppluginhost::KIND_ALL, $_SESSION["uid"], true);
$tmppluginhost->load_data(true);
//$tmppluginhost->load_data(true);
foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
$about = $plugin->about();

View File

@ -276,7 +276,7 @@ class RSSUtils {
$pluginhost->load(PLUGINS, PluginHost::KIND_ALL);
$pluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid);
$pluginhost->load_data();
//$pluginhost->load_data();
$basic_info = array();
foreach ($pluginhost->get_hooks(PluginHost::HOOK_FEED_BASIC_INFO) as $plugin) {
@ -403,7 +403,7 @@ class RSSUtils {
$pluginhost->load(PLUGINS, PluginHost::KIND_ALL);
$pluginhost->load($user_plugins, PluginHost::KIND_USER, $owner_uid);
$pluginhost->load_data();
//$pluginhost->load_data();
$rss_hash = false;

View File

@ -80,9 +80,9 @@ class UserHelper {
$pluginhost->load($plugins, PluginHost::KIND_USER, $owner_uid);
if (get_schema_version() > 100) {
/*if (get_schema_version() > 100) {
$pluginhost->load_data();
}
}*/
}
}