2 commits - plugins/calendar plugins/kolab_addressbook plugins/libkolab

Thomas Brüderli bruederli at kolabsys.com
Tue Jan 28 15:57:05 CET 2014


 plugins/calendar/calendar.php                          |    2 +-
 plugins/calendar/drivers/calendar_driver.php           |   14 ++++++++++----
 plugins/calendar/drivers/database/database_driver.php  |    2 +-
 plugins/calendar/drivers/kolab/kolab_driver.php        |    2 +-
 plugins/kolab_addressbook/lib/rcube_kolab_contacts.php |    5 +++++
 plugins/libkolab/lib/kolab_format_contact.php          |   16 ++++++++++++++++
 6 files changed, 34 insertions(+), 7 deletions(-)

New commits:
commit 2230e97ee901a2e8f6962724703b4649ab2ee19f
Author: Thomas Bruederli <thomas at roundcube.net>
Date:   Tue Jan 28 15:55:45 2014 +0100

    - Fix updating birthday events
    - Use address book search to fetch contacts with birthday values only
    
    Attention: this requires changes from [0950ff12dc] and clearing the cache
    for Kolab contact objects:
    
      DELETE FROM kolab_folders WHERE type='contact';

diff --git a/plugins/calendar/calendar.php b/plugins/calendar/calendar.php
index 82dba36..276fdcf 100644
--- a/plugins/calendar/calendar.php
+++ b/plugins/calendar/calendar.php
@@ -653,7 +653,7 @@ class calendar extends rcube_plugin
         'calendar_date_format' => null,  // clear previously saved values
         'calendar_time_format' => null,
         'calendar_contact_birthdays'    => get_input_value('_contact_birthdays', RCUBE_INPUT_POST) ? true : false,
-        'calendar_birthday_adressbooks' => array_filter((array)get_input_value('_birthday_adressbooks', RCUBE_INPUT_POST)),
+        'calendar_birthday_adressbooks' => (array)get_input_value('_birthday_adressbooks', RCUBE_INPUT_POST),
         'calendar_birthdays_alarm_type'   => get_input_value('_birthdays_alarm_type', RCUBE_INPUT_POST),
         'calendar_birthdays_alarm_offset' => $birthdays_alarm_value ?: null,
       );
diff --git a/plugins/calendar/drivers/calendar_driver.php b/plugins/calendar/drivers/calendar_driver.php
index a7ad0e5..fb29740 100644
--- a/plugins/calendar/drivers/calendar_driver.php
+++ b/plugins/calendar/drivers/calendar_driver.php
@@ -412,10 +412,16 @@ abstract class calendar_driver
    * @param  integer Event's new start (unix timestamp)
    * @param  integer Event's new end (unix timestamp)
    * @param  string  Search query (optional)
+   * @param  integer Only list events modified since this time (unix timestamp)
    * @return array A list of event records
    */
-  public function load_birthday_events($start, $end, $search = null)
+  public function load_birthday_events($start, $end, $search = null, $modifiedsince = null)
   {
+    // ignore update requests for simplicity reasons
+    if (!empty($modifiedsince)) {
+      return array();
+    }
+
     // convert to DateTime for comparisons
     $start  = new DateTime('@'.$start);
     $end    = new DateTime('@'.$end);
@@ -451,7 +457,7 @@ abstract class calendar_driver
       $cached = $cache->get($source);
 
       // iterate over (cached) contacts
-      foreach (($cached ?: $abook->list_records()) as $contact) {
+      foreach (($cached ?: $abook->search('*', '', 2, true, true, array('birthday'))) as $contact) {
         if (is_array($contact) && !empty($contact['birthday'])) {
           try {
             if (is_array($contact['birthday']))
@@ -472,7 +478,7 @@ abstract class calendar_driver
           // add stripped record to cache
           if (empty($cached)) {
             $cache_records[] = array(
-              'id' => $contact['ID'],
+              'ID' => $contact['ID'],
               'name' => $display_name,
               'birthday' => $bday->format('Y-m-d'),
             );
@@ -497,7 +503,7 @@ abstract class calendar_driver
           if ($bday <= $end && $bday >= $start) {
             $age = $year - $birthyear;
             $event = array(
-              'id'          => md5('bday_' . $contact['id'] . $year),
+              'id'          => md5('bday_' . $contact['ID'] . $year),
               'calendar'    => self::BIRTHDAY_CALENDAR_ID,
               'title'       => $event_title,
               'description' => $rcmail->gettext(array('name' => 'birthdayage', 'vars' => array('age' => $age)), 'calendar'),
diff --git a/plugins/calendar/drivers/database/database_driver.php b/plugins/calendar/drivers/database/database_driver.php
index 0c2d030..ca50f27 100644
--- a/plugins/calendar/drivers/database/database_driver.php
+++ b/plugins/calendar/drivers/database/database_driver.php
@@ -813,7 +813,7 @@ class database_driver extends calendar_driver
 
     // add events from the address books birthday calendar
     if (in_array(self::BIRTHDAY_CALENDAR_ID, $calendars)) {
-      $events = array_merge($events, $this->load_birthday_events($start, $end, $search));
+      $events = array_merge($events, $this->load_birthday_events($start, $end, $search, $modifiedsince));
     }
 
     return $events;
diff --git a/plugins/calendar/drivers/kolab/kolab_driver.php b/plugins/calendar/drivers/kolab/kolab_driver.php
index dd85ffc..7b41a31 100644
--- a/plugins/calendar/drivers/kolab/kolab_driver.php
+++ b/plugins/calendar/drivers/kolab/kolab_driver.php
@@ -758,7 +758,7 @@ class kolab_driver extends calendar_driver
 
     // add events from the address books birthday calendar
     if (in_array(self::BIRTHDAY_CALENDAR_ID, $calendars)) {
-      $events = array_merge($events, $this->load_birthday_events($start, $end, $search));
+      $events = array_merge($events, $this->load_birthday_events($start, $end, $search, $modifiedsince));
     }
 
     // add new categories to user prefs


commit 0950ff12dcfe5692867abc28bdbdfe5b1839391b
Author: Thomas Bruederli <thomas at roundcube.net>
Date:   Tue Jan 28 15:51:09 2014 +0100

    Tag contacts that have a birthday date set and allow to directly select them

diff --git a/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php b/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php
index bc20970..3fc8527 100644
--- a/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php
+++ b/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php
@@ -400,6 +400,11 @@ class rcube_kolab_contacts extends rcube_addressbook
         // NOTE: this is only some rough pre-filtering but probably includes false positives
         $squery = $this->_search_query($fields, $value, $mode);
 
+        // add magic selector to select contacts with birthday dates only
+        if (in_array('birthday', $required)) {
+            $squery[] = array('tags', '=', 'x-has-birthday');
+        }
+
         // get all/matching records
         $this->_fetch_contacts($squery);
 
diff --git a/plugins/libkolab/lib/kolab_format_contact.php b/plugins/libkolab/lib/kolab_format_contact.php
index a96312a..63efe9a 100644
--- a/plugins/libkolab/lib/kolab_format_contact.php
+++ b/plugins/libkolab/lib/kolab_format_contact.php
@@ -408,6 +408,22 @@ class kolab_format_contact extends kolab_format
     }
 
     /**
+     * Callback for kolab_storage_cache to get object specific tags to cache
+     *
+     * @return array List of tags to save in cache
+     */
+    public function get_tags()
+    {
+        $tags = array();
+
+        if (!empty($this->data['birthday'])) {
+            $tags[] = 'x-has-birthday';
+        }
+
+        return $tags;
+    }
+
+    /**
      * Helper method to copy contents of an Address vector to the contact data object
      */
     private function read_addresses($addresses, &$object, $type = null)




More information about the commits mailing list