/** * 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"; }
/** * testInternalAddressbookConfig * * @see http://forge.tine20.org/mantisbt/view.php?id=5846 */ public function testInternalAddressbookConfig() { $list = $this->objects['initialList']; $list->container_id = NULL; $listBackend = new Addressbook_Backend_List(); $listBackend->update($list); Admin_Config::getInstance()->delete(Tinebase_Config::APPDEFAULTS); $list = Addressbook_Controller_List::getInstance()->addListMember($list, $this->objects['contact1']); $appConfigDefaults = Admin_Controller::getInstance()->getConfigSettings(); $this->assertTrue(!empty($appConfigDefaults[Admin_Model_Config::DEFAULTINTERNALADDRESSBOOK]), print_r($appConfigDefaults, TRUE)); }
/** * migrate from SQL account storage to another one (for example LDAP) * - deletes all users, groups and roles because they will be * imported from new accounts storage backend */ protected function _migrateFromSqlAccountsStorage() { Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Deleting all user accounts, groups, roles and rights'); Tinebase_User::factory(Tinebase_User::SQL)->deleteAllUsers(); $contactSQLBackend = new Addressbook_Backend_Sql(); $allUserContactIds = $contactSQLBackend->search(new Addressbook_Model_ContactFilter(array('type' => 'user')), null, true); if (count($allUserContactIds) > 0) { $contactSQLBackend->delete($allUserContactIds); } Tinebase_Group::factory(Tinebase_Group::SQL)->deleteAllGroups(); $listsSQLBackend = new Addressbook_Backend_List(); $allGroupListIds = $listsSQLBackend->search(new Addressbook_Model_ListFilter(array('type' => 'group')), null, true); if (count($allGroupListIds) > 0) { $listsSQLBackend->delete($allGroupListIds); } $roles = Tinebase_Acl_Roles::getInstance(); $roles->deleteAllRoles(); // import users (from new backend) / create initial users (SQL) Tinebase_User::syncUsers(array('syncContactData' => TRUE)); $roles->createInitialRoles(); $applications = Tinebase_Application::getInstance()->getApplications(NULL, 'id'); foreach ($applications as $application) { Setup_Initialize::initializeApplicationRights($application); } }
/** * @see Tinebase_Setup_DemoData_Abstract */ protected function _beforeCreate() { $be = new Addressbook_Backend_Sql(); foreach ($this->_personas as $login => $fullName) { try { $user = Tinebase_User::getInstance()->getFullUserByLoginName($login); $contact = Addressbook_Controller_Contact::getInstance()->get($user->contact_id); } catch (Tinebase_Exception_NotFound $e) { list($given, $last) = explode(' ', $fullName); $group = Tinebase_Group::getInstance()->getGroupByName('Users'); $groupId = $group->getId(); $emailDomain = $this->_getMailDomain(); $user = new Tinebase_Model_FullUser(array('accountLoginName' => $login, 'accountPrimaryGroup' => $groupId, 'accountDisplayName' => $fullName, 'accountLastName' => $last, 'accountFirstName' => $given, 'accountFullName' => $fullName, 'accountEmailAddress' => $login . '@' . $emailDomain)); if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true) { $internalAddressbook = Tinebase_Container::getInstance()->getContainerByName('Addressbook', 'Internal Contacts', Tinebase_Model_Container::TYPE_SHARED); $user->container_id = $internalAddressbook->getId(); $contact = Admin_Controller_User::getInstance()->createOrUpdateContact($user); $user->contact_id = $contact->getId(); } Tinebase_Timemachine_ModificationLog::setRecordMetaData($user, 'create'); $user = Tinebase_User::getInstance()->addUser($user); Tinebase_Group::getInstance()->addGroupMember($groupId, $user); if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true) { $listBackend = new Addressbook_Backend_List(); $listBackend->addListMember($group->list_id, $user->contact_id); } $this->_setUserPassword($user); } if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true) { $ar = array_merge($this->_dataMapping[$login], $this->_dataMapping['default']); $filename = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'DemoData' . DIRECTORY_SEPARATOR . 'persona_' . $login . '.jpg'; if (file_exists($filename)) { $handle = fopen($filename, "r"); $content = fread($handle, filesize($filename)); fclose($handle); $be->_saveImage($contact->getId(), $content); } foreach ($ar as $property => $value) { $contact->{$property} = $value; } Addressbook_Controller_Contact::getInstance()->update($contact); } $this->_personas[$login] = $user; } $this->_createGroups(); $this->_createRoles(); $this->_createSharedTags(); }
/** * 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); }
/** * delete multiple groups * * @param array $_groupIds * @return void */ public function delete($_groupIds) { $this->checkRight('MANAGE_ACCOUNTS'); // check default user group / can't delete this group $defaultUserGroup = Tinebase_Group::getInstance()->getDefaultGroup(); if (in_array($defaultUserGroup->getId(), $_groupIds)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Can\'t delete default group: ' . $defaultUserGroup->name); foreach ($_groupIds as $key => $value) { if ($value == $defaultUserGroup->getId()) { unset($_groupIds[$key]); } } } if (empty($_groupIds)) { return; } $eventBefore = new Admin_Event_BeforeDeleteGroup(); $eventBefore->groupIds = $_groupIds; Tinebase_Event::fireEvent($eventBefore); if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true) { $listIds = array(); foreach ($_groupIds as $groupId) { $group = $this->get($groupId); if (!empty($group->list_id)) { $listIds[] = $group->list_id; } } if (!empty($listIds)) { $listBackend = new Addressbook_Backend_List(); $listBackend->delete($listIds); } } Tinebase_Group::getInstance()->deleteGroups($_groupIds); $event = new Admin_Event_DeleteGroup(); $event->groupIds = $_groupIds; Tinebase_Event::fireEvent($event); }
/** * inits (adds) some test users * */ public function initTestUsers() { $personas = array('jsmith' => 'John Smith', 'sclever' => 'Susan Clever', 'pwulf' => 'Paul Wulf', 'jmcblack' => 'James McBlack', 'rwright' => 'Roberta Wright'); foreach ($personas as $login => $fullName) { try { $user = Tinebase_User::getInstance()->getFullUserByLoginName($login); } catch (Tinebase_Exception_NotFound $e) { list($given, $last) = explode(' ', $fullName); $group = Tinebase_Group::getInstance()->getGroupByName('Users'); $groupId = $group->getId(); $user = new Tinebase_Model_FullUser(array('accountLoginName' => $login, 'accountPrimaryGroup' => $groupId, 'accountDisplayName' => $fullName, 'accountLastName' => $last, 'accountFirstName' => $given, 'accountFullName' => $fullName, 'accountEmailAddress' => $login . '@tine20.org')); if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true) { $internalAddressbook = Tinebase_Container::getInstance()->getContainerByName('Addressbook', 'Internal Contacts', Tinebase_Model_Container::TYPE_SHARED); $user->container_id = $internalAddressbook->getId(); $contact = Admin_Controller_User::getInstance()->createOrUpdateContact($user); $user->contact_id = $contact->getId(); } $user = Tinebase_User::getInstance()->addUser($user); Tinebase_Group::getInstance()->addGroupMember($groupId, $user); if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true) { $listBackend = new Addressbook_Backend_List(); $listBackend->addListMember($group->list_id, $user->contact_id); } // give additional testusers the same password as the primary test account Tinebase_User::getInstance()->setPassword($user, Zend_Registry::get('testConfig')->password); } $personas[$login] = $user; } Zend_Registry::set('personas', $personas); }
/** * 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); }