From 5d9abb1e11262b5ef7c6f4695590ce5bdb257b85 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 27 Dec 2012 19:20:12 +0400 Subject: [PATCH] add plugin storage table to schema; add ability to clear plugin data --- classes/pluginhost.php | 24 ++++++++++++++++-------- classes/pref/prefs.php | 21 +++++++++++++++++++-- include/functions.php | 21 +-------------------- js/prefs.js | 17 +++++++++++++++++ schema/ttrss_schema_mysql.sql | 9 +++++++++ schema/ttrss_schema_pgsql.sql | 9 ++++++++- schema/versions/mysql/101.sql | 12 ++++++++++++ schema/versions/pgsql/101.sql | 11 +++++++++++ 8 files changed, 93 insertions(+), 31 deletions(-) create mode 100644 schema/versions/mysql/101.sql create mode 100644 schema/versions/pgsql/101.sql diff --git a/classes/pluginhost.php b/classes/pluginhost.php index e43b39f9..d7db7481 100644 --- a/classes/pluginhost.php +++ b/classes/pluginhost.php @@ -1,9 +1,4 @@ load(join(",", $plugins), $kind); + $this->load(join(",", $plugins), $kind, $owner_uid); } function load($classlist, $kind, $owner_uid = false) { @@ -263,7 +258,7 @@ class PluginHost { if ($sync) $this->save_data(get_class($sender)); } - function get($sender, $name, $default_value) { + function get($sender, $name, $default_value = false) { $idx = get_class($sender); if (isset($this->storage[$idx][$name])) { @@ -278,5 +273,18 @@ class PluginHost { return $this->storage[$idx]; } + + function clear_data($sender) { + if ($this->owner_uid) { + $idx = get_class($sender); + + unset($this->storage[$idx]); + + db_query($this->link, "DELETE FROM ttrss_plugin_storage WHERE name = '$idx' + AND owner_uid = " . $this->owner_uid); + + $_SESSION["plugin_storage"] = $this->storage; + } + } } ?> diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php index 0922e43a..bb82b355 100644 --- a/classes/pref/prefs.php +++ b/classes/pref/prefs.php @@ -683,8 +683,9 @@ class Pref_Prefs extends Handler_Protected { $system_enabled = array_map("trim", explode(",", PLUGINS)); $user_enabled = array_map("trim", explode(",", get_pref($this->link, "_ENABLED_PLUGINS"))); - $tmppluginhost = new PluginHost($link); - $tmppluginhost->load_all($tmppluginhost::KIND_ALL); + $tmppluginhost = new PluginHost($this->link); + $tmppluginhost->load_all($tmppluginhost::KIND_ALL, $_SESSION["uid"]); + $tmppluginhost->load_data(true); foreach ($tmppluginhost->get_plugins() as $name => $plugin) { $about = $plugin->about(); @@ -707,6 +708,11 @@ class Pref_Prefs extends Handler_Protected { print "" . htmlspecialchars(sprintf("%.2f", $about[0])) . ""; print "" . htmlspecialchars($about[2]) . ""; + if (count($tmppluginhost->get_all($plugin)) > 0) { + print "".__("Clear data").""; + } + print ""; } @@ -752,6 +758,10 @@ class Pref_Prefs extends Handler_Protected { print "" . htmlspecialchars(sprintf("%.2f", $about[0])) . ""; print "" . htmlspecialchars($about[2]) . ""; + if (count($tmppluginhost->get_all($plugin)) > 0) { + print "".__("Clear data").""; + } + print ""; @@ -846,5 +856,12 @@ class Pref_Prefs extends Handler_Protected { set_pref($this->link, "_ENABLED_PLUGINS", $plugins); } + + function clearplugindata() { + $name = db_escape_string($_REQUEST["name"]); + + global $pluginhost; + $pluginhost->clear_data($pluginhost->get_plugin($name)); + } } ?> diff --git a/include/functions.php b/include/functions.php index b382b406..89e767e2 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1,6 +1,6 @@ authenticate($login, $password); - - if ($user_id) { - $_SESSION["auth_module"] = $module; - break; - } - - } else { - print T_sprintf("Fatal: authentication module %s not found.", $module); - die; - } - } */ global $pluginhost; foreach ($pluginhost->get_hooks($pluginhost::HOOK_AUTH_USER) as $plugin) { diff --git a/js/prefs.js b/js/prefs.js index 0b3f47c0..7ee88ab5 100644 --- a/js/prefs.js +++ b/js/prefs.js @@ -1925,3 +1925,20 @@ function toggleAdvancedPrefs() { exception_error("toggleAdvancedPrefs", e); } } + +function clearPluginData(name) { + try { + if (confirm(__("Clear stored data for this plugin?"))) { + notify_progress("Loading, please wait..."); + + new Ajax.Request("backend.php", { + parameters: "?op=pref-prefs&method=clearplugindata&name=" + param_escape(name), + onComplete: function(transport) { + notify(''); + updatePrefsList(); + } }); + } + } catch (e) { + exception_error("clearPluginData", e); + } +} diff --git a/schema/ttrss_schema_mysql.sql b/schema/ttrss_schema_mysql.sql index bb8bd102..0b0c587b 100644 --- a/schema/ttrss_schema_mysql.sql +++ b/schema/ttrss_schema_mysql.sql @@ -1,6 +1,7 @@ SET NAMES utf8; SET CHARACTER SET utf8; +drop table if exists ttrss_plugin_storage; drop table if exists ttrss_linked_feeds; drop table if exists ttrss_linked_instances; drop table if exists ttrss_access_keys; @@ -528,4 +529,12 @@ create table ttrss_linked_feeds ( subscribers integer not null, foreign key (instance_id) references ttrss_linked_instances(id) ON DELETE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=UTF8; +create table ttrss_plugin_storage ( + id integer not null auto_increment primary key, + name varchar(100) not null, + owner_uid integer not null, + content longtext not null, + foreign key (owner_uid) references ttrss_users(id) ON DELETE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=UTF8; + + commit; diff --git a/schema/ttrss_schema_pgsql.sql b/schema/ttrss_schema_pgsql.sql index 3c508bb3..f52d4191 100644 --- a/schema/ttrss_schema_pgsql.sql +++ b/schema/ttrss_schema_pgsql.sql @@ -1,3 +1,4 @@ +drop table if exists ttrss_plugin_storage; drop table if exists ttrss_linked_feeds; drop table if exists ttrss_linked_instances; drop table if exists ttrss_access_keys; @@ -256,7 +257,7 @@ create index ttrss_tags_post_int_id_idx on ttrss_tags(post_int_id); create table ttrss_version (schema_version int not null); -insert into ttrss_version values (100); +insert into ttrss_version values (101); create table ttrss_enclosures (id serial not null primary key, content_url text not null, @@ -461,4 +462,10 @@ create table ttrss_linked_feeds ( instance_id integer not null references ttrss_linked_instances(id) ON DELETE CASCADE, subscribers integer not null); +create table ttrss_plugin_storage ( + id serial not null primary key, + name varchar(100) not null, + owner_uid integer not null references ttrss_users(id) ON DELETE CASCADE, + content text not null); + commit; diff --git a/schema/versions/mysql/101.sql b/schema/versions/mysql/101.sql new file mode 100644 index 00000000..47ff2652 --- /dev/null +++ b/schema/versions/mysql/101.sql @@ -0,0 +1,12 @@ +begin; + +create table ttrss_plugin_storage ( + id integer not null auto_increment primary key, + name varchar(100) not null, + owner_uid integer not null, + content longtext not null, + foreign key (owner_uid) references ttrss_users(id) ON DELETE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=UTF8; + +update ttrss_version set schema_version = 101; + +commit; diff --git a/schema/versions/pgsql/101.sql b/schema/versions/pgsql/101.sql new file mode 100644 index 00000000..5be85900 --- /dev/null +++ b/schema/versions/pgsql/101.sql @@ -0,0 +1,11 @@ +begin; + +create table ttrss_plugin_storage ( + id serial not null primary key, + name varchar(100) not null, + owner_uid integer not null references ttrss_users(id) ON DELETE CASCADE, + content text not null); + +update ttrss_version set schema_version = 101; + +commit; -- 2.39.5