/** * repair groups * * * add missing lists * * checks if list container has been deleted (and hides groups if that's the case) * * @see 0010401: add repair script for groups without list_ids */ public function repairGroups() { $count = 0; $be = new Tinebase_Group_Sql(); $listBackend = new Addressbook_Backend_List(); $groups = $be->getGroups(); foreach ($groups as $group) { if ($group->list_id == null) { $list = Addressbook_Controller_List::getInstance()->createByGroup($group); $group->list_id = $list->getId(); $group->visibility = Tinebase_Model_Group::VISIBILITY_DISPLAYED; if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Add missing list for group ' . $group->name); } $be->updateGroupInSqlBackend($group); $count++; } else { if ($group->visibility === Tinebase_Model_Group::VISIBILITY_DISPLAYED) { try { $list = $listBackend->get($group->list_id); $listContainer = Tinebase_Container::getInstance()->get($list->container_id); } catch (Tinebase_Exception_NotFound $tenf) { if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Hide group ' . $group->name . ' without list / list container.'); } $group->visibility = Tinebase_Model_Group::VISIBILITY_HIDDEN; $be->updateGroupInSqlBackend($group); $count++; } } } } echo $count . " groups repaired!\n"; }
/** * 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); }