2 commits - plugins/kolab_addressbook plugins/libkolab
Thomas Brüderli
bruederli at kolabsys.com
Thu Aug 14 12:44:13 CEST 2014
plugins/kolab_addressbook/kolab_addressbook.php | 74 ++++++++++++++++++++++++
plugins/libkolab/lib/kolab_storage.php | 13 ++++
2 files changed, 87 insertions(+)
New commits:
commit fee3773c3bbe7e9e7e296c4d2dd0278e1f5f62da
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date: Thu Aug 14 12:41:08 2014 +0200
Apply contact folder renaming or deletion to the registered birthday calendar address books
diff --git a/plugins/kolab_addressbook/kolab_addressbook.php b/plugins/kolab_addressbook/kolab_addressbook.php
index a960a00..e9f143f 100644
--- a/plugins/kolab_addressbook/kolab_addressbook.php
+++ b/plugins/kolab_addressbook/kolab_addressbook.php
@@ -81,6 +81,10 @@ class kolab_addressbook extends rcube_plugin
$this->add_hook('preferences_list', array($this, 'prefs_list'));
$this->add_hook('preferences_save', array($this, 'prefs_save'));
}
+
+ $this->add_hook('folder_delete', array($this, 'prefs_folder_delete'));
+ $this->add_hook('folder_rename', array($this, 'prefs_folder_rename'));
+ $this->add_hook('folder_update', array($this, 'prefs_folder_update'));
}
@@ -820,4 +824,74 @@ class kolab_addressbook extends rcube_plugin
return $abook_prio;
}
+
+ /**
+ * Hook for (contact) folder deletion
+ */
+ function prefs_folder_delete($args)
+ {
+ // ignore...
+ if ($args['abort'] && !$args['result']) {
+ return $args;
+ }
+
+ $this->_contact_folder_rename($args['name'], false);
+ }
+
+ /**
+ * Hook for (contact) folder renaming
+ */
+ function prefs_folder_rename($args)
+ {
+ // ignore...
+ if ($args['abort'] && !$args['result']) {
+ return $args;
+ }
+
+ $this->_contact_folder_rename($args['oldname'], $args['newname']);
+ }
+
+ /**
+ * Hook for (contact) folder updates. Forward to folder_rename handler if name was changed
+ */
+ function prefs_folder_update($args)
+ {
+ // ignore...
+ if ($args['abort'] && !$args['result']) {
+ return $args;
+ }
+
+ if ($args['record']['name'] != $args['record']['oldname']) {
+ $this->_contact_folder_rename($args['record']['oldname'], $args['record']['name']);
+ }
+ }
+
+ /**
+ * Apply folder renaming or deletion to the registered birthday calendar address books
+ */
+ private function _contact_folder_rename($oldname, $newname = false)
+ {
+ $update = false;
+ $delimiter = $this->rc->get_storage()->get_hierarchy_delimiter();
+ $bday_addressbooks = (array)$this->rc->config->get('calendar_birthday_adressbooks', array());
+
+ foreach ($bday_addressbooks as $i => $id) {
+ $folder_name = kolab_storage::id_decode($id);
+ if ($oldname === $folder_name || strpos($folder_name, $oldname.$delimiter) === 0) {
+ if ($newname) { // rename
+ $new_folder = $newname . substr($folder_name, strlen($oldname));
+ $bday_addressbooks[$i] = kolab_storage::id_encode($new_folder);
+ }
+ else { // delete
+ unset($bday_addressbooks[$i]);
+ }
+ $update = true;
+ }
+ }
+
+ if ($update) {
+ $this->rc->user->save_prefs(array('calendar_birthday_adressbooks' => $bday_addressbooks));
+ }
+ }
+
}
commit 2e078bc4d5cb58734119b817f2bf6ca7c289d517
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date: Thu Aug 14 12:38:54 2014 +0200
Trigger folder_* plugin hooks when operating on IMAP folders
diff --git a/plugins/libkolab/lib/kolab_storage.php b/plugins/libkolab/lib/kolab_storage.php
index 7bae562..7287fc2 100644
--- a/plugins/libkolab/lib/kolab_storage.php
+++ b/plugins/libkolab/lib/kolab_storage.php
@@ -332,6 +332,9 @@ class kolab_storage
if ($folder = self::get_folder($name))
$folder->cache->purge();
+ $rcmail = rcube::get_instance();
+ $plugin = $rcmail->plugins->exec_hook('folder_delete', array('name' => $name));
+
$success = self::$imap->delete_folder($name);
self::$last_error = self::$imap->get_error_str();
@@ -352,6 +355,12 @@ class kolab_storage
{
self::setup();
+ $rcmail = rcube::get_instance();
+ $plugin = $rcmail->plugins->exec_hook('folder_create', array('record' => array(
+ 'name' => $name,
+ 'subscribe' => $subscribed,
+ )));
+
if ($saved = self::$imap->create_folder($name, $subscribed)) {
// set metadata for folder type
if ($type) {
@@ -389,6 +398,10 @@ class kolab_storage
{
self::setup();
+ $rcmail = rcube::get_instance();
+ $plugin = $rcmail->plugins->exec_hook('folder_rename', array(
+ 'oldname' => $oldname, 'newname' => $newname));
+
$oldfolder = self::get_folder($oldname);
$active = self::folder_is_active($oldname);
$success = self::$imap->rename_folder($oldname, $newname);
More information about the commits
mailing list