summaryrefslogtreecommitdiff
path: root/plugins/kolab_config
diff options
context:
space:
mode:
authorAleksander Machniak <machniak@kolabsys.com>2014-07-31 07:49:28 (GMT)
committerAleksander Machniak <machniak@kolabsys.com>2014-07-31 07:49:28 (GMT)
commitd33af1fac53e04d98bf1775dae552746861778dd (patch)
tree0461731178b53376c1096ae946225169b4f288af /plugins/kolab_config
parent5b7532a124d62fa34733e470afdacfab1e0c3483 (diff)
downloadroundcubemail-plugins-kolab-d33af1fac53e04d98bf1775dae552746861778dd.tar.gz
Add kolab_storage_config class for managing configuration objects
Diffstat (limited to 'plugins/kolab_config')
-rw-r--r--plugins/kolab_config/kolab_config.php75
-rw-r--r--plugins/kolab_config/package.xml6
2 files changed, 33 insertions, 48 deletions
diff --git a/plugins/kolab_config/kolab_config.php b/plugins/kolab_config/kolab_config.php
index 78979ca..d3e6636 100644
--- a/plugins/kolab_config/kolab_config.php
+++ b/plugins/kolab_config/kolab_config.php
@@ -31,10 +31,11 @@ class kolab_config extends rcube_plugin
public $task = 'utils';
private $enabled;
- private $default;
- private $folders;
+ private $config;
private $dicts = array();
+ const O_TYPE = 'dictionary';
+
/**
* Required startup method of a Roundcube plugin
*/
@@ -54,6 +55,8 @@ class kolab_config extends rcube_plugin
$this->add_hook('saved_search_list', array($this, 'saved_search_list'));
$this->add_hook('saved_search_get', array($this, 'saved_search_get'));
*/
+
+ // @TODO: responses (snippets)
}
/**
@@ -61,28 +64,14 @@ class kolab_config extends rcube_plugin
*/
private function load()
{
- // nothing to be done here
- if (isset($this->folders))
+ if ($this->loaded) {
return;
-
- $this->require_plugin('libkolab');
-
- $this->folders = kolab_storage::get_folders('configuration');
- foreach ($this->folders as $folder) {
- if ($folder->default) {
- $this->default = $folder;
- break;
- }
}
- // if no folder is set as default, choose the first one
- if (!$this->default)
- $this->default = reset($this->folders);
+ $this->require_plugin('libkolab');
- // check if configuration folder exist
- if ($this->default && $this->default->name) {
- $this->enabled = true;
- }
+ $this->config = kolab_storage_config::get_instance();
+ $this->loaded = true;
}
/**
@@ -96,24 +85,23 @@ class kolab_config extends rcube_plugin
{
$this->load();
- if (!$this->enabled) {
+ if (!$this->config->is_enabled()) {
return $args;
}
$lang = $args['language'];
$dict = $this->read_dictionary($lang, true);
- $dict['type'] = 'dictionary';
$dict['language'] = $args['language'];
$dict['e'] = $args['dictionary'];
if (empty($dict['e'])) {
// Delete the object
- $this->default->delete($dict);
+ $this->config->delete($dict['uid']);
}
else {
// Update the object
- $this->default->save($dict, 'configuration.dictionary', $dict['uid']);
+ $this->config->save($dict, self::O_TYPE, $dict['uid']);
}
$args['abort'] = true;
@@ -132,7 +120,7 @@ class kolab_config extends rcube_plugin
{
$this->load();
- if (!$this->enabled) {
+ if (!$this->config->is_enabled()) {
return $args;
}
@@ -153,33 +141,30 @@ class kolab_config extends rcube_plugin
*
* @param string The language (2 chars) to load
* @param boolean Only load objects from default folder
+ *
* @return array Dictionary object as hash array
*/
private function read_dictionary($lang, $default = false)
{
- if (isset($this->dicts[$lang]))
+ if (isset($this->dicts[$lang])) {
return $this->dicts[$lang];
+ }
- $query = array(array('type','=','dictionary'), array('tags','=',$lang));
-
- foreach ($this->folders as $folder) {
- // we only want to read from default folder
- if ($default && !$folder->default)
- continue;
-
- foreach ($folder->select($query) as $object) {
- if ($object['type'] == 'dictionary' && ($object['language'] == $lang || $object['language'] == 'XX')) {
- if (is_array($this->dicts[$lang]))
- $this->dicts[$lang]['e'] = array_merge((array)$this->dicts[$lang]['e'], $object['e']);
- else
- $this->dicts[$lang] = $object;
-
- // make sure the default object is cached
- if ($folder->default && $object['language'] != 'XX') {
- $object['e'] = $this->dicts[$lang]['e'];
- $this->dicts[$lang] = $object;
- }
+ $query = array(array('type','=',self::O_TYPE), array('tags','=',$lang));
+
+ foreach ($this->config->get_objects($query, $default) as $object) {
+ if ($object['language'] == $lang || $object['language'] == 'XX') {
+ if (is_array($this->dicts[$lang]))
+ $this->dicts[$lang]['e'] = array_merge((array)$this->dicts[$lang]['e'], $object['e']);
+ else
+ $this->dicts[$lang] = $object;
+/*
+ // make sure the default object is cached
+ if ($folder->default && $object['language'] != 'XX') {
+ $object['e'] = $this->dicts[$lang]['e'];
+ $this->dicts[$lang] = $object;
}
+*/
}
}
diff --git a/plugins/kolab_config/package.xml b/plugins/kolab_config/package.xml
index ac293b0..5e6d307 100644
--- a/plugins/kolab_config/package.xml
+++ b/plugins/kolab_config/package.xml
@@ -16,10 +16,10 @@
<email>machniak@kolabsys.com</email>
<active>yes</active>
</lead>
- <date>2012-05-23</date>
+ <date>2014-07-31</date>
<version>
- <release>2.0</release>
- <api>2.0</api>
+ <release>3.0</release>
+ <api>3.0</api>
</version>
<stability>
<release>stable</release>