Ejemplo n.º 1
0
 /**
  * creates or updates addressbook lists for an array of group ids
  * 
  * @param array $groupIds
  * @param string $contactId
  */
 public static function syncListsOfUserContact($groupIds, $contactId)
 {
     if (!Tinebase_Application::getInstance()->isInstalled('Addressbook')) {
         return;
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Syncing ' . count($groupIds) . ' group -> lists / memberships');
     }
     $listBackend = new Addressbook_Backend_List();
     $listIds = array();
     foreach ($groupIds as $groupId) {
         // get single groups to make sure that container id is joined
         $group = Tinebase_Group::getInstance()->getGroupById($groupId);
         if (!empty($group->list_id)) {
             try {
                 $list = $listBackend->get($group->list_id);
             } catch (Tinebase_Exception_NotFound $tenf) {
                 if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                     Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' List ' . $group->name . ' not found.');
                 }
                 $list = Addressbook_Controller_List::getInstance()->createByGroup($group);
             }
         } else {
             $list = Addressbook_Controller_List::getInstance()->createByGroup($group);
         }
         if ($group->list_id !== $list->getId()) {
             // list id changed / is new -> update group
             $group->list_id = $list->getId();
             Tinebase_Group::getInstance()->updateGroup($group);
         }
         $listIds[] = $list->getId();
     }
     $listBackend->setMemberships($contactId, $listIds);
 }
 /**
  * creates or updates addressbook lists for an array of group ids
  * 
  * @param array $groupIds
  * @param string $contactId
  */
 public static function syncListsOfUserContact($groupIds, $contactId)
 {
     // check addressbook and empty contact id (for example cronuser)
     if (!Tinebase_Application::getInstance()->isInstalled('Addressbook') || empty($contactId)) {
         return;
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Syncing ' . count($groupIds) . ' group -> lists / memberships');
     }
     $listBackend = new Addressbook_Backend_List();
     $listIds = array();
     foreach ($groupIds as $groupId) {
         // get single groups to make sure that container id is joined
         $group = Tinebase_Group::getInstance()->getGroupById($groupId);
         $list = NULL;
         if (!empty($group->list_id)) {
             try {
                 $list = $listBackend->get($group->list_id);
             } catch (Tinebase_Exception_NotFound $tenf) {
                 if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                     Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' List ' . $group->name . ' not found.');
                 }
             }
         }
         // could not get list by list_id -> try to get by name
         // if no list can be found, create new one
         if (!$list) {
             $list = $listBackend->getByGroupName($group->name);
             if (!$list) {
                 $list = Addressbook_Controller_List::getInstance()->createByGroup($group);
             }
         }
         if ($group->list_id !== $list->getId()) {
             // list id changed / is new -> update group and make group visible
             $group->list_id = $list->getId();
             $group->visibility = Tinebase_Model_Group::VISIBILITY_DISPLAYED;
             Tinebase_Timemachine_ModificationLog::setRecordMetaData($group, 'update');
             Tinebase_Group::getInstance()->updateGroup($group);
         }
         $listIds[] = $list->getId();
     }
     $listBackend->setMemberships($contactId, $listIds);
 }