Re-write code to create/subscribe/activate default kolab folders
with some performance improvements and proper event/task folders activation (Bug #1667)
This commit is contained in:
parent
a26efff495
commit
dfd761f4b9
1 changed files with 42 additions and 12 deletions
|
@ -28,6 +28,7 @@ class kolab_folders extends rcube_plugin
|
||||||
|
|
||||||
public $types = array('mail', 'event', 'journal', 'task', 'note', 'contact', 'configuration', 'file', 'freebusy');
|
public $types = array('mail', 'event', 'journal', 'task', 'note', 'contact', 'configuration', 'file', 'freebusy');
|
||||||
public $mail_types = array('inbox', 'drafts', 'sentitems', 'outbox', 'wastebasket', 'junkemail');
|
public $mail_types = array('inbox', 'drafts', 'sentitems', 'outbox', 'wastebasket', 'junkemail');
|
||||||
|
public $act_types = array('event', 'task');
|
||||||
|
|
||||||
private $rc;
|
private $rc;
|
||||||
private static $instance;
|
private static $instance;
|
||||||
|
@ -86,7 +87,7 @@ class kolab_folders extends rcube_plugin
|
||||||
|
|
||||||
// Create default folders
|
// Create default folders
|
||||||
if ($args['root'] == '' && $args['name'] = '*') {
|
if ($args['root'] == '' && $args['name'] = '*') {
|
||||||
$this->create_default_folders($folders, $args['filter'], $folderdata);
|
$this->create_default_folders($folders, $args['filter'], $folderdata, $args['mode'] == 'LSUB');
|
||||||
}
|
}
|
||||||
|
|
||||||
$args['folders'] = $folders;
|
$args['folders'] = $folders;
|
||||||
|
@ -476,7 +477,7 @@ class kolab_folders extends rcube_plugin
|
||||||
/**
|
/**
|
||||||
* Creates default folders if they doesn't exist
|
* Creates default folders if they doesn't exist
|
||||||
*/
|
*/
|
||||||
private function create_default_folders(&$folders, $filter, $folderdata = null)
|
private function create_default_folders(&$folders, $filter, $folderdata = null, $lsub = false)
|
||||||
{
|
{
|
||||||
$storage = $this->rc->get_storage();
|
$storage = $this->rc->get_storage();
|
||||||
$namespace = $storage->get_namespace();
|
$namespace = $storage->get_namespace();
|
||||||
|
@ -530,25 +531,54 @@ class kolab_folders extends rcube_plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
list($type1, $type2) = explode('.', $type);
|
list($type1, $type2) = explode('.', $type);
|
||||||
$exists = !empty($folderdata[$foldername]) || $foldername == 'INBOX';
|
|
||||||
|
|
||||||
// create folder
|
$activate = in_array($type1, $this->act_types);
|
||||||
if (!$exists && !$storage->folder_exists($foldername)) {
|
$exists = false;
|
||||||
$storage->create_folder($foldername);
|
$result = false;
|
||||||
$storage->subscribe($foldername);
|
|
||||||
|
// check if folder exists
|
||||||
|
if (!empty($folderdata[$foldername]) || $foldername == 'INBOX') {
|
||||||
|
$exists = true;
|
||||||
|
}
|
||||||
|
else if ((!$filter || $filter == $type1) && in_array($foldername, $folders)) {
|
||||||
|
// this assumes also that subscribed folder exists
|
||||||
|
$exists = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$exists = $storage->folder_exists($foldername);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set type
|
// create folder
|
||||||
$result = $this->set_folder_type($foldername, $type);
|
if (!$exists) {
|
||||||
|
$exists = $storage->create_folder($foldername);
|
||||||
|
}
|
||||||
|
|
||||||
|
// set type + subscribe + activate
|
||||||
|
if ($exists) {
|
||||||
|
if ($result = kolab_storage::set_folder_type($foldername, $type)) {
|
||||||
|
// check if folder is subscribed
|
||||||
|
if ((!$filter || $filter == $type1) && $lsub && in_array($foldername, $folders)) {
|
||||||
|
// already subscribed
|
||||||
|
$subscribed = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$subscribed = $storage->subscribe($foldername);
|
||||||
|
}
|
||||||
|
|
||||||
|
// activate folder
|
||||||
|
if ($activate) {
|
||||||
|
kolab_storage::set_state($foldername, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// add new folder to the result
|
// add new folder to the result
|
||||||
if ($result && (!$filter || $filter == $type1)) {
|
if ($result && (!$filter || $filter == $type1) && (!$lsub || $subscribed)) {
|
||||||
$folders[] = $foldername;
|
$folders[] = $foldername;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static getter for default folder of the given type
|
* Static getter for default folder of the given type
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue