- 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';
This commit is contained in:
Thomas Bruederli 2014-01-28 15:55:45 +01:00
parent 0950ff12dc
commit 2230e97ee9
4 changed files with 13 additions and 7 deletions

View file

@ -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,
);

View file

@ -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'),

View file

@ -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;

View file

@ -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