From 4024db83539ac80e4e6b167f911652d3791aa6bb Mon Sep 17 00:00:00 2001 From: nathangray Date: Wed, 26 Sep 2018 11:27:50 -0600 Subject: [PATCH] * Addressbook - fix birthday cache was not cleared when birthday edited --- api/src/Contacts.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/api/src/Contacts.php b/api/src/Contacts.php index bcad0b7353..9ed9418153 100755 --- a/api/src/Contacts.php +++ b/api/src/Contacts.php @@ -1053,15 +1053,30 @@ class Contacts extends Contacts\Storage if($isUpdate && $old['bday'] !== $to_write['bday'] || !$isUpdate && $to_write['bday']) { $year = (int) date('Y',time()); - Cache::unsetInstance(__CLASS__,"birthday-$year-{$to_write['owner']}"); + $this->clear_birthday_cache($year, $to_write['owner']); $year++; - Cache::unsetInstance(__CLASS__,"birthday-$year-{$to_write['owner']}"); + $this->clear_birthday_cache($year, $to_write['owner']); } } return $this->error ? false : $contact['id']; } + /** + * Since birthdays are cached for the instance for BIRTHDAY_CACHE_TIME, we + * need to clear them if a birthday changes. + * + * @param type $year + */ + protected function clear_birthday_cache($year, $owner) + { + // Cache is kept per-language, so clear them all + foreach(array_keys(Translation::get_installed_langs()) as $lang) + { + Cache::unsetInstance(__CLASS__,"birthday-$year-{$owner}-$lang"); + } + } + /** * Resize photo down to 240pixel width and returns it *