diff --git a/addressbook/inc/class.addressbook_bo.inc.php b/addressbook/inc/class.addressbook_bo.inc.php index da2474fe40..7e2fdee182 100755 --- a/addressbook/inc/class.addressbook_bo.inc.php +++ b/addressbook/inc/class.addressbook_bo.inc.php @@ -1504,6 +1504,15 @@ class addressbook_bo extends addressbook_so parent::deleteaccount($data); } + /** + * Called by delete_category hook, when a category gets deleted. + * Removes the category from addresses + */ + function delete_category($data) + { + parent::delete_category($data); + } + /** * Called by edit-account hook, when an account get edited --> not longer used * diff --git a/addressbook/inc/class.addressbook_so.inc.php b/addressbook/inc/class.addressbook_so.inc.php index 0e6ce00f88..1c80ab97dc 100755 --- a/addressbook/inc/class.addressbook_so.inc.php +++ b/addressbook/inc/class.addressbook_so.inc.php @@ -778,6 +778,20 @@ class addressbook_so } } + /** + * Remove deleted category from addresses + */ + function delete_category($data) + { + // Get addresses that use the category + $ids = $this->search(array('cat_id' => $data['cat_id']), array('contact_id', 'cat_id')); + foreach($ids as &$info) + { + $info['cat_id'] = implode(',',array_diff(explode(',',$info['cat_id']), array($data['cat_id']))); + $this->save($info); + } + } + /** * return the backend, to be used for the given $contact_id * diff --git a/addressbook/setup/setup.inc.php b/addressbook/setup/setup.inc.php index b0174c0451..74b6b177be 100755 --- a/addressbook/setup/setup.inc.php +++ b/addressbook/setup/setup.inc.php @@ -38,6 +38,7 @@ $setup_info['addressbook']['hooks']['sidebox_menu'] = 'addressbook_hooks::all_ho $setup_info['addressbook']['hooks']['settings'] = 'addressbook_hooks::settings'; $setup_info['addressbook']['hooks'][] = 'home'; $setup_info['addressbook']['hooks']['deleteaccount'] = 'addressbook.addressbook_bo.deleteaccount'; +$setup_info['addressbook']['hooks']['delete_category'] = 'addressbook.addressbook_bo.delete_category'; $setup_info['addressbook']['hooks']['search_link'] = 'addressbook_hooks::search_link'; $setup_info['addressbook']['hooks']['calendar_resources'] = 'addressbook_hooks::calendar_resources'; $setup_info['addressbook']['hooks']['edit_user'] = 'addressbook_hooks::edit_user';