Fix inconsistency in handling other users "root" folders (Bifrost#T203416)
Refactored some code to make sure we always deal with kolab_calendar instances.
This commit is contained in:
parent
1d72a95549
commit
3a2240a13d
1 changed files with 73 additions and 69 deletions
|
@ -91,24 +91,38 @@ class kolab_driver extends calendar_driver
|
||||||
|
|
||||||
$this->calendars = array();
|
$this->calendars = array();
|
||||||
foreach ($folders as $folder) {
|
foreach ($folders as $folder) {
|
||||||
if ($folder instanceof kolab_storage_folder_user) {
|
$calendar = $this->_to_calendar($folder);
|
||||||
$calendar = new kolab_user_calendar($folder, $this->cal);
|
|
||||||
$calendar->subscriptions = count($folder->children) > 0;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$calendar = new kolab_calendar($folder->name, $this->cal);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($calendar->ready) {
|
if ($calendar->ready) {
|
||||||
$this->calendars[$calendar->id] = $calendar;
|
$this->calendars[$calendar->id] = $calendar;
|
||||||
if ($calendar->editable)
|
if ($calendar->editable) {
|
||||||
$this->has_writeable = true;
|
$this->has_writeable = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->calendars;
|
return $this->calendars;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert kolab_storage_folder into kolab_calendar
|
||||||
|
*/
|
||||||
|
private function _to_calendar($folder)
|
||||||
|
{
|
||||||
|
if ($folder instanceof kolab_calendar) {
|
||||||
|
return $folder;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($folder instanceof kolab_storage_folder_user) {
|
||||||
|
$calendar = new kolab_user_calendar($folder, $this->cal);
|
||||||
|
$calendar->subscriptions = count($folder->children) > 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$calendar = new kolab_calendar($folder->name, $this->cal);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $calendar;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of available calendars from this source
|
* Get a list of available calendars from this source
|
||||||
*
|
*
|
||||||
|
@ -129,17 +143,17 @@ class kolab_driver extends calendar_driver
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$delim = $this->rc->get_storage()->get_hierarchy_delimiter();
|
$delim = $this->rc->get_storage()->get_hierarchy_delimiter();
|
||||||
$folders = $this->filter_calendars($filter);
|
$folders = $this->filter_calendars($filter);
|
||||||
$calendars = array();
|
$calendars = array();
|
||||||
|
|
||||||
// include virtual folders for a full folder tree
|
// include virtual folders for a full folder tree
|
||||||
if (!is_null($tree))
|
if (!is_null($tree))
|
||||||
$folders = kolab_storage::folder_hierarchy($folders, $tree);
|
$folders = kolab_storage::folder_hierarchy($folders, $tree);
|
||||||
|
|
||||||
|
$parents = array_keys($this->calendars);
|
||||||
|
|
||||||
foreach ($folders as $id => $cal) {
|
foreach ($folders as $id => $cal) {
|
||||||
$fullname = $cal->get_name();
|
|
||||||
$listname = $cal->get_foldername();
|
|
||||||
$imap_path = explode($delim, $cal->name);
|
$imap_path = explode($delim, $cal->name);
|
||||||
|
|
||||||
// find parent
|
// find parent
|
||||||
|
@ -147,72 +161,60 @@ class kolab_driver extends calendar_driver
|
||||||
array_pop($imap_path);
|
array_pop($imap_path);
|
||||||
$parent_id = kolab_storage::folder_id(join($delim, $imap_path));
|
$parent_id = kolab_storage::folder_id(join($delim, $imap_path));
|
||||||
}
|
}
|
||||||
while (count($imap_path) > 1 && !$this->calendars[$parent_id]);
|
while (count($imap_path) > 1 && !in_array($parent_id, $parents));
|
||||||
|
|
||||||
// restore "real" parent ID
|
// restore "real" parent ID
|
||||||
if ($parent_id && !$this->calendars[$parent_id]) {
|
if ($parent_id && !in_array($parent_id, $parents)) {
|
||||||
$parent_id = kolab_storage::folder_id($cal->get_parent());
|
$parent_id = kolab_storage::folder_id($cal->get_parent());
|
||||||
}
|
}
|
||||||
|
|
||||||
// turn a kolab_storage_folder object into a kolab_calendar
|
$parents[] = $cal->id;
|
||||||
if ($cal instanceof kolab_storage_folder) {
|
|
||||||
$cal = new kolab_calendar($cal->name, $this->cal);
|
|
||||||
$this->calendars[$cal->id] = $cal;
|
|
||||||
}
|
|
||||||
|
|
||||||
// special handling for user or virtual folders
|
if ($cal->virtual) {
|
||||||
if ($cal instanceof kolab_storage_folder_user) {
|
|
||||||
$calendars[$cal->id] = array(
|
$calendars[$cal->id] = array(
|
||||||
'id' => $cal->id,
|
'id' => $cal->id,
|
||||||
'name' => $fullname,
|
'name' => $cal->get_name(),
|
||||||
'listname' => $listname,
|
'listname' => $cal->get_foldername(),
|
||||||
'editname' => $cal->get_foldername(),
|
|
||||||
'color' => $cal->get_color(),
|
|
||||||
'active' => $cal->is_active(),
|
|
||||||
'title' => $cal->get_title(),
|
|
||||||
'owner' => $cal->get_owner(),
|
|
||||||
'history' => false,
|
|
||||||
'virtual' => false,
|
|
||||||
'editable' => false,
|
|
||||||
'group' => 'other',
|
|
||||||
'class' => 'user',
|
|
||||||
'removable' => true,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else if ($cal->virtual) {
|
|
||||||
$calendars[$cal->id] = array(
|
|
||||||
'id' => $cal->id,
|
|
||||||
'name' => $fullname,
|
|
||||||
'listname' => $listname,
|
|
||||||
'editname' => $cal->get_foldername(),
|
'editname' => $cal->get_foldername(),
|
||||||
'virtual' => true,
|
'virtual' => true,
|
||||||
'editable' => false,
|
'editable' => false,
|
||||||
'group' => $cal->get_namespace(),
|
'group' => $cal->get_namespace(),
|
||||||
'class' => 'folder',
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// additional folders may come from kolab_storage::folder_hierarchy() above
|
||||||
|
// make sure we deal with kolab_calendar instances
|
||||||
|
$cal = $this->_to_calendar($cal);
|
||||||
|
$this->calendars[$cal->id] = $cal;
|
||||||
|
|
||||||
|
$is_user = ($cal instanceof kolab_user_calendar);
|
||||||
|
|
||||||
$calendars[$cal->id] = array(
|
$calendars[$cal->id] = array(
|
||||||
'id' => $cal->id,
|
'id' => $cal->id,
|
||||||
'name' => $fullname,
|
'name' => $cal->get_name(),
|
||||||
'listname' => $listname,
|
'listname' => $cal->get_foldername(),
|
||||||
'editname' => $cal->get_foldername(),
|
'editname' => $cal->get_foldername(),
|
||||||
'title' => $cal->get_title(),
|
'title' => $cal->get_title(),
|
||||||
'color' => $cal->get_color(),
|
'color' => $cal->get_color(),
|
||||||
'editable' => $cal->editable,
|
'editable' => $cal->editable,
|
||||||
'rights' => $cal->rights,
|
'group' => $is_user ? 'other user' : $cal->get_namespace(),
|
||||||
'showalarms' => $cal->alarms,
|
'active' => $cal->is_active(),
|
||||||
'history' => !empty($this->bonnie_api),
|
'owner' => $cal->get_owner(),
|
||||||
'group' => $cal->get_namespace(),
|
|
||||||
'default' => $cal->default,
|
|
||||||
'active' => $cal->is_active(),
|
|
||||||
'owner' => $cal->get_owner(),
|
|
||||||
'children' => true, // TODO: determine if that folder indeed has child folders
|
|
||||||
'parent' => $parent_id,
|
|
||||||
'subtype' => $cal->subtype,
|
|
||||||
'caldavurl' => $cal->get_caldav_url(),
|
|
||||||
'removable' => !$cal->default,
|
'removable' => !$cal->default,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!$is_user) {
|
||||||
|
$calendars[$cal->id] += array(
|
||||||
|
'default' => $cal->default,
|
||||||
|
'rights' => $cal->rights,
|
||||||
|
'showalarms' => $cal->alarms,
|
||||||
|
'history' => !empty($this->bonnie_api),
|
||||||
|
'children' => true, // TODO: determine if that folder indeed has child folders
|
||||||
|
'parent' => $parent_id,
|
||||||
|
'subtype' => $cal->subtype,
|
||||||
|
'caldavurl' => $cal->get_caldav_url(),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($cal->subscriptions) {
|
if ($cal->subscriptions) {
|
||||||
|
@ -224,7 +226,6 @@ class kolab_driver extends calendar_driver
|
||||||
if ($this->rc->config->get('kolab_invitation_calendars') && !($filter & self::FILTER_INSERTABLE)) {
|
if ($this->rc->config->get('kolab_invitation_calendars') && !($filter & self::FILTER_INSERTABLE)) {
|
||||||
foreach (array(self::INVITATIONS_CALENDAR_PENDING, self::INVITATIONS_CALENDAR_DECLINED) as $id) {
|
foreach (array(self::INVITATIONS_CALENDAR_PENDING, self::INVITATIONS_CALENDAR_DECLINED) as $id) {
|
||||||
$cal = new kolab_invitation_calendar($id, $this->cal);
|
$cal = new kolab_invitation_calendar($id, $this->cal);
|
||||||
$this->calendars[$cal->id] = $cal;
|
|
||||||
if (!($filter & self::FILTER_ACTIVE) || $cal->is_active()) {
|
if (!($filter & self::FILTER_ACTIVE) || $cal->is_active()) {
|
||||||
$calendars[$id] = array(
|
$calendars[$id] = array(
|
||||||
'id' => $cal->id,
|
'id' => $cal->id,
|
||||||
|
@ -268,7 +269,7 @@ class kolab_driver extends calendar_driver
|
||||||
'active' => (bool)$prefs[$id]['active'],
|
'active' => (bool)$prefs[$id]['active'],
|
||||||
'showalarms' => (bool)$this->rc->config->get('calendar_birthdays_alarm_type'),
|
'showalarms' => (bool)$this->rc->config->get('calendar_birthdays_alarm_type'),
|
||||||
'group' => 'x-birthdays',
|
'group' => 'x-birthdays',
|
||||||
'editable' => false,
|
'editable' => false,
|
||||||
'default' => false,
|
'default' => false,
|
||||||
'children' => false,
|
'children' => false,
|
||||||
'history' => false,
|
'history' => false,
|
||||||
|
@ -337,11 +338,11 @@ class kolab_driver extends calendar_driver
|
||||||
return $calendars;
|
return $calendars;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the kolab_calendar instance for the given calendar ID
|
* Get the kolab_calendar instance for the given calendar ID
|
||||||
*
|
*
|
||||||
* @param string Calendar identifier (encoded imap folder name)
|
* @param string Calendar identifier (encoded imap folder name)
|
||||||
|
*
|
||||||
* @return object kolab_calendar Object nor null if calendar doesn't exist
|
* @return object kolab_calendar Object nor null if calendar doesn't exist
|
||||||
*/
|
*/
|
||||||
public function get_calendar($id)
|
public function get_calendar($id)
|
||||||
|
@ -351,9 +352,10 @@ class kolab_driver extends calendar_driver
|
||||||
// create calendar object if necesary
|
// create calendar object if necesary
|
||||||
if (!$this->calendars[$id]) {
|
if (!$this->calendars[$id]) {
|
||||||
if (in_array($id, array(self::INVITATIONS_CALENDAR_PENDING, self::INVITATIONS_CALENDAR_DECLINED))) {
|
if (in_array($id, array(self::INVITATIONS_CALENDAR_PENDING, self::INVITATIONS_CALENDAR_DECLINED))) {
|
||||||
$this->calendars[$id] = new kolab_invitation_calendar($id, $this->cal);
|
return new kolab_invitation_calendar($id, $this->cal);
|
||||||
}
|
}
|
||||||
else if ($id !== self::BIRTHDAY_CALENDAR_ID) {
|
// for unsubscribed calendar folders
|
||||||
|
if ($id !== self::BIRTHDAY_CALENDAR_ID) {
|
||||||
$calendar = kolab_calendar::factory($id, $this->cal);
|
$calendar = kolab_calendar::factory($id, $this->cal);
|
||||||
if ($calendar->ready) {
|
if ($calendar->ready) {
|
||||||
$this->calendars[$calendar->id] = $calendar;
|
$this->calendars[$calendar->id] = $calendar;
|
||||||
|
@ -370,13 +372,15 @@ class kolab_driver extends calendar_driver
|
||||||
* @param array Hash array with calendar properties
|
* @param array Hash array with calendar properties
|
||||||
* name: Calendar name
|
* name: Calendar name
|
||||||
* color: The color of the calendar
|
* color: The color of the calendar
|
||||||
|
*
|
||||||
* @return mixed ID of the calendar on success, False on error
|
* @return mixed ID of the calendar on success, False on error
|
||||||
*/
|
*/
|
||||||
public function create_calendar($prop)
|
public function create_calendar($prop)
|
||||||
{
|
{
|
||||||
$prop['type'] = 'event';
|
$prop['type'] = 'event';
|
||||||
$prop['active'] = true;
|
$prop['active'] = true;
|
||||||
$prop['subscribed'] = true;
|
$prop['subscribed'] = true;
|
||||||
|
|
||||||
$folder = kolab_storage::folder_update($prop);
|
$folder = kolab_storage::folder_update($prop);
|
||||||
|
|
||||||
if ($folder === false) {
|
if ($folder === false) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue